Draw a Simple Object
Outline Course Map OpenGL Example Functions’ Introduction
Fixed Pipeline Per-Vertex Operations Viewport culling & clipping Vertex pipeline Per-Vertex Operations Viewport culling & clipping Primitive assembly Rasterize Pixel pipeline Fragment Processing Per Fragment operations Frame Buffer operations Framebuffer
Course Map Transformation & Lighting Viewport culling & clipping We are here! Vertex pipeline Transformation & Lighting Viewport culling & clipping Primitive assembly Rasterize Pixel pipeline Texture blending Per Fragment operations Frame Buffer operations Framebuffer
Example 1/3
Example 2/3
Example 3/3
Result
Data Type
Clear the Buffers 1/2 void glClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); Set the current values for use in cleaning color buffers in RGBA mode red, green, blue, alpha: Specify the red, green, blue, and alpha values used when the color buffers are cleared void glClearDepth(GLdouble depth); Set the current values for use in cleaning depth buffer depth: Specifies the depth value used when the depth buffer is cleared
Clear the Buffers 2/2 void glClear(GLbitfield mask); Clear the specified buffers to their current clearing values mask: GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, GL_ACCUM_BUFFER_BIT, GL_STENCIL_BUFFER_BIT EX: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Color Representation RGBA: red, green, blue, alpha Each channel has intensity from 0.0~1.0 Values outside this interval will be clamp to 0.0 or 1.0 Alpha is used in blending and transparency Specify a color: void glColor{34}{sifd}[v](…); EX: glColor3f(1.0f, 0.0f, 0.0f);
Points, Lines and Polygons 1/4 Describe points, lines, polygons void glBegin(GLenum mode); Marks the beginning of a vertex-data list Vertex-data include vertex’s color, normal, position, etc. mode: can be any of the values in next page void glEnd(); Marks the end of a vertex-data list
Points, Lines and Polygons 2/4
Points, Lines and Polygons 3/4
Points, Lines and Polygons 4/4 Specifying the vertices void glVertex{234}{sifd}[v](…) Specifies a vertex for use in describing a geometric object You have to set vertex’s attributes before glVertex Ex: Use glColor before glVertex to set the vertex’s color Can only effective between a glBegin() and glEnd() pair
Completion of Drawing void glFlush(); void glFinish(); Forces previously issued OpenGL commands to begin execution. void glFinish(); Forces previous issued OpenGL commands to complete. void glutSwapBuffers(); Swap front and back buffers.
Thanks for listening! Any questions?