Open gles


Published on

Published in: Technology, Art & Photos
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Open gles

  1. 1. OpenGL & OpenGLES
  2. 2. Introduction to OpenGL <ul><li>OpenGL (Open Graphics Library)[2] is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics. </li></ul><ul><li>The interface consists of over 250 different function calls which can be used to draw complex three-dimensional scenes. </li></ul><ul><li>OpenGL was developed by Silicon Graphics Inc. (SGI) in 1992[3] and is widely used in CAD, virtual reality, scientific visualization,information visualization, and flight simulation. </li></ul><ul><li>It is also used in video games,where it competes with Direct3D on Microsoft Windows platforms . </li></ul><ul><li>OpenGL is managed by a non-profit technology consortium, the Khronos Group. </li></ul>
  3. 3. Introduction to OpenGLES <ul><li>OpenGL ES (OpenGL for Embedded Systems) is a subset of the OpenGL 3D graphics API designed for embedded devices such as mobile phones, PDAs and video game consoles. </li></ul><ul><li>It is defined and promoted by the Khronos Group,a graphics hardware and software industry consortium interested in open </li></ul><ul><li>APIs for graphics and multimedia. </li></ul>
  4. 4. The following APIs will provide central understanding in OpenGL & OpenGLES <ul><li>􀀁 glVertexPointer </li></ul><ul><li>􀀁 glDrawElements </li></ul><ul><li>􀀁 glColor </li></ul><ul><li>􀀁 glClear </li></ul><ul><li>􀀁 gluLookAt </li></ul><ul><li>􀀁 glFrustum </li></ul><ul><li>􀀁 glViewport </li></ul>
  5. 5. OpenGL ES offers two primary methods to facilitate drawing: <ul><li>glVertexPointer: to specify a series of points or </li></ul><ul><li>vertices. </li></ul><ul><li>glDrawElements: to draw them using one of the </li></ul><ul><li>primitive shapes </li></ul>
  6. 6. <ul><li>glVertexPointer( </li></ul><ul><li>// Are we using (x,y) or (x,y,z) in each point </li></ul><ul><li>3, </li></ul><ul><li>// each value is a float value in the buffer </li></ul><ul><li>GL10.GL_FLOAT, </li></ul><ul><li>// Between two points there is no space </li></ul><ul><li>0, </li></ul><ul><li>// pointer to the start of the buffer </li></ul><ul><li>mFVertexBuffer ); </li></ul>glVertexPointer API Definition
  7. 7. <ul><li>glVertexPointer takes native buffer rather than array floats.We need to convert these java-based floats into an accceptable C-like native buffer.We use Java.nio classes to convert float array into native buffer. </li></ul><ul><li>java.nio.ByteBuffer vbb = </li></ul><ul><li>java.nio.ByteBuffer.allocateDirect(3 * 3 * 4); </li></ul><ul><li>vbb.order(ByteOrder.nativeOrder()); </li></ul><ul><li>java.nio.FloatBuffer mFVertexBuffer = vbb.asFloatBuffer(); </li></ul>
  8. 8. glDrawElements API Definition <ul><li>glDrawElements( </li></ul><ul><li>// type of shape </li></ul><ul><li>GL10.GL_TRIANGLE_STRIP, </li></ul><ul><li>// Number of indices </li></ul><ul><li>3, </li></ul><ul><li>// How big each index is </li></ul><ul><li>GL10.GL_UNSIGNED_SHORT, </li></ul><ul><li>// buffer containing the 3 indices </li></ul><ul><li>mIndexBuffer ); </li></ul>
  9. 9. glColor <ul><li>We use it to set the default color for the subsequent drawing that takes place. </li></ul><ul><li>//Set the current color </li></ul><ul><li>glColor4f(1.0f, 0, 0, 0.5f); </li></ul><ul><li>Where 4f refers to 4 arguments, all are float </li></ul>
  10. 10. glClear <ul><li>This method is used to erase the drawing surface. we can reset not only the color, but also the depth and the type of stencils used. </li></ul><ul><li>GL_COLOR_BUFFER_BIT, </li></ul><ul><li>GL_DEPTH_BUFFER_BIT, </li></ul><ul><li>GL_STENCIL_BUFFER_BIT . </li></ul>
  11. 11. Understanding OpenGL Camera and Coordinates <ul><li>gluLookAt: Controls the direction of the camera </li></ul><ul><li>glFrustum: Controls the viewing volume or zoom </li></ul><ul><li>glViewport: Controls the size of the screen or the size of the camera’s “film” </li></ul>
  12. 12. Y-axis Frustrum Z-axis Point it up height 0,0,0 Near(3) Far(7)
  13. 13. <ul><li>gluLookAt(gl, 0,0,5, 0,0,0, 0,1,0); </li></ul>location of the camera Eye point direction the camera is pointing Look-at point whether the camera is up, down, or slanted Up vector
  14. 14. <ul><li>glFrustrum: to specify the area of the scene that you are interested in.The area as bounded by a box, also called the frustum or viewing volume. </li></ul><ul><li>frustrum= far point - near point </li></ul>
  15. 15. <ul><li>In OpenGL, you can imagine this box in one of two ways. </li></ul><ul><li>Prespective projection. </li></ul><ul><li>Orthographic projection. </li></ul>
  16. 16. <ul><li>Specifying a Frustum through glFrustum </li></ul><ul><li>//calculate aspect ratio first </li></ul><ul><li>float ratio = (float) w / h; </li></ul><ul><li>//indicate that we want a perspective projection </li></ul><ul><li>glMatrixMode(GL10.GL_PROJECTION); </li></ul><ul><li>//Specify the frustum: the viewing volume </li></ul><ul><li>gl.glFrustumf( </li></ul><ul><li>-ratio, // Left side of the viewing box </li></ul><ul><li>ratio, // right side of the viewing box </li></ul><ul><li>1, // top of the viewing box </li></ul><ul><li>-1, // bottom of the viewing box </li></ul><ul><li>3, // how far is the front of the box from the camera </li></ul><ul><li>7 ); // how far is the back of the box from the camera </li></ul>
  17. 17. glViewport <ul><li>It is responsible for specifying the rectangular area on the screen onto which the viewing volume will be projected. </li></ul>
  18. 18. <ul><li>glViewport( 0, // lower left &quot;x&quot; of the rectangle on </li></ul><ul><li>the screen. </li></ul><ul><li>0 ,// lower left &quot;y&quot; of the rectangle on </li></ul><ul><li>the screen </li></ul><ul><li>width, // width of the rectangle on the </li></ul><ul><li>screen </li></ul><ul><li>height ); // height of the rectangle on the </li></ul><ul><li>screen </li></ul>
  19. 19. <ul><li>The other classes in the package include: </li></ul><ul><li>GLU: This utility class contains utilities that wrap the underlying OpenGL ES API in order to aggregate some common functionality. </li></ul><ul><li>GLUtils: This utility class contains Android-specific utilities that are built to make interacting with the OpenGL ES easier. </li></ul><ul><li>Matrix: This is the transformation matrix that is essential for transformations such as scaling, moving, etc. </li></ul>
  20. 20. <ul><li>Visibility: It deals with the visibility aspects of OpenGL such as what triangle meshes are visible on the screen. </li></ul><ul><li>GLDebugHelper :A static utility class that allows you to wrap the “GL”and “EGL” interfaces so that you can control logging, errors, additional checks, etc. </li></ul><ul><li>GLSurfaceView.EGLConfigChooser :An EGL tells OpenGL the type of display characteristics. </li></ul><ul><li>GLSurfaceView.GLWrapper: This interface allows you to wrap the“gl” interface so that you can intercept the OpenGL calls across the entire system. </li></ul>
  21. 21. <ul><li>GLSurfaceView.Renderer: This interface allows for derived classes to draw. It allows GLSurfaceView to call draw when the surface has changed, etc </li></ul><ul><li>public static interface GLSurfaceView.Renderer </li></ul><ul><li>{ </li></ul><ul><li>void onDrawFrame(GL10 gl); </li></ul><ul><li>void onSuraceChanged(GL10 gl, int width, int height); </li></ul><ul><li>void onSurfaceCreated(GL10 gl, EGLConfig config); </li></ul><ul><li>} </li></ul>
  22. 22. <ul><li>onDrawFrame():- This is called to draw the current </li></ul><ul><li>frame.The main drawing happens </li></ul><ul><li>in this method . </li></ul><ul><li>onSurfaceCreated():- Whenever new surface is </li></ul><ul><li>created this method is called,we </li></ul><ul><li>can also call a no of OpenGL API’s </li></ul><ul><li>such as dithering or depth control. </li></ul><ul><li>onSurfaceChanged():- Whenever surface changes such </li></ul><ul><li>as width height of the window </li></ul><ul><li>this method is called. </li></ul>
  23. 23. <ul><li>Thank You </li></ul>