   D3DXSprite My Textures Are Bleeding
  Hi, I am using C++ and Direct X9.My problem (as seen below) is that my textures are showing the transparent borders around my tiles. I put those transparent tile borders there so that a tile would not show part of another tile. Worse, the transparent edges are blending rather than being invisible. Even though this makes a nice effect, it's not what I want.I load my tiles in as seperate textures, add the coordinates for the tile. Tiles are stored as floats and then converted to a rect using my GetTileRect() function for use with D3DXSprite. The coordinates are for the entire texture, except a pixel sized border around the edge. So a tile whose texture is 32x32 would be 2 to 31 and 2 to 31 for both sides, assuming 1 is the first pixel for a side.I then merge all my tiles together into one texture. Tiles coordinates are adjusted to reflect this. You can see the final merged texture in the background of my image (above). So, I am pretty sure that my coordinates are right. There must be some other reason for why my problem is occuring.//my draw codeg_pSprite->Begin(D3DXSPRITE_ALPHABLEND);//loop through list of sprites and text to rendervector<SPRITEX>::iterator itSprite=m_lstSpritexList.begin();while(itSprite!=m_lstSpritexList.end()){//draw sprite//get the rect for finding a tiles location on the textureRECT recTile=TextureManager.GetTileRect(itSprite->sTextureName,itSprite->sTileName);//width/height of tileint nTileWidth=recTile.right-recTile.left;int nTileHeight=recTile.bottom-recTile.top;//width/height of sprites destination rectangleint nDestWidth=itSprite->recDest.right-itSprite->recDest.left;int nDestHeight=itSprite->recDest.bottom-itSprite->recDest.top;//centre of spriteD3DXVECTOR2 Centre=D3DXVECTOR2(itSprite->recDest.left+((float)nDestWidth/2),itSprite->recDest.top+((float)nDestHeight/2));//position of spriteD3DXVECTOR2 Trans=D3DXVECTOR2(itSprite->recDest.left,itSprite->recDest.top);//factor to scale sprite byD3DXVECTOR2 Scale=D3DXVECTOR2((float)nDestWidth/nTileWidth,(float)nDestHeight/nTileHeight);//sprite rotation in radians (counter clockwise)float Rotation=(float)itSprite->fRotation*g_fDegreesToRadians;//make the sprite rotate, scale, and be in a specified positionD3DXMATRIX Mat;D3DXMatrixTransformation2D(&Mat,NULL,0.0,&Scale,&Centre,Rotation,&Trans);g_pSprite->SetTransform(&Mat);//draw spriteHRESULT hrDrawSprite=g_pSprite->Draw(TextureManager.GetTexture(itSprite->sTextureName),&recTile,NULL,NULL,itSprite->dwColor//0xFFFFFFFF keeps texture color);//necesary to allow font->drawtext() to work properly with sprite->draw()D3DXMatrixIdentity(&Mat);g_pSprite->SetTransform(&Mat);   ++itSprite;//next sprite}g_pSprite->End();Anyone able to help?[Edited by - utilae on December 6, 2005 3:49:29 AM]
  You can enable Alpha TESTing additionally to alpha blending. This will simply not draw pixels with a certain value above/below a reference value.You might also try to set filtering to point filter instead of linear, but that also affects the smoothness of the center part of the rectangles.   ;  EDIT:Ok, passing D3DXSprite the flag D3DXSPRITE_DONOTMODIFY_RENDERSTATE makes my Sprites draw properly.[Edited by - utilae on December 6, 2005 11:25:33 PM];Quote:Original post by utilaeEDIT:Ok, passing D3DXSprite the flag D3DXSPRITE_DONOTMODIFY_RENDERSTATE makes my Sprites draw properly.Yeah, that works because when the sprite class changes renderstates, it sets the texture filter to D3DTEXF_LINEAR. You probably had it set to D3DTEXF_POINT. You have to make sure if you tell it not to modify the renderstate, that you are always presenting it a renderstate it can use to render the sprites, otherwise you can and most likely will have some sort of problem, whether the sprites not show up or be freaked out.   ;  I would probably not use ID3DXSprite for 2D rendering. Although they fixed the performance issues in the latest version (Supposedly anyways) i've never been able to get it working correctly. I draw 2D stuff similar to OpenGL by creating an ortho transform matrix before drawing. This is more flexible than ID3DXSprite anyways.Just remember that D3D can be a bit screwy concerning pixel centers. So you might have to transform the vertices by +-0.5 depending.   ;Quote:Original post by curtmax_0I would probably not use ID3DXSprite for 2D rendering. Although they fixed the performance issues in the latest version (Supposedly anyways) i've never been able to get it working correctly. I draw 2D stuff similar to OpenGL by creating an ortho transform matrix before drawing. This is more flexible than ID3DXSprite anyways.Just remember that D3D can be a bit screwy concerning pixel centers. So you might have to transform the vertices by +-0.5 depending.The speed has indeed been increased by quite a noticable amount. I used to use textured quads for rendering 2D elements but I've actually found that ID3DXSprite is quite a good class to work with. Once you figure out how it's supposed to work (I wrote a wrapper for it), it can be streamlined and turn out very useful. Various artifacts tend to appear when you try to render normal textured quads (and stetch the quad by a decent amount), for some reason it seems this isn't the case when using ID3DXSprite.I can render hundreds of sprites with it and don't get a noticable speed hit. So I suppose in my personal case where I use it, I've had little problem.This is just one developer's opinion, however :) To each his own.   