PageRenderTime 19ms CodeModel.GetById 11ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/DeveloperUX/behaviortree
Java | 90 lines | 64 code | 26 blank | 0 comment | 0 complexity | 372c948032230ae55c642b7f0e23a34a MD5 | raw file
 1package com.example.atogl;
 2
 3import javax.microedition.khronos.opengles.GL10;
 4
 5import android.content.Context;
 6import android.opengl.GLU;
 7
 8public class GLTutorialTwelve extends GLTutorialBase {
 9	float lightAmbient[] = new float[] { 0.2f, 0.2f, 0.2f, 1.0f };
10	float lightDiffuse[] = new float[] { 1f, 1f, 1f, 1.0f };
11	float[] lightPos = new float[] {0,0,3,1};
12	
13	float matAmbient[] = new float[] { 1f, 1f, 1f, 1.0f };
14	float matDiffuse[] = new float[] { 1f, 1f, 1f, 1.0f };
15	
16	int light_tex;
17	int block_tex;
18	
19	public GLTutorialTwelve(Context c) {
20		super(c, 20);
21	}
22	
23	protected void init(GL10 gl) {
24		gl.glEnable(GL10.GL_LIGHTING);
25		gl.glEnable(GL10.GL_LIGHT0);
26		gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, matAmbient, 0);
27		gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, matDiffuse, 0);
28		
29		gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, lightAmbient,	0);
30		gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, lightDiffuse,	0);
31		gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, lightPos, 0);
32		
33		gl.glEnable(GL10.GL_DEPTH_TEST);
34		gl.glDepthFunc(GL10.GL_LEQUAL);
35		
36		gl.glEnable(GL10.GL_TEXTURE_2D);
37		
38		gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
39		gl.glClearDepthf(1.0f);
40		
41		gl.glEnable(GL10.GL_CULL_FACE);
42		gl.glShadeModel(GL10.GL_SMOOTH);
43		
44		light_tex = loadTexture(gl, R.drawable.light);
45		block_tex = loadTexture(gl, R.drawable.block);
46	}
47	
48	float xrot = 0.0f;
49	float yrot = 0.0f;
50	
51	public void onDrawFrame(GL10 gl) {
52		gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
53		
54		gl.glMatrixMode(GL10.GL_MODELVIEW);
55		
56		setupCube(gl);
57		
58		gl.glLoadIdentity();
59		GLU.gluLookAt(gl, 0, 0, 3, 0, 0, 0, 0, 1, 0);
60	
61		gl.glRotatef(xrot, 1, 0, 0);
62		gl.glRotatef(yrot, 0, 1, 0);
63		
64		gl.glMatrixMode(GL10.GL_MODELVIEW);
65		
66		gl.glActiveTexture(GL10.GL_TEXTURE0); 
67		gl.glClientActiveTexture(GL10.GL_TEXTURE0); 
68		gl.glEnable(GL10.GL_TEXTURE_2D); 
69		gl.glBindTexture(GL10.GL_TEXTURE_2D, light_tex); 
70		gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
71		gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texBuff);
72		
73		gl.glActiveTexture(GL10.GL_TEXTURE1); 
74		gl.glClientActiveTexture(GL10.GL_TEXTURE1); 
75		gl.glEnable(GL10.GL_TEXTURE_2D); 
76		gl.glBindTexture(GL10.GL_TEXTURE_2D, block_tex); 
77		gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
78		gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texBuff);
79		
80		gl.glTexEnvx(GL10.GL_TEXTURE_ENV , GL10.GL_TEXTURE_ENV_MODE, GL10.GL_MODULATE);
81	
82		drawCube(gl);
83		
84		gl.glActiveTexture(GL10.GL_TEXTURE0); 
85		gl.glClientActiveTexture(GL10.GL_TEXTURE0); 
86		
87		xrot += 1.0f;
88		yrot += 0.5f;
89	}
90}