0% found this document useful (0 votes)
62 views2 pages

Try GL

The document describes a Visual C++ program that renders a rotating cube using OpenGL. The program initializes settings like the number of pictures per rotation cycle and renders the cube by clearing the buffer, applying rotation transformations, and specifying vertex colors and positions to draw the cube's geometry as a series of quadrilaterals. Setting the depth test to false causes the cube to not be obscured by other surfaces, revealing its interior structure. The document also provides instructions to understand elements like the viewing geometry and cube coordinates defined in the OpenGL drawing code.

Uploaded by

kishanpal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views2 pages

Try GL

The document describes a Visual C++ program that renders a rotating cube using OpenGL. The program initializes settings like the number of pictures per rotation cycle and renders the cube by clearing the buffer, applying rotation transformations, and specifying vertex colors and positions to draw the cube's geometry as a series of quadrilaterals. Setting the depth test to false causes the cube to not be obscured by other surfaces, revealing its interior structure. The document also provides instructions to understand elements like the viewing geometry and cube coordinates defined in the OpenGL drawing code.

Uploaded by

kishanpal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Experiencing with an OpenGL Program CS3162 Introduction to Computer Graphics

Helena Wong, 2000

About OpenGL: OpenGL, originally developed by // Painting.cpp : implementation file


.. glColor3f(0.0, 1.0, 1.0); //v5
Silicon Graphics Incorporated (SGI) for their graphics glVertex3f(1.0, 1.0, -1.0);
workstations, lets applications create high-quality color //Initialization settings:
images independent of windowing systems, operating int gNumberOfPicturesPerCycle=20; //no. pictures to be painted in each animation cycle glColor3f(0.0, 1.0, 0.0); //v6
int gMilliSecondsPerPicture=100; //time duration for each picture, in milliseconds glVertex3f(1.0, -1.0, -1.0);
systems, and hardware. OpenGL's main purpose is to COLORREF gBackgroundColor=RGB(0,0,0); //background color: whiteness or blackness are best
render two- and three-dimensional objects into a frame int gWidthOfView=400; //width(in pixels) of the view glColor3f(0.0, 0.0, 1.0); //v7
buffer. int gHeightOfView=300; //height(in pixels) of the view glVertex3f(-1.0, 1.0, -1.0);

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

You might also like