10

For the life of me, I cannot find any good pure Android NDK examples for OpenGL ES 2. The one included native-activity sample project builds an ES 1 context. Are there any sample programs demonstrating the creation of an ES 2 context in pure C++?

TheBuzzSaw
  • 8,648
  • 5
  • 39
  • 58

1 Answers1

10

Creating an OpenGL ES 2 context should be about the same than creating an OpenGL ES 1. Based on the "native-activity" sample from the NDK, you just need to add this to the attribute list passed to eglChooseConfig:

const EGLint attribs[] =
{
    EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
    ...
    EGL_NONE
};

This should ensure your config is ES2-compatible.

Then pass this attribute list to eglCreateContext:

EGLint AttribList[] = 
{
    EGL_CONTEXT_CLIENT_VERSION, 2,
    EGL_NONE
};

with a call like this:

context = eglCreateContext(display, config, NULL, AttribList);
Benlitz
  • 1,952
  • 1
  • 17
  • 30
  • Ironically, I found the solution in a tutorial for OpenGL ES 2 on Raspberry Pi. Thanks for the clear answer, though. This is indeed the answer. – TheBuzzSaw Jul 14 '12 at 00:32