Seriously puzzeling.

I’m trying to write my firs, small and very simple graphics engine. I’m writing
it in c++ using OpenGL and GLUT on Linux.

Following is the function that has brought me some trouble:

void SGtriangle: :Draw()
{
/*
glBegin(GL_POLYGON);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(1.0f,-1.0f, 0.0f);
glEnd();
*/

glBegin(GL_POLYGON);
glColor4f((GLfloat) colors[0].r, (GLfloat) colors[0].g, (GLfloat) colors[0].b, (GLfloat) colors[ glVertex3d((GLdouble) vertices[0].x, (GLdouble) vertices[0].y, (GLdouble) vertices[0].z);
glColor4f((GLfloat) colors[1].r, (GLfloat) colors[1].g, (GLfloat) colors[1].b, (GLfloat) colors[1].a);
glVertex3d((GLdouble) vertices[1].x, (GLdouble) vertices[1].y, (GLdouble) vertices[1].z);
glColor4f((GLfloat) colors[2].r, (GLfloat) colors[2].g, (GLfloat) colors[2].b, (GLfloat) colors[2].a);
glVertex3d((GLdouble) vertices[2].x, (GLdouble) vertices[2].y, (GLdouble) vertices[2].z);
glEnd();

if(glGetError() == GL_NO_ERROR)
{
cerr << "Polygon drawn.
";
}
}

This is a member function of the following class:

class SGtriangle
{
vertex vertices[3];0].a);
color colors[3];
public:
void Draw();
SGtriangle();
SGtriangle(vertex pos1, vertex pos2, vertex pos3, color col);
SGtriangle(vertex pos1, vertex pos2, vertex pos3, color col1, color col2, color col3);
SGtriangle(const SGtriangle& tri);
};

struct vertex is typedef according to struct point which follows:
struct point
{
double x, y, z;
point(double px = 0, double py = 0, double pz = 0) : x(px), y(py), z(pz) { }
inline point(point& copy) : x(copy.x), y(copy.y), z(copy.z) { }
};

struct color is almost the same, just swap x, y, z with r, g, b, a.

The concerning function, SGtriangle: :Draw(), doesn’t do what I would expect it to do. In my program it is being called as follows:

Internal glut function calls --> the draw function which do all translation, rotation and then calls SGtriangle: :Draw() which is taken from vector<SGtriangle*>
–> following SGtriangle: :Draw() is called.

The problem is; I can’t see the calling SGtriangle. (Identical to the hardcoded.) This has brought me much head trouble because I know it’s right. I have checked and all concerning parameters (color, coordinates …) are right. And the function gets called, at the right time, every time in correct order. And as if that isn’t enough, the hardcoded triangle will, when uncommented, show up, also confirming that there is no translation or rotation error. The function will also, always, print ‘Polygon drawn.’ to the cerr stream, confirming that OpenGL didn’t
report any errors.

Please help. I just want to make this function work and I’m out of ideas. I’ve tried hundreds of things, but nothing - except the hardcoded stuff - shows up in
my program. I’ve left my last attempt in the code, but casting didn’t make a difference (nor should it).

[This message has been edited by jonkje (edited 03-31-2002).]

If the hardcoded triangle works, and the other doesn’t, then probably your values are incorrect. Use your debugger to see.

PS: Why use GL_POLYGON instead of GL_TRIANGLES?

V-man

Oops! Turns out that one of the corners got corruped another place in my code. Guess I didn’t check those values good enough.

[This message has been edited by jonkje (edited 04-01-2002).]

Check your alpha values. Zero means fully transparent, 1.0 is fully opaque. That should only matter if you have blending activated. That’s the only difference I can see.

BTW, you can probably also use the glVertex3dv and glColor4fv funtions.