NeHe is where I "learned" how to use OpenGL, what really irks me, is that I wasn't thinking when I wrote my triangle rendering system, and now two years later I an paying for it :doh >:( :x .
anyway this is how I render my triangles:
Code:
void
TRIANGLE::drawgeometry() const
{
// if using triangle's flat normal set it
if ( properties & TRIANGLE_LIT && !( properties & TRIANGLE_VERTEX_NORMALS ) )
{
glNormal3f( normal.x, normal.y, normal.z );
}
if ( !properties & TRIANGLE_COLORED )
{
glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
}
if( properties & TRIANGLE_INVERT_NORMALS )
{
for ( unsigned int a = 3; a > 0; --a )
{
unsigned int i = a % 3;
// the triangle will not be colored if GL_LIGHTING is enabled,
// don't know why.
// set the color
if ( properties & TRIANGLE_COLORED )
{
glColor4f( vertex[ i ].color.r, vertex[ i ].color.g, vertex[ i ].color.b, vertex[ i ].color.a );
}
// light the verticies
if ( properties & TRIANGLE_VERTEX_NORMALS )
{
glNormal3f( vertex[ i ].normal.x, vertex[ i ].normal.y, vertex[ i ].normal.z );
}
// set the verticies' texture coordanates
glTexCoord2f( vertex[ i ].u, vertex[ i ].v );
// set the vertex
glVertex3f( vertex[ i ].x, vertex[ i ].y, vertex[ i ].z );
}
}
else
{
for ( unsigned int i = 0; i < 3; ++i )
{
// the triangle will not be colored if GL_LIGHTING is enabled,
// don't know why.
// set the color
if ( properties & TRIANGLE_COLORED )
{
glColor4f( vertex[ i ].color.r, vertex[ i ].color.g, vertex[ i ].color.b, vertex[ i ].color.a );
}
// light the verticies
if ( properties & TRIANGLE_VERTEX_NORMALS )
{
glNormal3f( vertex[ i ].normal.x, vertex[ i ].normal.y, vertex[ i ].normal.z );
}
// set the verticies' texture coordanates
glTexCoord2f( vertex[ i ].u, vertex[ i ].v );
// set the vertex
glVertex3f( vertex[ i ].x, vertex[ i ].y, vertex[ i ].z );
}
}
if ( properties & TRIANGLE_COLORED )
{
glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
}
}
void
TRIANGLE::draw() const
{
#ifdef OPENGL
// set up the texture to use.
if ( texture && texture->getbase() != (unsigned int)NULL && texture->isbuilt() )
{
texture->set();
}
else
{
IMAGE * nullImage = getNullImage();
if ( nullImage && nullImage->getbase() != (unsigned int)NULL && nullImage->isbuilt() )
{
nullImage->set();
//texture = nullImage;
}
else
{
return;
}
}
bool b_bounding = POGEL::hasproperty( POGEL_BOUNDING );
bool b_wireframe = POGEL::hasproperty( POGEL_WIREFRAME );
//updateVert();
// draw the triangle's bounding box
if ( b_bounding )
{
bounding.draw( POINT() );
}
bool b_lit = this->hasproperty( TRIANGLE_LIT );
bool b_vertnorms = this->hasproperty( TRIANGLE_VERTEX_NORMALS );
bool b_doublesided = this->hasproperty( TRIANGLE_DOUBLESIDED );
bool b_transparent = this->hasproperty( TRIANGLE_TRANSPARENT );
// enable or disable lighting
if ( b_lit || b_vertnorms )
{
glEnable( GL_LIGHTING );
}
else
{
glDisable( GL_LIGHTING );
}
if ( !b_doublesided )
{
glEnable( GL_CULL_FACE );
glCullFace( GL_BACK );
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
}
else if ( glIsEnabled( GL_CULL_FACE ) )
{
glDisable( GL_CULL_FACE );
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
}
// set the transparency
bool blendEnabled = false;
if ( b_transparent )
{
blendEnabled = glIsEnabled( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE );
glEnable( GL_BLEND );
}
// begin either a solid face or lines for wireframe
if ( b_wireframe )
{
glBegin( GL_LINES );
}
else
{
glBegin( GL_TRIANGLES );
}
drawgeometry();
// end GL_TRIANGLES or GL_LINES
glEnd();
// disable the transparency
if ( b_transparent )
{
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
if( !blendEnabled )
{
glDisable( GL_BLEND );
}
}
#endif
}
really inefficient, but robust as h**l, the Idea was that I could just draw a triangle anywhere and not worry about setting anything up, but it is really slow.