Sign in to follow this  

texture rectangle and shaders

This topic is 3875 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:
 glBegin(GL_QUADS);
    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);

 glEnd();

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

glBegin(GL_QUADS);

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

glEnd();
}

Share this post


Link to post
Share on other sites

This topic is 3875 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.

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