Hey,
First, donāt handle surfaces. Only deal with pointers to surfaces. If you kept using that line which dereferenced the surface pointer, youād keep building up memory leakage. Thereās no way to free those surfaces anymore. You can take a lesson from Javaās objects (You can never have a variable that IS an object, only a pointer to one).
SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, rmask, gmask, bmask, amask);
The ā32ā in this call means youāre making a 32 bit surface. It wonāt be auto-converted. Iām pretty sure SDL_image leaves the conversion up to you as well. If you load a big monochrome bmp, you donāt want it to automatically take up several megabytes when it should take just a few kilobytes.
Sorry I donāt have the time to work out a solution for you, but try this:
Base = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, rmask, gmask, bmask, amask);
SDL_SetAlpha(Base, SDL_SRCALPHA, 255);
SDL_FillRect(Base, NULL, 0x00000000);
I know if you blit something with per-pixel alpha onto this surface or use a putpixel with alpha function on it, itāll work correctly. Per-surface alpha is disabled (in SDL_BlitSurface()) if you use per-pixel alpha, by the way.
Jonny D> To: sdl at libsdl.org> From: kixdemp at gmail.com> Date: Thu, 9 Aug 2007 10:06:27 -0400> Subject: Re: [SDL] SDL_CreateSurfaceFrom crashes> > > Uh - why?> Because Iām dumb and thought it would cause conflicts with Lua⦠XD> > I made it a pointer and uppercased the āBā.> > And this code:> > -----------------------> /* Create a 32-bit surface with the bytes of each pixel in R,G,B,A > order, as expected by OpenGL for textures /> > Uint32 rmask, gmask, bmask, amask;> > / SDL interprets each pixel as a 32-bit number, so our masks must > depend on the endianness (byte order) of the machine */> #if SDL_BYTEORDER == SDL_BIG_ENDIAN> rmask = 0xff000000;> gmask = 0x00ff0000;> bmask = 0x0000ff00;> amask = 0x000000ff;> #else> rmask = 0x000000ff;> gmask = 0x0000ff00;> bmask = 0x00ff0000;> amask = 0xff000000;> #endif> > Base = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32,> rmask, gmask, bmask, amask);> -----------------------> > provides per-surface alpha (nothing is displayed at first, then if I > fill it with black my objects show over a black background, if I fill it > with 50% white then it shows the same thing but transparent), and I need > per-pixel alpha.> > Also, that same code, for some reason makes blitting slow⦠:-/> Maybe Iām missing some depth conversions? Doesnāt SDL convert all > surfaces to screen depth upon creation? Or must I do that? What about > images loaded with IMG_Load(ā¦)?> > Thanks all of you for helping this noob in despair!> > _______________________________________________> SDL mailing list> SDL at lists.libsdl.org> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Learn. Laugh. Share. Reallivemoms is right place!
http://www.reallivemoms.com?ocid=TXT_TAGHM&loc=us