OpenGL Introduction

2,548 views

Published on

OpenGL Introduction

  1. 1. <ul><li>3D Computer Graphics </li></ul><ul><li>OpenGL </li></ul>David Kabala
  2. 2. Why Cool?
  3. 3. Computer Graphics <ul><li>Raster Graphics </li></ul><ul><ul><li>Images are created from pixel data </li></ul></ul><ul><li>Vector Graphics </li></ul><ul><ul><li>Images are created from primitives of points, lines, curves, and other shapes </li></ul></ul><ul><ul><li>Final image is computed by processing this representation </li></ul></ul>
  4. 4. OpenGL <ul><li>OpenGL is a mixture of Vector and Raster graphics </li></ul><ul><ul><li>Vector graphics </li></ul></ul><ul><ul><ul><li>polygons, surface normals, colors, etc. </li></ul></ul></ul><ul><ul><li>Raster graphics </li></ul></ul><ul><ul><ul><li>textures(images) that are mapped onto surfaces </li></ul></ul></ul><ul><ul><ul><li>Rasterizing vector graphics into frame buffer </li></ul></ul></ul><ul><li>Most platforms have an implementation of OpenGL </li></ul><ul><ul><li>Windows, Linux, Mac, iPhone, Android, PS3, and many more </li></ul></ul>
  5. 5. OpenGL Rendering Pipeline Vector Operations Rasterization Fragment Operations Frame Buffer Data
  6. 6. OpenGL Rendering Pipeline
  7. 7. OpenGL Rendering Pipeline <ul><li>ATI R600 Pipeline </li></ul>
  8. 8. OpenGL Changing with 3.0 <ul><li>Many parts of the OpenGL API have been deprecated in version 3.0, and removed in version 3.1 </li></ul><ul><li>This includes much of the fixed functionality of the pipeline </li></ul><ul><ul><li>Lighting </li></ul></ul><ul><li>Programing these portions in the pipeline is the path forward </li></ul>
  9. 9. OpenGL as a state machine <ul><li>OpenGL is organized for functional programming not object-oriented </li></ul><ul><li>Stays in a persistent state until it receives a message that tells it to change </li></ul><ul><li>Objects are bound </li></ul><ul><ul><li>Changes are made to the state </li></ul></ul><ul><ul><ul><li>Color, lighting, line width, etc </li></ul></ul></ul><ul><li>Immediate draw mode </li></ul>
  10. 10. OpenGL API <ul><li>All methods are prefixed with gl </li></ul><ul><ul><li>e.g. glEnable(GLbool), glVertex2i(GLint,GLint)‏ </li></ul></ul><ul><li>All Types are prefixed with GL </li></ul><ul><ul><li>e.g. GLbool, GLint, GLflaot, GLenum </li></ul></ul><ul><li>All constants are prefixed with GL_ </li></ul><ul><ul><li>e.g. GL_POINTS, GL_CULL_FACE, GL_QUADS </li></ul></ul>
  11. 11. OpenGL defined types <ul><li>C/C++ leave the number of bytes of each type up to the compiler writer </li></ul><ul><li>OpenGL has defined types that are the same size in all implementations </li></ul><ul><li>Important Types </li></ul><ul><li>GLshort </li></ul><ul><ul><li>16 bit integer </li></ul></ul><ul><li>GLint </li></ul><ul><ul><li>32 bit integer </li></ul></ul><ul><li>GLfloat </li></ul><ul><ul><li>32 bit floating point </li></ul></ul><ul><li>GLdouble </li></ul><ul><ul><li>64 bit floating point </li></ul></ul><ul><li>GLboolean </li></ul><ul><ul><li>8 bit unsigned integer </li></ul></ul><ul><li>GLenum </li></ul><ul><ul><li>32 bit unsigned integer </li></ul></ul>
  12. 12. Drawing <ul><li>Primitives are drawn by sending vertex positions inside of a glBegin and glEnd block </li></ul><ul><li>Example: </li></ul>void display ( void )‏ { //Setup state to start drawing //points glBegin(GL_POINTS); //Draw a point at 10,10 glVertex2i(10,10); glEnd(); }
  13. 13. glBegin/glEnd block <ul><li>OpenGL receives primitive geometry data “inside” a glBegin and glEnd block </li></ul><ul><li>glBegin(GLenum primitiveType)‏ </li></ul><ul><ul><li>primitiveType argument takes a GLenum value of the type of primitives to draw </li></ul></ul>void display ( void )‏ { glBegin(GL_POINTS); glVertex2i(10,10); glVertex2i(20,10); glVertex2i(0,0); glEnd(); glVertex2i(10,0); //Will not draw }
  14. 14. GlVertex variations <ul><li>Some sets of OpenGL methods take multiple numbers and types of arguments </li></ul>glVertex2i Type of argument Number of arguments glColor4f
  15. 15. Primitives <ul><li>Points </li></ul><ul><li>Lines </li></ul><ul><li>Triangles </li></ul><ul><li>Quadrilaterals </li></ul><ul><li>Polygons </li></ul>
  16. 16. Points <ul><li>send GL_POINTS as parameter to glBegin </li></ul><ul><li>Every glVertex produces a single point </li></ul><ul><li>Changing point drawing parameters </li></ul><ul><li>glPointSize(GLint size); </li></ul>void display ( void )‏ { //Setup state to start drawing //points glPointSize(5.0); glBegin(GL_POINTS); //Draw a point at 10,10 glVertex2i(10,10); glEnd(); }
  17. 17. Lines <ul><li>Line Draw Modes </li></ul><ul><ul><li>GL_LINES </li></ul></ul><ul><ul><li>GL_LINE_STRIP </li></ul></ul><ul><li>Changing line width </li></ul><ul><ul><li>glLineWidth(GLint size); </li></ul></ul><ul><ul><li>GL_LINE_LOOP </li></ul></ul>v1 v2 v2 v1 v3 v4 v1 v2 v3 v4 v5
  18. 18. Triangles <ul><li>GL_TRIANGLES </li></ul><ul><li>GL_TRIANGLE_STRIP </li></ul><ul><li>GL_TRIANGLE_FAN </li></ul>
  19. 19. Quads <ul><li>GL_QUADS </li></ul><ul><li>GL_QUAD_STRIP </li></ul>
  20. 20. Polygons <ul><li>GL_POLYGONS </li></ul><ul><li>Must be convex </li></ul><ul><li>Must be non-intersecting </li></ul><ul><li>Separate polygons must be in separate glBegin/glEnd blocks </li></ul>v1 v2 v3 v4 v5 v1 v2 v3 v4 v5 v6 v6 v8
  21. 21. Next Time <ul><li>Using GLUT (OpenGL Utility) to manage window and context creation </li></ul><ul><li>Transformations using matrix and vector algebra </li></ul>

×