Jump to content
  • Advertisement
Sign in to follow this  
fathom88

Texture Map Coordinate Question

This topic is 4793 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'm trying to texture an image to a square that I draw on the scene. However, I get a silly looking blue square instead. I don't think it's in the setup of the texture because I get that code from a tutorial. I think the problem is in the way I define the texture bind points. I assumed they would match up with the points of the square. Am I anchoring my texture points wrong or should I go back to my texture load routine? glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, mTextureName); glColor3f(1.0, 1.0, 1.0); //white glBegin(GL_QUADS); glTexCoord2d(-100.0, 100.0); glVertex2d(-100.0, 100.0); glTexCoord2d(100.0, 100.0); glVertex2d(100.0, 100.0); glTexCoord2d(100.0, -100.0); glVertex2d(100.0, -100.0); glTexCoord2d(-100.0, -100.0); glVertex2d(-100.0, -100.0); glEnd(); glBindTexture(GL_TEXTURE_2D, 0);

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by fathom88
I'm trying to texture an image to a square that I draw on the scene. However, I get a silly looking blue square instead. I don't think it's in the setup of the texture because I get that code from a tutorial. I think the problem is in the way I define the texture bind points. I assumed they would match up with the points of the square. Am I anchoring my texture points wrong or should I go back to my texture load routine?


Make sure your texture width and height are powers of two. Then try:

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, mTextureName);
glColor3f(1.0, 1.0, 1.0); //white

glBegin(GL_QUADS);

glTexCoord2d(0.0, 1.0);
glVertex2d(-100.0, 100.0);

glTexCoord2d(1.0, 1.0);
glVertex2d(100.0, 100.0);

glTexCoord2d(1.0, 0.0);
glVertex2d(100.0, -100.0);

glTexCoord2d(0.0, 0.0);
glVertex2d(-100.0, -100.0);

glEnd();

glBindTexture(GL_TEXTURE_2D, 0);




Tom

Share this post


Link to post
Share on other sites
Yeah, its with your coordinates.

Texture mapping clips the texture to the range [0,1] such that 1 represents the maximum value of the dimension in the texture. One way to think about it is like percent coordinates.

You should therefore change your code to:


glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, mTextureName);
glColor3f(1.0, 1.0, 1.0); //white

glBegin(GL_QUADS);

glTexCoord2d(-1.0, 1.0);
glVertex2d(-100.0, 100.0);

glTexCoord2d(1.0, 1.0);
glVertex2d(100.0, 100.0);

glTexCoord2d(1.0, -1.0);
glVertex2d(100.0, -100.0);

glTexCoord2d(-1.0, -1.0);
glVertex2d(-100.0, -100.0);

glEnd();

glBindTexture(GL_TEXTURE_2D, 0);


Which will render the texture 4 times on the image:
    
(-1,-1) +---+---+
| |0,0|
+---+---|
| | |
+---+---+ (1,1)


Random Tutorial

EDIT: Beaten :(

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!