I am trying to give an icon to my SDL2 application. SDL2 have a function named SDL_SetWindowIcon()
, but the problem is the function only set the icon in the window app not in the .exe file this mean that when I pin it in my Taskbar, I see this:
SDL2 function
SDL_Surface *iconSurface = IMG_Load("./src/Assets/img/Logo/icon.ico");
SDL_SetWindowIcon(window, iconSurface);
SDL_FreeSurface(iconSurface);
.rc file
MAIN ICON "File"
Makefile Content :
all:
cls
g++ -I src/include -L src/lib -o TKM main.cpp src/include/manmade/Class/* src/include/manmade/Components/* src/include/manmade/Part/* -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_ttf
./TKM
Coding Environment:
OS : Windows
Text Editor : VScode
Project build with a Makefile
It is @HolyBlackCat you respond to this question in the comment. I am just putting it in the answer section with more details.
I add see some video and website to get knowledge in C++ and SDL2.
Create a .rc
file.
Inside of the .rc
file write this line of code:
MAIN ICON "./thePath/of/yourImage.ico"
In the terminal launch this command:
windres -i yourRCFileName.rc -o yourRCFileName.o
Put the path of your .o
file(ex: yourRCFileName.o)
after main.cpp in the Makefile to assign your icon to the .exe file:
all:
cls
g++ -I src/include -L src/lib -o test main.cpp yourRCFileName.o -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_ttf
./test
It is like when you make it with .cpp file. When you make change in your .rc
file it will launch the command(@windress ...) otherwise nothing happen.
yourRCFileName.o: yourRCFileName.rc
@windres -i $^ -o $@
You put the path of your .o
file in the right section like always:
stackoverflowApp.exe: main.o yourRCFileName.o
g++ -std=c++20 -I src/include -L src/lib $^ -o $@ -lmingw32 -otherLibraires
./stackoverflowApp
The image need to be a .ico
or you are going to get the following error message:
C:\mingw64\bin\windres.exe: icon file `./src/Assets/img/apple.png' does not contain icon data
You can use a website such as https://icoconvert.com/ to convert your image but they accept only these image :
PNG, JPG or BMP image( maximum size: 50 MB )