# OpenGL Study 3

Lesson04

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);

//rotate around the y axis
glRotatef(rtri,0.0f,1.0f,0.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();

//reset the current modleview matrix

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

//rotate around the x axis

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

//with flat coloring
glColor3f(0.5f,0.5f,1.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();

rtri
+=0.2f;
-=0.15f;

return true;
}

Lesson05

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);

//rotate around the y axis
glRotatef(rtri,0.0f,1.0f,0.0f);

//draw a diamond made of 4 triangles,with smooth coloring
glBegin(GL_TRIANGLES);

//front
glColor3f(1.0f,0.0f,0.0f);//red
glVertex3f(0.0f,1.0f,0.0f);
glColor3f(
0.0f,1.0f,0.0f);//green
glVertex3f(-1.0f,-1.0f,1.0f);
glColor3f(
0.0f,0.0f,1.0f);//blue
glVertex3f(1.0f,-1.0f,1.0f);

//right
glColor3f(1.0f,0.0f,0.0f);//red
glVertex3f(0.0f,1.0f,0.0f);
glColor3f(
0.0f,0.0f,1.0f);//blue
glVertex3f(1.0f,-1.0f,1.0f);
glColor3f(
0.5f,0.5f,0.0f);//rg
glVertex3f(1.0f,-1.0f,-1.0f);

//back
glColor3f(1.0f,0.0f,0.0f);//red
glVertex3f(0.0f,1.0f,0.0f);
glColor3f(
0.5f,0.5f,0.0f);//rg
glVertex3f(1.0f,-1.0f,-1.0f);
glColor3f(
0.5f,0.0f,0.5f);//rb
glVertex3f(-1.0f,-1.0f,-1.0f);

//back
glColor3f(1.0f,0.0f,0.0f);//red
glVertex3f(0.0f,1.0f,0.0f);
glColor3f(
0.5f,0.0f,0.5f);//rb
glVertex3f(-1.0f,-1.0f,-1.0f);
glColor3f(
0.0f,1.0f,0.0f);//green
glVertex3f(-1.0f,-1.0f,1.0f);

glEnd();

//reset the current modleview matrix

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

//rotate around the x axis

//draw a cubic made of 6 quads,the vertex is represented in the model coordinate

//with flat coloring

//top,y=1
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(
-1.0f,1.0f,1.0f);
glVertex3f(
1.0f,1.0f,1.0f);
glVertex3f(
1.0f,1.0f,-1.0f);
glVertex3f(
-1.0f,1.0f,-1.0f);

//bottom,y=-1
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(
-1.0f,-1.0f,1.0f);
glVertex3f(
-1.0f,-1.0f,-1.0f);
glVertex3f(
1.0f,-1.0f,-1.0f);
glVertex3f(
1.0f,-1.0f,1.0f);

//front,z=1
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(
-1.0f,-1.0f,1.0f);
glVertex3f(
1.0f,-1.0f,1.0f);
glVertex3f(
1.0f,1.0f,1.0f);
glVertex3f(
-1.0f,1.0f,1.0f);

//right,x=1
glColor3f(1.0f,1.0f,0.0f);
glVertex3f(
1.0f,-1.0f,1.0f);
glVertex3f(
1.0f,-1.0f,-1.0f);
glVertex3f(
1.0f,1.0f,-1.0f);
glVertex3f(
1.0f,1.0f,1.0f);

//back,z=-1
glColor3f(0.0f,1.0f,1.0f);
glVertex3f(
-1.0f,-1.0f,-1.0f);
glVertex3f(
-1.0f,1.0f,-1.0f);
glVertex3f(
1.0f,1.0f,-1.0f);
glVertex3f(
1.0f,-1.0f,-1.0f);

//left,x=-1
glColor3f(1.0f,0.0f,1.0f);
glVertex3f(
-1.0f,-1.0f,1.0f);
glVertex3f(
-1.0f,1.0f,1.0f);
glVertex3f(
-1.0f,1.0f,-1.0f);
glVertex3f(
-1.0f,-1.0f,-1.0f);

glEnd();

rtri
+=0.2f;