Sign in to follow this  

Disable sprite and font antialiasing

This topic is 2022 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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: [b](code 1)[/b]

[img]http://i.imgur.com/LCoS4.png[/img]
The top left image is on one point of the screen, while the bottom left is on a distant point. [b](code 2)[/b]
The top right image is a button, and its top border must me only 1px tall. [b](code 3)[/b]
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: [b](code 4)[/b]

12x12px texture:
[img]http://i.imgur.com/y5O4L.png[/img]

32x32px texture:
[img]http://i.imgur.com/N3Cxt.png[/img]
(the first problem is also seen in this image, in the bottom border)
The texture is always being drawn as 12x12:
[code]
surface()->DrawTexture(checkTexture, 0, 0, 12, 12);
[/code]


[b]Code 1: Draw Filled Rect[/b]
[code]

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));
};
[/code]
[b]Where:[/b]
[u]currentContext[/u] is the current Panel (window, controls) being drawn.
[u][u][u]x[/u][/u][/u] is the x-position of the Panel relative to the left of the screen.
[u][u][u]y[/u][/u][/u] is the y-position of the Panel relative to the top of the screen.
[u][u][u]left[/u][/u][/u] is the x-position of the rect relative to the left of the Panel
[u][u][u]top[/u][/u][/u] is the y-position of the rect relative to the top of the Panel

[u][u][u]wide[/u][/u][/u] is the width of the rect
[u][u][u]tall[/u][/u][/u] is the width of the rect

[b]Code 2 - Draw text[/b]
[code]

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);
}
[/code]
[b]Where:[/b]

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

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

[b]Code 3 - Draw border[/b]
[code]

void Border::Draw(int wide, int tall)
{
// left
for(int i = 0; i < sides[0].count; i++)
{
border_t border = sides[0].borders[i];
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[i];
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[i];
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[i];
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);
}
};
[/code]
[b]Where:[/b]
[u][u]wide[/u][/u] is the width of the border
[u][u]tall[/u][/u] is the height of the border

[b]Code 4 - Draw texture[/b]
[code]

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();
}
[/code] Edited by igorlira

Share this post


Link to post
Share on other sites
Sounds like it could be the half pixel texture offset. Have a read of this and see if it helps: [url="http://msdn.microsoft.com/en-us/library/bb219690(VS.85).aspx"]http://msdn.microsoft.com/en-us/library/bb219690(VS.85).aspx[/url]

Share this post


Link to post
Share on other sites
Sign in to follow this