Game Development Reference
In-Depth Information
/*
* Now we're ready to draw some 3D objects
*/
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -3.0f);
glRotatef(mAngle, 0, 0, 1.0f);
glRotatef(mAngle*0.25f, 1, 0, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
Cube_draw();
glRotatef(mAngle*2.0f, 0, 1, 1);
glTranslatef(0.5f, 0.5f, 0.5f);
Cube_draw();
mAngle += 1.2f;
}
Java Callbacks
The Java callbacks are used to send messages from the native layer to the Java layer (see Listing 5-13).
The cube renderer implements two callbacks:
jni_send_str( const char * text) : This callback sends a string message to Java
(mostly for debugging purposes). It does so by attaching to the current thread.
This step must be done if you call JNI in a C function outside a JNI native
implementation. The callback then loads the Java class opengl.jni.Natives.java .
Finally, it calls the Java method opengl.jni.Natives.OnMessage(String) .
jni_gl_swap_buffers () : This is the most important callback. It tells Java that it is
time to swap the OpenGL buffers. In OpenGL lingo, that means render the
graphics. This step must be performed at the end of each frame of the rendering
loop. The callback implementation is similar to the previous one. The main
difference is that it invokes the Java method opengl.jni.Natives.GLSwapBuffers
() .
Listing 5-13. Java Callbacks from cuberenderer.c
/**
* Send a string back to Java
*/
static jmethodID mSendStr;
static jclass jNativesCls;
static JavaVM *g_VM;
Search WWH ::




Custom Search