“Mattias Engdeg?rd” wrote
i’m trying to create an exact duplicate of some surface data.
for some reason this is harder than it seems. what is making it
tricky is that i want it to work with all surfaces types
(alphas, colorkeys, etc)
newsurface = SDL_ConvertSurface(surface, surface->format, surface->flags)
great solution. now when i use this in the whole of my puzzle,
it isn’t working very nicely.
i’m writing a routine to duplicate a section of another image.
the meat of it looks like this. i create the ‘subimage’ with
CreateRGBSurfaceFrom, then use ConvertSurface to make the
/* blah, blah, code to error check positions and sizes /
/ i have srcsurf as the given source, then use tempsurf /
/ and dupesurf to hold results. /
/ also srcformat is srcsurf->format */
firstpixel = ((char*)srcsurf->pixels) +
(srcsurf->pitch * height) +
(srcformat->BytesPerPixel * width);
tempsurf = SDL_CreateRGBSurfaceFrom(firstpixel, x, y,
printf(“tempsurf = %d x %d\n”, tempsurf->w, tempsurf->h);
dupesurf = SDL_ConvertSurface(tempsurf, srcformat,
printf(“pixels: orig=%d, temp=%d, dupe=%d\n”,
you’ll notice i have some sanity-checking print values in
the code. i’m testing with 32bit images, so for my testing
this works well. the printout when calling this function…
tempsurf = 200 x 200
pixels: orig=1111, temp=1111, dupe=0
the results i get from this are an all black image. all the
formats and flags seem correct, there’s just no pixel data.
(ps, in this test there is no alpha or colorkey, nothing fancy,
although now that i think about it, srcsurf is the screen surface,
(but that is being created as SWSURFACE, so i should be safe…?)
on another note, if i change the Convert line to use tempsurf->format
instead of srcsurf->format, i get a nasty crash. strange, but i haven’t
dug into it yet.