OpenGL Basic Functions
OpenGL Basic Functions
Functions
Outline
Today
drawing
Next Class
skeleton
of an application
compiling OpenGL
simple movement
OpenGL Libraries
gl
glut
glu
glux
- opengl
- windowing functions
- common objects and procedures
- interface to X for glut
command format
glVertex3f (1.0, 0.25, 0.333);
gl library
specify a point
3 parameters
parameters types are floats
Parameter Types
b 8-bit integer
s 16-bit integer
i 32-bit integer
f 32-bit float
d 64-bit float
ub
8-bit unsigned int
us
16-bit unsigned int
ui32-bit unsigned int
GLbyte
GLshort
GLint
GLfloat
GLdouble
GLubyte
GLushort
GLuint
example
To set the drawing color to blue
glColor3f ( 0.0, 0.0, 1.0 );
or
GLfloat blue[] = {0.0, 0.0, 1.0};
glColor3fv (blue);
Depth
Drawing Stuff
glBegin ( drawing mode );
glVertex...
glVertex...
...
glEnd();
Modes:
GL_POINTS
GL_POLYGON
GL_LINES
GL_TRIANGLES
GL_QUADS
GL_LINE_STRIP
GL_LINE_LOOP
GL_TRIANGLE_STRIP _FAN
GL_GUAD_STRIP
P1
P3
P2
GL_LINES
GL_LINE_STRIP
GL_LINE_LOOP
example - Triangles
1
2
3
0
4
5
2
3
0
4
5
2
3
0
4
5
P0
P3
P2
P1
Color Interpolation
glBegin (GL_LINES)
glColor3f (1.0,0.0,0.0);
glVertex2f(1.0,0.0);
glColor3f (1.0,1.0,0.0);
glVertex2f(0.0,1.0);
glEnd();
// red
// yellow
glShadeModel
(GL_SMOOTH)
instead of GL_FLAT
Line Properties
glLineWidth (float)
default is 1.0
glEnable (GL_LINE_STIPPLE)
glDisable ()
glLineStipple (int factor,short pattern)
(1, 0xAAAA) yields - - - - - - - (2, 0xAAAA) yields -- -- -- -
Polygon Properties
Fill Pattern
glEnable (GL_POLYGON_STIPPLE)
glPolygonStipple ( mask );
GLubyte mask[] = {0x00, 0x03,
mask is 32x32 bitmap
Polygon Outline
glPolygonMode
(GL_FRONT_AND_BACK, GL_LINE)
default is GL_FILL
note that you can make the front filled while the back is outlined!!!
Flushing
non-blocking function
glFinish();
blocking function
bigger example:
creating a cone
(0, 0, 0)
(0, 0, -30)
(x, y, -30)
(x, y, -30)
View of the
cone from above,
looking down the z axis
X
Y
Given that
x2 + y2 = r2
then
y2 = r2 - x2
y = sqrt (r2 - x2)
glBegin (GL_TRIANGLE_FAN);
glColor3f (1.0, 0.0, 0.0);
glVertex3f (0.0,0.0,0.0);
glColor3f (0.0, 1.0, 1.0);
// radius = 20
for (x=20; x>=-20; x-=5)
{
y = sqrt (400 - (x*x));
glVertex3f(x, y, -30);
}
for (x=-20; x<=20; x+=5)
{
y = sqrt (400 - (x*x));
glVertex3f(x, 0-y, -30);
}
glEnd();