SDL buffer channels question

This is a discussion on SDL buffer channels question within the Game Programming forums, part of the General Programming Boards category; Hi, I have a question about the channels in a SDL_Buffer and then a question about SDL in general. My ...

  1. #1
    Algorithm engineer
    Join Date
    Jun 2006
    Posts
    286

    SDL buffer channels question

    Hi, I have a question about the channels in a SDL_Buffer and then a question about SDL in general.

    My question about SDL_Buffer channels is why isn't there any standard order in which the different channels lie inside of the buffer? My system doesn't use big endian (I guess it uses little endian), so according to an example here the masks for r, g, b and alpha should be

    Code:
        rmask = 0x000000ff;
        gmask = 0x0000ff00;
        bmask = 0x00ff0000;
        amask = 0xff000000;
    In other words, the channels would be in the order a, b, g, r if you take the least significant byte last. However, the screen buffer that is created by sdl with SDL_SetVideoMode will get channels in the order r, g, b, where b is in the LSB, and no alpha channel. Here the order is reversed. Why? According to the example, it seems like the order of the channels is important, but apparently it doesn't match with that of the screen buffer. I'm starting to doubt that it matters at all.

    Also, when I create an optimized (for blitting to the screen buffer) buffer using SDL_DisplayFormatAlpha, or if I render a text (using the SDL_ttf library) with TTF_RenderText_Blended, the channels will be in the order a, r, g, b. Here the channels are in the same order as in the screen buffer, only an alpha channel has been added in the MSB. However, if I load an image from a file (using the SDL_img library) with IMG_Load, the channels will be in the order b, g, r (the image files doesn't have alpha channels). Now the order of r, g and b has once again been reverted, matching the order of the example I linked to before.

    So, my question again - why isn't there any standard order in which the different channels lie inside of the buffer (at least a unifying standard for the specific endianness), why does it differ so much?

    And then a question about SDL. It doesn't seem to be very much information about it. Although the official documentation covers every part briefly, there doesn't seem to be any deep going documentation about it. How comes? It is a pretty well used library after all, isn't it? The only wiki I have found about it doesn't seem to be very large, and I have only found one small forum about it.
    Come on, you can do it! b( ~_')

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,409
    Although the official documentation covers every part briefly
    It seems to be notorious for being poorly documented i'm afraid, bags of good tutorials out there though, maybe you will find the answer in one of those or a forum like gamedev, sorry cant help further, mebbe the coder that built those libraries just couldnt be bothered putting all his function arguments in the same order each time eh..

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    82
    TriKri, there are standards, and well defined implementations, SDL is a layer over all of that and chooses to screw with your mind. >:]

    Honestly though, you couldn't get a better answer here than you would at SDL's forums, you should ask your questions there. I'm betting there are ways to get around and make what you need known or happen when you really get in to it.

    http://forums.libsdl.org
    Last edited by since; 12-09-2009 at 01:00 PM.

  4. #4
    Algorithm engineer
    Join Date
    Jun 2006
    Posts
    286
    Come on, you can do it! b( ~_')

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question abt read(fd, buffer, 1024)
    By tesla in forum Networking/Device Communication
    Replies: 1
    Last Post: 09-12-2009, 03:52 AM
  2. clear buffer
    By justins in forum C Programming
    Replies: 5
    Last Post: 05-19-2007, 06:16 AM
  3. Replies: 16
    Last Post: 10-29-2006, 04:04 AM
  4. Input buffer question
    By n3xus in forum C++ Programming
    Replies: 5
    Last Post: 02-01-2006, 08:39 PM
  5. A Little Performance Related SDL Question...
    By Comrade_Yeti in forum Game Programming
    Replies: 14
    Last Post: 12-09-2005, 06:46 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21