Results 1 to 8 of 8

Thread: Can't get SDL_GetRGBA to work.

  1. #1

    Can't get SDL_GetRGBA to work.

    This is probably just a stupid mistake, but I can't get SDL_GetRGBA to work:

    Code:
    var theimage : PSDL_Surface;
      pixel : Uint32;
      fmt : PSDL_PixelFormat;
      r, g, b, a : PUint8;
    [...]
      theimage := IMG_Load('test.png');
      fmt := theimage^.format;
      pixel := SDL_GetPixel(theimage, y, x);
      SDL_GetRGBA(pixel, fmt, r, g, b, a);
    Whenever it gets to the SDL_GetRGBA call, the program just closes. If I comment out this line, everything's fine. Am I declaring my variables incorrectly?
    Laserbrain Studios - Currently developing Hidden Asset!
    Ascii Sector
    - Real-time roguelike in space!

  2. #2

    Re: Can't get SDL_GetRGBA to work.

    So... Nobody can see anything wrong with this?
    Laserbrain Studios - Currently developing Hidden Asset!
    Ascii Sector
    - Real-time roguelike in space!

  3. #3

    Re: Can't get SDL_GetRGBA to work.

    I'm really no good rendering with SDL, but my first gripe would be that x and y where out of bounds or pixel is null...
    Amnoxx

    Oh, and this code appears to be an approximate replacement for return(random() & 0x01);

    Phoenix Wiki
    http://www.phoenixlib.net/

    Phoenix Forum
    http://www.pascalgamedevelopment.com/viewforum.php?f=71

  4. #4

    Re: Can't get SDL_GetRGBA to work.

    x and y are within bounds. If I use them to get the color value of the pixel, no problem. And even if I check that the pixel isn't null, the program always just exits when I get to the SDL_GetRGBA call.
    Laserbrain Studios - Currently developing Hidden Asset!
    Ascii Sector
    - Real-time roguelike in space!

  5. #5

    Re: Can't get SDL_GetRGBA to work.

    This is really getting annoying. I've also asked on the SDL mailing list, but haven't found out what's wrong yet. Has anybody used SDL_GetRGBA and can you post the procedure you used it in so I can check if it works on my setup?
    Laserbrain Studios - Currently developing Hidden Asset!
    Ascii Sector
    - Real-time roguelike in space!

  6. #6

    Re: Can't get SDL_GetRGBA to work.

    I figured it out with help from the SDL mailing list. I just had to allocate memory for the r, g, b and a pointers. I thought the SDL_GetRGBA call did this, but guess not.
    Laserbrain Studios - Currently developing Hidden Asset!
    Ascii Sector
    - Real-time roguelike in space!

  7. #7

    Re: Can't get SDL_GetRGBA to work.

    Quote Originally Posted by PP2005
    I figured it out with help from the SDL mailing list. I just had to allocate memory for the r, g, b and a pointers. I thought the SDL_GetRGBA call did this, but guess not.
    Hi PP2005,
    I do it like so:

    [pascal]var theimage : PSDL_Surface;
    pixel : Uint32;
    fmt : PSDL_PixelFormat;
    r, g, b, a : Uint8;
    [...]
    theimage := IMG_Load('test.png');
    fmt := theimage^.format;
    pixel := SDL_GetPixel(theimage, y, x);
    SDL_GetRGBA(pixel, fmt, @r, @g, @b, @a);[/pascal]

    So I don't have to allocate any memory myself
    cheers,
    Paul

  8. #8

    Re: Can't get SDL_GetRGBA to work.

    Thanks!
    Laserbrain Studios - Currently developing Hidden Asset!
    Ascii Sector
    - Real-time roguelike in space!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •