Advertisement

DX7::D3DX Sprite question

Started by November 16, 1999 07:33 PM
14 comments, last by Evil 25 years, 3 months ago
Um, I'm pretty sure you DON'T want ALPHATESTENABLE enabled. That doesn't do what you want.

First, make sure you are creating your surface with the DDSD_CKSRCBLT flag. After that, set everything up like this:

DDCOLORKEY m_CK;
m_CK.dwColorSpaceHighValue = RGB(0,0,0);
m_CK.dwColorSpaceLowValue = RGB(0,0,0);
m_ptex->SetColorKey(DDCKEY_SRCBLT, &m_CK);
m_pd3dDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
m_pd3dDevice->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE, TRUE);
m_pd3dDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
m_pd3dDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPH);

Thy this setup both with and without COLORKEYBLENDENALBE. If that doesn't work, you could try adding a call to D3DXPrepareDeviceForSprite. If all that fails, you can try screwing around with ALPHATESTENABLE, but I don't think that'll be much help. Not much more I can think of. Generally I just use an alpha channel and don't even bother with color keying.

Thanks for taking the time to assist me with this! Unfortunately, after trying the renderstates you suggested, it still isn't working.

We may be on the right track though, if I can figure out this: How do I set the DDSD_CKSRCBLT flag when I'm using D3DXCreateTextureFromFile and D3DXLoadTextureFromFile? The only flags I saw on the create function had to do with mipmapping. I've been working under the (possibly incorrect) assumption that textures created with these functions would have DDSD_CKSRCBLT set. I'm not really familiar with D3D textures, so I don't know if there's a way to force this flag after creating the texture with the D3DX functions.

The sprite.cpp example already has a call to D3DXPrepareDeviceForSprite every frame, so I didn't make any change there.

You said you generally just use an alpha channel and don't bother with color keying. Is that something I could do in this situation? I suppose I'll have to figure out how to do that, or make my own texture load routine, if the D3DXLoad/Create function don't allow for color keying.

Thanks for taking the time to help!

------------------------
E.N.D. - http://listen.to/evil
Advertisement
Using an alpha channel is almost certainly something that would work for you. It involves storing a grayscale image that represents the transparency of the corresponding portions of the image you are rendering. Not only does it allow you to do simple on/off type transparency, but very fine levels of translucency as well. You can create images with alpha channels built right into them using the DirectX Texture Tool that comes with the DirectX SDK. It saves to the DDS file format which is supported by the texture loading functions.

As for creating surfaces with the CKSRCBLT flag, I'm pretty sure that the D3DX functions do not do this. The reason being that with that flag you actually have to specify the color key values in the surface description that you are creating. You also might want to check to see if your video card supports color keying.

Thanks! I think we finally found the problem in the form of the flag. I'll look at working around it with alpha channels. It seems like a pretty big omission on Microsoft's part not to include a "simple" way of colorkeying in their D3DX sprite functions though. It's not like 99% of sprites don't need it. I think I'm going to write them about this one.

My video card is a Diamond Viper 550, so I don't think there's any doubt that it does support color keying. Color keying works fine on my laptop too, as long as I'm blitting and not using D3DX.

Thanks for the help bud!

------------------------
E.N.D. - http://listen.to/evil
I'm playing around with the new D3DX utility library included in DirectX 7. I'm having one small problem I was hoping the gurus here could clear up for me:

In the included sample application 'Sprite', there is a demonstration of alpha-blending. However, in that demo, there is no color keyed transparency, so the rotating doughnut is surrounded by a black box.

I made a couple of modifications which I thought was going to correct the output: Right before the operations to draw the sprite, I SetColorKey on the source texture. I also SetRenderState to enable color keying. Still no dice - the black bounding box remains.

Can anyone tell me what I forgot? I'd really appreciate it.

Thanks in advance!

------------------------
E.N.D. - http://listen.to/evil
No problem.

This topic is closed to new replies.

Advertisement