• Advertisement
Sign in to follow this  

IDirectTexture8

This topic is 4737 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

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?

Share this post


Link to post
Share on other sites
Advertisement
Simply disable mapmap-generation for the textures, (aka) 1 mipmap-level when loading... otherwise D3D might get a little too happy with the mipmapping.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Here we go:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/anch_directx.asp

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Yupp, it should be available for DirectX 8.1... and for what it is...
A 2D-renderer for Direct3D, which provides all the basic features necessary, does everything for you... check it out unless you rely on more advanced uses.

Share this post


Link to post
Share on other sites
I took a look. It looks like what I need. I don't do anything advanced, so it's just a matter of trying it out. Thanks.

Share this post


Link to post
Share on other sites
I tried using ID3DXSPRITE, but ran into a problem. It requires a RECT with the rectangle to draw from the texture, but texture coordinates are decimal numbers and RECT is 4 longs. Also, do I have to worry about texels with ID3DXSPRITE? Instead of going from 0.0 to 1.0, going from (-.5)/width to (width-.5)/width?

EDIT: Of course, I tried drawing with pixel coordinates anyway, and although it shouldn't work, it did. It was stretched though, so after taking a screenshot & doing a bit of math to figure out HOW stretched, I found that it rounds texture width & height up to the nearest power of 2, so I adjusted it. Being the splashscreen that I tested, the image was 640x480. By adding whitespace in the image, my problem was solved. The rest of the images have powers of 2 for their heights & widths, so this is good.

Thanks everyone who helped me, especially Syranide for suggesting ID3DXSprite.

[Edited by - GameCheetz on March 2, 2005 9:13:46 AM]

Share this post


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

  • Advertisement