Back to project page OpenGlDraw_Android.
The source code is released under:
GNU General Public License
If you think the Android project OpenGlDraw_Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.example.opengldraw.gl; //from w w w.j av a 2 s .c o m import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; import android.content.Context; import android.opengl.GLES10; import android.opengl.GLSurfaceView; public class RendererDraw implements GLSurfaceView.Renderer { private ShapeDrawer shapeDrawer; volatile float myAngleY; volatile float myAngleX; private Context ctx; // private static boolean boundaryX; public RendererDraw(Context aCtx) { super(); ctx = aCtx; } @Override public void onDrawFrame(GL10 gl) { gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); gl.glTranslatef(0.0f, -0.5f, -5.0f); gl.glRotatef(myAngleY, 0, 1, 0); gl.glRotatef(myAngleX, 1, 0, 0); // if(boundaryX) {myAngleX += 1;} else {myAngleX -= 1;}; // myAngleY -= 1; // if(myAngleY < -359) { // myAngleY = 0; // } // if(myAngleX < - 30) {boundaryX = true;} // if(myAngleX > 30) {boundaryX = false;} // gl.glRotatef(myAngleY, 0, 1, 0); // gl.glRotatef(myAngleX, 1, 0, 0); shapeDrawer.draw(gl); } @Override public void onSurfaceChanged(GL10 gl, int width, int height) { GLES10.glViewport(0, 0, width, height); float ratio = (float) width / height; gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10); } @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { GLES10.glClearColor(0.4f, 0.4f, 0.4f, 1.0f); gl.glDisable(GL10.GL_DITHER); gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST); gl.glShadeModel(GL10.GL_SMOOTH); gl.glEnable(GL10.GL_DEPTH_TEST); gl.glEnable(GL10.GL_LIGHTING); gl.glEnable(GL10.GL_LIGHT0); float lightAmbient[] = new float[] { 0.5f, 0.5f, 0.5f, 1.0f }; float lightDiffuse[] = new float[] { 0.3f, 0.3f, 0.3f, 1.0f }; float lightSpecular[] = new float[] { 0.3f, 0.3f, 0.3f, 1.0f}; float[] lightPos = new float[] { 1, 1, 1, 1 }; 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_SPECULAR, lightSpecular, 0); gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, lightPos, 0); /* set the materials to the same color values as the object (or at least one of the materials) */ float matAmbient[] = new float[] { 234/255f, 234/255f, 234/255f, 1 }; float matDiffuse[] = new float[] { 234/255f, 234/255f, 234/255f, 1 }; gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, matAmbient, 0); gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, matDiffuse, 0); shapeDrawer = new ShapeDrawer(ctx); } public ShapeDrawer getShapeDrawer() { return shapeDrawer; } }