PageRenderTime 20ms CodeModel.GetById 10ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/DeveloperUX/behaviortree
Java | 89 lines | 54 code | 22 blank | 13 comment | 0 complexity | 95e677f179105b29ac712304578e778f MD5 | raw file
 1package com.example.atogl;
 2
 3import java.nio.FloatBuffer;
 4
 5import javax.microedition.khronos.opengles.GL10;
 6
 7import android.content.Context;
 8import android.opengl.GLU;
 9
10/**
11 * http://www.zeuscmd.com/tutorials/opengles/10-Transformations.php
12 * @author bburns
13 */
14public class GLTutorialFour extends GLTutorialBase {
15	float[] triangle = new float[] { -0.25f, -0.25f, 0.0f,
16									  0.25f, -0.25f, 0.0f,
17									 -0.25f,  0.25f, 0.0f };
18	
19	float[] square = new float[] { 	-0.25f, -0.25f, 0.0f,
20			0.25f, -0.25f, 0.0f,
21			-0.25f, 0.25f, 0.0f,
22			0.25f, 0.25f, 0.0f };
23	
24	float[] colors = new float[] { 	1, 0, 0, 1,
25									0, 1, 0, 1,
26									0, 0, 1, 1 };
27
28	FloatBuffer squareBuff;
29	FloatBuffer triangleBuff;
30	FloatBuffer colorBuff;
31
32	float xrot = 0.0f;
33	float yrot = 0.0f;
34	
35	public GLTutorialFour(Context c) {
36		super(c, 20);
37	
38		squareBuff = makeFloatBuffer(square);
39		triangleBuff = makeFloatBuffer(triangle);
40		colorBuff = makeFloatBuffer(colors);
41	}
42	
43	protected void init(GL10 gl) {
44		// Setup background color
45		gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
46		
47		// Smooth shading
48		gl.glShadeModel(GL10.GL_SMOOTH);
49	}
50	
51	public void onDrawFrame(GL10 gl) {
52		xrot += 1f;
53		yrot += 1f;
54			
55		// Clear screen
56		gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
57		
58		// Scene view matrix
59		gl.glMatrixMode(GL10.GL_MODELVIEW);
60		gl.glLoadIdentity();
61		gl.glPushMatrix();
62		gl.glTranslatef(-0.25f,0.0f,-2f);
63		gl.glRotatef(xrot, 1.0f, 0.0f, 0.0f);
64
65		// Setup triangle data and draw it.
66		gl.glVertexPointer(3, GL10.GL_FLOAT, 0, triangleBuff);
67		gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
68	
69		gl.glColorPointer(4, GL10.GL_FLOAT, 0, colorBuff);
70		gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
71			
72		gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 3);
73		
74		// Reset to identity
75		gl.glPopMatrix();
76		
77		// Clear the color array
78		gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
79		
80		// Translation to square location.
81		gl.glTranslatef(0.25f, 0.0f, -2f);
82		gl.glRotatef(yrot, 0, 1, 0);
83
84		// Setup square data & draw it
85		gl.glVertexPointer(3, GL10.GL_FLOAT, 0, squareBuff);
86		gl.glColor4f(0.25f, 0.25f, 0.75f, 1.0f);
87		gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
88	}
89}