Introduction

freeglut can initialize an OpenGL ES (GLES) context. It works under platforms that supports EGL:

freeglut ES is provided as a separate library, because OpenGL ES has a distinct library from plain OpenGL (-lGLESv1_CM -lGLESv2 instead of -lGL, and different headers too). We could consider dynamically loading the OpenGL symbols we need, like libSDL.

It is possible to select OpenGL ES 1, 2 or 3 (if the device and driver supports it) by calling e.g. glutInitContextVersion(3,0) before creating a window.

Compiling

The following explains how to use freeglut ES for Mesa EGL.
See also the Android page.

First, check README.cmake to install the dependencies for your system.

Then:

apt-get install libgles1-mesa-dev libgles2-mesa-dev
cd /usr/src/freeglut-3.0.0/
mkdir native-gles/ && cd native-gles/
cmake \
  -DCMAKE_INSTALL_PREFIX=/tmp/freeglut-native-gles \
  -D CMAKE_BUILD_TYPE=Debug \
  -DFREEGLUT_GLES=ON \
  -DFREEGLUT_BUILD_DEMOS=NO \
  ..
make -j4
make install

Using in your projects

Get the 'freeglut-gles' module through pkg-config.

If you use CMake, you can do that with:

include(FindPkgConfig)
pkg_check_modules(freeglut REQUIRED freeglut-gles>=3.0.0)
if(freeglut_FOUND)
  include_directories(${freeglut_STATIC_INCLUDE_DIRS})
  link_directories(${freeglut_STATIC_LIBRARY_DIRS})
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${freeglut_STATIC_CFLAGS_OTHER}")
  add_definitions(${freeglut_STATIC_CFLAGS_OTHER})
endif()
cd your_project/
mkdir native-gles/ && cd native-gles/
PKG_CONFIG_PATH=/tmp/freeglut-native-gles/share/pkgconfig/ cmake ..

Examples: