Jump to content
  • Advertisement
Sign in to follow this  
theStudent

OpenGL Question about Texture mapping

This topic is 2855 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

Hello all, I'm new to OpenGL and I've ran into a problem. I want to draw a background texture and draw other objects in the foreground (I've enabled depth test, and clear the depth buffer on display). Problem is that if I attempt to draw the background texture, my foreground object are drawn in some fixed color of which I have no control over and my shading doesn't work either. I've narrowed it down to these 2 lines of code:


glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);


It doesn't even matter if I draw the background or not, if my initialization function has those two lines of code (even if display function has no texture drawing at all), my objects are drawn like so:
bado.png

If I comment out those two lines, it draws like I want it to:
goodo.png

Here's the code for loading the texture:

pix.readBMPFile("space_texture.bmp");
glBindTexture(GL_TEXTURE_2D, textName);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, nCols, nRows, 0, GL_RGB, GL_UNSIGNED_BYTE, pixel);


And the one for drawing it in display function:

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

glBindTexture(GL_TEXTURE_2D, 2501);
drawTexture();


The texture draws fine but my foreground objects get that weird color which I can't change no matter what color I choose to draw with. If I disable those two lines mentioned above, foreground draws fine. I have no idea of texture mapping so I'm probably doing something very stupid. I'd like to draw the background texture and keep my foreground objects with their own colors and shading. Does anybody know how I could this. Thanks in advance for any help.

Doh, had forgotten the actual drawing routine.

void drawTexture()
{
glBegin(GL_QUADS);
glTexCoord2f(0.0,0.); glVertex3f(-700.,-700., -1000.);
glTexCoord2f(1., 0.); glVertex3f(700., -700., -1000.);
glTexCoord2f(1., 1.); glVertex3f(700., 700., -1000.);
glTexCoord2f(0., 1.); glVertex3f(-700., 700., -1000.);
glEnd();
}


[Edited by - theStudent on October 23, 2010 12:04:42 AM]

Share this post


Link to post
Share on other sites
Advertisement

Hey , Well it seems that you didn't disable the background texture when you try to render the foreground objects use glDisable/glEnable for it.

Share this post


Link to post
Share on other sites
Quote:
Original post by ff8

Hey , Well it seems that you didn't disable the background texture when you try to render the foreground objects use glDisable/glEnable for it.


You are awesome, many thanks. This was driving me crazy.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!