Try GL
Try GL
On the right is a source code (painting.cpp) of a Visual float gFieldYOfView=45.0; //The field of view, in degrees, in y-direction ------ (v) glColor3f(0.0, 0.0, 0.0); //v8
float gZNear=3.0; //Distance from viewer to the near clipping plane glVertex3f(-1.0, -1.0, -1.0);
C++ program which renders a rotating cube using float gZFar=7.0; //Distance from viewer to the far clipping plane
OpenGL. glColor3f(1.0, 0.0, 1.0); //v9
bool gDepthTest=true; //Enable depth buffer ----- (]) glVertex3f(-1.0, 1.0, 1.0);
In previous exercises, you have experienced with
some Visual C++ painting programs. You should be GLfloat gObjectRotationX = 1.0; //degree of rotation(x) of the object in next picture glColor3f(1.0, 0.0, 0.0); //v10
already familiar with the format of this source code. GLfloat gObjectRotationY = 10.0; //degree of rotation(y) of the object in next picture glVertex3f(-1.0, -1.0, 1.0);
GLfloat gObjectRotationZ = 5.0; //degree of rotation(z) of the object in next picture
glEnd();
Tasks: void DoPainting(CDC *pDC,int WhichCallInCurrentCycle)
1. According to the instructor’s instruction, download { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear with background color glBegin(GL_QUADS); //draws a quadrilateral
the Visual C++ program which contains this source glColor3f(1.0, 0.0, 1.0); //v11
glPushMatrix(); glVertex3f(-1.0, 1.0, 1.0);
code.
glTranslatef(0.0, 0.0, -5.5); //define a translation glColor3f(1.0, 1.0, 1.0); //v12
2. Compile and run this program. glRotatef(gObjectRotationX, 1.0, 0.0, 0.0); //define a rotation transformation glVertex3f(1.0, 1.0, 1.0);
3. Change the value of gDepthTest (]) to false and glRotatef(gObjectRotationY, 0.0, 1.0, 0.0); // with rotation angle and vector
glRotatef(gObjectRotationZ, 0.0, 0.0, 1.0); // of rotation (eg. 1,0,0 = x-axis) glColor3f(0.0, 1.0, 1.0); //v13
re-run the program. What is the difference? glVertex3f(1.0, 1.0, -1.0);
4. Try to understand the remaining part of this source gObjectRotationX += 1.0; //prepare for bigger rotation in next picture
gObjectRotationY += 10.0; glColor3f(0.0, 0.0, 1.0); //v14
code. (Hints: in this code of OpenGL function gObjectRotationZ += 5.0; glVertex3f(-1.0, 1.0, -1.0);
calls, the coloring in r,g,b are specified in the range glEnd();
of 0 – 1.0, not 0-255). You may ask your instructor glBegin(GL_QUAD_STRIP);
for anything which you can’t understand. //Draws a connected group of 4 quadrilaterals: q1,q2,q3,q4. glBegin(GL_QUADS); //draws a quadrilateral
//The vertices are coded in a specific order such that: glColor3f(0.5f, 0.5f, 0.5f); //v15
5. Imagine the geometry of the viewing system. Draw //v1,v2,v3,v4 => q1 glVertex3f(-1.0, -1.0, 1.0);
it on a paper. (Hints: you can get the relevant //v3,v4,v5,v6 => q2
//... glColor3f(0.5f, 0.5f, 0.5f); //v16
dimensions from the variables gFieldYOfVew, glVertex3f(1.0, -1.0, 1.0);
gZNear, and gZFar. (v) glColor3f(1.0, 0.0, 1.0); //v1
glVertex3f(-1.0, 1.0, 1.0); glColor3f(0.5f, 0.5f, 0.5f); //v17
6. Imagine the geometry of the cube in the modeling glVertex3f(1.0, -1.0, -1.0);
coordinate system, ie. According to the code in the glColor3f(1.0, 0.0, 0.0); //v2
function body: glBegin .. glEnd .., draw the cube glVertex3f(-1.0, -1.0, 1.0); glColor3f(0.0, 0.0, 0.0); //v18
with the axes on a paper, mark which corner is glVertex3f(-1.0, -1.0, -1.0);
glColor3f(1.0, 1.0, 1.0); //v3 glEnd();
specified with v1, v2, etc., (Hints: The z-axis is glVertex3f(1.0, 1.0, 1.0);
pointing towards you, ie. Out of the paper). glPopMatrix();
glColor3f(1.0, 1.0, 0.0); //v4 }
glVertex3f(1.0, -1.0, 1.0);