PageRenderTime 33ms CodeModel.GetById 22ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

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

https://bitbucket.org/DeveloperUX/behaviortree
Java | 75 lines | 49 code | 22 blank | 4 comment | 0 complexity | fc5007984d7e78f036a173711d1d6066 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// The font in this tutorial is from:
 9// http://lumina.sourceforge.net/Tutorials/Hello_World.html
10// Thanks!
11public class GLTutorialThirteen extends GLTutorialBase {
12	float lightAmbient[] = new float[] { 0.2f, 0.2f, 0.2f, 1.0f };
13	float lightDiffuse[] = new float[] { 1f, 1f, 1f, 1.0f };
14	float[] lightPos = new float[] {0,0,3,1};
15	
16	float matAmbient[] = new float[] { 1f, 1f, 1f, 1.0f };
17	float matDiffuse[] = new float[] { 1f, 1f, 1f, 1.0f };
18		
19	BitmapFont font;
20	
21	public GLTutorialThirteen(Context c) {
22		super(c, 20);	
23	}
24	
25	protected void init(GL10 gl) {
26		gl.glEnable(GL10.GL_LIGHTING);
27		gl.glEnable(GL10.GL_LIGHT0);
28		gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, matAmbient, 0);
29		gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, matDiffuse, 0);
30		
31		gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, lightAmbient,	0);
32		gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, lightDiffuse,	0);
33		gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, lightPos, 0);
34		
35		gl.glEnable(GL10.GL_DEPTH_TEST);
36		gl.glDepthFunc(GL10.GL_LEQUAL);
37		
38		gl.glEnable(GL10.GL_BLEND);
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, 1.0f, 0.0f);
44		gl.glClearDepthf(1.0f);
45		
46		gl.glEnable(GL10.GL_CULL_FACE);
47		gl.glShadeModel(GL10.GL_SMOOTH);
48		
49		font = new BitmapFont(loadTexture(gl, R.drawable.font));
50	}
51	
52	float xrot = 0.0f;
53	float yrot = 0.0f;
54	
55	public void onDrawFrame(GL10 gl) {
56		gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
57		
58		gl.glMatrixMode(GL10.GL_MODELVIEW);
59		
60		gl.glLoadIdentity();
61		GLU.gluLookAt(gl, 0, 0, 3, 0, 0, 0, 0, 1, 0);
62		gl.glTranslatef(0, 0, -6);
63		
64		gl.glRotatef(xrot, 1, 0, 0);
65		gl.glRotatef(yrot, 0, 1, 0);
66		
67		//gl.glMatrixMode(GL10.GL_MODELVIEW);
68		
69		gl.glActiveTexture(GL10.GL_TEXTURE0); 
70		gl.glClientActiveTexture(GL10.GL_TEXTURE0);
71		
72		font.draw(gl, "Hello");
73		yrot += 0.1;
74	}
75}