Not logged inGosu Forums
Forum back to Help Search Register Login
Up Topic Gosu / Gosu Exchange / Game Application Icon
- - By SPK Date 2013-07-19 16:46
Greetings from hot Germany...

I searched the forum, read the entire (Ruby) documentation of Gosu, but couldn't find a way for my Game to have a nice application icon.
Unless I missed something (most likely) is it just not implemented or not doable because-of-some-api-restrictions?
Parent - - By lol_o2 Date 2013-07-19 17:31
I don't know if it's possible to make icon for .rb file, but you can certainly set it to compiled (packed) application using Ocra (or maybe Releasy). In Ocra you just add --icon <filename> so your application (exe) will have the icon.
Parent - - By SPK Date 2013-07-19 17:45
Ocra is not an option, because it's not cross-platform. I only use Linux.

I'll give Releasy a look.
Parent - By Spooner Date 2013-07-20 11:24
Releasy will add an icon for OSX/Windows builds (but, for windows, only if it is built on Windows). It doesn't consider Linux icons at all.
Parent - By EdwinOdesseiron Date 2013-07-19 22:48
There's a program called "resource hacker". It lets you open any .exe file and change the icon (open exe, Icon => 1 => 1024). It probably will work with .rb files, but I'm not too sure about it.
P.S. It takes icons in .ico file, you can easily convert them with IrfanView
Parent - - By jlnr (dev) Date 2013-07-20 01:07
I have no idea where application icons come from on Linux. Is there a standard across distributions? If you find out, please let me know :)
Parent - - By SPK Date 2013-09-08 00:20
I finally managed to compile gosu!

Now I implemented icon support for games running in a X window.
I think the implementation is still a bit ugly and may have bugs and is C++ only at the moment, but omfg it's working after countless hours of despair.

My next goal is the Ruby implementation and maybe Windows/Mac(uses X?) support.

Time to get some sleep!
Parent - - By jlnr (dev) Date 2013-09-08 11:52
Cool :) How does it work? Does it happen in code or is it just configuration?

OS X does not use X, though it is there for exotic software. Anyway, replacing the icon on OS X is easy as pie because Mac apps are just folders in disguise. :) And on Windows, Ocra can compile an icon into the EXE file and I think Spooner's Releasy library makes this functionality available too. So it's really only Linux that was/is a mystery to me.
Parent - - By SPK Date 2013-09-08 13:14
It happens in code, similar to setCaption(). A Windows implementation isn't much work, I just cannot test it. (Imo better than having to rely on third party programs)

How do I create a gem from gosu source? Just run rake?
Parent - - By jlnr (dev) Date 2013-09-08 16:49
Ruby programmers will always have to rely on ocra anyway :)

To build the Linux/Mac gem, set the GOSU_RELEASE_VERSION environment variable to 0.7.49 and run rake linux:gem.
Parent - - By SPK Date 2013-09-10 21:05
Okay, I need Gosu::Bitmap in Ruby or a way to get either the bitmap or the pixels of a Gosu::Image.

If you don't have a better idea, then I'm trying to wrap the Bitmap class.
I need access to the pixels of the icon in my current implementation. Gosu::Image doesn't provide that I just noticed. :S

And lol @GosusDarkSide. :P
Parent - - By RunnerPack Date 2013-09-11 00:07
Have you tried Image#to_blob?
Parent - - By SPK Date 2013-09-11 20:58
^ No. (But I did now, and the result is the same as below).

I think I give up. :D Can't get it to work.

Calling toBitmap() on the imagedata of my image results in a crash.
(I simplified the code)

_wrap_Window_icone___(int argc, VALUE *argv, VALUE self) {

  Gosu::Window *arg1 = (Gosu::Window *) 0 ;
  Gosu::Image *icon = (Gosu::Image *) 0;

  arg1 = reinterpret_cast< Gosu::Window * >(argp1);
  icon = reinterpret_cast< Gosu::Image *>(argv[0]);

  // Gives me a return value
  std::cout << sizeof(icon->getData().toBitmap()) << std::endl;

  // FAILS, ruby interpreter crashes

  // same
  Gosu::Bitmap bmp = getData().toBitmap());


I could provide the stacktrace, but it's useless.  My Ruby code looks like this:

gem "gosu", ">9.0.00"
require 'gosu'

class Test < Gosu::Window

def initialize
  super(640, 480, false)

  bitmap =, "./icon.png", false)
  self.icon = bitmap # <= apocalypse
# ...
Parent - - By RunnerPack Date 2013-09-12 23:44
Well, from what I know of Windows, it's probably not going to accept a raw RGBA (ARGB?) chunk when it's expecting an Icon resource. There's probably some Windows API function for generating an Icon from a blob of pixels – which is what I assumed you were using when I suggested #to_blob. How exactly are you using #to_blob with the above code?
Parent - By SPK Date 2013-09-13 11:19
The function setIcon(image) works (in C++), but the wrapper doesn't. I get the bitmap of an image from image.getData().toBitmap() thus I don't need to_blob.

Huh, Windows API?
Parent - - By jlnr (dev) Date 2013-09-13 11:17
Image#to_blob is exactly what you want. :) It returns a binary RGBA string that should be easy to work with in C & Ruby. You can probably write it in pure Ruby using the Win32API module (or what it's called these days). It is just a Ruby-ish/RMagick compatible wrapper around ImageData::toBitmap().

But I think that setting the icon in code is not generally the right way, because if the .exe binary has the right icon, it will be used in Explorer, for shortcuts and for the window itself (I think). Setting the icon in code is probably useful mostly for instant messengers etc?

Edit: And you cannot just cast the arguments into Gosu::Window. The C++ classes have to be wrapped up as a Data struct/thingie for the Ruby C API. If you look at the SWIG generated methods, you will see how to extract the C++ pointers back out of the Data.
Parent - - By SPK Date 2013-09-13 11:36
Posted almost simultaneously. :P

Why is it wrong to set the icon in code? The title is also set in code. And because of the #ifdef magic it's only Linux anyway, so it's not even possible to set the icon in Windows.
My code lies within the Ruby_Gosuwrapper.cxx thingie and I mostly copied from your other methods, so I guess it should be legal to cast to Gosu::Window. 

Okay, let's assume I use to_blob, how would the cast to Gosu::Bitmap look like?
Simple as reinterpret_cast<Gosu::Bitmap *>(VALUE)?

I don't want to spend the whole night on trial and error again... :)
Parent - - By jlnr (dev) Date 2013-09-13 21:04
Nope, VALUE will be a Ruby string. If you need a Gosu::Bitmap, you can either memcpy the string's contents into the, or look up how the image's VALUE is converted into a Gosu::Image in the SWIG generated code.

It's not wrong, but if the icon is ALSO set in the EXE file via Ocra (so that the EXE 'looks' right in Explorer), it will be a no-op in most of the cases? :)
Parent - - By SPK Date 2013-09-13 23:20
Finally got it working with SWIG_ConvertPtr without #to_blob.
What now? Pull request and you look over the code or do you don't want to see the code in gosu? :'(
(Will do it tomorrow, time to sleep.)

Yes, then it would be a no-op. But that's a problem of Windows. :P
Parent - By jlnr (dev) Date 2013-09-14 03:27
Oh, definitely send a PR! Then we can discuss more code stuff on github. :)
Up Topic Gosu / Gosu Exchange / Game Application Icon

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill