Easy way to change desktop game icon

muruba

New member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
Patreon Silver
Joined
Jul 5, 2017
Messages
230
Subj, basically
 

muruba

New member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
Patreon Silver
Joined
Jul 5, 2017
Messages
230
I mean it would be good to have an easy way to change glfw target app icon. I found mx tutorials for it (which failed for me) but even then it was windows-only...
 

muruba

New member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
Patreon Silver
Joined
Jul 5, 2017
Messages
230
Actually it seems pretty easy to do:

1. Create default ICO file with CX default icon in multiple resolutions.
2. Create RES file
3. Update makefile to include RES file during linking stage.

and voila!

I tried with GCC and a hello world app and it seems to work fine (outside of CX build pipeline for now).

As a bonus we can add application info along with icon so it gets included to the final EXE file as well (things like company info/copyright/version etc).

https://stackoverflow.com/questions/708238/how-do-i-add-an-icon-to-a-mingw-gcc-compiled-executable

I might try my contribution wings with this, but need to finish my website and release my too-awesome-to-be-true game on IOS first as the icon is somewhat in "who cares" category I believe :)
 

muruba

New member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
Patreon Silver
Joined
Jul 5, 2017
Messages
230
aargh, what I said is true for the exe file, not the icon when the application is running, anyways... :eek:
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
686
You are talking about the icon in the taskbar and the corner of the window? I did it about a year ago with the tutorial in the old forum and it worked here. Will investigate...
These kind of tasks should definitely be automated in the ide or with some kind of tool. I hate it, if I solved a problem and after a few month I face the fact, that it will be nearly as hard to do as it was the first time.

Now I found the link to the mx forum Topic I was using.
 
Last edited:

muruba

New member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
Patreon Silver
Joined
Jul 5, 2017
Messages
230
Yes, using your method the icon of the EXE file is updated (in windows explorer view), however when the app runs it is showing win's default icon in the corner as well as when ALT-TABing it, so I guess it requires glfwSetWindowIcon on top of it...
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
686
My old build shows the new icon everywhere - None of the issues you described. I will try a new build with Cerberus soon
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
686
Ok. Here (Win10) it works with Cerberus. Both 32 and 64 bit.
The only problem I ran into was, that I couldn't use the old res-file (32 bit) for the 64 bit build.
And I had to use the windres of the 64 bit MinGW Version.

@muruba Did you use the rc-file mentioned in the tutorial with the two icons?
 

muruba

New member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
Patreon Silver
Joined
Jul 5, 2017
Messages
230
Ok. Here (Win10) it works with Cerberus. Both 32 and 64 bit.
@muruba Did you use the rc-file mentioned in the tutorial with the two icons?

No! Now all good, thanks a lot for your help! :)

upload_2017-8-9_11-4-23.png
 

Attachments

  • upload_2017-8-9_11-3-57.png
    upload_2017-8-9_11-3-57.png
    63.4 KB · Views: 294

muruba

New member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
Patreon Silver
Joined
Jul 5, 2017
Messages
230
TMP=build/$(dir $(OUT))

OBJS=$(patsubst %.o,$(TMP)%.o,$(OBJS0)) my.res

all : $(OUT)
 

Gerry Quinn

Active member
Tutorial Author
Joined
Jun 24, 2017
Messages
163
I remember that used to be a PITA even with MSVC. I think the icons had to be poked into the .exe resources in the right order or something.

Knowing MS, whatever quirks were present on Windows 1.3 are still there in Windows 10.
 

Pierrou

Well-known member
Joined
Jul 6, 2017
Messages
235
Hi,
I'm trying to add icons to my Win32 or Win64 apps with no success.
I made a res file using the method above (windres), compiled the Debug64 app and put my icon.res file inside the ..\glfw3\gcc_winnt\build\Debug64 folder
Then I modified makefile like this
Code:
(...)

OBJS0=\
context.o \
egl_context.o \
init.o \
input.o \
monitor.o \
osmesa_context.o \
vulkan.o \
wgl_context.o \
win32_init.o \
win32_joystick.o \
win32_monitor.o \
win32_time.o \
win32_thread.o \
win32_window.o \
window.o \
stb_vorbis.o \
stb_image.o \
icon.res \
main.o

(...)

and I get this error message :
mingw32-make: *** No rule to make target 'icon.res', needed by 'Debug64/CerberusGame'. Stop.
TRANS FAILED: Error executing 'mingw32-make CCOPTS=" -m64 -O0" LDOPTS=" -m64 -LC:/Cerberus_18-4/libs/Win64" LIBOPTS=" -lopenal32" OUT="Debug64/CerberusGame"', return code=2
Abnormal program termination.
Exit code: -1

Any idea?
Thanks!

(EDIT : adding icons to MSVC projects is quite easy but I must use gcc this time)
 

dawlane

Well-known member
CX Code Contributor
Joined
Jun 21, 2017
Messages
895
The problem is icon.res, which is a MSVC compiled resource file.
The icon needs to be compiled with windres first to generate a object (.o) file, so the MinGW linker can include it into the final executable. Microsoft object files are not interchangeable with MinGW, even when the MinGW documentation states that you can use MSVC .lib files. This was why TDM-MinGW versions greater than 4.9 couldn't deal with the OpenAL32 export library (.lib) files supplied with MonkeyX/Cerberus.
 

Pierrou

Well-known member
Joined
Jul 6, 2017
Messages
235
Thanks dawlane it works!
Now I understand windres parameters better thank you.
I had to name my output file icon.o instead of icon.res and I also found out that i had to add -F pe-i386 if I intended to compile a 32bit app
What worked for my 32bit compilation was generating an icon.o file using windres
Code:
C:\TDM-GCC-64\bin\windres.exe -i C:\...\icon.rc -F pe-i386 -O coff -o C:\...\icon.o
Then copying the icon.o inside the C:\...\xxx.buildv2018-04-21\glfw3\gcc_winnt\build\Debug32 folder
And then adding
Code:
icon.o \
just before main.o
in the OBJS0=\ section of my C:\...\xxx.buildv2018-04-21\glfw3\gcc_winnt\Makefile

Now that I know how to do it, it looks simple but I couldn't have found it out without your help.
 
Last edited:
Top Bottom