I've written a special set of components, so program's user interface is
being drawn on form's surface by OpenGL. The main container for all other
ones prepares scene, so world coordinates match internal component's ones.
Thus, world's (0,0) should match screen's (0,0); (10, 10) should match (10,
10) and so on (note, that once "mathematical" OY vector now became "screen"
OY vector pointing down instead of up).
I'm doing it in a following way:
<code>
glViewport(0, 0, FRect.Width, FRect.Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, FRect.Width - 1, -(FRect.Height - 1), 0, 0.1, 100);
glTranslatef(0, 0, -10);
</code>
However it seems, that even such evaluated surface covers entire form area
and opposite screen corners' coordinates match the screen equivalents,
OpenGL still interpolates textures somewhere.
I use these commands to draw button:
<code>
if not(FBuffersValid) or (FRect.width<>FTexWidth) or
(FRect.Height<>FTexHeight) then
RebuildBuffers;
ScreenRect:=FRect + Offset;
SetupClippingPlanes(ClipRect);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
case FButtonState of
bsIdle: glBindTexture(GL_TEXTURE_2D, FIdleTexture);
bsHotTrack: glBindTexture(GL_TEXTURE_2D, FHottrackTexture);
bsPressed: glBindTexture(GL_TEXTURE_2D, FPressedTexture);
end;
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(ScreenRect.left, ScreenRect.top);
glTexCoord2f(FTexWidth / FNearest2Width, 0);
glVertex2i(ScreenRect.right, ScreenRect.top);
glTexCoord2f(FTexWidth / FNearest2Width, FTexHeight / FNearest2Height);
glVertex2i(ScreenRect.right, ScreenRect.bottom);
glTexCoord2f(0, FTexHeight / FNearest2Height);
glVertex2i(ScreenRect.left, ScreenRect.bottom);
glEnd();
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
DisableClippingPlanes;
</code>
I use several internal methods, but I believe, that their purpose is pretty
obvious.
How can I solve the unwanted interpolation problem?
TIA,
Best regards -- Spook.
You have several problems.
I seem to recall that exactly matching (0 .. width-1) (0...height-1) isn't
quite right, you need a 1/2 pixel shift, because you want to light the
*center* of a pixel on the screen.
The same is true for textures, the correct texture coordinates for a
16-texel wide texture are (1/(2*16) and 1-(1/(2*26)),
again to get the texture coordinates to be on the dead center of texels.
jbw
> You have several problems.
>
> I seem to recall that exactly matching (0 .. width-1) (0...height-1) isn't
> quite right, you need a 1/2 pixel shift, because you want to light the
> *center* of a pixel on the screen.
In fact this is not neccesary. Screen pixels are addresses as integers. So
in the last step of rasterization the transformed floating point coordinates
are rounded to screen coordinated. A 0.5 shift creates some ambiguity (round
up or round down), so mapping to [0 .. {width|height}-1] put's you on the
safe side.
> The same is true for textures, the correct texture coordinates for a
> 16-texel wide texture are (1/(2*16) and 1-(1/(2*26)),
> again to get the texture coordinates to be on the dead center of texels.
Indeed. I thourougly explained the details in this post
<http://preview.tinyurl.com/cgndc8>
Eventually I'm going to create some nicely illustrated article about it.
Wolfgang
Hmm, I thought that that wasn't quite true with AA, but I admit I'm fuzzy on
that, it's
been so long ago now ... Perhaps it was a hardware-specific issue.
>> The same is true for textures, the correct texture coordinates for a
>> 16-texel wide texture are (1/(2*16) and 1-(1/(2*26)),
>> again to get the texture coordinates to be on the dead center of texels.
>
> Indeed. I thourougly explained the details in this post
> <http://preview.tinyurl.com/cgndc8>
>
> Eventually I'm going to create some nicely illustrated article about it.
>
yep, just so. For readers, note my typo, I meant 1 - (1/(2*16)) of course,
not 26.
Fat fingers.
>
> Wolfgang
>
>