Jump to content
  • Advertisement
Sign in to follow this  
logank9

Does C++ use hex codes?

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

I'm trying to do color keying (removing the background of an image) through a tutorial for Lazyfoo, but I'm kind of confused on how the colors work. Does C++ use hex codes the same as in HTML? The background of my image is red (FF0000) but I'm not sure how to find out what the hex code, or whatever C++ uses is. Any help is appreciated. :)

Share this post


Link to post
Share on other sites
Advertisement
C++ has no notion of color. Representation of color depends on any additional libraries or APIs you might be using. C++ does have hexadecimal integer literals which are denoted with a prefix of 0x. 0xFF0000 is a legitimate int value. Whether or not it has anything to do with the color red depends on what you do with the int.

Share this post


Link to post
Share on other sites
Yes and no.

Yes, C++ allows you to specify data in hexadecimal. However, C++ is too low level to understand pixel colours like HTML.

I am assuming that you are using SDL from your mention of Lazy Foo. SDL has a concept of pixel colours. It says that pixels are nominally 4 unsigned 8 bit values R,G,B,A. These values are 0 - 255, or if you want to use hex 0x00 - 0xff. The format of a pixel in a particular surface may vary with the hardware or operating system. However, SDL provides convenience functions to extract and manipulate these values. A pixel outside a surface is usually stored in a Uint32.

Lets say we want to fill the SDL_Surface "screen" with the colour red. Red is R,G,B (0xff, 0x00, 0x00).

We can write:

Uint32 red = SDL_MapRGB(screen->format, 0xff, 0x00, 0x00);
SDL_FillRect(screen, NULL, red);


We can use such mapped RGB pixels for setting the colourkey of bitmaps, or even to read and write to the raw pixel data of a surface.

You may want to research SDL_MapRGB, SDL_MapRGBA, SDL_GetRGB, SDL_GetRGBA, SDL_SetColorKey, SDL_PixelFormat in the SDL documentation wiki.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!