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