How to get an EGL display/context to a specific GLSurfaceView

Vanderdeckken picture Vanderdeckken · Jun 28, 2011 · Viewed 7.2k times · Source

This is a follow up to my original Question, which was probably too broad (whereas this one is probably too specific but maybe I can apply Newton's Method).

My specific situation is: OpenGL ES 2.0, on Android, using only Java (no JNI/Native code).

I am trying to understand how EGL and Android's GLES implimentation work together (or don't). I am having trouble because the EGL interface(API) does not seem well suited to Android's Java centric, Activity based OS.

As a specific example: I have subclassed GLSurfaceView and create an instance using an XML layout and then use findViewById() to retrieve a reference. Using this approach I have the textured triangle example working (GLES 2.0 on Android 2.2, API level 8). This example does not use EGL. As a learning exercise I wanted to re-write it using EGL.

All the examples I can find use eglGetDisplay() and eglInitialize(), and create a context in puff of greasy black smoke. None of the examples, references and questions I have found apply specifically to ES2.0/EGL/Android/Java. Am I completely missing something? This question is related (I think) but does not have any responses and the example used in the ES 2.0 Programming Guide is a stand alone C implementation.

Answer

Romain Guy picture Romain Guy · Jun 28, 2011

There is nothing Android specific to EGL really. When you create an EGL window surface (eglCreateWindowSurface) you give it a Surface or a SurfaceHolder (which a SurfaceView will give you.) This means you can pretty much copy/paste an EGL example from C, C++ or any other language and have it work on Android in minutes. That's how I do it ;-)

Update: I just read your other message. You need EGL to initialize a GLES context.