Texture Map Coordinate Question
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);
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
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:
Which will render the texture 4 times on the image:
Random Tutorial
EDIT: Beaten :(
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); //whiteglBegin(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 :(
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement