Game Development Reference
In-Depth Information
■
Caution
Before the
cuberenderer.c
file can be compiled, the header file
opengl_jni_Natives.h
must be
created. This header contains the prototypes for the native methods in
opengl.jni.Natives.java
. To do this, use
the
javah
command:
javah -cp [CLASS_PATH] -d include opengl.jni.Natives
, where
CLASS_PATH
points to
the project
bin
folder.
Scene Initialization
Scene initialization is performed by the
init_scene()
function (see Listing 5-11). Its job is to perform
trivial GL initialization calls, such as setting a perspective correction hint, background color, and shade
model, and in this case, enabling face culling and depth tests.
init_scene()
is meant to mirror the Java method
CubeRenderer.surfaceCreated
, which initializes the
scene after the surface is created. Note that Java lines such as
gl.glDisable(GL10.GL_DITHER)
become
glDisable(GL_DITHER)
. Because the context is already initialized in Java, you can simply make the GL
commands you need in the equivalent C function.
Listing 5-11.
Scene Initialization from cuberenderer.c
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include <EGL/egl.h>
#include <GLES/gl.h>
#include <GLES/glext.h>
#include "include/opengl_jni_Natives.h"
#define ONE 1.0f
#define FIXED_ONE 0x10000
// Prototypes
void jni_printf(char *format, ...);
void jni_gl_swap_buffers ();
// Rotation Angle
static float mAngle = 0.0;
extern void Cube_draw();
static void init_scene(void)
{
glDisable(GL_DITHER);
/*
* Some one-time OpenGL initialization can be made here