View Full Version : Can't get SDL_GetRGBA to work.
Christian Knudsen
29-08-2009, 12:17 PM
This is probably just a stupid mistake, but I can't get SDL_GetRGBA to work:
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?
Christian Knudsen
31-08-2009, 09:01 PM
So... Nobody can see anything wrong with this?
Andreaz
01-09-2009, 06:03 AM
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...
Christian Knudsen
01-09-2009, 08:49 AM
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.
Christian Knudsen
01-09-2009, 01:48 PM
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?
Christian Knudsen
01-09-2009, 02:51 PM
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. :)
paul_nicholls
01-09-2009, 11:59 PM
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:
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);
So I don't have to allocate any memory myself :)
cheers,
Paul
Christian Knudsen
02-09-2009, 09:17 AM
Thanks! :)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.