2d orthogonal projection problem.

I’ve set up my 2d world to be
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glViewport(0,0,430,360);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, WINDOW_WIDTH, 0, WINDOW_HEIGHT);

My display function does two things: draw a background from a texture map (drawGround) and draw an object
This is in my main file

void doIdle()
{
glutPostRedisplay();
}

/*my display function */
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
drawGround();
glDisable(GL_TEXTURE_2D);

worldGroup->drawGroup();
glFlush();
glutSwapBuffers();
}

void drawGround()
{
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_POLYGON);
glTexCoord2f(0.0f, 0.2969f); glVertex2f(0, 0);
glTexCoord2f(0.0f, 1.0f); glVertex2f( 0, WINDOW_HEIGHT);
glTexCoord2f(0.8398f, 1.0f); glVertex2f( WINDOW_WIDTH, WINDOW_HEIGHT);
glTexCoord2f(0.8398f, 0.2969f); glVertex2f( WINDOW_WIDTH, 0);
glEnd();

}

And the code to draw the object is in a different file/class (ie the worldGroup->drawObj() call)
And that function has these few lines.
void simWaypoint::drawObj(){
objPosY);
GLfloat currentcolor[3];
glGetFloatv( GL_CURRENT_COLOR, currentcolor);

glBegin(GL_POLYGON);
glColor3fv(objColor);
glVertex2f(objPosX - 2, objPosY - 2);
glVertex2f(objPosX - 2, objPosY + 2);
glVertex2f(objPosX + 2, objPosY + 2);
glVertex2f(objPosX + 2, objPosY - 2);
glEnd();

glColor3fv(currentcolor);
}

What I get is just the background and I cant see my red square drawn by the other objects function.
If I comment out drawGround in the main program, I can see my red dot there. Help!

I’m deeply suspicious of the line:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

Clearing the depth buffer implies that you a) have a depth buffer and b) have enabled it. In a 2d app, depth-buffering really doesn’t make any sense, since everything is at the same depth.

If you have enabled GL_DEPTH_TEST and haven’t changed glDepthFunc from the default GL_LESS, GL isn’t going to draw your red dot because it’s at exactly the same depth (0) as your background.

HTH
Mike

thats why i was wondering how the shapes are ordered in my 2d application?
I assumed that it would be layered according to which I drew last. So having the draw for my object last meant that I drew it over the background?
So If i disabled the depth test… how would the shapes be ordered?

No depth test means last drawn is always ‘on top’.

Originally posted by amoskoh:

I assumed that it would be layered according to which I drew last. […]
So If i disabled the depth test… how would the shapes be ordered?

The way you assumed.

Also known as “Painter’s Algorithm” - later paint goes on top of earlier. Depth-buffering is designed specifically to avoid this, which makes your use of it somewhat ironic.

oh. ok yeah it turns out ok when i remove the depth test.
Thanks a bunch