lec 12 opengl primitives
TRANSCRIPT
-
7/25/2019 Lec 12 OpenGL Primitives
1/16
OpenGL Primitives
Instructor: Marryam Murtaza
-
7/25/2019 Lec 12 OpenGL Primitives
2/16
The ten glBegin-style OpenGL Primitives
Points (1 primitive) GL_POINTS
Polylines (3 primitives) GL_LINES GL_LINE_STRIP
GL_LINE_LOOP
OpenGL Primitives
Filled Polygons (6primitives) Triangles
GL_TRIANGLES GL_TRIANGLE_STRIP
GL_TRIANGLE_FAN
Quadrilaterals
GL_QUADS GL_QUAD_STRIP
General Polygons GL_POLYGON
-
7/25/2019 Lec 12 OpenGL Primitives
3/16
A primitive is given a number of vertices speci!e" #ithglVertex$% &o# #e loo' at #hat the primitives "o #ith thevertices they are given%
&umbers in"icate verte( or"ering%
)lueob*ects mar' #hat is actually ren"ere"%
Points GL_POINTS
Attribtes
glPoint+ize,%$.
OpenGL Primitives: Points
/
0,1
23
-
7/25/2019 Lec 12 OpenGL Primitives
4/16
Polylines GL_LINES
GL_LINE_STRIP
GL_LINE_LOOP
OpenGL Primitives: Polylines
/
0,1
23
3
3
/
0,1
2
/
0,1
2
-
7/25/2019 Lec 12 OpenGL Primitives
5/16
4olor5 thic'ness5 stippling%
/% gl4olor2f$ sets color%
,% glLine6i"th1%$ sets thic'ness% The "efault thic'ness is/%%
2%
glLine+tipple15 7289$.1% glnableGL;LI&;+TIPPL$.
Line Attributes
a$% thin lines b$% thic' lines c$%stipple" lines
it is disabled by passing the same argumentto glDisable()
-
7/25/2019 Lec 12 OpenGL Primitives
6/16
Polygons: Triangles GL_TRIANGLES
4loc'#ise orcountercloc'#ise
"oes not matter yet$%
GL_TRIANGLE_STRIP
GL_TRIANGLE_FAN
OpenGL Primitives:Polygons !riangles
/
0
, 1
2
3
3
/
0
,
12
/
0
, 1
2
3
-
7/25/2019 Lec 12 OpenGL Primitives
7/16
Polygons in OpenGL
Triangles
glBegin(GL_TRIANGLES);
glVertex2fv(p0);
glVertex2fv(p1);
glVertex2fv(p2);
glVertex2fv(p3);
glVertex2fv(p4);
glVertex2fv(p5);
glVertex2fv(p6);
glVertex2fv(p7);
glEnd();
glBegin(GL_TRIANGLES);
glVertex2fv(p0);
glVertex2fv(p1);
glVertex2fv(p2);
glVertex2fv(p3);
glVertex2fv(p4);
glVertex2fv(p5);
glVertex2fv(p6);
glVertex2fv(p7);
glEnd();
p0p1
p2
p3
p4
p5
p6
p7
-
7/25/2019 Lec 12 OpenGL Primitives
8/16
OpenGL: !riangle "trips
An OpenGL triangle stripprimitive re"ucesthis re"un"ancy by sharing vertices:glBegin!GL_TRIANGLE_STRIP"#
glVertex$%&!&'"#
glVertex$%&!&("#glVertex$%&!&)"#
glVertex$%&!&$"#
glVertex$%&!&*"#
glVertex$%&!&+"#
glEn,!"#
v0
v2
v1
v3
v4
v5
triangle is v5 v/5 v,triangle / is v,5 v/5 v2 why not v1, v2, v3?$triangle , is v,5 v25 v1triangle 2 is v15 v25 v0 again5 notv25 v15 v0$
-
7/25/2019 Lec 12 OpenGL Primitives
9/16
OpenGL: !riangle Fan
The GL_TRIANGLE_FANprimitive is another #ay tore"uce verte( re"un"ancy:
v0
v1
v2
v3
v4
v5
v6
-
7/25/2019 Lec 12 OpenGL Primitives
10/16
gl)egin GL;T
-
7/25/2019 Lec 12 OpenGL Primitives
11/16
Polygons
>e!nition Ob*ect that is close" as in a line loop5 but that
has an interior
+imple Polygon &o pair of e"ges of a polygon cross each other
+imple &onsimple
-
7/25/2019 Lec 12 OpenGL Primitives
12/16
Polygons: ?ua"rilaterals
GL_QUADS
4loc'#ise orcountercloc'#ise"oes not matter yet$%
GL_QUAD_STRIP
&ote "i@erences inverte( or"ering
Polygons: General
GL_POLYGON
OpenGL Primitives:Polygons Quad#s$ General
/
0
, 2
1
9
3
/
0
,
1
2
,
B
3
/
0
1
2
B
9
3
-
7/25/2019 Lec 12 OpenGL Primitives
13/16
Polygons in OpenGL
?ua"rilaterals
glBegin(GL_QUADS);
glVertex2fv(p0);
glVertex2fv(p1);
glVertex2fv(p2);
glVertex2fv(p3);
glVertex2fv(p4);
glVertex2fv(p5);
glVertex2fv(p6);
glVertex2fv(p7);
glEnd();
glBegin(GL_QUADS);
glVertex2fv(p0);
glVertex2fv(p1);
glVertex2fv(p2);
glVertex2fv(p3);
glVertex2fv(p4);
glVertex2fv(p5);
glVertex2fv(p6);
glVertex2fv(p7);glEnd();
p0p1
p2
p3
p4
p5
p6
p7
-
7/25/2019 Lec 12 OpenGL Primitives
14/16
Polygons in OpenGL
?ua"strip
glBegin(GL_QUAD_STRIP);
glVertex2fv(p1);
glVertex2fv(p2);
glVertex2fv(p3);
glVertex2fv(p0);
glVertex2fv(p4);
glVertex2fv(p7);
glVertex2fv(p5);
glVertex2fv(p6);
glEnd();
glBegin(GL_QUAD_STRIP);
glVertex2fv(p1);
glVertex2fv(p2);
glVertex2fv(p3);
glVertex2fv(p0);
glVertex2fv(p4);
glVertex2fv(p7);
glVertex2fv(p5);
glVertex2fv(p6);glEnd();
p0p1
p2
p3
p4
p5
p6
p7
-
7/25/2019 Lec 12 OpenGL Primitives
15/16
Polygons in OpenGL
Polygon
glBegin(GL_POLYGON);
glVertex2fv(p0);
glVertex2fv(p1);
glVertex2fv(p2);
glVertex2fv(p3);
glVertex2fv(p4);
glVertex2fv(p5);
glVertex2fv(p6);
glVertex2fv(p7);
glEnd();
glBegin(GL_POLYGON);
glVertex2fv(p0);
glVertex2fv(p1);
glVertex2fv(p2);glVertex2fv(p3);
glVertex2fv(p4);
glVertex2fv(p5);
glVertex2fv(p6);
glVertex2fv(p7);glEnd();
p0p1
p2
p3
p4
p5
p6
p7
-
7/25/2019 Lec 12 OpenGL Primitives
16/16
/% 6hat is the "i@erence bet#een
i% Cua"5
ii% Cua"strip an"
iii% polygons% Implement these using openGL
,% >ra# 1 rectangles using for loop%
Assignment