You Like My Tutorials? Click The Banner To Keep 'Em Coming!

glGameDeveloper(): The Game Developer's Source for OpenGL Coding
Main Menu
Latest News
Archived News
Tutorials
Links
E-Mail Me

Other
Message Board
My Guestbook

Tutorials -- Drawing and Coloring Primitives
 


Drawing and Coloring Primitives in OpenGL Page 2 of 3
< Previous Jump to Page: 1 | 2 | 3 Next >

Drawing a 3D Primitive

Now we'll turn our flat triangle into a pyramid shape. Take out the lines that drew the previous polygon (but keep the glTranslate and glRotate lines). Then copy and paste these lines in. Then move on to the next page.

glBegin(GL_POLYGON);
	glNormal3f( 1, 0, 0);
	
	// top vertex
	glColor4f(1, 0, 0, 1);	glVertex3f( 0,  1,  0);
	// bottom left vertex
	glColor4f(0, 1, 0, 1);	glVertex3f(-1, -1,  1);
	// bottom right vertex
	glColor4f(0, 0, 1, 1);	glVertex3f( 1, -1,  1);
glEnd();

glBegin(GL_POLYGON);
	glNormal3f( 1, 0, 0);
	
	// top vertex
	glColor4f(1, 0, 0, 1);	glVertex3f( 0,  1,  0);
	// bottom left vertex
	glColor4f(0, 1, 0, 1);	glVertex3f( 1, -1, -1);
	// bottom right vertex
	glColor4f(0, 0, 1, 1);	glVertex3f( 1, -1,  1);
glEnd();

glBegin(GL_POLYGON);
	glNormal3f( 1, 0, 0);
	
	// top vertex
	glColor4f(1, 0, 0, 1);	glVertex3f( 0,  1,  0);
	// bottom left vertex
	glColor4f(0, 1, 0, 1);	glVertex3f( 1, -1, -1);
	// bottom right vertex
	glColor4f(0, 0, 1, 1);	glVertex3f(-1, -1, -1);
glEnd();

glBegin(GL_POLYGON);
	glNormal3f( 1, 0, 0);
	
	// top vertex
	glColor4f(1, 0, 0, 1);	glVertex3f( 0,  1,  0);
	// bottom left vertex
	glColor4f(0, 1, 0, 1);	glVertex3f(-1, -1,  1);
	// bottom right vertex
	glColor4f(0, 0, 1, 1);	glVertex3f(-1, -1, -1);
glEnd();


// bottom square polygon
glBegin(GL_POLYGON);
	glNormal3f( 1, 0, 0);
	
	glColor4f(0, 0, 1, 1);	glVertex3f( 1, -1,  1);
	glColor4f(0, 1, 0, 1);	glVertex3f(-1, -1,  1);
	glColor4f(0, 0, 1, 1);	glVertex3f(-1, -1, -1);
	glColor4f(0, 1, 0, 1);	glVertex3f( 1, -1, -1);
glEnd();

Move on to the next page to continue.

Drawing and Coloring Primitives in OpenGL Page 2 of 3
< Previous Jump to Page: 1 | 2 | 3 Next >

This site best viewed with MS Internet Explorer 5.0 at 16-bit color and at least 800x600.

All Contents of this site are Copyright 1999, 2000 Joe Zimmerman. No part of this site (code, HTML, etc.) may be reproduced without my permission.

Click Here!