Sign in to follow this  

RGB Color Code

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

Hi all, I am trying to make the background of some of my images transparent and I thought I knew how to, but something must be missing. Here is the code:
void DrawPaddles(SDL_Surface *paddle1, SDL_Surface *paddle2, int x1, int y1, int x2, int y2)
{
    int r = 255;
    int g = 0;
    int b = 255;
    SDL_SetColorKey(paddle1, SDL_SRCCOLORKEY, SDL_MapRGB(paddle1->format, r, g, b));
    SDL_SetColorKey(paddle2, SDL_SRCCOLORKEY, SDL_MapRGB(paddle2->format, r, g, b));
    
    SDL_Rect rect1;
    rect1.x = x1;
    rect1.y = y2;
    
    SDL_Rect rect2;
    rect2.x = x2;
    rect2.y = y2;
    
    SDL_BlitSurface(paddle1, NULL, screen, &rect1);
    SDL_BlitSurface(paddle2, NULL, screen, &rect2);
} 



It draws the Paddles, but they are not transparent, I figured out that I need the r, g and be values to make white, but where can I find a table so I can manually change the I want to be transparent? [Edited by - Joshnathan on December 14, 2004 1:28:25 PM]

Share this post


Link to post
Share on other sites
a white RGB value is 255, 255, 255

I like to use MSPaint's color palette. I load an image and use the eyedropper tool to select the color from the image, and then I click on Colors->Edit Colors->Define Custom Colors and it tells me the exact RGB value. Or in picking a color I play around with the palette till I get a color I like, then just note the RGB values.

You might also want to look up the SDL_DisplayFormat function in the SDL docs, you should call it after your SDL_SetColorKey function calls.

Share this post


Link to post
Share on other sites
Here is a huge list of RGB values if this is what you are looking for. Link

When you are setting a transparent color, make sure that color is being used in your graphics file.

Also in your code, you are saying that Pinkish (255,0,255) is your transparent color, so your images must have a background of color. I'd suggust just making the background of all your images pure green (0,255,0) and then making the program use R=0,G=255,and B=0. I hope this helps!

Share this post


Link to post
Share on other sites

This topic is 4749 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this