Alpha transparency on created surface?

Hello everyone! :slight_smile:

Okay, I need a surface that is fully blank that I can draw objects on.
Like, if I were to blit it alone on the screen, nothing would be displayed.

Transparency on loaded PNGā€™s does work fine, but how can I make said
surface?

Iā€™m sure this was asked before, but I Googleā€™d and none of the solutions
worked for meā€¦ :-/

I tried SDL_SetAlpha(surf, 0, 0); but nothingā€¦ I fill the surface with
(0,0,0,0).

Thanks!

Is one of the parameters to SDL_SetAlpha supposed to be set to
SDL_SRCALPHA? I canā€™t remember exactly, but itā€™s worth a check.

Also make sure you specify an alpha mask when creating the surface.

Hope this helps!

PeterOn 08/08/07, L-28C wrote:

Hello everyone! :slight_smile:

Okay, I need a surface that is fully blank that I can draw objects on.
Like, if I were to blit it alone on the screen, nothing would be displayed.

Transparency on loaded PNGā€™s does work fine, but how can I make said
surface?

Iā€™m sure this was asked before, but I Googleā€™d and none of the solutions
worked for meā€¦ :-/

I tried SDL_SetAlpha(surf, 0, 0); but nothingā€¦ I fill the surface with
(0,0,0,0).

Thanks!


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

When you say ā€œnothing would be displayedā€, do you mean just a black screen?
Because you can do that with a call to SDL_FillRect. If you mean that it
would show through to the desktop, though, I donā€™t know that thatā€™s
possibleā€¦ correct me if Iā€™m wrong, of course, but thinking about how the
Windows API and other stuff like that works, it would take some extra code
to get that to work. Especially cross-platform.On 8/8/07, Peter Mackay <mackay.pete+sdl at gmail.com> wrote:

Is one of the parameters to SDL_SetAlpha supposed to be set to
SDL_SRCALPHA? I canā€™t remember exactly, but itā€™s worth a check.

Also make sure you specify an alpha mask when creating the surface.

Hope this helps!

Peter

On 08/08/07, L-28C wrote:

Hello everyone! :slight_smile:

Okay, I need a surface that is fully blank that I can draw objects on.
Like, if I were to blit it alone on the screen, nothing would be
displayed.

Transparency on loaded PNGā€™s does work fine, but how can I make said
surface?

Iā€™m sure this was asked before, but I Googleā€™d and none of the solutions
worked for meā€¦ :-/

I tried SDL_SetAlpha(surf, 0, 0); but nothingā€¦ I fill the surface with
(0,0,0,0).

Thanks!


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

ā€“
su; cd /; rm -rf *

(not responsible for anything that happens if youā€™re foolish enough to type
that)

Hey,

Just like the other guy said, it takes SDL_SRCALPHA to make alpha blending work. Try:
SDL_SetAlpha(surface, SDL_SRCALPHA, 255);

This will set that flag on your surface and set the opacity to full so that if it doesnā€™t recognise the RGBA format (i.e. something else is wrong), you at least get to see something. Just remember that SDL_SRCALPHA enables alpha blending on RGBA surfaces and without it, you can do direct pixel copying.

Jonny D> To: sdl at libsdl.org> From: kixdemp at gmail.com> Date: Tue, 7 Aug 2007 20:46:33 -0400> Subject: [SDL] Alpha transparency on created surface?> > Hello everyone! :-)> > Okay, I need a surface that is fully blank that I can draw objects on. > Like, if I were to blit it alone on the screen, nothing would be displayed.> > Transparency on loaded PNGā€™s does work fine, but how can I make said > surface?> > Iā€™m sure this was asked before, but I Googleā€™d and none of the solutions > worked for meā€¦ :-/> > I tried SDL_SetAlpha(surf, 0, 0); but nothingā€¦ I fill the surface with > (0,0,0,0).> > Thanks!> > _______________________________________________> SDL mailing list> SDL at lists.libsdl.org> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Messenger Caf? ? open for fun 24/7. Hot games, cool activities served daily. Visit now.
http://cafemessenger.com?ocid=TXT_TAGLM_AugWLtagline

Hmmā€¦ The docs on SDL_CreateRGBSurface(ā€¦) say that if you specify an
alpha mask > 0, then SDL_SRCALPHA will be automatically setā€¦

Well, I set a mask of 255, but the surface is still black instead of
transparent. :-/

I called SDL_SetAlpha(ā€¦) with the parameters you specified, but the
same thing is displayed.

I basically just want the surface to be filled with (0,0,0,0) (nothing)
instead of (0,0,0) (black).

Thanks you three! :wink:

(P.S; talking about SDL_CreateRGBSurface, whatā€™s the advantage on using
hardware surfaces over software ones?)

I found the right word to say what I want to do!

Per-pixel alpha. :wink:

How do you do that? I thought of loading a 1x1 PNG and filling my
surface with that single pixel, but that wouldnā€™t be very efficientā€¦

Thanks!

L-28C wrote:> Hmmā€¦ The docs on SDL_CreateRGBSurface(ā€¦) say that if you specify an

alpha mask > 0, then SDL_SRCALPHA will be automatically setā€¦

Well, I set a mask of 255, but the surface is still black instead of
transparent. :-/

I called SDL_SetAlpha(ā€¦) with the parameters you specified, but the
same thing is displayed.

I basically just want the surface to be filled with (0,0,0,0) (nothing)
instead of (0,0,0) (black).

Thanks you three! :wink:

(P.S; talking about SDL_CreateRGBSurface, whatā€™s the advantage on using
hardware surfaces over software ones?)

Well, since nobody seemed to have the answer the previous question, I
loaded up a 1x1 transparent PNG called ā€˜tpixelā€™ and did this:

base = *SDL_CreateRGBSurfaceFrom(tpixel->pixels, w, h,
tpixel->format->BitsPerPixel, tpixel->pitch, 0, 0, 0, 0);

(note the * before the function call; ā€˜baseā€™ is not a pointer)

It crashes right thereā€¦ Am I using the function wrongly? o_O

Thanks people!

L-28C wrote:> I found the right word to say what I want to do!

Per-pixel alpha. :wink:

How do you do that? I thought of loading a 1x1 PNG and filling my
surface with that single pixel, but that wouldnā€™t be very efficientā€¦

Thanks!

L-28C wrote:

Hmmā€¦ The docs on SDL_CreateRGBSurface(ā€¦) say that if you specify an
alpha mask > 0, then SDL_SRCALPHA will be automatically setā€¦

Well, I set a mask of 255, but the surface is still black instead of
transparent. :-/

I called SDL_SetAlpha(ā€¦) with the parameters you specified, but the
same thing is displayed.

I basically just want the surface to be filled with (0,0,0,0) (nothing)
instead of (0,0,0) (black).

Thanks you three! :wink:

(P.S; talking about SDL_CreateRGBSurface, whatā€™s the advantage on using
hardware surfaces over software ones?)

Uh - why?

-bill!On Wed, Aug 08, 2007 at 09:34:45PM -0400, L-28C wrote:

base = *SDL_CreateRGBSurfaceFrom(tpixel->pixels, w, h,
tpixel->format->BitsPerPixel, tpixel->pitch, 0, 0, 0, 0);

(note the * before the function call; ā€˜baseā€™ is not a pointer)

base = *SDL_CreateRGBSurfaceFrom(tpixel->pixels, w, h,
tpixel->format->BitsPerPixel, tpixel->pitch, 0, 0, 0, 0);

(note the * before the function call; ā€˜baseā€™ is not a pointer)

Uh - why?

The asterisk is de-referencing the pointer returned by the function.
That means the right side of the equate resolves to a surface structure.
If base is a surface structure then youā€™d also have to have an overload
defined for operator=.>>> On 8/9/2007 at 12:16 AM, Bill Kendrick wrote:

On Wed, Aug 08, 2007 at 09:34:45PM -0400, L-28C wrote:

ā€“
Lilith

Hello !

Well, since nobody seemed to have the answer the previous question, I
loaded up a 1x1 transparent PNG called ā€˜tpixelā€™ and did this:

base = *SDL_CreateRGBSurfaceFrom(tpixel->pixels, w, h,
tpixel->format->BitsPerPixel, tpixel->pitch, 0, 0, 0, 0);

(note the * before the function call; ā€˜baseā€™ is not a pointer)

It crashes right thereā€¦ Am I using the function wrongly? o_O

For me this does not make much sense.

For example if base is a SDL_Surface and not a pointer to
a SDL_Surface, i think you cannot do base = *SDL_gives_surface_address_back.

If base for example is a ** pointer, you may need to do it
in that way (* base ) = SDL_CreateRGBSurface ā€¦

But if you are not advanced in Pointers, than using them the easiest
way is the best :---------------------------

/* Create a 32-bit surface with the bytes of each pixel in R,G,B,A order,
as expected by OpenGL for textures */
SDL_Surface *surface;
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

surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,
                               rmask, gmask, bmask, amask);
if(surface == NULL) {
    fprintf(stderr, "CreateRGBSurface failed: %s\n", SDL_GetError());
    exit(1);
}

CU

SDL returns surfaces as pointers for a various reasons, it is best to
store surfaces in your own programs as pointers too.

SDL_CreateRGBSurfaceFrom expects ā€œtpixel->pixelsā€ to contain at least
"w" x ā€œhā€ pixels, is this the case? Are ā€œwā€ and ā€œhā€ both 1?On 09/08/07, L-28C wrote:

Well, since nobody seemed to have the answer the previous question, I
loaded up a 1x1 transparent PNG called ā€˜tpixelā€™ and did this:

base = *SDL_CreateRGBSurfaceFrom(tpixel->pixels, w, h,
tpixel->format->BitsPerPixel, tpixel->pitch, 0, 0, 0, 0);

(note the * before the function call; ā€˜baseā€™ is not a pointer)

It crashes right thereā€¦ Am I using the function wrongly? o_O

Thanks people!

L-28C wrote:

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!

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

Nope, didnā€™t workā€¦ :-/

I got an idea though. Iā€™ll look into the SDL.NET source, I donā€™t
remember having this problem while coding this same game on C#.

Then Iā€™ll report back to yā€™all. :stuck_out_tongue:

Jonathan Dearborn wrote:> 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: @Leo_M_Cabrera
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


New home for Mom, no cleanup required. All starts here.
http://www.reallivemoms.com?ocid=TXT_TAGHM&loc=us



SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

LOL.----------------------
Assembly assembly = Assembly.GetCallingAssembly();
Stream stream =
assembly.GetManifestResourceStream(ā€œSdlDotNet.Graphics.Transparent.pngā€);
resizeBuffer = ReadFully(stream, stream.Length);
resizeSurface = new Surface(resizeBuffer);

They use a 1x1 PNG like I was doing it. XD

SDL needs to support this without having to use a transparent dot.
Cheers, Sam, you can do it! :smiley:

Now it shouldnā€™t be hard to figure it out. :wink:
Thanks all!

L-28C wrote:

Nope, didnā€™t workā€¦ :-/

I got an idea though. Iā€™ll look into the SDL.NET source, I donā€™t
remember having this problem while coding this same game on C#.

Then Iā€™ll report back to yā€™all. :stuck_out_tongue:

Jonathan Dearborn wrote:

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: @Leo_M_Cabrera
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


New home for Mom, no cleanup required. All starts here.
http://www.reallivemoms.com?ocid=TXT_TAGHM&loc=us



SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

L-28C wrote:> LOL.


Assembly assembly = Assembly.GetCallingAssembly();
Stream stream =
assembly.GetManifestResourceStream(ā€œSdlDotNet.Graphics.Transparent.pngā€);
resizeBuffer = ReadFully(stream, stream.Length);
resizeSurface = new Surface(resizeBuffer);

They use a 1x1 PNG like I was doing it. XD

SDL needs to support this without having to use a transparent dot.
Cheers, Sam, you can do it! :smiley:

Now it shouldnā€™t be hard to figure it out. :wink:
Thanks all!

L-28C wrote:

Nope, didnā€™t workā€¦ :-/

I got an idea though. Iā€™ll look into the SDL.NET source, I donā€™t
remember having this problem while coding this same game on C#.

Then Iā€™ll report back to yā€™all. :stuck_out_tongue:

Jonathan Dearborn wrote:

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: @Leo_M_Cabrera
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


New home for Mom, no cleanup required. All starts here.
http://www.reallivemoms.com?ocid=TXT_TAGHM&loc=us



SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Now it shouldnā€™t be hard to figure it out. :wink:

Wasnā€™t. What they did is resize the pixel to whatever image size you
specifyā€¦ o_O

And sorry if I sent just a blank e-mail, I think I accidentally pressed
ā€™Sendā€™.

L-28C wrote:> LOL.


Assembly assembly = Assembly.GetCallingAssembly();
Stream stream =
assembly.GetManifestResourceStream(ā€œSdlDotNet.Graphics.Transparent.pngā€);
resizeBuffer = ReadFully(stream, stream.Length);
resizeSurface = new Surface(resizeBuffer);

They use a 1x1 PNG like I was doing it. XD

SDL needs to support this without having to use a transparent dot.
Cheers, Sam, you can do it! :smiley:

Now it shouldnā€™t be hard to figure it out. :wink:
Thanks all!

L-28C wrote:

Nope, didnā€™t workā€¦ :-/

I got an idea though. Iā€™ll look into the SDL.NET source, I donā€™t
remember having this problem while coding this same game on C#.

Then Iā€™ll report back to yā€™all. :stuck_out_tongue:

Jonathan Dearborn wrote:

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: @Leo_M_Cabrera
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


New home for Mom, no cleanup required. All starts here.
http://www.reallivemoms.com?ocid=TXT_TAGHM&loc=us



SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org