Game Development Reference
In-Depth Information
Listing 3-2 shows the MyGLRenderer.java file.
Listing 3-2. The Renderer Class for the OpenGL Sample
package opengl.test;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.opengl.GLU;
public class MyGLRenderer implements GLSurfaceView.Renderer {
Mytriangle mytriangle;
public MyGLRenderer(Context context) {
mytriangle = new Mytriangle();
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
gl.glClearDepthf(1.0f);
gl.glEnable(GL10. GL_DEPTH_TEST );
gl.glDepthFunc(GL10. GL_LEQUAL );
gl.glHint(GL10. GL_PERSPECTIVE_CORRECTION_HINT , GL10. GL_NICEST );
gl.glShadeModel(GL10. GL_SMOOTH );
gl.glDisable(GL10. GL_DITHER );
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
if (height == 0) height = 1;
float aspect = (float)width / height;
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL10. GL_PROJECTION );
gl.glLoadIdentity();
GLU. gluPerspective (gl, 45, aspect, 0.1f, 100.f);
gl.glMatrixMode(GL10. GL_MODELVIEW );
gl.glLoadIdentity();
}
@Override
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10. GL_COLOR_BUFFER_BIT | GL10. GL_DEPTH_BUFFER_BIT );
gl.glLoadIdentity();
gl.glTranslatef(-1.5f, 0.0f, -6.0f);
mytriangle.draw(gl);
gl.glTranslatef(3.0f, 0.0f, 0.0f);
}
}
 
Search WWH ::




Custom Search