Your SlideShare is downloading. ×
0
Graphics Programming in
OpenGL
Arvind Devaraj
Arvind Devaraj2
OpenGL and GLUT Overview
�� OpenGL is graphics API.OpenGL is graphics API.
�� Makes graphics programmingMa...
Arvind Devaraj
A
Arvind Devaraj
High Level
� Represent Objects as Primitives
� Apply Transformations on objects
� Projection : Visible port...
Arvind Devaraj5
OpenGL Geometric Primitives
GL_QUAD_STRIPGL_QUAD_STRIP
GL_POLYGONGL_POLYGON
GL_TRIANGLE_STRIPGL_TRIANGLE_S...
Arvind Devaraj6
Shapes Tutorial
Arvind Devaraj
Transformations
Arvind Devaraj8
Camera Analogy
�� Graphics Rendering is like taking aGraphics Rendering is like taking a
photographphotogr...
Arvind Devaraj9
Transformations
�� Steps in Forming an ImageSteps in Forming an Image
� specify geometry (world coordinate...
Arvind Devaraj1
0
Camera Analogy of
Transformations
�� Projection transformationsProjection transformations
� adjust the l...
Arvind Devaraj1
1
Affine Transformations
�� Want transformations which preserveWant transformations which preserve
geometr...
Arvind Devaraj
Affine Transformations
� Basic Transformations
� Any transformation is Composition of these
Arvind Devaraj
Affine Transformation Matrix
Arvind Devaraj1
4
3D Transformations
�� A vertex is transformed by 4 x 4 matricesA vertex is transformed by 4 x 4 matrices...
Arvind Devaraj1
5
Programming
Transformations
�� Prior to rendering, view, locate, andPrior to rendering, view, locate, an...
Arvind Devaraj1
6
v
e
r
t
e
x
Modelview
Matrix
Projection
Matrix
Perspective
Division
Viewport
Transform
Modelview
Modelvi...
Arvind Devaraj1
7
Viewing Transformations
�� Position the camera/eye in the scenePosition the camera/eye in the scene
� pl...
Arvind Devaraj
Arvind Devaraj1
9
Transformations in OpenGL
�� ModelingModeling
�� ViewingViewing
� orient camera
� projection
�� Animatio...
Arvind Devaraj2
0
Transformation Tutorial
Arvind Devaraj
Projection
Arvind Devaraj2
2
Projection Tutorial
Arvind Devaraj2
3
Connection: Viewing and
Modeling
�� Moving camera is equivalent to movingMoving camera is equivalent to ...
Arvind Devaraj2
4
Double Buffering
1
2
4
8
16
1
2
4
8
16
Front
Buffer
Back
Buffer
Display
Arvind Devaraj2
5
Depth Buffering and
Hidden Surface Removal
1
2
4
8
16
1
2
4
8
16
Color
Buffer
Depth
Buffer
Display
Arvind Devaraj
Lighting
Arvind Devaraj2
7
Phong Principles
�� Lighting simulates how objects reflectLighting simulates how objects reflect
lightli...
Arvind Devaraj
Arvind Devaraj
Various Lighting Models
Arvind Devaraj3
0
Simulating Lights
�� PhongPhong lighting modellighting model
� Computed at vertices
�� Lighting contribu...
Arvind Devaraj3
1
Surface
Normals
�� NormalsNormals define how a surface reflectsdefine how a surface reflects
lightlight
...
Arvind Devaraj3
2
Light Position Tutorial
Arvind Devaraj
Texture Mapping
Arvind Devaraj3
4
Texture
Mapping
�� Apply image to geometryApply image to geometry
�� UsesUses
� Reduce Geometric complex...
Arvind Devaraj
Texture Mapping
Reduce Geometric Complexity
Arvind Devaraj
Arvind Devaraj
Reflections – Environmental
Map
Arvind Devaraj3
8
Texture Mapping
s
t
x
y
z
image
geometry screen
Arvind Devaraj3
9
Texture Example
�� The texture (below) is aThe texture (below) is a
256 x 256 image that has been256 x 2...
Arvind Devaraj4
0
Tutorial: Texture
Arvind Devaraj4
1
OpenGL’s State Machine
All Rendering info are remembered as state
info
State Information
Lighting
Shadin...
Arvind Devaraj4
2
OpenGL’s State MachineAll Rendering info are remembered as state
info
Manipulating vertex attribute chan...
Arvind Devaraj
Shaders
� Allow these transformations to be user
programmable
Arvind Devaraj
Arvind Devaraj
Shaders
Arvind Devaraj
Arvind Devaraj4
7
Getting to the Framebuffer
BlendingBlendingDepth
Test
Depth
Test DitheringDithering Logical
Operations
L...
Arvind Devaraj
Blending
Stencil test
Depth test
Arvind Devaraj
Alpha : for blending effect
Arvind Devaraj
Arvind Devaraj5
1
Blending (using Alpha)
�� AlphaAlpha--Measure of OpacityMeasure of Opacity
� simulate translucent object...
Arvind Devaraj5
2
Blending
�� Combine pixels with whatCombine pixels with what’’s in alreadys in already
in thein the fram...
Arvind Devaraj
Blending- Demo
� Exercises
� add multiple shaders
� simple blend
� Demo (url devmaster)
� Advanced (notes)
...
Arvind Devaraj
Stencil test
Arvind Devaraj
Stencil test
Arvind Devaraj
Accumulation buffer
� The accumulation buffer is simply an
extra image buffer that is used to
accumulate co...
Arvind Devaraj
Accumulation buffer
� Color buffer loses precision, so use float
buffer
�� CompositingCompositing
�� Antial...
Arvind Devaraj
OpenGLES
� There is no support for glBegin or
glEnd. Use vertex arrays and vertex
buffer objects instead.
�...
Arvind Devaraj
OpenGLES
� There is no support for the fixed-function
graphics pipeline. You must use your own
vertex and f...
Arvind Devaraj
OpenGLES- Buffer Objects
� OpenGL cannot directly see any of your
memory
� Therefore, the first step is to ...
Arvind Devaraj
OpenGLES- Buffer Objects
� Pass arrays of vertices, colors, etc. to OpenGL
in a large chunk
glVertexPointer...
Arvind Devaraj
OpenGLES - BufferObjects
� void InitializeVertexBuffer() {
glGenBuffers(1, &positionBufferObject);
glBindBu...
Arvind Devaraj
Exercises
� Moving ball animation
� Blending
� Texturing
���������������������������������������������������������������������������
����������������������������������������������...
Upcoming SlideShare
Loading in...5
×

Graphics programming in open gl

1,864

Published on

My presentation on Graphics programming

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,864
On Slideshare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
50
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Transcript of "Graphics programming in open gl"

  1. 1. Graphics Programming in OpenGL Arvind Devaraj
  2. 2. Arvind Devaraj2 OpenGL and GLUT Overview �� OpenGL is graphics API.OpenGL is graphics API. �� Makes graphics programmingMakes graphics programming h/wh/w independentindependent �� GLUT is a toolkitGLUT is a toolkit library of utilities using OpenGLlibrary of utilities using OpenGL makes easier to use OpenGLmakes easier to use OpenGL
  3. 3. Arvind Devaraj A
  4. 4. Arvind Devaraj High Level � Represent Objects as Primitives � Apply Transformations on objects � Projection : Visible portions are rendered � Add realism by adding Light and Texture � Remember using State information � Customize using Shaders � Framebuffer operations
  5. 5. Arvind Devaraj5 OpenGL Geometric Primitives GL_QUAD_STRIPGL_QUAD_STRIP GL_POLYGONGL_POLYGON GL_TRIANGLE_STRIPGL_TRIANGLE_STRIP GL_TRIANGLE_FANGL_TRIANGLE_FAN GL_POINTSGL_POINTS GL_LINESGL_LINES GL_LINE_LOOPGL_LINE_LOOPGL_LINE_STRIPGL_LINE_STRIP GL_TRIANGLESGL_TRIANGLES GL_QUADSGL_QUADS
  6. 6. Arvind Devaraj6 Shapes Tutorial
  7. 7. Arvind Devaraj Transformations
  8. 8. Arvind Devaraj8 Camera Analogy �� Graphics Rendering is like taking aGraphics Rendering is like taking a photographphotograph �� 3D model3D model �� 2D image2D image camera tripod model viewing volume
  9. 9. Arvind Devaraj9 Transformations �� Steps in Forming an ImageSteps in Forming an Image � specify geometry (world coordinates) � specify camera (camera coordinates) � project (window coordinates) � map to viewport (screen coordinates) �� Each step uses transformationsEach step uses transformations �� Transformation = change in coordinateTransformation = change in coordinate systemssystems
  10. 10. Arvind Devaraj1 0 Camera Analogy of Transformations �� Projection transformationsProjection transformations � adjust the lens of the camera �� Viewing transformationsViewing transformations � tripod–define position and orientation of the viewing volume in the world �� Modeling transformationsModeling transformations � moving the model �� ViewportViewport transformationstransformations � enlarge or reduce the physical photograph
  11. 11. Arvind Devaraj1 1 Affine Transformations �� Want transformations which preserveWant transformations which preserve geometrygeometry � Rotation, translation, scaling � Projection � Concatenation (composition)
  12. 12. Arvind Devaraj Affine Transformations � Basic Transformations � Any transformation is Composition of these
  13. 13. Arvind Devaraj Affine Transformation Matrix
  14. 14. Arvind Devaraj1 4 3D Transformations �� A vertex is transformed by 4 x 4 matricesA vertex is transformed by 4 x 4 matrices � all affine operations are matrix multiplications � all matrices are stored column-major in OpenGL � matrices are always post-multiplied � product of matrix and vector is v � M � � � � � � � � � � � � � 151173 141062 13951 12840 mmmm mmmm mmmm mmmm M
  15. 15. Arvind Devaraj1 5 Programming Transformations �� Prior to rendering, view, locate, andPrior to rendering, view, locate, and orient:orient: � eye/camera position � 3D geometry �� Manage the matricesManage the matrices � including matrix stack �� Combine (composite) transformationsCombine (composite) transformations
  16. 16. Arvind Devaraj1 6 v e r t e x Modelview Matrix Projection Matrix Perspective Division Viewport Transform Modelview Modelview Projection � � � object eye clip normalized device window Transformation Pipeline
  17. 17. Arvind Devaraj1 7 Viewing Transformations �� Position the camera/eye in the scenePosition the camera/eye in the scene � place the tripod down; aim camera �� ToTo ““fly throughfly through”” a scenea scene � change viewing transformation and redraw scene �� gluLookAtgluLookAt(( eyeeyexx,, eyeeyeyy,, eyeeyezz,, aimaimxx,, aimaimyy,, aimaimzz,, upupxx,, upupyy,, upupzz )) � up vector determines unique orientation tripod
  18. 18. Arvind Devaraj
  19. 19. Arvind Devaraj1 9 Transformations in OpenGL �� ModelingModeling �� ViewingViewing � orient camera � projection �� AnimationAnimation �� Map to screenMap to screen
  20. 20. Arvind Devaraj2 0 Transformation Tutorial
  21. 21. Arvind Devaraj Projection
  22. 22. Arvind Devaraj2 2 Projection Tutorial
  23. 23. Arvind Devaraj2 3 Connection: Viewing and Modeling �� Moving camera is equivalent to movingMoving camera is equivalent to moving every object in the world towards aevery object in the world towards a stationary camerastationary camera �� Viewing transformations are equivalentViewing transformations are equivalent to several modeling transformationsto several modeling transformations
  24. 24. Arvind Devaraj2 4 Double Buffering 1 2 4 8 16 1 2 4 8 16 Front Buffer Back Buffer Display
  25. 25. Arvind Devaraj2 5 Depth Buffering and Hidden Surface Removal 1 2 4 8 16 1 2 4 8 16 Color Buffer Depth Buffer Display
  26. 26. Arvind Devaraj Lighting
  27. 27. Arvind Devaraj2 7 Phong Principles �� Lighting simulates how objects reflectLighting simulates how objects reflect lightlight � material composition of object � light’s color and position
  28. 28. Arvind Devaraj
  29. 29. Arvind Devaraj Various Lighting Models
  30. 30. Arvind Devaraj3 0 Simulating Lights �� PhongPhong lighting modellighting model � Computed at vertices �� Lighting contributorsLighting contributors � Surface material properties � Light properties � Lighting model properties
  31. 31. Arvind Devaraj3 1 Surface Normals �� NormalsNormals define how a surface reflectsdefine how a surface reflects lightlight glNormal3f(glNormal3f( x, y, zx, y, z )) � Current normal is used to compute vertex’s color
  32. 32. Arvind Devaraj3 2 Light Position Tutorial
  33. 33. Arvind Devaraj Texture Mapping
  34. 34. Arvind Devaraj3 4 Texture Mapping �� Apply image to geometryApply image to geometry �� UsesUses � Reduce Geometric complexity � Add Realism � Reflections
  35. 35. Arvind Devaraj Texture Mapping Reduce Geometric Complexity
  36. 36. Arvind Devaraj
  37. 37. Arvind Devaraj Reflections – Environmental Map
  38. 38. Arvind Devaraj3 8 Texture Mapping s t x y z image geometry screen
  39. 39. Arvind Devaraj3 9 Texture Example �� The texture (below) is aThe texture (below) is a 256 x 256 image that has been256 x 256 image that has been mapped to a rectangularmapped to a rectangular polygonpolygon
  40. 40. Arvind Devaraj4 0 Tutorial: Texture
  41. 41. Arvind Devaraj4 1 OpenGL’s State Machine All Rendering info are remembered as state info State Information Lighting Shading Texturing Blending
  42. 42. Arvind Devaraj4 2 OpenGL’s State MachineAll Rendering info are remembered as state info Manipulating vertex attribute changes state info glColor() glNormal() glTexCoord()
  43. 43. Arvind Devaraj Shaders � Allow these transformations to be user programmable
  44. 44. Arvind Devaraj
  45. 45. Arvind Devaraj Shaders
  46. 46. Arvind Devaraj
  47. 47. Arvind Devaraj4 7 Getting to the Framebuffer BlendingBlendingDepth Test Depth Test DitheringDithering Logical Operations Logical Operations Scissor Test Scissor Test Stencil Test Stencil Test Alpha Test Alpha Test Fragment Framebuffer
  48. 48. Arvind Devaraj Blending Stencil test Depth test
  49. 49. Arvind Devaraj Alpha : for blending effect
  50. 50. Arvind Devaraj
  51. 51. Arvind Devaraj5 1 Blending (using Alpha) �� AlphaAlpha--Measure of OpacityMeasure of Opacity � simulate translucent objects � glass, water, etc. � composite images � Antialiasing glEnable( GL_BLEND )
  52. 52. Arvind Devaraj5 2 Blending �� Combine pixels with whatCombine pixels with what’’s in alreadys in already in thein the framebufferframebuffer glBlendFuncglBlendFunc(( srcsrc,, dstdst )) FramebufferFramebuffer PixelPixel ((dstdst)) Blending Equation Blending Equation FragmentFragment ((srcsrc)) BlendedBlended PixelPixel pfr CdstCsrcC ��� ��
  53. 53. Arvind Devaraj Blending- Demo � Exercises � add multiple shaders � simple blend � Demo (url devmaster) � Advanced (notes) Other blending modes Texture blending
  54. 54. Arvind Devaraj Stencil test
  55. 55. Arvind Devaraj Stencil test
  56. 56. Arvind Devaraj Accumulation buffer � The accumulation buffer is simply an extra image buffer that is used to accumulate composite images.
  57. 57. Arvind Devaraj Accumulation buffer � Color buffer loses precision, so use float buffer �� CompositingCompositing �� AntialiasingAntialiasing �� FilteringFiltering �� Motion BlurMotion Blur
  58. 58. Arvind Devaraj OpenGLES � There is no support for glBegin or glEnd. Use vertex arrays and vertex buffer objects instead. � The only supported rasterization primitives are points, lines and triangles. Quads are not supported � There is no support for display lists.
  59. 59. Arvind Devaraj OpenGLES � There is no support for the fixed-function graphics pipeline. You must use your own vertex and fragment shader programs. � There is no support for viewing transforms such as glFrustumf. You must compute your own transformation matrix, pass it to the vertex shader as a uniform variable, and perform the matrix multiplication in the shader. � There is no support for specialized functions such as glVertexPointer and glNormalPointer. Use glVertexAttribPointer instead.
  60. 60. Arvind Devaraj OpenGLES- Buffer Objects � OpenGL cannot directly see any of your memory � Therefore, the first step is to allocate some memory that OpenGL can see . This is done with something called a buffer object. Think of a buffer object as an array of GPU memory.
  61. 61. Arvind Devaraj OpenGLES- Buffer Objects � Pass arrays of vertices, colors, etc. to OpenGL in a large chunk glVertexPointer( 3, GL_FLOAT, 0, coords ) glColorPointer( 4, GL_FLOAT, 0, colors ) glEnableClientState( GL_VERTEX_ARRAY ) glEnableClientState( GL_COLOR_ARRAY ) glDrawArrays( GL_TRIANGLE_STRIP, 0, numVerts );
  62. 62. Arvind Devaraj OpenGLES - BufferObjects � void InitializeVertexBuffer() { glGenBuffers(1, &positionBufferObject); glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject); glBufferData(GL_ARRAY_BUFFER, siz, vertexPositions, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); }
  63. 63. Arvind Devaraj Exercises � Moving ball animation � Blending � Texturing
  64. 64. ��������������������������������������������������������������������������� ��������������������������������������������������������������������������������� �����������������������������������������������������
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×