Home Robotics C++ Physics II AP Physics B Electronics AP Java Astronomy Independent Study Summer Session Contests  About
                                                       

OpenGL Review Exercise

 

 

 

¢  In the code glColor3f(0.0, 1.0, 0.0)

 

     Ø  What do the numbers in parentheses represent?

 

        Red, Green, and Blue components of the color   

 

     Ø  What does f stand for?

 

        floating point or numbers with decimals

 

¢  Write the function that forces previously issued OpenGl command to begin execution

 

     glFlush() or glFinish()

 

¢  Blocks of code enclosed by glBegin(mode) and glEnd() are used to draw  in OpenGL.

     Provide the code for mode in order to draw the following items.

 

     Ø  Individual points

 

          GL_POINTS

 

     Ø  Line segments

 

          GL_LINES or GL_LINE_STRIP_ or GL_LINE_LOOP

 

     Ø  A convex polygon

 

         GL_POLYGON

 

¢  Write code that will set line width to 2.0

 

     glLineWidth(2.0);

 

¢  What does the GL in OpenGL stand for?

 

     Graphics library.

 

¢  What is the purpose of the glutInit() function?

 

     Initializes glut and processes any command line arguments.

 

¢  What is the purpose of the glutInitDisplayMode () function?

 

     Specifies whether to use an RGBA or color-index color model. You can also specify whether you want a single or  double buffered window.

 

¢  What is the purpose of the glutMainLoop (void) function and when is it called?

 

     The last thing called. All windows that have been created are now displayed. Event processing begins.

 

¢  By default, the camera is located where? 

 

    At the Origin.

 

¢  By default, the camera is pointing in which direction? 

 

    Toward the negative z axis

  

¢  Write code, using gluLookAt() that will position the camera on the x axis, 4 units from the origin, looking toward the origin, with positive y as the positive direction.

 

     gluLookAt(4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)

 

¢  Fill in the blanks with the name of the function being decribed.

 

    Ø  __________________________ sets the current matrix with a matrix that has 1’s along the diagonal and 0s elsewhere  

 

       glLoadIdentify()

 

    Ø  ________________________ moves the camera to the location specified by the 3 parameters

 

        glTranslate (a,b,c)

 

    Ø  __________________________ multiplies the current matrix by a matrix that stretches, shrinks, or reflects an object

         along the axes. 

 

         glScale()

 

    Ø   __________________________ multiplies the current matrix by a matrix that rotates an object through the speficied angle in a counerclockwise direction about the ray from the origin through the point specified by the x, y, and z parameters

 

         glRotate(angle, x, y, z)

 

     Ø  __________________________is used to specify the desired shading technique. 

 

           glShadeModel().

 

     Ø   __________________________initialized the window size 

 

             glutInitWindowSize()

 

     Ø   __________________________initializes the window position

 

             glutInitWindowPosition()

 

¢  The glFrustrum() function takes the following parameters

 

      Ø    ________________left

   

      Ø  _________________right

 

      Ø     ________________bottom

 

      Ø    ________________top

 

      Ø      ________________near

 

      Ø   ________________far

 

 ¢  What is the difference between a perspective an an orthographic projection?

 

A perspective projection presents the object as it appears, with items in the distance appearing smaller. An orthographic projections keeps original dimensions.

 

 ¢  Fill in the blanks

 

     Ø  The human eye perceives color when certain cells in the retina, called 

          _______________ become excited after being struck by photons.  Cone cells or cones

 

     Ø  The A in RGBA stands for ________________________ alpha, the transparency

 

     Ø  With ________________________________ display mode, OpenGL uses a lookup table.  color-index

 

¢  What does GLUT stand for?  Graphics Library Utility Toolkit

 

¢  What does GLU stand for?   OpenGl Utility Library

 

¢  We refer to the OpenGL API. What does API stand for? 

 

             Application Programming Interface

 

¢  OpenGL was originally developed by ___________________________________ (name of company)  Silicon Graphics

 

¢  What is accomplished by the viewing transformation?

 

     Positions and aims the camera.

 

¢  What is the purpose of the projection transformation?

 

     Defines the viewing volumn and clipping planes.

 

¢  Place code between the begin and end statements below that will draw a polygon with 5 sides. Do not specify a color

 

     glBegin(GL_POLYGON);

 

            glVertex2f(0.0, 0.0);

            glVertex2f(2.0, 3.0);

            glVertex2f(6.0, 3.0);

            glVertex2f(6.0, 2.0);

            glVertex2f(3.0, 0.0);

 

      glEnd();

 

¢  Display lists improve performance because

 

You can use them to store OpenGL commands for later use. Calculations performed only once. A display list is precompiled after it is created. Geometric calculations are made only once.

 

¢  Define ambient light

 

The ambient component is the light from that source that's been scattered so much by the environment that its direction is impossible to determine - it seems to come from all directions. Backlighting in a room has a large ambient component, since most of the light that reaches your eye has bounced off many surfaces first. A spotlight outdoors has a tiny ambient component; most of the light travels in the same direction, and since you're outdoors, very little of the light reaches your eye after bouncing off other objects. When ambient light strikes a surface, it's scattered equally in all directions.

 

¢  Define diffuse light

 

Diffuse light comes from one direction, so it's brighter if it comes squarely down on a surface than if it barely glances off the surface. Once it hits a surface, however, it's scattered equally in all directions, so it appears equally bright, no matter where the eye is located. Any light coming from a particular position or direction probably has a diffuse component.

 

¢  Define emissive light

 

Materials may have an emissive color, which simulates light originating from an object. The emissive color of a surface adds intensity to the object, but is unaffected by any light sources. Also, the emissive color does not introduce any additional light into the overall scene.

 

¢  Explain the difference between methods for treating RGB for light versus for materials

 

For light, the numbers correspond to a percentage of full intensity for each color. For materials, the numbers correspond to the reflected proportions of those colors.

 

¢  The function glLight () takes 3 parameters. List and describe each.

 

     Ø    Light: identifies the light source.

 

     Ø    Pname: defines the characteristic of the light being set.

 

     Ø    Param: indicates the values to which pname characteristic is set

 

 

¢  Give code that will set the last parameter in the function glLight()

 

light_ambient [] = {0.0, 0.0, 0.0, 1.0}

 

¢  Describe a directional light source and give an example.

 

One that is located infinitely far away from the scene. The effect of an infinite location is that the rays of light can be considered parallel by the time they reach an object.

An example is the sun.

 

¢  Describe a positional light source and give an example.

 

A light source that is nearer to the scene; its exact position within the scene determines the effect it has on a scene, and, specifically, the direction from which the light rays come.

An example is a desk lamp.

 

In the space following each line of code (the applicable line is indicated with Ø) below, explain what the line of code does. Use the back if necessary  and indicate which line is being addressed. Explain what the function does and the meaning of any parameters. Note that not all functions are provided.

 

void init(void)

{

   Ø  GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };

 

   Sets the effect that the material has on reflected light. Numbers are red, green,

   blue, and alpha. Float means the numbers have decimals.     

 

  Ø  GLfloat mat_shininess[] = { 50.0 };

 

Controls the size and brightness of the highlight. Can assign numbers in range 0.0 to 128.0.   The higher the number, the smaller and brighter (more focused) the highlight.

 

 Ø  glShadeModel (GL_SMOOTH);

 

  Sets the shading model, parameters can be GL_SMOOTH or GL_FLAT

  

void display(void)

{

  Ø  glutSolidSphere (1.0, 20, 16);       

 

   Draws a solid sphere with radius 1.0, 20 slices, and 16 stacks.

 

  Ø  glFlush ();

 

   Forces previously issued OpenGL commands to start executing.

 

}

 

¢  When using Microsoft Windows routines On C++ compilers, the following 2 lines must be added to the code – typically in the OpenGL implementation file. Why are these 2 lines added?

 

#pragma comment(lib, “opengl32.lib”)

#pragma comment(lib, “glu32.lib”)

 

To link the OpenGL library files to the project.

 

¢  When using Microsoft Windows routines (in lieu of GLUT) we typically break the program into at least 3 files. Briefly describe these 3 files.

 

     Ø  File 1

 

Class containing Windows procedures and the main function

 

     Ø  File 2

 

The header file for OpenGL procedures

 

     Ø  File 3

 

The implementation file for OpenGL procedures