Display over background

I was able to display a .bmp file for a background on a window…After reading the code(provided by another person) it looks like it maps the .bmp from window edge to window edge. Problem is that now I can’t display new objects in front of this background…

Basically one function draws the map in function drawglscene. If I write code after the funciton drawmap, nothing shows no matter where in the z-axis I place the object. But if I comment out my drawmap funciton the other objects display.

Any suggestions??

What z value you use for drawing the background?

This is the code…see how it maps the texture to the screen size…

I’m gonna look into the ortho2d() and normal() to see if they have a z-axis to put the .bmp file at as soon as I get outa work;

AS for the objects, I tried +/- z-axis locations and still they did not display unless I commented out drawmap();

void DrawMap()
{
// Window size (GLdouble)
int w = 800;
int h = 600;

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, w, 0, h);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT);

glDisable(GL_DITHER);
glShadeModel(GL_FLAT);

glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );

glBegin(GL_QUADS);
	GLfloat fw = (GLfloat) w;
	GLfloat fh = (GLfloat) h;
	glNormal3f( 0.0f, 0.0f, 1.0f);
	glTexCoord2f(1.0f, 1.0f); glVertex3f( fw, fh, 0.0f);
	glTexCoord2f(0.0f, 1.0f); glVertex3f(0, fh, 0.0f);
	glTexCoord2f(0.0f, 0.0f); glVertex3f(0, 0, 0.0f);
	glTexCoord2f(1.0f, 0.0f); glVertex3f( fw, 0, 0.0f);
glEnd();
glDisable(GL_TEXTURE_2D);

glMatrixMode(GL_PROJECTION);
glPopMatrix();

glMatrixMode(GL_MODELVIEW);
glPopMatrix();

glPopAttrib();

}

Ok, I don’t see nothing wrong in you code, but one consideration.

gluOrtho2D create a visualization box between -1 and 1 in the z axis. then any vertex drawing with z < -1 or z > 1 is not displayed (is clip).

You use depth test?
You say that if you comment DrawMap works, but what Projection Matrix you use then?

[This message has been edited by Boresight (edited 05-23-2001).]

Basically I tested using a simple triangle. I translated this at varying z-depths.

This is what I have in drawglscene(Very Basics):
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix

DrawMap();

glTranslatef(0.0,0.0,-4.0);


//Test object is triangle
//at later date, change to rectangles.
//map ship textures to the rectangles.
glBegin(GL_TRIANGLES);							// Drawing Using Triangles
	glVertex3f( 0.0f, 1.0f, 0.0f);				// Top
	glVertex3f(-1.0f,-1.0f, 0.0f);				// Bottom Left
	glVertex3f( 1.0f,-1.0f, 0.0f);				// Bottom Right
glEnd();

You mentioned “gluOrtho2D create a visualization box between -1 and 1 in the z axis. then any vertex drawing with z < -1 or z > 1 is not displayed (is clip)”

How would I expand this “box”, for example, 6 and -6 in the z-axis.

Or does ortho2d automatically display in 1 to -1 z-axis? If so what would be a solution to expand this viewing area.

My goal:

Display background map.

Dsplay objects(containing ship .bmp’s) in front of the background.

Move the objects with each mouse click.

Try disabling Z buffering before calling DrawMap.

You can use glOrtho(left, right, bottom, top, zNear, zFar) instead of gluOrtho2D().

Also, try this code instead:

drawOneTriangle();
glTranslatef(0.0f, 0.0f, -4.0f);
DrawMap();

I think (not at home so I can’t test it) that the way you do it, you draw the map, then draw a triangle translated down the negative z axis i.e. [i]into the screen, behind the map[\i]. You could either try my code, or try changing the glTranslatef that you’ve got to a positive value. I’d also throw in a call to glTranslatef(0.0f, 0.0f, some_negative_z_value) after your // reset the current modelview matrix line to move the “camera” away from your objects.

Hope that helps.

I’ve been thumbing through my opengl book and I’m getting bummed now.

I changed from the ortho2d to glortho. I implemented it as glOrtho(0,w,0,h, 0, -10); //(left,right,bottom,top,near,far)

I was hoping to display objects between -1 to -6 in the z-axis. I noticed that when altering the triangle’s vertices that it does display on the sceen.

The catch is that it seems to take on the color of the .bmp file so I can never distinguish if it is displayed on the screen. Tested this by moving the vertices of the background quad to -6 in the z-axis. The trianlge appears, but the color is green like the map.

The code does disable the texture after the image is mapped to a quad in my DrawMap() function so this should not be happening.

I’ve included a link to the source code with the small image below.

So if someone wouldnt mind pointing out what I’m doing wrong, it would be very appreciated.

http://members.nbci.com/drumdummy/MapTest.zip

There is a problem in the code you posted.

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, w, 0, h);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

Note that the Projection Matrix is pushed followed by the Modelview Matrix. Then later, you Pop them off as follows-

glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();

This would pop the Modelview Matrix into the Projection matrix and the Projection into the Modelview.

You may also wish to do a-

glDepthMask(glFalse);

before drawing your background so that it doesn’t write its value into the Z-Buffer.

try:
glDisable(GL_DEPTH_TEST);
//draw here your background-image
glClear(GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
//draw other stuff …

Try this. It’s very hacked together with not much thought gone into it but it achieves your desired effect I think:

void DrawMap()
{
// Window size (GLdouble)
int w = 1152;
int h = 864;
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
glOrtho(0.0f,w,0.0f,h, -1.0f, 1.0f); //(left,right,bottom,top,near,far)
glMatrixMode(GL_MODELVIEW);
glPushAttrib(GL_LIGHTING_BIT);
glLoadIdentity();
glShadeModel(GL_FLAT);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
const GLfloat fw((GLfloat) w);
const GLfloat fh((GLfloat) h);
glBegin(GL_QUADS);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( fw, fh, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0, fh, 0.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(0, 0, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( fw, 0, 0.0f);
glEnd();
glDisable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
glPopAttrib();
}

//=================================
// S C E N E C O D E H E R E
//=================================
int DrawGLScene(GLvoid) // Here’s Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
DrawMap();
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(0.0f, 0.0f, -10.0f);
glBegin(GL_TRIANGLES); //Draw using a trianle
glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red
glVertex3f( 0.0f, 1.0f, 0.0f); // Top
glColor3f(0.0f,1.0f,0.0f); // Set The Color To Green
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glEnd(); // Finished Drawing The Triangle
return TRUE; // Everything Went OK
}

Hope that helps.

Thanks so much for all the help!

ffish, your method worked, now I need to run through the code to understand how it worked and why.

Thanks alot guys, now time to continue with the learning process.

This thread will now self-destruct

Originally posted by Sheepie:
[b]There is a problem in the code you posted.

<code snipped>

Note that the Projection Matrix is pushed followed by the Modelview Matrix. Then later, you Pop them off as follows-

<more code snipped>

This would pop the Modelview Matrix into the Projection matrix and the Projection into the Modelview.

[/b]

That’s not quite right. The ModelView and Projection matrices each have their own stack, so it’s not possible to “pop the ModelView Matrix into the Projection matrix and the Projection into the Modelview” just by using glPush/Pop.

Well, I did not even know that. And all along, I have been carefully making sure I had each Push go with each Pop. I guess my Assembly programming has left its mark.