Archived

This topic is now archived and is closed to further replies.

Problems creating a background

This topic is 6012 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites