Reputation: 11
I'm fairly new to low level openGL coding and I have a problem that perhaps I'm just too tired to find a solution to. I'm sure the answer is simple and I'm doing something utterly stupid but here goes...
I have a texture of 1024 x 512,and I'm rendering a 2D quad which intends to use a portion of that texture. The quad is of the same size as the texture portion I am trying to render, eg 100 x 100 between vertices to render a 100 x 100 texture portion. The texture pixels are from 0(s) and 104(t) assuming zero based pixel coords, and therefore the UV(st) is being calculated as 0 / 1024 and 104 / 512 to the extents of 100 / 1024 and 204 / 512.
However when I render the quad, I get a line from the pixel coords at 103(t), which is part of a different section of the image so it really stands out. I can get around the problem by setting the UV to 0 / 1024 and 105 / 512, but this seems very wrong to me.
I've been searching for a while and can't find what I'm doing wrong. I've tried GL_LINEAR, GL_NEAREST,clamping etc in glparams to no avail. Can someone please direct me to my error?
Upvotes: 1
Views: 1750
Reputation: 162164
That is because texture coordinates don't address pixels, thus your assumption
and therefore the UV(st) is being calculated as 0 / 1024 and 104 / 512 to the extents of 100 / 1024 and 204 / 512
is wrong!
This is kind of a FAQ, I recently answered it in OpenGL Texture Coordinates in Pixel Space
Upvotes: 1