Monday, February 12, 2007

OpenGL

今天看了red book一点点,想自己写点,但是include library非常麻烦,单单要让program compile已经很痛苦了。没有挣扎干脆继续看看课本,惜只买到中文版,还要一边读一边翻译成英文
Every time after an action or frame, we need to call the function:
glFlush(); /glFinish();
--- to rienforce the system to refresh or execute the previous lines of program(functions) will ensure that the orders are excuted in some time(instead of forever)

for Polygons, to be valid, must fulfill:
simple polygon
convex
no holes inside

to model curves, we have a lot of small segment of straight lines to make the 'curve' looks smooth

enclose the functions of the vertice with glBegin() and glEnd()
example:
glBegin(GL_POLYGON);
glVertex2f(0.0, 0.0);
glVertex2f(0.0, 3.0);
glVertex2f(4.0, 3.0);
glVertex2f(6.0, 1.5);
glVertex2f(4.0, 0.0);
glEnd();

If replace the GL_POLYGON with GL_POINTS they will be five oints only.
there are some functions that we can use in between. Such as glColor(), glIndex(), glSecondaryColor(), glNormal(), glMaterial(), glFogCoord(), glTexCoord(), glMultiTexCoord(), glEdgeFlag(), glArrayElement(), glEvalCoord(), glEvaPoint() (to create coordinate), glCallList(), glCallLists

Here is a ineffiecient way to draw a circle:
#define PI 3.1415926535898
GLint circle_points = 100;
glBegin(GL_LINE_LOOP);
for (i = 0; i < circle_points; i++ ){
angle = 2*PI/circle_points;
glVertex2f(cos(angle), sin(angle));
}
glEnd();