Archived

This topic is now archived and is closed to further replies.

Mission Impossible (Colorkey in D3D8)

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

OK, since we all know that Microsoft terminated DirectDraw we also know that we can''t do transparent blit anymore... we can however use textures and point sprites which are cool, but... Anyway, I have a bitmap class (in C++) that draws, loads, locks and blah blah blah... an IDirect3DSurface8 object. So far so goos only I need to blit it (with and without colorkey) to a D3D8 back-buffer... Without colorkey there''s no problem, I simply do IDirect3DDevice::CopyRects(...), end of story. But with colorkey... that I couldn''t manage to do... (I''d tried to manually copy the pixels one-by-one, only it dropped the FPS from 60 to 14...) If you have an ideas for me on how I can blit my surface to the back-buffer using an hardware blitter (Assemblly is OK) or you have a realy fast algorithm that does that without the hardware, or you have any other kind of ideas that will blit the surface with my colorkey and keep my FPS on 60, just reply to me and I''ll be greatful. P.S. my colorkey is not a range of colors, it''s just one color represented by a single DWORD variable.

Share this post


Link to post
Share on other sites

The best way to work with 3D is load your bitmaps into a texture using D3DXLoadTextureFromFile and blit them using the D3DXSprite interface. To modify the contents of the textures you need to get the Surface using GetSurfaceLevel(), lock it, do your drawing, unlock it, then draw it using D3DXSprite to the backbuffer.

If it would help, download the D3DXSprite wrapper on my site:

  Downloads:  ZeroOne Realm

Share this post


Link to post
Share on other sites
Note that to use color keys with D3DXCreateTextureFromFileEx the surface format you specify ( D3D8_FMT... ) must contain an alpha channel. This means (unfortunately) that all your 256 color sprites now have to be loaded into memory as 16bit images (D3D8FMT_A8P8 = 8bits palette index, 8 bits alpha), and so doubles the required memory. Also, before you can use the color key you have to set the following render states:

g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_ALPHAREF, 0x01 );
g_pd3dDevice->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL );

I''m still not sure if 2D in D3D8 is worth it.

Share this post


Link to post
Share on other sites
As I''ve wrote, I''m NOT looking for a way to do it usingtextures or sprites, I want to blit my surface as-is, no textures (because of the pow2 dimensions & the alpha channel).

Share this post


Link to post
Share on other sites

You cannot do what you want. If you don''t want anything to do with textures or sprites (and I assume 3D), then why are you using D3D8?

DirectDraw7 is still available. CDX (www.cdxlib.com) uses DirectDraw and has some optimzed blitting routines (transparency, shadows, etc). It''s open source so even if you don''t want to use the library you can look at the blit routines.


Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites