# OpenGL Study 2

Lesson02:

//here we do all the drawings
bool DrawGLScene(GLvoid)
{

//clear the screen and the depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

//reset the current modelview matrix

//move left 1.5 units,deep 6.0 units from current position

//move the model from (0,0,0) to (-1.5,0.0,-6.0),it can also be implemented by move the view point
glTranslatef(-1.5f,0.0f,-6.0f);

//draw a triangle
glBegin(GL_TRIANGLES);
glVertex3f(
0.0f,1.0f,0.0f);
glVertex3f(
-1.0f,-1.0f,0.0f);
glVertex3f(
1.0f,-1.0f,0.0f);
glEnd();

//move from (-1.5,0.0,-6.0) to (1.5,0.0,-6.0)
glTranslatef(3.0f,0.0f,0.0f);

//draw a quad,the vertex is represented in the model coordinate
glVertex3f(
-1.0f,1.0f,0.0f);
glVertex3f(
-1.0f,-1.0f,0.0f);
glVertex3f(
1.0f,-1.0f,0.0f);
glVertex3f(
1.0f,1.0f,0.0f);
glEnd();

return true;
}

绘制前先清除颜色缓存和深度缓存，将当前矩阵置为单位矩阵。

Lesson03

//here we do all the drawings
bool DrawGLScene(GLvoid)
{

//clear the screen and the depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

//reset the current modelview matrix

//move left 1.5 units,deep 6.0 units from current position

//move the model from (0,0,0) to (-1.5,0.0,-6.0),it can also be implemented by move the view point
glTranslatef(-1.5f,0.0f,-6.0f);

//draw a triangle,with smooth coloring
glBegin(GL_TRIANGLES);
glColor3f(
1.0f,0.0f,0.0f);
glVertex3f(
0.0f,1.0f,0.0f);
glColor3f(
0.0f,1.0f,0.0f);
glVertex3f(
-1.0f,-1.0f,0.0f);
glColor3f(
0.0f,0.0f,1.0f);
glVertex3f(
1.0f,-1.0f,0.0f);
glEnd();

//move from (-1.5,0.0,-6.0) to (1.5,0.0,-6.0)
glTranslatef(3.0f,0.0f,0.0f);

//draw a quad,the vertex is represented in the model coordinate

//with flat coloring
glColor3f(0.5f,0.5f,0.0f);
glVertex3f(
-1.0f,1.0f,0.0f);
glVertex3f(
-1.0f,-1.0f,0.0f);
glVertex3f(
1.0f,-1.0f,0.0f);
glVertex3f(
1.0f,1.0f,0.0f);
glEnd();

return true;
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：OpenGL Study 2 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)