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.
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.
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.
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.
//=================================
// 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
}
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.