IDirectTexture8
I'm drawing textures to the screen 1 to 1 for a 2D game. I want it to not perform ANY antialiasing whatsoever. The result is currently blurry with boxes around each sprite being drawn. Each sprite is drawn to the backbuffer using 2 triangles. Since blurring seems to be the default, how do I turn it off?
Also, I tried using IDirectSuface8 instead. Since copyRects doesn't support alpha, I have to check each pixel for transparency, then send it a lot of 1x1 rectangles. This looks the way I want it, but lags horribly.
Is there any way to have my cake & eat it too?
Simply disable mapmap-generation for the textures, (aka) 1 mipmap-level when loading... otherwise D3D might get a little too happy with the mipmapping.
Here's my call to the constructor for the textures:
D3DXCreateTextureFromResourceEx(m_pD3DDevice, NULL, MAKEINTRESOURCE(resource), width, height, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, X_DEFAULT, D3DX_DEFAULT, D3DRGBA(0,0,1,0),NULL, NULL, &loadedSprites[numSprites]);
I already have a 1 for the number of mipmap levels.
D3DXCreateTextureFromResourceEx(m_pD3DDevice, NULL, MAKEINTRESOURCE(resource), width, height, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, X_DEFAULT, D3DX_DEFAULT, D3DRGBA(0,0,1,0),NULL, NULL, &loadedSprites[numSprites]);
I already have a 1 for the number of mipmap levels.
There's tucked-away DX documentation about how texels need to be mapped to pixel locations. Stuff in there about .5 offsetting due to the way pixels and texels are addressed. I don't recall the details immediately.
Here we go:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/anch_directx.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/anch_directx.asp
double sourceX=(tileNum%numCols)*(1.0/numCols)+(0.5/(width*numCols));
double sourceY=(tileNum/numCols)*(1.0/numRows)+(0.5/(height*numRows));
The +(0.5/(width*... is to adjust by half a pixel to deal with the pixel-texel offset thing. Without that, the sprite just displays offset, but just as blurry.
EDIT: Your link went to the main page of DirectX9's MSDN documentation. I've searched through the documentation there for information already... I assume you meant a more specific link.
double sourceY=(tileNum/numCols)*(1.0/numRows)+(0.5/(height*numRows));
The +(0.5/(width*... is to adjust by half a pixel to deal with the pixel-texel offset thing. Without that, the sprite just displays offset, but just as blurry.
EDIT: Your link went to the main page of DirectX9's MSDN documentation. I've searched through the documentation there for information already... I assume you meant a more specific link.
Oops. My bad: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/ProgrammingGuide/GettingStarted/Direct3DTextures/coordinates/MappingTexelsToPixels.asp
You should be offsetting your vertices' x and y by .5. Not .5 / some number. Unless I'm reading you wrong. Also, the accurate thing is to subtract .5, not add.
You should be offsetting your vertices' x and y by .5. Not .5 / some number. Unless I'm reading you wrong. Also, the accurate thing is to subtract .5, not add.
The texture goes from 0 to 1, so subtracting .5 isn't .5 pixels, it's half the width. That's why I divide it by the conversion from pixels to texture height/width... I looked at your link & it does seem to be that type of artifact, so my math must be wrong somewhere... I've more than quadruple checked it, but I'll check it again.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement