opengl programming guide (red book) state management and drawing geometric objects 고려대학교...
TRANSCRIPT
OpenGL Programming Guide
(Red Book)
State Management and Drawing Geometric Objects
고려대학교
그래픽스 연구실
강 신 진
Goal
Clear the window to an arbitrary color Force any pending drawing to complete Draw with any geometric primitive Turn states on and off any query states
variables Control the display of geometric primitives Specify normal vectors at appropriate
points
Contents
A Drawing Survival Kit Describing Points, Lines, and
Polygons Basic State Management Display Points, Lines, and Polygons Normal Vectors
A Drawing Survival Kit
Clearing Window
Buffer Name
Color buffer GL_COLOR_BUFFER_BIT
Depth buffer GL_DEPTH_BUFFER_BIT
Accumulation buffer GL_ACCUM_BUFFER_BIT
Stencil buffer GL_STENCIL_BUFFER_BIT
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);glClear(GL_CLEAR_BUFFER_BIT);
Lesson27\Lesson 27.exe
Specifying a Color
Description of the shape of an object Independent of the description of its color
Order of Programming Setting the color or coloring scheme Drawing the objects
To set a color
glColor3f(1.0f, 1.0f, 1.0f); //black
glColor3f(0.0f, 1.0f, 1.0f); //cyan
Forcing Completion of Drawing
Void glFlush(void);
Forces previously issued OpenGL commands to begin execution, thus guaranteeing that they complete in finite time
Void glFinish(void);
Forces all previously issued OpenGL commands to complete. The command doesn’t return until all effects from previous commands are fully realized.
Coordinate System Survival Kit
glutReshapeFunc(reshape)
Void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,0.1f,100.0f);
}
Describing Points, Lines, and Polygons
점선폴리곤\lesson1.exe
What are Points, Lines and Polygons?
Differences between mathematician and OpenGL1. Difference from the limitations of computer-based
calculations.
Floating-point calculations are of finite precision, and they have round-off errors
2. Difference from the limitations of a graphics display
The smallest displayable unit is a pixel, and pixel is not infinitely small
Specifying Vertices
glVertex2s(2, 3);glVertex3d(0.0, 0.0, 3.141592653898);glVertex4f(2.3, 1.0, -2.2, 2.0);
glDouble dvect[3] = {5.0, 9.0, 1992.0};
glVertex3dv(dvect);
glVertex() type
glVertex*() type
Between glBegin() and glEnd()
OpenGL Geometric Drawing Primitives
Void glBegin(GLenum mode);
glBegin \모드Debug\lesson1.exe
Restriction on Using glBegin() and glEnd()
glVertex*() Set vertex coordinates
glColor*() Set current color
glIndex*() Set current color index
glNormal*() Set normal vector coordinates
glTexCoord*() Set texture coordinates
glMultiTexCoord*ARB()
Set texture coordinates for multitexturing
glEdgeFlag*() Control drawing of edges
glMaterial*() Set material properties
glArrayElement() Extract vertex array data
glEvalCoord*(), ~Point*()
Generate coordinates
glCallList(), glCallLists()
Execute display list(s)
Basic State Management
Basic State Management
Method
Void glEnable(GLenum cap);Void glDisable(GLenum cap);
Checking & Debugging method
GLboolean glIsEnabled(GLenum capability);
Capability Example
GL_BLEND, GL_DEPTH_TEST, GL_LINE_STIPPLE, GL_LIGHTING etc.
Display Points, Lines, and Polygons
Point Detail
Controlling size of a rendered point
Void glPointSize(GLfloat size);
Whether antialiasing is enabled or disabled
Disabled widths are rounded to integer widths
Enabled noninteger widths aren’t rounded, variation of intensity
Antilaliasing\Debug\Antilaliasing.exe
Line Details
Controlling width of a rendered line
Void glLineWidth(GLfloat size);
Stippled Lines
glLineStipple(1, 0x3F07);glEnable(GL_LINE_STIPPLE);
Polygon Details - 1
Polygons as Points, Outlines or Solids
Void glPolygonMode(GLenum face, GLenum mode);
glPolygonMode(GL_FRONT, GL_FILL);glPolygonMode(GL_BACK, GL_LINE);glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
Reserving and Culling Polygon Faces
Void glFrontFace(GLenum mode); //GL_CW, GL_CCW
glBegin \모드 Debug\lesson1.exe
Polygon Details - 2
Void glCullFace(GLenum mode);
mode GL_FRONT, GL_BACK, GL_FRONT_AND_BACK
Stippling Polygons
glEnable(GL_POLYGON_STIPPLE);Void glPolygonStipple(const GLubyte *mask);
Boundary Edges
Void glEdgeFlags(GLboolean flag);Void glEdgeFlagv(const GLboolean *flag);
Normal Vectors
Normal Vectors
Normal Vector
A normal vector is a vector that points in a direction that’s perpendicular to surface
OpenGL Method
Void glNormal3{bsidf}(TYPE nx, TYPE ny, TYPE nz);Void glNormal3{bsidf}v(const TYPE *v);
Normalization
glEnable(GL_NORMALIZE);