Problems creating a background

Started by
5 comments, last by Running_Wolf 22 years, 9 months ago
I have been trying to create a static 2D background that I place 3D objects in front of. I''m just loading a background texture and displaying it but something doesn''t work because anything I create after the background doesn''t show up. Here is my code: LoadBackGroundTexture(Filename, *texture); // It is a class. This is done when an instance of the class is created. // This is what happens every time I call the Draw() command. glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D(0, 128, 0, 128); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glBindTexture(GL_TEXTURE_2D, texture[0]); glBegin(GL_TRIANGLES); glTexCoord2f(1.0, 1.0); glVertex2i(128, 0); glTexCoord2f(0.0, 0.0); glVertex2i(0, 128); glTexCoord2f(1.0, 0.0); glVertex2i(128, 128); glTexCoord2f(0.0, 0.0); glVertex2i(0, 128); glTexCoord2f(1.0, 1.0); glVertex2i(128, 0); glTexCoord2f(1.0, 0.0); glVertex2i(0, 0); glEnd(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glLoadIdentity(); What am I doing wrong?
L.I.G. == Life Is Good
Advertisement
Perhaps you need to call glEnable(GL_TEXTURE_2D)? Or maybe your "camera" is still located at (0, 0, 0) along with your quad, try zooming out a bit (glTranslatef(0.0, 0.0, -3.0)).

Jason A.

---
I write code.
DelphiGL (http://delphigl.cfxweb.net)
---I write code.DelphiGL (http://delphigl.cfxweb.net)
GL_TEXTURE_2D is enabled. And I am translating out of the screen by 6.0
L.I.G. == Life Is Good
are you seeing pure black or pure white? If you are seeing black that means you are staring into the void which means either your camera is to close to the triangles, or the triangles are getting back face culled (try disabling GL_CULL_FACE if you have it enabled), or the vertex color is set to black which would then modulate with the texture (0 x texture = 0) giving you a black triangle.

If you are seeing white then something is wrong with your texture, either it didn''t load or some texture parameters were set wrong (maybe the filter method is set to GL_LINEAR_MIPMAP_NEAREST and you are using glTexImage2D instead of gluBuild2DMipmaps. Step into LoadBackGroundTexture (Click on the line of code that calls this function, press Ctrl+F10, then press F11 to step into the code) and make sure that the texture is actually being loaded, and that the texture object has been created and bound before glTexImage2D or gluBuild2DMipmaps is called.

Jason A.

---
I write code.
DelphiGL (http://delphigl.cfxweb.net)
---I write code.DelphiGL (http://delphigl.cfxweb.net)
My textures are loaded correctly. I see my background correctly and when I comment out drawing the background I see the Triangle correctly. It is when both are being drawn that the problem occurs.
L.I.G. == Life Is Good
Never Mind...I fixed it. I wasn''t disabling Depth Testing! Thanks for your help!
L.I.G. == Life Is Good
No problem, glad you got it running

Jason A.

---
I write code.
DelphiGL (http://delphigl.cfxweb.net)
---I write code.DelphiGL (http://delphigl.cfxweb.net)

This topic is closed to new replies.

Advertisement