Disable sprite and font antialiasing

Started by
0 comments, last by Postie 11 years, 9 months ago
Hello,

I'm working on a DirectX overlay, so I need to draw 2D things etc.
The problem is: In some areas of the screens, the vertices and the texts I draw are being antialiased, as seen below: (code 1)

LCoS4.png
The top left image is on one point of the screen, while the bottom left is on a distant point. (code 2)
The top right image is a button, and its top border must me only 1px tall. (code 3)
The bottom right image is the same button text being renderized on another point of the screen. (just like the top left)

The other problem: tiny sprites (like 12x12px) are being stretched: (code 4)

12x12px texture:
y5O4L.png

32x32px texture:
N3Cxt.png
(the first problem is also seen in this image, in the bottom border)
The texture is always being drawn as 12x12:

surface()->DrawTexture(checkTexture, 0, 0, 12, 12);



Code 1: Draw Filled Rect


void Surface::DrawFilledRect(int left, int top, int wide, int tall)
{
int x, y;
currentContext->GetAbsPos(x, y);

DWORD color = drawColor;

SVertex vertex []= {
{ x + left, y + top, 0.0f, 0.0f, color },
{ x + left + wide, y + top, 0.0f, 0.0f, color },
{ x + left, y + top + tall, 0.0f, 0.0f, color },
{ x + left + wide, y + top + tall, 0.0f, 0.0f, color }
};

device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, vertex, sizeof(SVertex));
};

Where:
currentContext is the current Panel (window, controls) being drawn.
x is the x-position of the Panel relative to the left of the screen.
y is the y-position of the Panel relative to the top of the screen.
left is the x-position of the rect relative to the left of the Panel
top is the y-position of the rect relative to the top of the Panel

wide is the width of the rect
tall is the width of the rect

Code 2 - Draw text


void Surface::DrawString(const char* str, int height, int left, int top)
{
int x, y;
currentContext->GetAbsPos(x, y);

RECT r;
r.left = x + left;
r.top = y + top;
r.right = x + left + 100;
r.bottom = y + top + 100;

fnt->DrawTextA(0, str, strlen(str), &r, 0, drawColor);
}

Where:

currentContext is the current Panel (window, controls) being drawn.
x is the x-position of the Panel relative to the left of the screen.
y is the y-position of the Panel relative to the top of the screen.

left
is the x-position of the text relative to the left of the Panel
top is the y-position of the text relative to the top of the Panel
fnt is the font.

Code 3 - Draw border


void Border::Draw(int wide, int tall)
{
// left
for(int i = 0; i < sides[0].count; i++)
{
border_t border = sides[0].borders;
surface()->DrawSetColor(border.color[0], border.color[1], border.color[2], border.color[3]);
int addx = border.addx;
int addy = border.addy;
surface()->DrawFilledRect(addx, addy, 1, tall - addy);
}
// top
for(int i = 0; i < sides[1].count; i++)
{
border_t border = sides[1].borders;
surface()->DrawSetColor(border.color[0], border.color[1], border.color[2], border.color[3]);
int addx = border.addx;
int addy = border.addy;
surface()->DrawFilledRect(addx, addy, wide - addy, 1);
}
// right
for(int i = 0; i < sides[2].count; i++)
{
border_t border = sides[2].borders;
surface()->DrawSetColor(border.color[0], border.color[1], border.color[2], border.color[3]);
int addx = border.addx;
int addy = border.addy;
surface()->DrawFilledRect(wide - 1 - addx, addy, 1, tall - addy);
}
// bottom
for(int i = 0; i < sides[3].count; i++)
{
border_t border = sides[3].borders;
surface()->DrawSetColor(border.color[0], border.color[1], border.color[2], border.color[3]);
int addx = border.addx;
int addy = border.addy;
surface()->DrawFilledRect(addx, tall - 1 - addy, wide - addx, 1);
}
};

Where:
wide is the width of the border
tall is the height of the border

Code 4 - Draw texture


void Surface::DrawTexture(SurfaceTexture* stexture, int left, int top, int wide, int tall)
{
IDirect3DTexture9* texture = (IDirect3DTexture9*)stexture;

int x = 0, y = 0, wid = 0, tal = 0;
if(currentContext)
currentContext->GetAbsPos(x, y);

::ID3DXSprite* spr = NULL;
::D3DXCreateSprite(device, &spr);

RECT r;
r.left = 0;
r.top = 0;
r.right = wide;
r.bottom = tall;

D3DXVECTOR3 center;
center.x = 0.0f;
center.y = 0.0f;
center.z = 0.0f;

D3DXVECTOR3 pos;
pos.x = left + x;
pos.y = top + y;
pos.z = 0.0f;

spr->Begin(D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_TEXTURE);
spr->Draw(texture, &r, &center, &pos, drawColor);
spr->End();

spr->Release();
}
Advertisement
Sounds like it could be the half pixel texture offset. Have a read of this and see if it helps: http://msdn.microsoft.com/en-us/library/bb219690(VS.85).aspx
[size="2"]Currently working on an open world survival RPG - For info check out my Development blog:[size="2"] ByteWrangler

This topic is closed to new replies.

Advertisement