Game Development Reference
In-Depth Information
JNIEXPORT void JNICALL Java_com_opengl_shader_ViewRenderer_drawFrame
(JNIEnv * env, jclass cls, jint ticks)
{
Display(ticks);
}
JNIEXPORT void JNICALL Java_com_opengl_shader_ViewRenderer_setRotationSpeed
(JNIEnv * env, jclass cls, jint val)
{
doSetRotationSpeed((double)val);
}
}
You have the following three C++ functions:
Init : To initialize the scene.
Display : To draw a frame of the scene.
doSetRotationSpeed : To set the rotation speed.
Before you look at the implementations, you must create the two shader programs, vertex
and fragment, which will be used to draw the icosahedron.
Project Shaders
Listing 4-10 declares the two shader programs that will be used to compute the position and
color of the vertices and the faces of the icosahedron.
Listing 4-10. Shaders Used in the Icosahedron Project
// vertex Shader
attribute vec3 Position;
attribute vec3 Normal;
uniform mat4 Proj;
uniform mat4 Model;
varying vec3 NormVec;
varying vec3 LighVec;
void main(void)
{
vec4 Pos = Model * vec4(Position, 1.0);
gl_Position = Proj * Pos;
NormVec = (Model * vec4(Normal,0.0)).xyz;
LighVec = -Pos.xyz;
}
// Fragment Shader
varying highp vec3 NormVec;
varying highp vec3 LighVec;
 
Search WWH ::




Custom Search