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
texture rectangle and shaders
Suppose the texture is 100x100 and I don't want to calculate the outermost pixels so I render as:
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:
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:
// Untestedvoid 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();}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement