SFML community forums

Help => General => Topic started by: Chuckleluck on November 13, 2011, 02:57:22 am

Title: [SOLVED]Custom Icons in SFML?
Post by: Chuckleluck on November 13, 2011, 02:57:22 am
Is there a way to change the window icon from the default icon to a custom .ico image on a window created by the sf::RenderWindow class, like you can with a Win32-made window?
Title: [SOLVED]Custom Icons in SFML?
Post by: Felheart on November 13, 2011, 03:26:42 am
I suppose you mean the .exe file icon. not the icon thats displayed in the title bar. (in case you mean that, there is a sfml function for that).

you could either use reshacker or something like that.

or you could include one icon as a "resource" with the id IDI_ICON1 or something like that. (then you could also set it as the title-bar icon)

edit: i meant
http://www.sfml-dev.org/documentation/1.6/classsf_1_1Window.php#a36fa09e52af66878b8b826457b8f1dfa
Title: Re: Custom Icons in SFML?
Post by: Naufr4g0 on November 13, 2011, 02:29:38 pm
Quote from: "Chuckleluck"
Is there a way to change the window icon from the default icon to a custom .ico image on a window created by the sf::RenderWindow class, like you can with a Win32-made window?


You have to create a .rc file and then import it in your project.
This is the code:
Code: [Select]

IDR_APP_ICON ICON "(.ico filename)"
GLUT_ICON ICON "(.ico filename)"
Title: [SOLVED]Custom Icons in SFML?
Post by: Chuckleluck on November 14, 2011, 03:41:57 am
What kind of variable will the last argument accept?  It says it's a Uint8*, but I don't know what that is. :oops:

Could someone give me an example of how to use SetIcon?
Title: [SOLVED]Custom Icons in SFML?
Post by: Walker on November 14, 2011, 07:43:07 am
Depending on your IDE, you could try right clicking on Uint8 to find the definition. This is a very common typedef for an unsigned char (Unsigned integer of 8 bits).

The SetIcon function wants a Uint8 pointer which is called pixels(this is a big clue). Hey! 8 bits per channel per pixel - maybe this is related. You need to provide the window with an array of pixels, which, conveniently sf::Image provides. http://sfml-dev.org/documentation/1.6/classsf_1_1Image.php#ad1594ab4251d6fc833a48dd242918631
Title: [SOLVED]Custom Icons in SFML?
Post by: Chuckleluck on November 14, 2011, 05:05:06 pm
So I need to include an Image object?  Could you please provide an example?
Title: [SOLVED]Custom Icons in SFML?
Post by: luiscubal on November 14, 2011, 05:18:39 pm
window.SetIcon(image.GetWidth(), image.GetHeight(), image.GetPixelsPtr());

That should work.
Title: [SOLVED]Custom Icons in SFML?
Post by: Chuckleluck on November 14, 2011, 05:31:49 pm
Yes!  It works now.  Thank you to Felheart, Naufr4g0, Walker and luiscubal for your help  :D