Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3307058
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:21:42+00:00 2026-05-17T21:21:42+00:00

I’m learning the SDL library and one of the functions to create a surface

  • 0

I’m learning the SDL library and one of the functions to create a surface is SDL_CreateRGBSurface. The four parameters I’m wondering about are R, G, B, and A masks. What exactly is a mask in this context?

I’m also following a book about SDL and the author passed in 5 bits of red, 5 bits of blue, and 6 bits of green for the mask values. What does that mean though? What do the mask values do?

I filled in a rectangle onto the screen using a random number (Uint32 color) and got green. When I changed the mask values I noticed that the color changed even with the same color value.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:21:42+00:00Added an answer on May 17, 2026 at 9:21 pm

    Basically what’s happening is that when the SDL determines how much of each color to display, it looks at which bits are set in the mask to determine which bits to pay attention to in the color. It’s not quite as simple as a bitwise AND because the values are shifted over. For example,

    color = 0x00800000 = 00000000 10000000 00000000 00000000
    

    and you’ve set your masks to be

    Rmask = 0xFF000000 = 11111111 00000000 00000000 00000000
    Gmask = 0x00FF0000 = 00000000 11111111 00000000 00000000
    Bmask = 0x0000FF00 = 00000000 00000000 11111111 00000000
    Amask = 0x000000FF = 00000000 00000000 00000000 11111111
    

    then the color will be green {R=0, G=128, B=0}. The bits of color specified by Rmask are 0, the bits specified by Gmask are 0x80 == 128, and the bits specified by Bmask are 0. If you were to reverse the masks for the same color:

    Rmask = 0x000000FF
    Gmask = 0x0000FF00
    Bmask = 0x00FF0000
    Amask = 0xFF000000
    

    now the color will be blue {R=0, G=0, B=128}. It appears that the example you’re looking at uses 16 bit color without an alpha channel. Since 16 bits do not divide evenly by 3 color channels, green gets an extra bit (as the human eye is believed to be more sensitive to green).

    Example:

    color = 0x1234 = 00010 010001 10100
    
    Rmask = 0xF800 = 11111 000000 00000
    Gmask = 0x07E0 = 00000 111111 00000
    Bmask = 0x001F = 00000 000000 11111
    Amask = 0
    

    The color will be {R=2, G=17/2=8.5, B=20}. (the extra bit for green means the value needs to be halved to normalize it).

    I’m not sure of how exactly SDL does it, or what types of crazy masks you can use with SDL, but I would imagine the actual algorithm is along the lines of a bitwise AND, then right-shift as many bits as are cleared in the least significant portion of the mask? Or else working from most significant to least significant bit, for each bit that’s set in the mask, shift the total left and add 1 if the corresponding bit of the color is set.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I have text I am displaying in SIlverlight that is coming from a CMS
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.