Reputation: 526
In OpenGL, to keep program rendering frames I need a while
loop, all the code that put inside the loop is executed every loop. The loop looks like this:
while(!glfwWindowShouldClose(window))
{
// Check and call events
glfwPollEvents();
// Rendering commands here
...
// Swap the buffers
glfwSwapBuffers(window);
}
Now I'm jumping into OpenGL ES and trying to learn from this example:
https://github.com/googlesamples/android-ndk/tree/master/gles3jni
However, I couldn't find any while
or for
loop in the code. Instead, There're something else likes extending the GLSurfaceView
and implementing the GLSurfaceView.Renderer
. I don't really get how it works.
Therefore, I wonder how the iteration goes every time it render a frame? Is every thing written in the .cpp file executed every loop or just functions that being called by the JNI? And once It finish rendering the very first frame, where does it start at the beginning of the 2nd loop? Your attention and help is very much appreciated.
Upvotes: 0
Views: 717
Reputation: 2711
In Android, you do not need to do the looping yourself - the rendering loop is managed for you by the OS. It is implemented in GLSurfaceView.Renderer
, which calls onDrawFrame
which is called each frame, you just need to override this method in your renderer. It is all done in the Java code - if you wish to implement your OpenGL ES code in cpp, you create a rendering method in your JNI code and call it from your overridden onDrawFrame
, like it is done in the project you are looking at.
Upvotes: 1