Jump to content
  • Advertisement
Sign in to follow this  
LonelyStar

Providing Texture Coordinates in Pixel

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

Hi everbody, Is there a way to provide texture coords for a GL_TEXTURE_2D texture in pixels as one has to do for GL_TEXTURE_RECTANGLE_ARB? So that, for i.E. a 1024x1024 texture, texture coordinates go from 0-1023 instead of 0-1??? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
glMatrixMode(GL_TEXTURE);
glPushMatrix();
glScalef(1/texture.width, 1/texture.height, 1);
glMatrixMode(GL_MODELVIEW);


Remember to glPopMatrix(); when you change the texture.

Share this post


Link to post
Share on other sites
If you really wanted to you could scale the texture matrix, or you could just divide by the size of the texture just before you make the call, i.e.:
GLint currentTextureBinding = 0;
GLfloat currentTextureWidth;
GLfloat currentTextureHeight;

void glTexCoord2iAbsolute(GLint x, GLint y)
{
GLint boundTextureId;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &boundTextureId);
if (boundTextureId != currentTextureBinding)
{
currentTextureBinding = boundTextureId;
glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &currentTextureWidth);
glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &currentTextureHeight);
}
glTexCoord2f(x / currentTextureWidth, y / currentTextureHeight);
}

Obviously that can be made more efficient.

Enigma

Share this post


Link to post
Share on other sites
It's the same as TexCoord2f...usefull only when your tx coords are >>1 otherwise you have a lot of noise or even a tex coord clamped to (0,0).

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!