PageRenderTime 20ms CodeModel.GetById 13ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/Research/Example projects/android2.1_TestOGL/src/com/example/atogl/GLTutorialNine.java

https://bitbucket.org/DeveloperUX/behaviortree
Java | 76 lines | 50 code | 21 blank | 5 comment | 0 complexity | da26798d378f7e5a989b0ef6a7d09c2e MD5 | raw file
 1package com.example.atogl;
 2
 3import javax.microedition.khronos.opengles.GL10;
 4
 5import android.content.Context;
 6import android.opengl.GLU;
 7
 8/**
 9 * http://www.zeuscmd.com/tutorials/opengles/20-Transparency.php
10 * @author bburns
11 *
12 */
13public class GLTutorialNine extends GLTutorialBase {
14	float lightAmbient[] = new float[] { 0.3f, 0.3f, 0.3f, 1.0f };
15	float lightDiffuse[] = new float[] { 0.6f, 0.6f, 0.6f, 1.0f };
16	float[] lightPos = new float[] {0,0,3,1};
17	
18	float matAmbient[] = new float[] { 1f, 1f, 1f, 1.0f };
19	float matDiffuse[] = new float[] { 1f, 1f, 1f, 1.0f };
20	
21	int tex;
22	
23	public GLTutorialNine(Context c) {
24		super(c, 20);
25	}
26	
27	protected void init(GL10 gl) {
28		gl.glEnable(GL10.GL_LIGHTING);
29		gl.glEnable(GL10.GL_LIGHT0);
30		gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, matAmbient, 0);
31		gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, matDiffuse, 0);
32		
33		gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, lightAmbient,	0);
34		gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, lightDiffuse,	0);
35		gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, lightPos, 0);
36		
37		gl.glEnable(GL10.GL_BLEND);
38		gl.glDisable(GL10.GL_DEPTH_TEST);
39		gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE);
40
41		gl.glEnable(GL10.GL_TEXTURE_2D);
42		
43		gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
44		gl.glClearDepthf(1.0f);
45		
46		gl.glVertexPointer(3, GL10.GL_FLOAT, 0, cubeBuff);
47		gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
48		gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texBuff);
49		gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
50		
51		gl.glShadeModel(GL10.GL_SMOOTH);
52		
53		tex = loadTexture(gl, R.drawable.glass);
54	}
55	
56	float xrot = 0.0f;
57	float yrot = 0.0f;
58	
59	public void onDrawFrame(GL10 gl) {		
60		gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
61	
62		setupCube(gl);
63		
64		gl.glMatrixMode(GL10.GL_MODELVIEW);
65		gl.glLoadIdentity();
66		GLU.gluLookAt(gl, 0, 0, 3, 0, 0, 0, 0, 1, 0);
67	
68		gl.glRotatef(xrot, 1, 0, 0);
69		gl.glRotatef(yrot, 0, 1, 0);
70	
71		drawCube(gl);
72		
73		xrot += 1.0f;
74		yrot += 0.5f;
75	}
76}