PageRenderTime 17ms CodeModel.GetById 12ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 1ms

/Research/Example projects/AndroidGL_0.2/AndroidGL/src/edu/union/GLTutorialTwo.java

https://bitbucket.org/DeveloperUX/behaviortree
Java | 58 lines | 43 code | 15 blank | 0 comment | 0 complexity | e130153ce299a3af787dbe5b8924242e MD5 | raw file
 1package edu.union;
 2
 3import java.nio.ByteBuffer;
 4import java.nio.ByteOrder;
 5import java.nio.FloatBuffer;
 6
 7import javax.microedition.khronos.opengles.GL10;
 8
 9import android.content.Context;
10import android.graphics.Canvas;
11import android.graphics.OpenGLContext;
12import android.opengl.GLU;
13import android.view.SurfaceHolder;
14import android.view.View;
15
16public class GLTutorialTwo extends View { 
17	private OpenGLContext glContext;
18	
19	float[] square = new float[] { 	0.25f, 0.25f, 0.0f,
20									0.75f, 0.25f, 0.0f,
21									0.25f, 0.75f, 0.0f,
22									0.75f, 0.75f, 0.0f };
23	
24	FloatBuffer squareBuff;
25	
26	public GLTutorialTwo(Context c) {
27		super(c);
28		glContext = new OpenGLContext(0);
29		GL10 gl = (GL10)glContext.getGL();
30		
31		gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
32		
33		ByteBuffer bb = ByteBuffer.allocateDirect(square.length*4);
34		bb.order(ByteOrder.nativeOrder());
35		squareBuff = bb.asFloatBuffer();
36		squareBuff.put(square);
37		squareBuff.position(0);
38				
39		gl.glMatrixMode(GL10.GL_PROJECTION);
40		gl.glLoadIdentity();
41		GLU.gluOrtho2D(gl, 0.0f,1.2f,0.0f,1.0f);
42		
43		gl.glVertexPointer(3, GL10.GL_FLOAT, 0, squareBuff);
44		gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
45	}
46	
47	protected void onDraw(Canvas canvas) {
48		GL10 gl = (GL10)glContext.getGL();
49		
50		glContext.waitNative(canvas, this);
51		
52		gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
53		gl.glColor4f(1,1,1,1);
54		gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
55		
56        glContext.waitGL();
57	}
58}