#### Archived

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

# weird color key problem

This topic is 5994 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

This one has stymied me so far - I''ll start with the basics and we''ll go from there. Here''s my code:
// set the transparency key to black
if (SDL_Failed(SDL_SetColorKey(psSurface, SDL_SRCCOLORKEY, SDL_MapRGB(psSurface->format, 0, 0, 0))))
throw Error("could not set transparency key", "asteroids.cpp", __LINE__);

And that was taken from another program where I tested it and it worked fine. The problem? For some reason, black (0, 0, 0) isn''t transparent, yet the images i''m blitting are semi-transparent (cept their black backgrounds). But then there are some images that aren''t transparent or semi-transparent, just completely opaque. It''s driving me nuts. tell me what more you need and let''s crack this nut _________________________________________________________________ Drew Sikora A.K.A. Gaiiden ICQ #: 70449988 AOLIM: DarkPylat Blade Edge Software Staff Member, GDNet Public Relations, Game Institute 3-time Contributing author, Game Design Methods , Charles River Media (coming April/May 2002) Online column - Design Corner at Pixelate NJ IGDA Chapter - NJ developers unite!! [Chapter Home | Chapter Forum]

##### Share on other sites
Okay, many thanks to Redleaf for suggesting that I try setting the color key for the surfaces with the images on them, rather than the destination surface. So I was doing it backwards. Doh!

However the images are still semi-transparent, which is something i still haven''t figured out.

##### Share on other sites
hmm. are you sure, that the images are EXACTLY 0,0,0 where you want them to be transparent?

---
cone3d
http://cone3d.gamedev.net
Multitasking - screwing up several things at once.

##### Share on other sites
quote:
Original post by cone3d
hmm. are you sure, that the images are EXACTLY 0,0,0 where you want them to be transparent?

That''s what I was thinking. Gaiiden, make sure that the part of the image you are trying to make transparent is 0,0,0. All of the pixels that you want to be transparent. Maybe you have a lighter and darker shade of black together, that''s why some of it might look transparent. Lets say you have

*^*^*^*
^*^*^*^
*^*^*^*

* = 0,0,0
^ = 0,0,1

Then when you get rid of the colors, it shows up semi-transparent because the other pixels are still there.

Something tells me that this isn''t your problem though.

------------------------------
Simple DirectMedia Layer:

Main Site - (www.libsdl.org)
Cone3D Tutorials- (cone3D.gamedev.net)
GameDev.net''s Tutorials - (Here)

OpenGL:

Main Site - (www.opengl.org)
NeHe Tutorials - (nehe.gamedev.net)
Online Books - (Red Book) (Blue Book)

##### Share on other sites
No, the black in my images is totally transparent now, thanks to Redleaf. However my green starship and gray asteroids are semi-transparent So if i were to draw the starship first then the asteroid, when an asteroid passes over the starship (no collision detection yet) you can see the starship through the asteroid! Maybe it''s the colors somehow? I made all my images in MS Paint. Hmmmm

##### Share on other sites
hmm. now it seems that your asteroid has the black (0,0,0) on some parts of itself. 0,0,0 IS a really common color, so I think you should better try using really seldom-used colors for the transparency, like 255,0,255.

---
cone3d
http://cone3d.gamedev.net
Multitasking - screwing up several things at once.

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 10
• 14
• 30
• 13
• 11
• ### Forum Statistics

• Total Topics
631788
• Total Posts
3002356
×