1. glOrtho
The glOrtho function describes a perspective matrix that produces a
parallel projection. The (left, bottom, near) and (right, top, near)
parameters specify the points on the near clipping plane that are mapped
to the lower-left and upper-rightcorners of the window, respectively,
assuming that the eye is located at (0, 0, 0). The far parameter specifies the
location of the far clipping plane. Both the near and the far can be either
positive or negative.
Because OpenGL uses matrices to set up all its transformations, thecall to
gluOrtho2D() mustbepreceded by two setup functions:
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); //toreset the matrix
World Window
The space in which objects are described is called world coordinates (the
numbers used for x and y are those in the world, wherethe objects are
defined).
World coordinates use the Cartesian xy-coordinatesystemused in
mathematics, based on whatever units are convenient.
We define a rectangular worldwindow in these world coordinates.
The world window specifies which part of the world should be drawn:
whichever part lies inside the window should be drawn, and whichever part
lies outside should be clipped away and not drawn.
OpenGL does the clipping automatically.
The function setWindow sets the world window size:
void setWindow(GLdoubleleft, GLdouble right, GLdouble bottom, GLdouble
top)
{
glMatrixMode(GL_PROJECTION);
o glLoadIdentity();
o gluOrtho2D(left, right, bottom, top);
}
2. Viewport
In addition, we define a rectangular viewport in the screen window on the
display.
A mapping (consisting of scalings [changesize] and translations [move
object]) between the world window and the viewportis established by
OpenGL.
The objects inside the world window appear automatically at proper sizes
and locations inside the viewport(in screencoordinates, which arepixel
coordinates on the display).
void setViewport(GLintleft, GLint right, GLint bottom, GLint top)
{
glViewport(left, bottom, right - left, top - bottom);
}
Calls: setWindow(-5.0,5.0, -0.3, 1.0);
o setViewport(0, 640, 0, 480);
In myInit();
We use natural coordinates for whatwe are drawing (the world window).
OpenGL converts our coordinates to screen coordinates when we set up a
screen window and a viewport. The viewportmay be smaller than the
screen window. The default viewportis the entire screen window.
The conversion requires scaling and shifting: mapping the world window to
the screen window and the viewport.
Windows aredescribed by their left, top, right, and bottom values,
w.l,
w.t,
w.r,
w.b.
Viewports aredescribed by the samevalues but in screen window
coordinates.
v.l,
v.t,
v.r,
v.b,
3. glMatrixMode
Specify which matrix is the current matrix
C Specification
void glMatrixMode( GLenum mode);
Parameters
Mode specifies which matrix stack is the target for subsequent matrix
operations. Three values are accepted:
GL_MODELVIEW,
GL_PROJECTION,and
GL_TEXTURE.
The initial value is GL_MODELVIEW.Additionally, if
the ARB_imaging extension is supported, GL_COLOR is also accepted.
Description
glMatrixMode sets the current matrix mode.
mode can assume one of four values:
GL_MODELVIEW applies subsequent matrix operations to the modelview
matrix stack.
GL_PROJECTION applies subsequent matrix operations to the projection
matrix stack.
GL_TEXTURE applies subsequent matrix operations to the texture matrix
stack.
GL_COLOR applies subsequent matrix operations to the color matrix stack.
glRotate
Multiply the current matrix by a rotation matrix
C Specification
void glRotated( GLdouble angle,
GLdouble x,
GLdouble y,
GLdouble z);
4. void glRotatef( GLfloat angle,
GLfloat x,
GLfloat y,
GLfloat z);
Parameters
Angle specifies the angle of rotation, in degrees.
x, y, z specify the x, y, and z coordinates of a vector, respectively.
Description
glRotate produces a rotation of angle degrees around the vector x y z .
The current matrix (see glMatrixMode) is multiplied by a rotation matrix
with the product replacing the current matrix, as if glMultMatrix were
called with the following matrix as its argument:
x 2 1 - c + c x y 1 - c - z s x z 1 - c + y s 0 y x 1 - c
+ z s y 2 1 - c + c y z 1 - c - x s 0 x z 1 - c - y s y z
1 - c + x s z 2 1 - c + c 0 0 0 0 1
Where c = cos angle , s = sin angle , and x y z = 1 (if not, the GL
will normalize this vector).
If the matrix mode is either GL_MODELVIEW or GL_PROJECTION,all objects
drawn after glRotate is called are rotated.
Use glPushMatrix and glPopMatrix to save and restore the unrotated
coordinate system.
Notes
This rotation follows the right-hand rule, so if the vector x y z points
toward the user, the rotation will be counterclockwise.
glTranslate
Multiply the current matrix by a translation matrix
C Specification
void glTranslated(GLdouble x,
GLdouble y,
5. GLdouble z);
void glTranslatef(GLfloat x,
GLfloat y,
GLfloat z);
Parameters
x, y, z specify the x, y, and z coordinates of a translation vector.
Description
glTranslate produces a translation by x y z . The current matrix is
multiplied by this translation matrix, with the product replacing the
current matrix, as if glMultMatrixc were called with the following
matrix for its argument:
1 0 0 x 0 1 0 y 0 0 1 z 0 0 0 1
If the matrix mode is either GL_MODELVIEW or GL_PROJECTION,all
objects drawn after a call to glTranslate are translated.
Use glPushMatrix and glPopMatrix to save and restore the untranslated
coordinate system.
glScale
Multiply the current matrix by a general scaling matrix
C Specification
void glScaled(GLdouble x,
GLdouble y,
GLdouble z);
void glScalef(GLfloat x,
GLfloat y,
GLfloat z);
Parameters
x, y, z specify scale factors along the x, y, and z axes, respectively.
Description
6. glScale produces a non-uniform scaling along the x, y, and z axes. The
three parameters indicate the desired scale factor along each of the three
axes.
The current matrix is multiplied by this scale matrix, and the product
replaces the current matrix.
If the matrix mode is either GL_MODELVIEW or GL_PROJECTION,all
objects drawn after glScale is called are scaled.
Use glPushMatrix and glPopMatrix to save and restore the unscaled
coordinate system.
Notes
If scale factors other than 1 are applied to the modelview matrix and
lighting is enabled, lighting often appears wrong. In that case, enable
automatic normalization of normals by calling glEnable with the
argument GL_NORMALIZE.
glutSolidSphere,glutWireSphere
glutSolidSphere and glutWireSphere render a solid or wireframe
sphere respectively.
Usage
void glutSolidSphere(GLdouble radius,
GLint slices, GLint stacks);
void glutWireSphere(GLdouble radius,
GLint slices, GLint stacks);
Parameters
Radius the radius of the sphere.
Slices the number of subdivisions around the Z axis (similar to lines of
longitude).
Stacks the number of subdivisions along the Z axis (similar to lines of
latitude).
Description
Renders a sphere centered at the modeling coordinates origin of the
specified radius.The sphere is subdivided around the Z axis into slices
and along the Z axis into stacks.
glutSolidCube, glutWireCube
7. glutSolidCube and glutWireCube render a solid or wireframe cube
respectively.
Usage
void glutSolidCube(GLdoublesize);
void glutWireCube(GLdoublesize);
Description
glutSolidCube and glutWireCube render a solid or wireframe cube
respectively. The cube is centered at the modeling coordinates origin
with sides of length size.
glutSolidCone, glutWireCone
glutSolidCone and glutWireCone render a solid or wireframe cone
respectively.
Usage
void glutSolidCone(GLdouble base, GLdouble height,
GLint slices, GLint stacks);
void glutWireCone(GLdouble base, GLdouble height,
GLint slices, GLint stacks);
Parameters
Base the radius of the base of the cone.
Height the height of the cone.
Slices the number of subdivisions around the Z axis.
Stacks the number of subdivisions along the Z axis.
Description
glutSolidCone and glutWireCone render a solid or wireframe cone
respectively oriented along the Z axis. The base of the cone is placed at
Z = 0, and the top at Z = height.The cone is subdivided around the Z
axis into slices, and along the Z axis into stacks.
glutSolidTorus, glutWireTorus
glutSolidTorus and glutWireTorus render a solid or wireframe torus
(doughnut) respectively.
Usage
void glutSolidTorus(GLdouble innerRadius,
GLdouble outerRadius,
GLint nsides, GLint rings);
void glutWireTorus(GLdouble innerRadius,
8. GLdouble outerRadius,
GLint nsides, GLint rings);
InnerRadius inner radius of the torus.
OuterRadius outer radius of the torus.
Nsides number of sides for each radial section.
Rings number of radial divisions for the torus.
Description
glutSolidTorus and glutWireTorus render a solid or wireframe torus
(doughnut) respectively centered at the modeling coordinates origin
whose axis is aligned with the Z axis.
glColor3f function
Sets the current color.
Syntax
void glColor3f(
GLfloat red,
GLfloat green,
GLfloat blue
);
Parameters
Red the new red value for the current color.
Green the new green value for the current color.
Blue the new blue value for the current color.
Returnvalue this function does not return a value.
glutCreateMenu
Creates a new pop-up menu.
Usage
int glutCreateMenu(void (*func)(int value));
Parameters
Func the callback function for the menu that is called when a menu entry
from the menu is selected. The value passed to the callback is
determined by the value for the selected menu entry.
Description
9. glutCreateMenu creates a new pop-up menu and returns a unique small integer
identifier. The rangeof allocated identifiers starts at one. The menu identifier
range is separate fromthe window identifier range. Implicitly, the currentmenu is
set to the newly created menu. This menu identifier can be used when
calling glutSetMenu.
When the menu callback is called becausea menu entry is selected for the menu,
the currentmenu willbe implicitly set to the menu with the selected entry before
the callback is made.