1. Device Context (HDC) <--> Rendering Context (HGLRC)
2. State Functions
1) Query Numeric States:
void glGetbooleanv(GLenum pname, GLboolean *params);
void glGetDoublev(GLenum pname, GLdouble *params);
void glGetFloatv(GLenum pname, GLfloat *params);
void glGetIntegerv(GLenum pname, GLint *params);
2) Enabling and Disabling States
void glEnable(GLenum cap);
void glDisable(GLenum cap);
3) Query Capability State
GLboolean glIsEnabled(GLenum cap); // return GL_TRUE or GL_FALSE
4) Query String Values
const GLubyte* glGetString(GLenum name);
name can be :
GL_VENDOR, GL_RENDERER, GL_VERSION, GL_EXTENSIONS
5) Finding Error
GLenum glGetError();
OpenGL Error Codes:
GL_NO_ERROR
GL_INVALID_ENUM
GL_INVALID_VALUE
GL_INVALID_OPERATION
GL_STACK_OVERFLOW
GL_OUT_OF_MEMORY
GL_TABLE_TOO_LARGE
6) Giving OpenGL a Hint
In the fact that some operations in OpenGL may vary slightly from implementation to implementation (or driver to driver), glHint() provides an attempt to specify your desired level of trade-off between image quality and speed for several different OpenGL behaviors.
void glHint(GLenum target, GLenum hint);
OpenGL Behaviors:
GL_POINT_SMOOTH_HINT, GL_LINE_SMOOTH_HINT, GL_POLYGON_SMOOTH_HINT
GL_FOG_HINT
GL_PERSPECTIVE_CORRECTION_HINT
hint values:
GL_FATEST, GL_NICEST, GL_DONT_CARE
3. Handling Primitives (simply put, primitives are basic geometric entities such as points, lines and triangles)
1) void glBegin(GLenum mode)/ glEnd()
Valid glBegin() modes:
GL_POINTS
GL_LINES
GL_LINE_STRIP
GL_LINE_LOOP
GL_TRIANGLES
GL_TRIANGLE_STRIP: Series of connected triangles
GL_TRIANGLE_FAN: Set of triangles containing a common central vertex
GL_QUADS
GL_QUAD_STRIP
GL_POLYGON
Valid glBegin()/glEnd() Functions:
glVertex*(): void glVertex{234}{dfis}() or void glVertex{234}{dfis}v()
glColor*()
glSecondaryColor*()
glIndex*(): Set the current color index
glNormal*(): Set normal vector coordinates (法向量)
glTexCoord*(): Set texture coordinates
glMultiTexCoord*(): Set texture coordinates for multitexturing
glFogCoord*(): Set the fog coordinate
glArrayElement(): Specifies attributes for a single vertex based on elements in a vertex array
glEvalCoord*(): Generates coordinates when rendering Bezier curves and surfaces
glEvalPoint*(): Generate coordinates when rendering Bezier curves and surfaces
glMaterial*(): Sets material properties (affect shading when lighting is used)
glEdgeFlag*(): Controls the drawing of edges
glCallList*(): Executes a display list
glCallLists*(): Executes display lists
2) Draw Points
2.1) General Routine
glBegin(GL_POINTS);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(1.0, 0.0, 0.0);
glEnd();
2.2) Modifying Point Size
void glPointSize(GLfloat size);
Getting the current point size:
GLfloat oldsize;
glGetFloatv(GL_POINT_SIZE, &oldsize);
2.3) Antialiasing Points
if (!glIsEnabled(GL_POINT_SMOOTH))
glEnable(GL_POINT_SMOOTH);
Getting point size range and granularity:
GLfloat sizes[2];
GLfloat granularity;
// retrieve the point size range
glGetFloatv(GL_POINT_SIZE_RANGE, sizes);
GLfloat minPointSize = sizes[0];
GLfloat maxPointsize = sizes[1];
// retrieve the point size granularity
glGetFloatv(GL_POINT_SIZE_GRANULARITY, &granularity);
2.4) Effect of Distance
void glPointParameter{if}(GLenum pname, type param);
void glPointParameter{if}(GLenum pname, const type *params);
3) Drawing Lines in 3D
glBegin(GL_LINES);
glVertex3f(-2.0, -1.0, 0.0);
glVertex3f(3.0, 1.0, 0.0);
glEnd();
3.1) Modifying Line Width
void glLineWidth(GLfloat width);
Sample:
// retrieve the current line width
GLfloat oldWidth;
glGetFloatv(GL_LINE_WIDTH, &oldWidth);
// if our line width is small, make it big
if (oldWidth < 1.0)
glLineWidth(5.0);
3.2) Antialiasing Lines
GLfloat sizes[2];
GLfloat granularity;
glGetFloatv(GL_LINE_WIDTH_RANGE, sizes);
GLfloat minLineWidth = sizes[0];
GLfloat maxLineWidth = sizes[1];
glGetFloatv(GL_LINE_WIDTH_GRANULARITY, &granularity);
3.3) Specifying a Stipple Pattern
glEnable(GL_LINE_STIPPLE);
void glLineStipple(GLint factor, GLushort pattern);
Querying Line Stipple Pattern and Repeat:
GLushort currentStipplePattern;
GLint currentStippleRepeat;
glGetShortv(GL_LINE_STIPPLE_PATTERN, ¤tStipplePattern);
glGetIntv(GL_LINE_STIPPLE_REPEAT, ¤tStippleRepeat);
4) Drawing Polygons in 3D
void glPolygonMode(GLenum face, GLenum mode);
Parameters:
face - GL_FRONT, GL_BACK, GL_FRONT_AND_BACK
mode - GL_POINT, GL_LINES, GL_FILL