Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Concepts. Derive a new class from Activity of the framework Prepare the data beforehand, e.g., vertices, colours, normal vectors, texture.

Similar presentations


Presentation on theme: "Programming Concepts. Derive a new class from Activity of the framework Prepare the data beforehand, e.g., vertices, colours, normal vectors, texture."— Presentation transcript:

1 Programming Concepts

2 Derive a new class from Activity of the framework Prepare the data beforehand, e.g., vertices, colours, normal vectors, texture coordinates, etc. Create your Renderer Check GPU version Prepare vertex shader program(s) Prepare fragment shader program(s) Compile and link your GPU program(s) Implement methods: onSurfaceCreated, onSurfaceChanged, onDrawFrame, etc.

3 Create a class derived from Activity public class MainActivity extends Activity { \\body }

4 Define OnCreate Method (Pseudo code) public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); create GLSurfaceView supportsEs2 = Check if the system supports OpenGL ES 2.0. if (supportsEs2) { Set GLSurfaceView.setEGLContextClientVersion for OpenGL ES 2.0. Set GLSurfaceView.setRenderer for rendering } else { // This is where you could create an OpenGL ES 1.x compatible // renderer if you wanted to support both ES 1 and ES 2. return; } setContentView(mGLSurfaceView); }

5 Define onCreateOptionsMenu // Inflate the menu resource (defined in XML) into the Menu provided in the callback. @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; }

6 Renderer public class MyRenderer implements GLSurfaceView.Renderer { // three matrices: projection, view, model // vertices // handles for passing information: // matrix, position, color }

7 Initialization of Data final float[] myVerticesData = { X0, Y0, Z0, // position in 3Dimensional Space R0, G0, B0, A0//red,green,blue,alpha X1, Y1, Z1, R1, G1, B1, A1 X2, Y2, Z2, R2, G2, B2, A2 //more if more vertices };

8 Initialization of a Buffer mMyVerticesBuffer = ByteBuffer.allocateDirect( myVerticesData.length*mBytesPerFloat ).order( ByteOrder.nativeOrder() ).asFloatBuffer(); mMyVerticesBuffer.put( myVerticesData ).position(0);

9 onSurfaceCreated method // called at the start of rendering // or the OpenGL ES drawing context has to be recreated public void onSurfaceCreated(GL10 glUnused, EGLConfig config) { 1.set the LookAtMatrix of the Camera 2.prepare a vertexShaderProgram 3.prepare a fragmentShaderProgram 4.Check vertexShader( vertexShaderProgram ) 5.Check fragmentShader( fragmentShaderProgram ) 6.Create a GPU program for the vertex and fragment programs 7.Link GPU program(s) 8.Get the GPU program handles of the parameters 9.Use the GPU program }

10 onSurfaceChanged method The onSurfaceChanged() method is called when the surface changes size. Possible functions: – set the OpenGL viewport – set the camera

11 onDrawFrame method The onDrawFrame() method is called every frame. It is responsible for drawing the scene. Usually clear the framebuffer and then call functions to draw the current scene.


Download ppt "Programming Concepts. Derive a new class from Activity of the framework Prepare the data beforehand, e.g., vertices, colours, normal vectors, texture."

Similar presentations


Ads by Google