EXE Icon GLFW Windows Tutorial

Monkey Targets Forums/Desktop/EXE Icon GLFW Windows Tutorial

Soap(Posted 2014) [#1]
This assumes using mingw to build and not vs. If using vs look below.

First prepare an .ICO file "icon.ico"

You can use the site

http://iconverticons.com/online/

Make a folder anywhere. Create a "makeicon.bat" file inside:

windres icon.rc -O coff -o icon.res


The batch file is to make remaking your icon faster if you need to do that. If you prefer you can use cmd directly instead.

Now make the file icon.rc in the same folder
id ICON "icon.ico"
GLFW_ICON ICON "icon.ico"


The first is so explorer knows which icon to use, the second is for GLFW to use in showing an icon on the top left of the window etc. I'm not sure how to make both lines into one as it appears to double the filesize for both lines, but compression should deal with that.

You should have three files now. If you open/run makeicon.bat it should produce a icon.res file.

Make a Desktop_Game build.

Copy and paste the icon.res file into the glfw build folder in the same folder as main.o

Now edit the makefile within the gcc_winnt folder and add ../icon.res to the end of the "OBJS=" right behind main.o is fine "../main.o ../icon.res"

The next time you make a build both your exe should have an icon and when you open your exe it should have the icon at the top left corner instead of the default icon GLFW chooses to use if you do not have a GLFW_ICON resource defined.

As a bonus you can add some extra lines to icon.rc so that when you right click and go to properties on the exe it shows extra info.
1 VERSIONINFO
FILEVERSION     1,0,0,0
PRODUCTVERSION  1,0,0,0
BEGIN
  BLOCK "StringFileInfo"
  BEGIN
    BLOCK "080904E4"
    BEGIN
      VALUE "CompanyName", "My Company Name"
      VALUE "FileDescription", "My excellent application"
      VALUE "FileVersion", "1.0"
      VALUE "InternalName", "my_app"
      VALUE "LegalCopyright", "My Name"
      VALUE "OriginalFilename", "my_app.exe"
      VALUE "ProductName", "My App"
      VALUE "ProductVersion", "1.0"
    END
  END

  BLOCK "VarFileInfo"
  BEGIN
    VALUE "Translation", 0x809, 1252
  END
END


http://msdn.microsoft.com/en-us/library/aa381058.aspx

For more info on those details.

If using vs then you can skip the second half once you have your res file.
Copy and paste your res file into the vc2010 build folder
Open up the project in vc
Right click MonkeyGame -> Add -> Existing Item -> icon.res
Rebuild and the icons should work

References:

http://www.monkey-x.com/Community/posts.php?topic=6196&post=71147

http://www.monkey-x.com/Community/posts.php?topic=1651&post=37041

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


Phil7(Posted 2016) [#2]
I'm using Windows 10 and I tried the solution above, but windres hasn't been found. Maybe I just don't know how to use it properly... any clues?


k.o.g.(Posted 2016) [#3]
It is important to set the environment variables to your MinGW Installation


Or you could start "windres" directly in your MinGW/bin Folder


Phil7(Posted 2016) [#4]
Thanks! So windres is part of MinGW...


k.o.g.(Posted 2016) [#5]
Hi Phil7

Yes it is and the OP said, this tutorial is for MinGW based installations
This assumes using mingw to build and not vs.



Phil7(Posted 2016) [#6]
I was assuming that statement was just concerning the steps to take and the folders to use...
Finally I got it working, but there seem to be some changes in the makefile.
OBJS0=\
context.o \
init.o \
input.o \
monitor.o \
wgl_context.o \
win32_init.o \
win32_monitor.o \
win32_time.o \
win32_tls.o \
win32_window.o \
window.o \
winmm_joystick.o \
stb_vorbis.o \
stb_image.o \
main.o


TMP=build/$(dir $(OUT))

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

In the last line I added $(TMP)icon.res
Maybe someone can check if that's the way to do it, as I have never used a makefile before.