# Setting the program icon with a mask

**URL:** <https://discourse.libsdl.org/t/setting-the-program-icon-with-a-mask/9395>\
**Category:** SDL Development\
**Created:** [September 23, 2003, 2:08am UTC](https://discourse.libsdl.org/t/setting-the-program-icon-with-a-mask/9395 "2003-09-23T02:08:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mika\_Halttunen](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/6a8cbe/32.png) [@Mika\_Halttunen](https://discourse.libsdl.org/u/Mika_Halttunen)\
**Post date:** [September 23, 2003, 2:08am UTC](https://discourse.libsdl.org/t/setting-the-program-icon-with-a-mask/9395/1 "2003-09-23T02:08:01Z")

</div>

Greetings!

I know how to set a program icon with SDL\_WM\_SetIcon(), but what I don’t  
know, is the mask thing. So, in what format should the mask be in etc.?  
I tried with an Uint8 array [32\*32], filling it with zeros and ones, but  
it didn’t work.

Thanks in advance!  
Bye,–  
Mika Halttunen  
@Mika_Halttunen

---

<div class="post-metadata">

**Author:** ![Bill\_Kendrick](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/df788c/32.png) [@Bill\_Kendrick](https://discourse.libsdl.org/u/Bill_Kendrick)\
**Post date:** [September 23, 2003, 2:56am UTC](https://discourse.libsdl.org/t/setting-the-program-icon-with-a-mask/9395/2 "2003-09-23T02:56:01Z")

</div>

In Bug Squish (in fact, most of my games), I create a 100% opaque mask  
for the square-shaped icon I used:

int masklen;  
Uint8 \* mask;  
SDL\_Surface \* icon;

…

/\* Load icon from PNG: \*/

icon = IMG\_Load(“icon.png”);

/\* Create mask: \*/

masklen = (((icon → w) + 7) / 8) \* (icon → h);  
mask = malloc(masklen \* sizeof(Uint8));  
memset(mask, 0xFF, masklen);

/\* Set icon: \*/

SDL\_WM\_SetIcon(icon, mask);

/\* Free icon surface & mask: \*/

free(mask);  
SDL\_FreeSurface(icon);

Some error checking would be good in there, too 😉

I don’t think I’ve ever tried making an icon with any transparency, though.

Good luck!

-bill!On Tue, Sep 23, 2003 at 12:06:41PM +0300, Mika Halttunen wrote:

> Greetings!
> 
> I know how to set a program icon with SDL\_WM\_SetIcon(), but what I don’t  
> know, is the mask thing. So, in what format should the mask be in etc.?  
> I tried with an Uint8 array [32\*32], filling it with zeros and ones, but  
> it didn’t work.

–  
bill at [newbreedsoftware.com](http://newbreedsoftware.com) Got kids? Get Tux Paint!  
[Bill Kendrick](http://newbreedsoftware.com/bill/)[Tux Paint - Free art software for kids of all ages](http://newbreedsoftware.com/tuxpaint/)

---

<div class="post-metadata">

**Author:** ![slouken](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ec9cab/32.png) [@slouken](https://discourse.libsdl.org/u/slouken)\
**Post date:** [September 24, 2003, 7:02am UTC](https://discourse.libsdl.org/t/setting-the-program-icon-with-a-mask/9395/3 "2003-09-24T07:02:01Z")

</div>

By the way, if you pass in NULL for the mask, SDL will use a 100% opaque  
mask itself, and will look for colorkey or alpha information in the surface  
you pass to create a mask itself.

See ya!  
-Sam Lantinga, Software Engineer, Blizzard Entertainment\> On Tue, Sep 23, 2003 at 12:06:41PM +0300, Mika Halttunen wrote:

> > Greetings!
> > 
> > I know how to set a program icon with SDL\_WM\_SetIcon(), but what I don’t  
> > know, is the mask thing. So, in what format should the mask be in etc.?  
> > I tried with an Uint8 array [32\*32], filling it with zeros and ones, but  
> > it didn’t work.

> In Bug Squish (in fact, most of my games), I create a 100% opaque mask  
> for the square-shaped icon I used:

---

<div class="post-metadata">

**Author:** ![Mika\_Halttunen](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/6a8cbe/32.png) [@Mika\_Halttunen](https://discourse.libsdl.org/u/Mika_Halttunen)\
**Post date:** [September 25, 2003, 2:51am UTC](https://discourse.libsdl.org/t/setting-the-program-icon-with-a-mask/9395/4 "2003-09-25T02:51:01Z")

</div>

> > > I know how to set a program icon with SDL\_WM\_SetIcon(), but what I don’t  
> > > know, is the mask thing. So, in what format should the mask be in etc.?  
> > > I tried with an Uint8 array [32\*32], filling it with zeros and ones, but  
> > > it didn’t work.
> 
> > In Bug Squish (in fact, most of my games), I create a 100% opaque mask  
> > for the square-shaped icon I used:
> 
> By the way, if you pass in NULL for the mask, SDL will use a 100% opaque  
> mask itself, and will look for colorkey or alpha information in the surface  
> you pass to create a mask itself.

Thanks guys! It works now. I should have figured out that colorkey stuff  
myself, though :)–  
Mika Halttunen  
@Mika_Halttunen
