Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » How to add an icon to the game

This thread is locked; no one can reply to it. rss feed Print
How to add an icon to the game
AleX-G Squadron
Member #13,593
October 2011
avatar

I am trying to make a new icon for a game, but can't find how to add it.
Anyone pls help!

www.anothergames.com

SiegeLord
Member #7,827
October 2006
avatar

This perhaps: al_set_display_icon ?

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

AleX-G Squadron
Member #13,593
October 2011
avatar

How can i use it?
Sorry, i am a bit of newbie :S

www.anothergames.com

Don Freeman
Member #5,110
October 2004
avatar

I think he means like you click to start the program. It depends on the compiler/platform. If you just mean the icon on the title bar, then use al_set_display_icon. The link SiegeLord gave tells you how to use it. ;)

--
"Everyone tells me I should forget about you, you don’t deserve me. They’re right, you don’t deserve me, but I deserve you."
"It’s so simple to be wise. Just think of something stupid to say and then don’t say it."

AleX-G Squadron
Member #13,593
October 2011
avatar

How can i use this?
void al_set_display_icon(ALLEGRO_DISPLAY *display, ALLEGRO_BITMAP *icon)
Don't get a thing :(

does it mean?
void al_set_display_icon(ALLEGRO_DISPLAY *display, ALLEGRO_BITMAP *image)

It doesn't work like this....

Tried like this:
ALLEGRO_BITMAP *image = "image.ico"

www.anothergames.com

AMCerasoli
Member #11,955
May 2010
avatar

Alex, I think you're way too newbie... You shouldn't start learning a graphic library if you don't know the programming language that it uses first.

Have you initialized Allegro, created a display and loaded the image you want to use as an icon?.

ALLEGRO_BITMAP *image = "image.ico"

That's too crazy man, with Allegro you'll work almost all the time with pointers, that means that you're locating and deallocating memory manually all the time.

To allocate memory for an ALLEGRO_BITMAP you need to use al_load_bitmap() which returns a pointer, pointing to the direction recently allocated. And then you need to free that memory with al_destroy_bitmap().

So basically after initialize Allegro, and create a new display.

ALLEGRO_BITMAP *icon = al_load_bitmap("youricon.png"); // Note that it's a normal
                                                       // .png file not an .ico file
al_set_display_icon(your_display, icon);               // Allegro doesn't support .ico files

And that should work.

Edit: And BTW why did you put this post in the Allegro Development category?

AleX-G Squadron
Member #13,593
October 2011
avatar

I did it like you said, it shows this:
Unhandled exception at 0x00000000 in game.exe: 0xC0000005: Access violation.

I have already created a game, just want to add an icon. Also, thanks for pointing out pointers, i am a bit of laggy there :-/

Also, i didn't know this command al_set_display_icon(display, icon);

I wrote in my third post(and tried out in the program), this:
ALLEGRO_BITMAP *image = "image.ico"
than wrote the line(and tried out in the program):
void al_set_display_icon(ALLEGRO_DISPLAY *display, ALLEGRO_BITMAP *image)

Also, created the display the same way (if you think i don't know anything):
const int WIDTH = 700;
const int HEIGHT = 700;
ALLEGRO_DISPLAY *display = NULL;
display = al_create_display(WIDTH, HEIGHT);

www.anothergames.com

Neil Walker
Member #210
April 2000
avatar

Pointer/string issue aside, I think he's just getting mixed with wanting to use a .ico file for the game icon as embedded in the game, not just when running.

In which case, look for windres or you can probably do it directly within visual studio if you are using that.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

AleX-G Squadron
Member #13,593
October 2011
avatar

Actually, i want to use the icon 32x32 for the windows taskbar,
a little icon + the title of the game while running and the icon of the game inside the folder

www.anothergames.com

AMCerasoli
Member #11,955
May 2010
avatar

if you think i don't know anything

What I think it doesn't matter, what really matters is that if you show someone this:

ALLEGRO_BITMAP *image = "image.ico"

Is obvious that you're lacking the basics concepts about the C programming language.

I took the time to try to see if there is a problem, but there isn't. This works perfect on my system:

#SelectExpand
1#include <iostream> 2#include <allegro5/allegro.h> 3#include "allegro5/allegro_image.h" 4 5int main () { 6
7 al_init();
9 10 ALLEGRO_DISPLAY *display = al_create_display(800,600); 11 ALLEGRO_BITMAP *icon = al_load_bitmap ("icon.png"); 12 13 al_set_display_icon(display, icon); 14 15 al_rest(3); 16 17 al_destroy_bitmap(icon); 18 al_destroy_display(display); 19 return 0; 20}

Thomas Fjellstrom
Member #476
June 2000
avatar

Actually, i want to use the icon 32x32 for the windows taskbar,

Allegro doesn't support the .ico format. Turn it into a bmp or a png file.

I have already created a game,

I'm not entirely sure how you created a game with such basic misunderstandings. Trying to insert a function declaration as is, is quite odd.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

AleX-G Squadron
Member #13,593
October 2011
avatar

@cerasoli
thanks man
I found the real problem to my code
Now i have the icon :)

www.anothergames.com

Go to: