Hi,
I’m quite new to opengl so this may be a FAQ but I didn’t find the answer while searching the forum archives (searched for grid and GL_LINES) or the wiki (though the problem might be related to the Polygon Offset thingy).
I want to draw a simple filled polygon (as GL_POLYGON) with the x, y and z axis drawn as lines (as GL_LINES). The polygon lies across the three axis (I mean it is located so that the axis “goes throuh it” (see below)).
The problem I meet is that if I draw the polygon first it looks like it is “behind” the axis lines, and if I draw the axis first, then the polygon sort of completely “masks” them while there should be only parts of the axis lines that should be masked.
Here is the code (a slight extrapolation from one of the first example from the Red Book):
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glLoadIdentity();
gluLookAt(7.0, -10.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
glColor3f(0.0,0.0,1.0);
glBegin(GL_LINES);
glVertex3f(-50.0, 0.0, 0.0);
glVertex3f(50.0, 0.0, 0.0);
glEnd();
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINES);
glVertex3f(0.0, -50.0, 0.0);
glVertex3f(0.0, 50.0, 0.0);
glEnd();
glColor3f(0.0,1.0,0.0);
glBegin(GL_LINES);
glVertex3f(0.0, 0.0, -50.0);
glVertex3f(0.0, 0.0, 50.0);
glEnd();
glColor3f(1.0, 1.0, 1.0);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glBegin(GL_POLYGON);
glVertex3i(1, 1, 1);
glVertex3i(-1, -1, 1);
glVertex3i(-1, -1, -1);
glVertex3i(1, 1, -1);
glEnd();
glFlush();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode(GL_MODELVIEW);
}
I’d be really thankful if someone could give me an hint.
TIA