opengl basic functions
TRANSCRIPT
-
8/9/2019 OpenGL Basic Functions
1/21
Simple OpenGLSimple OpenGL
FunctionsFunctions
-
8/9/2019 OpenGL Basic Functions
2/21
Outline
Todaydrawing lines, polygons, etc
setting colors,clearing the screen
Next Class
skeleton of an applicationcompiling OpenGL
simple movement
-
8/9/2019 OpenGL Basic Functions
3/21
OpenGL Libraries
gl - opengl
glut - windowing functions
glu - common objects and procedures
glux - interface to X for glut
-
8/9/2019 OpenGL Basic Functions
4/21
command format
glVertex3f (1.0, 0.25, 0.333);
gl library first letter of a function is always small
specify a point first letter of command is always capitalied
! parameters parameters types are floats
see parameter types on next page
-
8/9/2019 OpenGL Basic Functions
5/21
"arameter #ypes
b $-bit integer GLbyte
s %&-bit integer GLshort
i !'-bit integer GLintf !'-bit float GLfloat
d &(-bit float GLdouble
ub $-bit unsigned int GLubyte
us %&-bit unsigned int GLushort
ui!'-bit unsigned int GLuint
-
8/9/2019 OpenGL Basic Functions
6/21
example
#o set the drawing color to blue
glColor3f ( 0.0, 0.0, 1.0 );
or
GLfloat blue[] = {0.0, 0.0, 1.0};
glColor3fv (blue);
-
8/9/2019 OpenGL Basic Functions
7/21
)learing the *creen
glClearColor ( R, G, , ! )
glClear (GL"C#L#R"$%%&R"')
to clear to black, use RGBA values of 0.0
later in the semester, you will also need to clear the Depth
Buffer along with the olor Buffer
-
8/9/2019 OpenGL Basic Functions
8/21
+rawing *tuff
gleg* ( drawing mode );
glVertex...
glVertex...
...gl&*+();
odesGL"#'-
GL"#L/G#-GL"L'-& GL"L'-&"R' GL"L'-&"L##
GL"R'!-GL& GL"R'!-GL&"R' "%!-
GL"$! GL"G$!"R'
-
8/9/2019 OpenGL Basic Functions
9/21
example - drawing lines
Given four points "., "%, "', and "!
GL/L012* GL/L012/*#30" GL/L012/LOO"
". "%
"! "'
-
8/9/2019 OpenGL Basic Functions
10/21
example - #riangles
%
.
'
!
(
4
-
8/9/2019 OpenGL Basic Functions
11/21
example - #riangle *trip
.
!
4
(
% '
-
8/9/2019 OpenGL Basic Functions
12/21
example - #riangle 5ans
%
.
'
!
(
4
-
8/9/2019 OpenGL Basic Functions
13/21
6now your Limitations
Don't try to draw this star as a single polygon is "! inside the star or outside7
is "., "%, "' going clockwise or counterclockwise7
".
"%
"'
"!
-
8/9/2019 OpenGL Basic Functions
14/21
)olor 0nterpolation
gleg* (GL"L'-&)
glColor3f (1.0,0.0,0.0); re+
gl4erte2f(1.0,0.0);
glColor3f (1.0,1.0,0.0); 6ello7 gl4erte2f(0.0,1.0);
gl&*+();
8e get a line that starts out red and turns yellowassuming we left the default as gl8a+e9o+el (GL"9##:) instead of GL"%L!
-
8/9/2019 OpenGL Basic Functions
15/21
Line "roperties
Changing the width glL*e+t8 (float)
default is %9. Creating dashed and dotted lines gl&*able (GL"L'-&"'L&)
gltor,
-
8/9/2019 OpenGL Basic Functions
16/21
"olygon "roperties
Fill Pattern gl&*able (GL"#L/G#-"'L&)
glol6go*tle ( ?a
-
8/9/2019 OpenGL Basic Functions
17/21
5lushing
8hen you are done, don>t forget to flush
gl%lu
-
8/9/2019 OpenGL Basic Functions
18/21
bigger example
creating a cone ?ow can 0 create a @smooth@ cone7
use a triangle fan with lots of triangles
-
8/9/2019 OpenGL Basic Functions
19/21
!" !" !#
!" !" $%!#
x" y" $%!#x" y" $%!#
So" how do we compute a &unch o (alues or x and y)
-
8/9/2019 OpenGL Basic Functions
20/21
*
+Given that2 B 62 = r2
then
62 = r2 2
y = sqrt (r2 - x2)
*o, we run a loop where x changes, and compute the y valueA 5or example, with r B '., and x B %., then y B %C
6 =
-
8/9/2019 OpenGL Basic Functions
21/21
gleg* (GL"R'!-GL&"%!-);
glColor3f (1.0, 0.0, 0.0);
gl4erte3f (0.0,0.0,0.0); glColor3f (0.0, 1.0, 1.0);
ra+u< = 20
for (=20; =20; =5)
{
6 =