Jump to content
  • Advertisement


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


weird color key problem

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

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 this post

Link to post
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 this post

Link to post
Share on other sites
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)


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

Share this post

Link to post
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 this post

Link to post
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.

Multitasking - screwing up several things at once.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!