Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED]Custom Icons in SFML?  (Read 13247 times)

0 Members and 1 Guest are viewing this topic.

Chuckleluck

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
[SOLVED]Custom Icons in SFML?
« 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?

Felheart

  • Newbie
  • *
  • Posts: 23
    • View Profile
[SOLVED]Custom Icons in SFML?
« Reply #1 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

Naufr4g0

  • Full Member
  • ***
  • Posts: 112
    • View Profile
Re: Custom Icons in SFML?
« Reply #2 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)"

Chuckleluck

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
[SOLVED]Custom Icons in SFML?
« Reply #3 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?

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
[SOLVED]Custom Icons in SFML?
« Reply #4 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

Chuckleluck

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
[SOLVED]Custom Icons in SFML?
« Reply #5 on: November 14, 2011, 05:05:06 pm »
So I need to include an Image object?  Could you please provide an example?

luiscubal

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
[SOLVED]Custom Icons in SFML?
« Reply #6 on: November 14, 2011, 05:18:39 pm »
window.SetIcon(image.GetWidth(), image.GetHeight(), image.GetPixelsPtr());

That should work.

Chuckleluck

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
[SOLVED]Custom Icons in SFML?
« Reply #7 on: November 14, 2011, 05:31:49 pm »
Yes!  It works now.  Thank you to Felheart, Naufr4g0, Walker and luiscubal for your help  :D