Color loss using LPD3DXSPRITE

Started by
6 comments, last by Oddball 20 years, 1 month ago
Hi! I''m programming a 2D tile-based game using DirectX 8. I''m using the ID3DXSprite::Draw() method to display each tile to the screen. However, for some reason it''s not displaying the full color depth, and the graphics look quite bad. Here''s parts of my code which I think might be causing this color loss: To load the texture from file... D3DXCreateTextureFromFileEx( g_pd3dDevice, "tiles.png", 0, 0, 1, 0,D3DFMT_A8R8G8B8 ,D3DPOOL_MANAGED,D3DX_FILTER_NONE, D3DX_FILTER_NONE,0, &SrcInfo , NULL, &pd3dTexture); To draw the sprite to the screen... trans.x = (float) DestRect->left; trans.y = (float) DestRect->top; pd3dxSprite->Draw( pSrcTexture, SrcRect, NULL, NULL, NULL, &trans, 0xFFFFFFFF ); Just to experiment, when loading the texture from file, I used the D3DFMT_X8R8G8B8 value. To my surprise, it actually displayed the full colors, but of course, it didn''t have the transparency that I need. Why isn''t D3DFMT_A8R8G8B8 giving me the full color depth? or is there a way to use D3DFMT_X8R8G8B8 and still have parts of the image be transparent? Thank you!
Advertisement
You need transparency, Ok,
-do you want the black parts of the sprite to be transparent?
if so you have to specify the colorkey to 0xff000000 when loading the texture, and if you have done that you can load your
textures with D3DFMT_R5G6B5, it works fine (full colors + black color removed).
-if you want just to add some alpha blending to the sprite,
you decrease the alpha value in the sprite->Draw method,
fot example use the 0x7fffffff color.
Do you still have problems? ask me!!
mine from morocco
You need transparency, Ok,
-do you want the black parts of the sprite to be transparent?
if so you have to specify the colorkey to 0xff000000 when loading the texture, and if you have done that you can load your
textures with D3DFMT_R5G6B5, it works fine (full colors + black color removed).
-if you want just to add some alpha blending to the sprite,
you decrease the alpha value in the sprite->Draw method,
fot example use the 0x7fffffff color.
Do you still have problems? ask me!!
mine from morocco
Thanks for your reply. I need only the black portions to be transparent. Therefore, I followed your advice, and set the colorkey to 0xff000000 and set the mode to D3DFMT_R5G6B5. While it showed full colors, the transparency did not work. The black portions of the images still appeared when drawn to the screen. What could be wrong? Thanks again.
i''m also having this problem, any idea what''s causing this?
I''m going to be vague because I don''t have my material in front of me *shh I''m at work*...

You have to enable alpha testing, set your alpha function to test for alpha values > 1, etc.

I''m sorry I don''t remember the code for this. I''m new as well and only read it once in Jim Adams'' book. (And implemented it.)

If I remember I''ll look up the code and post the answer to this thread tomorrow (if someone else hasn''t already answered by then).



"Good code will come and go, but bad code sticks around."
"Good code will come and go, but bad code sticks around."
oddball u cant set the colour key to 0 for black, if you do, it says there is no colour key.


use d3dcolor_xrgb(0,0,0)

u dont need any alpha testing or that stuff then, the sprite class does it automatically
JohnnyBravo''s right. The alpha byte of your transparent color must be 255 because your image doesn''t have an alpha channel, therefore ALL the colors will load with an alpha of 255. Therefore you should set your transparent color to 0xff000000 What the function then does is look for any 32-bit word in the texture that matches THAT and then sets it to 0x00000000.

Here''s a code snip anyway for setting alpha test in case you''re still having troubles even after you change that. (I''ll leave it up to you to look up these commands in the SDK to determine what this code is doing.)

b = SUCCEEDED(pDxDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE));assert(b);b = SUCCEEDED(pDxDevice->SetRenderState(D3DRS_ALPHAREF, 0x01));assert(b);b = SUCCEEDED(pDxDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL));assert(b);






"Good code will come and go, but bad code sticks around."
"Good code will come and go, but bad code sticks around."

This topic is closed to new replies.

Advertisement