0% found this document useful (0 votes)
255 views16 pages

Lec 12 OpenGL Primitives

The document discusses the 10 primitive types in OpenGL used to render geometric shapes from vertices. It describes the primitives for points, lines, triangles, quadrilaterals and general polygons. It explains how primitives like triangle strips and fans can reduce vertex redundancy by sharing vertices between shapes. Attributes for color, thickness and stippling are also covered. Examples are provided of rendering shapes with each primitive type using OpenGL calls.

Uploaded by

AliRazaMughal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
255 views16 pages

Lec 12 OpenGL Primitives

The document discusses the 10 primitive types in OpenGL used to render geometric shapes from vertices. It describes the primitives for points, lines, triangles, quadrilaterals and general polygons. It explains how primitives like triangle strips and fans can reduce vertex redundancy by sharing vertices between shapes. Attributes for color, thickness and stippling are also covered. Examples are provided of rendering shapes with each primitive type using OpenGL calls.

Uploaded by

AliRazaMughal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

OpenGL Primitives

Instructor: Marryam Murtaza

OpenGL Primitives

The ten glBegin-style OpenGL Primitives


Points (1 primitive)
GL_POINTS

Polylines (3 primitives)
GL_LINES
GL_LINE_STRIP
GL_LINE_LOOP

Filled Polygons (6
primitives)
Triangles
GL_TRIANGLES
GL_TRIANGLE_STRIP
GL_TRIANGLE_FAN

Quadrilaterals
GL_QUADS
GL_QUAD_STRIP

General Polygons
GL_POLYGON

OpenGL Primitives: Points

A primitive is given a number of vertices (specified with


glVertex). Now we look at what the primitives do with the
vertices they are given.
Numbers indicate vertex ordering.
Blue objects mark what is actually rendered.

Points
GL_POINTS

Attributes
glPointSize(20.0);

6
5

1
4

3
2

OpenGL Primitives: Polylines

Polylines
GL_LINES

6
5

GL_LINE_LOOP

6
5

GL_LINE_STRIP

1
4

3
2

Line Attributes

1.
2.

3.
4.

Color, thickness, stippling.


glColor3f() sets color.
glLineWidth(4.0) sets thickness. The default thickness is
1.0.
glLineStipple(4, 03F07);
glEnable(GL_LINE_STIPPLE);

a). thin lines


stippled lines

b). thick lines

c).

it is disabled by passing the same argument


to glDisable()

OpenGL Primitives:
Polygons Triangles

Polygons: Triangles

GL_TRIANGLES
Clockwise or
counterclockwise
does not matter (yet).

GL_TRIANGLE_STRIP

5
4

2
3

GL_TRIANGLE_FAN

Polygons in OpenGL

Triangles
glBegin(GL_TRIANGLES);
glBegin(GL_TRIANGLES);
glVertex2fv(p0);
glVertex2fv(p0);
glVertex2fv(p1);
glVertex2fv(p1);
glVertex2fv(p2);
glVertex2fv(p2);
glVertex2fv(p3);
glVertex2fv(p3);
glVertex2fv(p4);
glVertex2fv(p4);
glVertex2fv(p5);
glVertex2fv(p5);
glVertex2fv(p6);
glVertex2fv(p6);
glVertex2fv(p7);
glVertex2fv(p7);
glEnd();
glEnd();

p0
p7

p1

p6

p2
p5

p3
p4

OpenGL: Triangle Strips

An OpenGL triangle strip primitive reduces


this redundancy by sharing vertices:
glBegin(GL_TRIANGLE_STRIP);
glVertex3fv(v0);
glVertex3fv(v1);
glVertex3fv(v2);
glVertex3fv(v3);
glVertex3fv(v4);
glVertex3fv(v5);
glEnd();

triangle
triangle
triangle
triangle

0
1
2
3

is
is
is
is

v0,
v2,
v2,
v4,

v2

v0

v4

v5
v1
v3

v1,
v1,
v3,
v3,

v2
v3 (why not v1, v2, v3?)
v4
v5 (again, not v3, v4, v5)

OpenGL: Triangle Fan

The GL_TRIANGLE_FAN primitive is another way to


reduce vertex redundancy:
v4

v3

v5

v0

v2

v6

v1

OpenGL: Triangle Fan


glBegin (GL_TRIANGLE_FAN);

glColor3f (0,.5, 1); glVertex2f ( 150,


50);

glColor3f (1, 0, 0); glVertex2f (10,5);

glColor3f (1, 1, 1); glVertex2f(0,20);

glColor3f (0, 0, 1); glVertex2f ( 20,70);

glColor3f (0, 1, 0); glVertex2f (20,150);

glColor3f (1, 0, 0); glVertex2f (200,200);


glEnd();

Polygons

Definition
Object that is closed as in a line loop, but that
has an interior

Simple Polygon
No pair of edges of a polygon cross each other

Simple

Nonsimple

OpenGL Primitives:
Polygons Quads, General

Polygons: Quadrilaterals

GL_QUADS
Clockwise or
counterclockwise
does not matter (yet).

5
4

GL_QUAD_STRIP
1

Note differences in
vertex ordering!

Polygons: General
GL_POLYGON

2
3

Polygons in OpenGL

Quadrilaterals
glBegin(GL_QUADS);
glBegin(GL_QUADS);
glVertex2fv(p0);
glVertex2fv(p0);
glVertex2fv(p1);
glVertex2fv(p1);
glVertex2fv(p2);
glVertex2fv(p2);
glVertex2fv(p3);
glVertex2fv(p3);
glVertex2fv(p4);
glVertex2fv(p4);
glVertex2fv(p5);
glVertex2fv(p5);
glVertex2fv(p6);
glVertex2fv(p6);
glVertex2fv(p7);
glVertex2fv(p7);
glEnd();
glEnd();

p0
p7

p1

p6

p2
p5

p3
p4

Polygons in OpenGL

Quadstrip
glBegin(GL_QUAD_STRIP);
glBegin(GL_QUAD_STRIP);
glVertex2fv(p1);
glVertex2fv(p1);
glVertex2fv(p2);
glVertex2fv(p2);
glVertex2fv(p3);
glVertex2fv(p3);
glVertex2fv(p0);
glVertex2fv(p0);
glVertex2fv(p4);
glVertex2fv(p4);
glVertex2fv(p7);
glVertex2fv(p7);
glVertex2fv(p5);
glVertex2fv(p5);
glVertex2fv(p6);
glVertex2fv(p6);
glEnd();
glEnd();

p0
p7

p1

p6

p2
p5

p3
p4

Polygons in OpenGL

Polygon
glBegin(GL_POLYGON);
glBegin(GL_POLYGON);
glVertex2fv(p0);
glVertex2fv(p0);
glVertex2fv(p1);
glVertex2fv(p1);
glVertex2fv(p2);
glVertex2fv(p2);
glVertex2fv(p3);
glVertex2fv(p3);
glVertex2fv(p4);
glVertex2fv(p4);
glVertex2fv(p5);
glVertex2fv(p5);
glVertex2fv(p6);
glVertex2fv(p6);
glVertex2fv(p7);
glVertex2fv(p7);
glEnd();
glEnd();

p0
p7

p1

p6

p2
p5

p3
p4

Assignment
1. What is the difference between
i.
quad,
ii.
quadstrip and
iii. polygons.
Implement these using openGL

2. Draw 4 rectangles using for loop.

You might also like