Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create an OpenGL ES 2 context in a native activity?

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++?

like image 628
TheBuzzSaw Avatar asked Jul 13 '12 22:07

TheBuzzSaw


People also ask

What is OpenGL es2?

Android includes support for high performance 2D and 3D graphics with the Open Graphics Library (OpenGL®), specifically, the OpenGL ES API. OpenGL is a cross-platform graphics API that specifies a standard software interface for 3D graphics processing hardware.

What is the difference between OpenGL and OpenGL es?

The main difference between the two is that OpenGL ES is made for embedded systems like smartphones, while OpenGL is the one on desktops. On the coding level, OpenGL ES does not support fixed-function functions like glBegin/glEnd etc... OpenGL can support fixed-function pipeline (using a compatibility profile).

Can I update OpenGL version Android?

You can't. The OpenGL version supported depends on the hardware capabilities of your GPU.


1 Answers

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);
like image 83
Benlitz Avatar answered Oct 24 '22 22:10

Benlitz