1 / 11

Programming Concepts

Programming Concepts. Programming Concepts. 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)

cachez
Download Presentation

Programming Concepts

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming Concepts

  2. Programming Concepts • 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) { • set the LookAtMatrix of the Camera • prepare a vertexShaderProgram • prepare a fragmentShaderProgram • Check vertexShader( vertexShaderProgram ) • Check fragmentShader( fragmentShaderProgram ) • Create a GPU program for the vertex and fragment programs • Link GPU program(s) • Get the GPU program handles of the parameters • 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.

More Related