|

OpenGL/ FPC - Chapter 9 - by Delax
Now that we know the Depth Functions, we can start to build our own 3D objects. Actually this is very simple as an object is composed of primitives. So we use triangles, quads etc to build more complex 3D objects.
Let's take a pyramid for example. A pyramid is composed out of 4 triangles and one quad. 4 triangles as front, left, back and right and the quad as bottom.
glBegin( GL_TRIANGLES );
glColor3f(1.0,0.0,0.0);
glVertex3f( 0.0, 1.0, 0.0);
glVertex3f(-1.0,-1.0, 1.0);
glVertex3f( 1.0,-1.0, 1.0);
glColor3f(0.0,1.0,0.0);
glVertex3f( 0.0, 1.0, 0.0);
glVertex3f( 1.0,-1.0, 1.0);
glVertex3f( 1.0,-1.0, -1.0);
glColor3f(0.0,0.0,1.0);
glVertex3f( 0.0, 1.0, 0.0);
glVertex3f( 1.0,-1.0, -1.0);
glVertex3f(-1.0,-1.0, -1.0);
glColor3f(1.0,1.0,0.0);
glVertex3f( 0.0, 1.0, 0.0);
glVertex3f(-1.0,-1.0,-1.0);
glVertex3f(-1.0,-1.0, 1.0);
glEnd();
glBegin( GL_QUADS );
glColor3f(1.0,0.0,1.0);
glVertex3f( 1.0,-1.0,-1.0);
glVertex3f( 1.0,-1.0, 1.0);
glVertex3f(-1.0,-1.0, 1.0);
glVertex3f(-1.0,-1.0,-1.0);
glEnd();
Get the source code here.
Not that complicated, is it? About every object can be composed out of these simple primitives. But as I mentioned before: you have to look out in what direction your surfaces are pointing (clockwise or counter clockwise).
Try to build a cube for yourself. Or how about a simple house? Fool around a bit and get comfortable with building something in a 3D space.
Delax/ Sundancer Inc.
[delax@sundancerinc.de]
Back to previous page
|