Your SlideShare is downloading. ×
OpenGL ES on Android
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

OpenGL ES on Android

804

Published on

Published in: Technology, Art & Photos
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
804
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. OpenGL ES on Android
  • 2. OpenGL ES ● ● ● ● ● ● ● ● subset of OpenGL for Embedded Systems royalty free adopted by every major handset OS version 1.x fixed function version 2.x fully programmable version 3.x builds on version 2 http://www.khronos.org/opengles/ http://en.wikipedia.org/wiki/OpenGL_ES
  • 3. Android GLSurfaceView ● ● ● ● ● ● built in to Android manages OpenGL ES surfaces draws into the Android view system provides dedicated render thread handles EGL interface with window system supports continuous or on-demand rendering ● makes getting started relatively easy
  • 4. Android Renderer ● a custom implementation ○ GLSurfaceView.Renderer ● 3 interface methods called by system ○ onSurfaceCreated ○ onSurfaceChanged ○ onDrawFrame ● define model data in renderer ○ pass to OpenGL ES in onDrawFrame ● define matrices in renderer
  • 5. Model Data ● OpenGL ES version 1 ○ set points and colors with direct method calls glBegin(GL_TRIANGLES); glVertex3f(-0.5f, -0.25f, 0.0f); glColor3f(1.0f, 0.0f, 0.0f); ... glEnd(); ● OpenGL ES version 2 ○ define arrays and buffers to draw with final float[] triangle1VerticesData = { -0.5f, -0.25f, 0.0f, // X, Y, Z, 1.0f, 0.0f, 0.0f, 1.0f, // R, G, B, A 0.5f, -0.25f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.559016994f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f };
  • 6. Buffers ● ● ● ● Android is written in Java OpenGL ES is written in C model data is passed via buffers model data is cached somewhere ○ client memory: FloatBuffer ○ graphics memory: VBO, IBO
  • 7. Matrices ● model matrix ○ places a drawing in the world ● view matrix ○ positions drawings relative to our eye ● projection matrix ○ projects the view onto the screen ○ enables 3 dimensional perspective
  • 8. Shaders ● GLSL ES: http://www.khronos.org/opengles/sdk/docs/manglsl/ ● model data passes through shaders ● vertex shaders ○ perform operations on each vertex ○ pass results to fragment shaders ● fragment shaders ○ use results of vertex shaders ○ applies additional operations per pixel ○ draws to screen by sending data to OpenGL ES
  • 9. Shader Program ● links vertex output to fragment input ● provides mechanism to pass model data ○ App puts model data in buffers ○ OpenGL ES passes data from buffers to shaders ● used by OpenGL ES to execute drawing ● App can have multiple shader programs
  • 10. Light ● version 2 requires us to write our own lighting ○ per-vertex ○ per-fragment ● ray tracing ○ very accurate and realistic but very expensive ● rasterization ○ very good approximation ○ fast enough for real time graphics on mobile devices
  • 11. Light Types ● Ambient ○ pervades entire scene, no single source ○ indirect diffuse lighting ● Diffuse ○ light from a source bounces directly off an object ○ illumination of object depends on angle to source ● Specular ○ moves as we move relative to an object ○ perceived as "shininess"
  • 12. Light Sources ● Directional ○ consistent strength from undefined location ○ consistent direction no matter where you are ● Point ○ strength fades from a center point ○ travels in all directions ● Spot ○ strength fades from a point ○ travels with attenuation and direction
  • 13. Textures ● Coordination ○ OpenGL y-axis is flipped relative to images ■ more expensive: flip bitmap when loaded ■ less expensive: flip texture coordinates ○ texture coordinates are called texels ○ (s,t) instead of (x,y) ● Load image bitmap into application ● Supply shaders with texture data ● Shaders draw the texture
  • 14. Texture Filtering ● minification & magnification ● mipmapping ● nearest neighbor ○ blocky when magnified ● bilinear ○ smoother when magnified ● trilinear ○ smoother when multiple levels are side by side
  • 15. Blending ● effect of combining colors ● OpenGL provides several modes ○ additive ○ multiplicative ○ interpolative ● occurs in fragment shader ○ after calculating final color ○ normally overwrites previous value ○ blending… blends with previous value
  • 16. Vertex Buffer Objects ● instead of transferring data every frame ○ from client memory to OpenGL ● transfer once and draw from graphics cache ● generate an OpenGL buffer ○ give it the data in the client buffer ○ free client memory
  • 17. Index Buffer Objects ● VBO's can contain a lot of redundant data ○ specifically, redundant vertex data ● instead, define each vertex once only in IBO ● reference each vertex by index in IBO

×