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

Author Topic: How do i put icons at my application?  (Read 9128 times)

0 Members and 3 Guests are viewing this topic.

Assassinbeast

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
    • Email
How do i put icons at my application?
« on: November 14, 2012, 11:22:27 pm »
ive looked at

http://www.sfml-dev.org/documentation/2.0/classsf_1_1Window.php#a63af61e026fba08e3153fd013620bcc0

void sf::Window::setIcon, but i didn't really understand it because it only have 3 parameters which is width, height and pixels. But where should i load the big & small icons?

Thanks for all your support  ;D

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How do i put icons at my application?
« Reply #1 on: November 14, 2012, 11:24:32 pm »
There's only one icon, which is used for both big and small sizes.
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: How do i put icons at my application?
« Reply #2 on: November 14, 2012, 11:33:29 pm »
Well if you use a sf::RenderWindow, then you should look at the documentation for the rendern window, where you'd see sf::RenderWindow::setIcon.

Also keep in mind that this will only change the icon at runtime, but the application icon in for example the explorer won't change. You'd have to set this in your IDE. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Assassinbeast

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
    • Email
Re: How do i put icons at my application?
« Reply #3 on: November 15, 2012, 12:26:57 am »
I have only the express version of visual studio, so i cant use resources.

Quote
Well if you use a sf::RenderWindow, then you should look at the documentation for the rendern window, where you'd see sf::RenderWindow::setIcon.

Yes, i use renderwindow. But where in the code should i write so my program knows where to load the icon, and what can i write in the 3rd parameter of sf::Window::SetIcon?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: How do i put icons at my application?
« Reply #4 on: November 15, 2012, 12:48:49 am »
I have only the express version of visual studio, so i cant use resources.
Yes you can! You simply have to write the .rc file on your own, without the resource editor. ;)

Yes, i use renderwindow. But where in the code should i write so my program knows where to load the icon, and what can i write in the 3rd parameter of sf::Window::SetIcon?
Load the image into a sf::Image, then pass its size (width & height) as the first two parameters and for the third one: image.getPixelsPtr().
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

mateandmetal

  • Full Member
  • ***
  • Posts: 171
  • The bird is the word
    • View Profile
    • my blog
Re: How do i put icons at my application?
« Reply #5 on: November 15, 2012, 05:10:05 am »
There is a tutorial on the SFML Wiki:

Tutorial: Create and Use SetIcon
- Mate (beverage) addict
- Heavy metal addict _lml
- SFML 2 addict
- My first (and free) game: BichingISH!

Assassinbeast

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
    • Email
Re: How do i put icons at my application?
« Reply #6 on: November 15, 2012, 01:00:54 pm »
Quote
Load the image into a sf::Image, then pass its size (width & height) as the first two parameters and for the third one: image.getPixelsPtr().

#include <SFML/Graphics.hpp>

sf::Image myicon;

int main()
{
        myicon.loadFromFile("snake.ico");
        sf::RenderWindow mywindow(sf::VideoMode(800,600,32),"icon");
        sf::Event ev;
        mywindow.setIcon(32,32,myicon.getPixelsPtr());
        while(mywindow.isOpen())
        {
                while(mywindow.pollEvent(ev))
                {
                        if(ev.type == sf::Event::Closed)
                                mywindow.close();
                }
                mywindow.clear(sf::Color(0,200,0));
                mywindow.display();
        }
}

I get an error in the console window that says:

Failed to load image "snake.ico". Reason : Image not of any known type, or corrupt.

 :-\
Also.... how can i pass the width and height?
myicon.width or height doesn't exist.

There is a tutorial on the SFML Wiki:

Tutorial: Create and Use SetIcon


That tutorial is from 1.6, and in 2.0 theres no .width or .height  :-\

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How do i put icons at my application?
« Reply #7 on: November 15, 2012, 01:10:56 pm »
Quote
Failed to load image "snake.ico". Reason : Image not of any known type, or corrupt.
Read the error message (and then the doc).

Quote
Also.... how can i pass the width and height?
myicon.width or height doesn't exist.
Read the doc.
Laurent Gomila - SFML developer

Assassinbeast

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
    • Email
Re: How do i put icons at my application?
« Reply #8 on: November 15, 2012, 09:55:00 pm »
There's only one icon, which is used for both big and small sizes.

I got it to work with this code

#include <SFML/Graphics.hpp>

sf::Image myicon;

int main()
{
        myicon.loadFromFile("snake.png");
        sf::RenderWindow mywindow(sf::VideoMode(800,600,32),"icon");
        sf::Event ev;
        mywindow.setIcon(32,32,myicon.getPixelsPtr());
        while(mywindow.isOpen())
        {
                while(mywindow.pollEvent(ev))
                {
                        if(ev.type == sf::Event::Closed)
                                mywindow.close();
                }
                mywindow.clear(sf::Color(0,200,0));
                mywindow.display();
        }
}

But the big icon on the taskbar isn't showing. Why is that?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
AW: Re: How do i put icons at my application?
« Reply #9 on: November 15, 2012, 11:27:02 pm »
Also keep in mind that this will only change the icon at runtime, but the application icon in for example the explorer won't change. You'd have to set this in your IDE. ;)
... which includes the Win7 taskbar icon...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Assassinbeast

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
    • Email
Re: How do i put icons at my application?
« Reply #10 on: November 15, 2012, 11:48:09 pm »
Quote
... which includes the Win7 taskbar icon...

Sorry im being so reckless sometimes  :(
I really appreciate all your help man, thanks alot  :)

 

anything