How to add an icon to the game
AleX-G Squadron

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

SiegeLord

This perhaps: al_set_display_icon ?

AleX-G Squadron

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

Don Freeman

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

AleX-G Squadron

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"

AMCerasoli

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

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

Neil Walker

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.

AleX-G Squadron

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

AMCerasoli

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

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.

AleX-G Squadron

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

Thread #608569. Printed from Allegro.cc