3. arvind.iisc@gmail.com OpenGL Discussion GroupArvind Devaraj
Demos and Additional Material
� https://www.facebook.com/groups/ope
ngl/
� Is a community of OpenGL professionals
� Join the community to get more info
� We have tons of demos – Graphics
programming using GLUT, Android, iPhone
� Get your queries answered by expert
4. arvind.iisc@gmail.com OpenGL Discussion GroupArvind Devaraj4
OpenGLES Overview
�� OpenGL is graphics API.OpenGL is graphics API.
�� Makes programmingMakes programming h/wh/w independentindependent
�� OpenGLESOpenGLES is a subsetis a subset for embeddedfor embedded
platformplatform
6. arvind.iisc@gmail.com OpenGL Discussion GroupArvind Devaraj
OpenGLES Overview
�� Triangles used to approximate anyTriangles used to approximate any
geometrygeometry
7. arvind.iisc@gmail.com OpenGL Discussion GroupArvind Devaraj
OpenGLES Overview
� Renders 3D geometry defined by Triangles
� GPU is efficient in processing geometry and
images
8. arvind.iisc@gmail.com OpenGL Discussion GroupArvind Devaraj
OpenGLES Overview
� Represent Objects as Triangles
� Apply Transformations on triangles
� Rasterize the triangles to get pixels
� Add realism by adding Light and
Texture
� More realism using Shaders
12. arvind.iisc@gmail.com OpenGL Discussion GroupArvind Devaraj1
2
Camera Analogy
�� Everything inside the viewing volume isEverything inside the viewing volume is
capturedcaptured
camera
model
viewing
volume
15. arvind.iisc@gmail.com OpenGL Discussion GroupArvind Devaraj1
5
Transformations
�� Transform theTransform the modelmodel
�� i.ei.e move the objectmove the object
�� Transform the camera (Transform the camera (viewview))
� i.e change the viewing volume
�� ProjectionProjection from 3D to 2Dfrom 3D to 2D
� adjust the lens of the camera
16. arvind.iisc@gmail.com OpenGL Discussion GroupArvind Devaraj1
6
Transformations - APIs
�� Transform theTransform the modelmodel
�� glRotateglRotate // glTranslateglTranslate etcetc
�� Transform the camera (Transform the camera (viewview))
� gluLookAt
�� ProjectionProjection from 3D to 2Dfrom 3D to 2D
�� glFrustumglFrustum
19. arvind.iisc@gmail.com OpenGL Discussion GroupArvind Devaraj1
9
v
e
r
t
e
x
Modelview Projection
Object space Eye space Screen space
Transformation
Each triangle (vertex) from 3D model is
converted to screen space
24. arvind.iisc@gmail.com OpenGL Discussion GroupArvind Devaraj
Rasterization
How about overlapping
region
Pixels in individual
triangles are called
fragments
Combine fragments to
get final output pixel
26. arvind.iisc@gmail.com OpenGL Discussion GroupArvind Devaraj
Fragment Processing
There are many ways to combine Fragments
Display nearest to camera Blend with existing image
34. arvind.iisc@gmail.com OpenGL Discussion GroupArvind Devaraj3
4
Lights
�� Lighting depends onLighting depends on
� Surface material
� Direction and Position of Light
�� Mathematical modelsMathematical models
53. arvind.iisc@gmail.com OpenGL Discussion GroupArvind Devaraj
Android – Renderer
class ClearRenderer implements GLSurfaceView.Renderer {
public void onSurfaceCreated(GL10 gl, EGLConfig config) {}
public void onSurfaceChanged(GL10 gl, int w, int h) {
gl.glViewport(0, 0, w, h);
}
public void onDrawFrame(GL10 gl) {
draw_triangle();
}
}
54. arvind.iisc@gmail.com OpenGL Discussion GroupArvind Devaraj
Android - Renderer
draw_triangle() {
// set the vertex info from user data
glVertexAttribPointer
(…, 3, FLOAT,…..vertexData);
glDrawArrays(GL_TRIANGLES)
}