Jump to content
  • Advertisement
Sign in to follow this  

texture rectangle and shaders

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

Suppose the texture is 100x100 and I don't want to calculate the outermost pixels so I render as:
    glTexCoord2f(xoffset, yoffset);
    glVertex2f(0.0, 0.0);

    glTexCoord2f(width, yoffset);
    glVertex2f(width, 0.0);

    glTexCoord2f(width, height);
    glVertex2f(width, height);

    glTexCoord2f(xoffset, height);
    glVertex2f(0.0, height);


where offset=1 say
Now what size texture will the above render to 98*98 ? I want to render to 100*100 except not to calculate some of the pixels. If it becomes a 98*98 texture output then I'm guessing I'd have to do some more work to get it back to 100*100? regards Adrian

Share this post

Link to post
Share on other sites
The resulting rectangle will be width and height as specified. However using an integer for glTexCoord2f won't work, you will need the integer version glTexCoord2i. But you should stick to floating point texture coordinates.
You are using the floating point version of glVertex with integers which will also lead to problems if width=100 and height=100.

Try this:

// Untested
void RenderQuad (GLint width, GLint height, GLint xoffset, GLint yoffset)
GLint vpx = 640; //Size of viewport on X axis
GLint vpy = 480; // Y

GLint tx = 100; //Size of texture on X axis
GLint ty = 100; // Y


glTexCoord2f(xoffset/tx, yoffset/ty);
glVertex2i(xoffset, yoffset);

glTexCoord2f((tx - xoffset)/tx, yoffset/ty);
glVertex2i(width - xoffset, yoffset);

glTexCoord2f((tx - xoffset)/tx, (ty - yoffset)/ty);
glVertex2i(width - xoffset, height - yoffset);

glTexCoord2f(xoffset/tx, (ty - yoffset)/ty);
glVertex2i(xoffset, height - yoffset);


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!