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