package edu.union; import javax.microedition.khronos.opengles.GL10; import android.content.Context; import android.opengl.GLU; /** * http://www.zeuscmd.com/tutorials/opengles/15-Lighting.php * @author bburns */ public class GLTutorialFourteen extends GLTutorialBase { float lightAmbient[] = new float[] { 0.2f, 0.3f, 0.6f, 1.0f }; float lightDiffuse[] = new float[] { 0.9f, 0.9f, 0.9f, 1.0f }; float[] lightPos = new float[] {0,0,3,1}; float matAmbient[] = new float[] { 0.6f, 0.6f, 0.6f, 1.0f }; float matDiffuse[] = new float[] { 0.6f, 0.6f, 0.6f, 1.0f }; SphereGenerator sphere; int earthTex; public GLTutorialFourteen(Context c) { super(c, 20); } protected void init(GL10 gl) { earthTex = loadTexture(gl, R.drawable.earth); sphere = new SphereGenerator(earthTex, 12, 12, 1.0f); gl.glEnable(GL10.GL_LIGHTING); gl.glEnable(GL10.GL_LIGHT0); gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, matAmbient, 0); gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, matDiffuse, 0); gl.glEnable(GL10.GL_TEXTURE_2D); gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, lightAmbient, 0); gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, lightDiffuse, 0); gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, lightPos, 0); gl.glEnable(GL10.GL_DEPTH_TEST); gl.glDepthFunc(GL10.GL_LEQUAL); gl.glEnable(GL10.GL_CULL_FACE); gl.glShadeModel(GL10.GL_SMOOTH); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glClearDepthf(1.0f); } float xrot = 0.0f; float yrot = 0.0f; public void onDrawFrame(GL10 gl) { gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); GLU.gluLookAt(gl, 0, 0, 3, 0, 0, 0, 0, 1, 0); gl.glRotatef(xrot, 1, 0, 0); gl.glRotatef(yrot, 0, 1, 0); sphere.draw(gl); //xrot += 1.0f; //yrot += 0.5f; } }