# The perfect transparent surface. ( Improved question )

**URL:** <https://discourse.libsdl.org/t/the-perfect-transparent-surface-improved-question/14945>\
**Category:** SDL Development\
**Created:** [November 5, 2007, 4:58pm UTC](https://discourse.libsdl.org/t/the-perfect-transparent-surface-improved-question/14945 "2007-11-05T16:58:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miguel\_Pragier](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/ad7895/32.png) [@Miguel\_Pragier](https://discourse.libsdl.org/u/Miguel_Pragier)\
**Post date:** [November 5, 2007, 4:58pm UTC](https://discourse.libsdl.org/t/the-perfect-transparent-surface-improved-question/14945/1 "2007-11-05T16:58:21Z")

</div>

Miguel Pragier \<pragier [gmail.com](http://gmail.com)\> writes:

> What’s the?better way to create a 100% transparent surface?  
> ?  
> If exist a kind of 'design pattern" to create transparent surfaces, can  
> anyone point me a code sample?  
> ?  
> And can anyone tell me?any information?about the color masks?  
> ?
> 
> * * *
> 
> SDL mailing list  
> SDL [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

What’s the best SDL’s way to create a 800x600 32Bpp surface 100% transparent?

I know the SDL\_CreateRGBSurface, but don’t know much about the color mask.  
specially the AMask.

Thank you, everybody.

---

<div class="post-metadata">

**Author:** ![Alberto\_Luaces\_Ferna](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/a/74df32/32.png) [@Alberto\_Luaces\_Ferna](https://discourse.libsdl.org/u/Alberto_Luaces_Ferna)\
**Post date:** [November 6, 2007, 9:08am UTC](https://discourse.libsdl.org/t/the-perfect-transparent-surface-improved-question/14945/2 "2007-11-06T09:08:45Z")

</div>

El Monday 05 November 2007 17:58:21 Miguel Pragier escribi?:

> > What’s the?better way to create a 100% transparent surface?  
> > ?  
> > If exist a kind of 'design pattern" to create transparent surfaces, can
> 
> anyone point me a code sample?
> 
> > ?  
> > And can anyone tell me?any information?about the color masks?
> 
> What’s the best SDL’s way to create a 800x600 32Bpp surface 100%  
> transparent?
> 
> I know the SDL\_CreateRGBSurface, but don’t know much about the color mask.  
> specially the AMask.

Every mask is the binary mask that specify where its colour component is  
stored. From the documentation example:

```
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);

```

What do you mean by 100% transparent? Invisible?

---

<div class="post-metadata">

**Author:** ![Miguel\_Pragier](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/ad7895/32.png) [@Miguel\_Pragier](https://discourse.libsdl.org/u/Miguel_Pragier)\
**Post date:** [November 6, 2007, 12:04pm UTC](https://discourse.libsdl.org/t/the-perfect-transparent-surface-improved-question/14945/3 "2007-11-06T12:04:20Z")

</div>

Alberto Luaces \<aluaces udc.es\> writes:

> Every mask is the binary mask that specify where its colour component is  
> stored.

> ```
> surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,
> rmask, gmask, bmask, amask);
> 
> ```
> 
> What do you mean by 100% transparent? Invisible?

Yes. Invisible.  
I’m going to try some masks combinations.

Thank you for now, Mr. Luaces.

---

<div class="post-metadata">

**Author:** ![Alberto\_Luaces\_Ferna](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/a/74df32/32.png) [@Alberto\_Luaces\_Ferna](https://discourse.libsdl.org/u/Alberto_Luaces_Ferna)\
**Post date:** [November 6, 2007, 5:00pm UTC](https://discourse.libsdl.org/t/the-perfect-transparent-surface-improved-question/14945/4 "2007-11-06T17:00:40Z")

</div>

El Tuesday 06 November 2007 13:04:20 Miguel Pragier escribi?:

> > Every mask is the binary mask that specify where its colour component is  
> > stored.
> > 
> > ? ? surface = SDL\_CreateRGBSurface(SDL\_SWSURFACE, width, height, 32,  
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?rmask, gmask, bmask, amask);
> > 
> > What do you mean by 100% transparent? Invisible?
> 
> Yes. Invisible.

Sorry if I do not fully understand you, but if you are going to blit an  
invisible surface, why bother to try to display it at all?

> I’m going to try some masks combinations.

If you are using Windows your pixel format will be tipically RGBA, 8 bits for  
every of the four components, stored in little endian format. However it is  
better to do as the example shown in the documentation and mind the endianess  
of your system.

---

<div class="post-metadata">

**Author:** ![Miguel\_Pragier](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/ad7895/32.png) [@Miguel\_Pragier](https://discourse.libsdl.org/u/Miguel_Pragier)\
**Post date:** [November 7, 2007, 12:10pm UTC](https://discourse.libsdl.org/t/the-perfect-transparent-surface-improved-question/14945/5 "2007-11-07T12:10:03Z")

</div>

My intention is to create the invisible surface, and, over this, to blit.  
Is the same as draw over a transparent paper. 🙂

2007/11/6, Alberto Luaces :\>

> El Tuesday 06 November 2007 13:04:20 Miguel Pragier escribi?:
> 
> > > Every mask is the binary mask that specify where its colour component  
> > > is  
> > > stored.
> > > 
> > > surface = SDL\_CreateRGBSurface(SDL\_SWSURFACE, width, height, 32,  
> > > rmask, gmask, bmask, amask);
> > > 
> > > What do you mean by 100% transparent? Invisible?
> > 
> > Yes. Invisible.
> 
> Sorry if I do not fully understand you, but if you are going to blit an  
> invisible surface, why bother to try to display it at all?
> 
> > I’m going to try some masks combinations.
> 
> If you are using Windows your pixel format will be tipically RGBA, 8 bits  
> for  
> every of the four components, stored in little endian format. However it  
> is  
> better to do as the example shown in the documentation and mind the  
> endianess  
> of your system.
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![Alberto\_Luaces\_Ferna](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/a/74df32/32.png) [@Alberto\_Luaces\_Ferna](https://discourse.libsdl.org/u/Alberto_Luaces_Ferna)\
**Post date:** [November 7, 2007, 12:31pm UTC](https://discourse.libsdl.org/t/the-perfect-transparent-surface-improved-question/14945/6 "2007-11-07T12:31:15Z")

</div>

El Wednesday 07 November 2007 13:10:03 Miguel Pragier escribi?:

> My intention is to create the invisible surface, and, over this, to blit.  
> Is the same as draw over a transparent paper. 🙂

Then it will be useful to use

int SDL\_SetAlpha(SDL\_Surface \*surface, Uint32 flag, Uint8 alpha);

with your transparent surface. Keep in mind what is said in the documentation:

“0 (SDL\_ALPHA\_TRANSPARENT) is now considered transparent.”\> 2007/11/6, Alberto Luaces \<@Alberto\_Luaces\_Ferna\>:

> > El Tuesday 06 November 2007 13:04:20 Miguel Pragier escribi?:
> > 
> > > > Every mask is the binary mask that specify where its colour component
> > 
> > is
> > 
> > > > stored.
> > > > 
> > > > surface = SDL\_CreateRGBSurface(SDL\_SWSURFACE, width, height, 32,  
> > > > rmask, gmask, bmask, amask);
> > > > 
> > > > What do you mean by 100% transparent? Invisible?
> > > 
> > > Yes. Invisible.
> > 
> > Sorry if I do not fully understand you, but if you are going to blit an  
> > invisible surface, why bother to try to display it at all?
> > 
> > > I’m going to try some masks combinations.
> > 
> > If you are using Windows your pixel format will be tipically RGBA, 8 bits  
> > for  
> > every of the four components, stored in little endian format. However it  
> > is  
> > better to do as the example shown in the documentation and mind the  
> > endianess  
> > of your system.
