Hi everyone,
I am using glTexCoord2f function for rendering a texture to an OpenGL device context. However, it is behaving somewhat weird. I have not been unable to figure out the problem yet.
I am trying to render a subset of a texture into the screen. The idea is that a portion of the texture should be in the center.
This is what I do. The fraction value in bmpX and bmpY is the region of interest. I am also showing areas in the bmp/2.0 to the left and right direction and bmpY/2.0 in the top and bottom direction. So, the region around bmp should always be shown on the screen, but that is not the case. I am pretty sure I am screwing up something majorly hereā¦
float leftXFactor = bmpX / 2.0;
float bottomYFactor = bmpY / 2.0;
float rightXFactor = bmpX + leftXFactor;
if (rightXFactor > 1.0)
rightXFactor = 1.0;
float topYFactor = bmpY + bottomYFactor;
if (topYFactor > 1.0)
topYFactor = 1.0;
glBegin(GL_QUADS);
glTexCoord2f(leftXFactor, bottomYFactor); glVertex2i(0, height); glTexCoord2f(rightXFactor, bottomYFactor);
glVertex2i(width, height);
glTexCoord2f(rightXFactor, topYFactor);
glVertex2i(width, 0);
glTexCoord2f(leftXFactor, topYFactor);
glVertex2i(0, 0);
glEnd();
I would really appreciate any help.
Cheers,
xarg