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