0% found this document useful (0 votes)
117 views

7 Opengl Primitives

Primitives are basic building blocks for graphics in OpenGL and include points, lines, line strips, triangles, triangle strips and polygons. They are defined using glBegin and glEnd along with glVertex calls to specify vertices. Vertices can include coordinates as well as colors, normals and texture coordinates. Common primitive types are rendered through examples.

Uploaded by

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

7 Opengl Primitives

Primitives are basic building blocks for graphics in OpenGL and include points, lines, line strips, triangles, triangle strips and polygons. They are defined using glBegin and glEnd along with glVertex calls to specify vertices. Vertices can include coordinates as well as colors, normals and texture coordinates. Common primitive types are rendered through examples.

Uploaded by

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

Primitives in OpenGL

• Primitives are “basic building blocks” for


graphics in OpenGL.
• Some primitive types
– GL_POINTS
– GL_LINES (Used in Lab 1!)
– GL_LINESTRIP
– GL_TRIANGLES
– GL_QUADS
– GL_POLYGON
Complex shapes can
be built by using many primitives!
Primitives in OpenGL

•Primitive defining statements all starts with


glBegin(<primitive_type>) and ends with glEnd()‫‏‬
•Vertices are defined using glVertex*()
•where * can be 2f, 2d, 3f, 3d, ...
•Ex.: void glVertex2f( GLfloat vx, GLfloat vy );
•glVertex2fv(GLfloat *v) (pointer to array)
•GLfloat typedefined as float (32 bit)
•GLdouble typedefined as double (64 bit)
•Colors, normals, texture coordinates can be
specified for each vertex
Primitives in OpenGL
Primitives in OpenGL
Primitives in OpenGL
GL_LINES

glBegin(GL_LINES);
glVertex2f(-0.5,-0.5); // 1
glVertex2f( 0.5,-0.5); // 2
glVertex2f( 0.5, 0.5); // 3
glVertex2f(-0.5, 0.5); // 4
glEnd();
GL_LINE_STRIP

glBegin(GL_LINE_STRIP);
glVertex2f(-0.5,-0.5); // 1
glVertex2f( 0.5,-0.5); // 2
glVertex2f( 0.5, 0.5); // 3
glVertex2f(-0.5, 0.5); // 4
glEnd();
GL_LINE_LOOP

glBegin(GL_LINE_LOOP);
glVertex2f(-0.5,-0.5); // 1
glVertex2f( 0.5,-0.5); // 2
glVertex2f( 0.5, 0.5); // 3
glVertex2f(-0.5, 0.5); // 4
glEnd();
GL_TRIANGLES

glBegin(GL_TRIANGLES);
glVertex3f(-0.5,-0.5,0.0); // 1
glVertex3f(0.5,-0.5,0.0); // 2
glVertex3f(0.25, 0.5,0.0); // 3
glVertex3f(-0.5, 1.25, 0.0); // 4
glVertex3f(0.5, 1.25, 0.0); // 5
glVertex3f(0.25, 0.75, 0.0); // 6
glEnd();
GL_TRIANGLE_STRIP

glBegin(GL_TRIANGLE_STRIP);
glVertex3f(-0.5,-0.5,0.0); // 1
glVertex3f(0.5,-0.5,0.0); // 2
glVertex3f(0.25, 0.5,0.0); // 3
glVertex3f(0.5, 0.75, 0.0); // 4
glEnd();

You might also like