Sign in to follow this  
fathom88

Texture Map Coordinate Question

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this