Loading an image into hardware memory

After finding out that IMG_Load loads images into software surfaces, I set up a simple routine to try to load the resulting image into hardware. For some reason, it produces a blank surface. Anyone see what the problem is with this?
(Note: this is Object Pascal code, not C. Shouldn’t be too hard to read, though.)

begin
format := FSurface.format;
dummy := SDL_AllocSurface(IMAGE_FORMAT, FSurface.w, FSurface.h, format^.BitsPerPixel,
format^.RMask, format^.GMask, format^.BMask, format^.AMask);
if (dummy = nil) or (SDL_BlitSurface(FSurface, nil, dummy, nil) <> 0) then
raise ESdlImageException.Create(BAD_LOAD); //throw an exception
SDL_FreeSurface(FSurface);
FSurface := dummy;
end;

Dummy is declared as an SDL_Surface pointer, and format as an SDL_PixelFormat pointer. IMAGE_FORMAT is a constant declared as SDL_HWSURFACE or SDL_SRCCOLORKEY.

As far as I can tell, this ought to produce an exact copy of the image, but in a hardware surface instead of a software surface. Any idea why it’s not working?

Dummy is declared as an SDL_Surface pointer, and format as an SDL_PixelFormat pointer. IMAGE_FORMAT is a constant declared as SDL_HWSURFACE or SDL_SRCCOLORKEY.

As far as I can tell, this ought to produce an exact copy of the image, but in a hardware surface instead of a software surface. Any idea why it’s not working?

Is the pixel format paletted? If so, you need to copy the palette as
well as blitting the pixels. In C, the following would do it:

SDL_SetColors(dummy, FSurface.format.palette.colors, 0,
FSurface.format.palette.colors);On Mon, Jun 23, 2008 at 11:37 AM, Mason Wheeler wrote:


http://pphaneuf.livejournal.com/

Yep! That was it, all right. (Except that the last parameter needed to be .ncolors, not .colors.) :stuck_out_tongue:
But it works now. Thanks!>----- Original Message ----

From: Pierre Phaneuf
Subject: Re: [SDL] Loading an image into hardware memory

Is the pixel format paletted? If so, you need to copy the palette as
well as blitting the pixels. In C, the following would do it:

SDL_SetColors(dummy, FSurface.format.palette.colors, 0,
FSurface.format.palette.colors);

Yep! That was it, all right. (Except that the last parameter needed to be .ncolors, not .colors.) :stuck_out_tongue:
But it works now. Thanks!

Oops, yes, that’s right! Also, a nice way to test for whether you need
to do this is to check whether FSurface.format.palette is NULL, if
it’s not, then you should do it.On Mon, Jun 23, 2008 at 11:58 AM, Mason Wheeler wrote:


http://pphaneuf.livejournal.com/