Skip to main content
gamedev.net
🔒 Locked

DirectDraw color key problem

Started by TornSoul Jul 25, 2002 at 2:48 PM 12 replies 2.4k views
Original Post
TornSoul
TornSoul
here we go... Alright, I started working on a tile engine and got to a decent milestone with it, only to notice that the color key isn''t working 100%. Anyone''s who''s willing to help, you can check out the demo to see what I mean at: http://tornsoul.rini.net/TiledWorld.zip It''s written in C++ in Visual Studio .NET. If you look around the character, there''s a black border around her that really shouldn''t be there. I think my problem is the way that I''m loading the bitmaps. (I''ve tried loading other bitmaps with color keys and I get borders for every single one). I''m loading bitmaps through GDI by capturing the device context, loading the bitmap, then blitting the image over. When I create the surface and blit the image over, I use the exact dimensions of the bitmap, so it doesn''t have to stretch the bitmap. The problem could possible lie in the differences in color. The demo is 640x480x16 and the bitmaps I''m loading are 8-bit. I know that GDI finds the closest color to match each pixel, and maybe it''s screwing with my sprites there. Could someone please please offer me some help with maybe a better bitmap loading routine? or maybe any idea on how to fix this? I''m going crazy! TornSoul AIM: TornSoul666
Arion
Arion

Hmm, the only black I''m getting is her shadow. I can''t see any other black decides that. So that probably doesn''t help very much. I really don''t know what to suggest. I guess it could be a video card thing. Aside from the I don''t know. Using a GeForce2 64Meg here.


Guy
TornSoul
TornSoul
Well, on some computers it''s harder to see than others. I know it''s there. How do you load your bitmaps? Through GDI? Or another way?

AIM: TornSoul666
nicho_tedja
nicho_tedja
Hm...nice sprite, gonna make an RPG?
I noticed the black thing, and yeah, it''s weird. On my computer, sometimes it''s there, sometimes it''s gone. I was thinking it could probably the sprite itself. Make sure the transparent area is pure black (RGB(0,0,0)) not something like RGB(1,0,1). But, since it''s not there all the time, I think it''s because something else.

Btw, are you using DirectX or GDI? If you''re using DirectX, I think it''s best to use its own bitmap function such as LoadTextureFromFile. But for GDI, I''d prefer to use masks.


My compiler generates one error message: "Doesn''t compile."
-Albert Tedja-
My compiler generates one error message: "does not compile."
Cahaan
Cahaan
Load your bitmap through GDI => OK.

Well I know how to solve your problem since I've actually met the same problem before.

The shit u're getting is coming from the fact the hardware acceleration stuff is doing an algorithmic operation on the surface to make it smoother, but in your case (and in mine too), it's not relevant.

This is how I fixed it and I suggest you to simply do this :

replace your DirectDraw init line by this one :

ddrval = DirectDrawCreateEx((GUID*)DDCREATE_EMULATIONONLY, (VOID **) &lpDD, IID_IDirectDraw7, NULL);

By doing this you'll make every ddraw operation using your CPU in place of your graphic card.

DON'T CARE, because with ddraw, you WIN everytime by doing this.(I've experienced and tested it, so believe me).

- Drawing will be faster (since you don't access video memory)
- And your colorkeying will not be f**** up.


EDIT: BTW this works if you're using directdraw 7. (I was assuming it).

[edited by - Cahaan on July 26, 2002 3:34:44 AM]
Darkhaven Beta-test stage coming soon.
TornSoul
TornSoul
Hmm...yeah, I''m going to be making a tile engine for an RPG. This is of course the very start of it. Thanks a lot Cahaan. That''s exactly what the problem was. I guess the Hardware Abstraction Layer was doing some weird shit to my bitmap. I really appreciate all the feedback I got.
Cahaan
Cahaan
No prob
I''m glad to help when I can.
Darkhaven Beta-test stage coming soon.
Pipo DeClown
Pipo DeClown
I know DirectDraw. but I never did make a tilesengine.
Where can I find some code? Im not a directdraw newb.
siaspete
siaspete
There's a lot of samples in the SDK, and there was a tile-based game tutorial over at www.2dgame.nl, but I can't get that page to come up at the moment.

Edit, the page seems to have moved to:
http://www.2dgame-tutorial.com/


Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions


[edited by - siaspete on July 26, 2002 6:38:11 AM]
AvalonX86
AvalonX86
I tried this solution for my colorkey problem (instead of using NULL as the first parameter of the Init). When I run my program it pops up with the normal "Failed to Initialize DirectDraw" window and when I run through the program, here are the errors I get after this line is run. I''m using DirectX 8.1 if this makes a difference.
Direct3D8: (ERROR) :GUID reference is invalid
First-chance exception in myrpg.exe (KERNEL32.DLL): 0xC0000005: Access Violation.
TornSoul
TornSoul
quote:
Original post by Pipo DeClown
I know DirectDraw. but I never did make a tilesengine.
Where can I find some code? Im not a directdraw newb.


Actually, the math portion isn't really that hard at all. I had just started with DirectDraw and I wanted to create something interesting with it and while I'd be doing other things, it just sort of came to me how everything would work. One thing I'd suggest is to use linked lists for your maps. I was reading about it somewhere (I can't remember where now), but the point is very valid. It's good for using maps with multiple layers. This way, you only take up the extra memory for an extra layer in the tiles that need it.

One thing I'd like to ask is for the people who've responded to download http://tornsoul.rini.net/tw.zip and try both of the executables and tell me the results on your computers. This would help me in understanding what's going on a bit more.

[edited by - TornSoul on July 26, 2002 5:08:31 PM]
Cahaan
Cahaan
Avalonx86:

Try to reboot, and see if it works.
Darkhaven Beta-test stage coming soon.
Kaezin
Kaezin
On the hard version, there is a tiny black outline on the character, but not on the soft version. Soft runs faster, too.

[edited by - Kaezin on July 27, 2002 1:12:17 PM]
Half the people you know are below average.Trogdor the Burninator
AvalonX86
AvalonX86
A reboot doesn''t fix anything..thanx for the suggestion anyways Cahaan..and it still works fine when I switch the parameter back to NULL. (altho no colorkey effects show up) Doesn''t really make sense to me unless DDCREATE_EMULATIONONLY does something weird I don''t know about... I''m prolly going to redo my engine in D3D so could get alpha transparency there but would love to have a DirectDraw version for ppl without decent videocards.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.