Set Window Icon

Started by paco, July 28, 2008, 14:54:40

Previous topic - Next topic

paco

Hi

I'm writing a game using GTGE http://www.goldenstudios.or.id/ and LWJGL to take advantage of OpenGL. I want to change the window icon and I found the Display.setIcon function:

setIcon

public static int setIcon(java.nio.ByteBuffer[] icons)

    Sets one or more icons for the Display.

        * On Windows you should supply at least one 16x16 icon and one 32x32.
        * Linux (and similar platforms) expect one 32x32 icon.
        * Mac OS X should be supplied one 128x128 icon

    The implementation will use the supplied ByteBuffers with image data in RGBA and perform any conversions nescesarry for the specific platform.

    NOTE: The display will make a deep copy of the supplied byte buffer array, for the purpose of recreating the icons when you go back and forth fullscreen mode. You therefore only need to set the icon once per instance.

    Parameters:
        icons - Array of icons in RGBA mode. Pass the icons in order of preference. 
    Returns:
        number of icons used, or 0 if display hasn't been created


I've been searching for an example but I didn't find anything. I don't know how to load in ByteBuffers the icons. I have got the icon for Windows (16x16 and 32x32) and Linux (32x32). For Mac, my icon editor says that 128x128 is not a valid format. I suppose that I need the three icons but I don't know if they need to be "icon" or "image" (png, gif, etc.). The function is confusing for me. I don't know if it's needed to convert the loaded image in other format before calling "setIcon" method.

Thanks in advance.

Sorry for my english.

bobjob

i havnt used the function yet. But by the discription it seems to take a ByteBuffer, similar to the way openGL takes a ByteBuffer to load a texture.

paco

Quote from: bobjob on July 28, 2008, 21:36:27
i havnt used the function yet. But by the discription it seems to take a ByteBuffer, similar to the way openGL takes a ByteBuffer to load a texture.

Thanks, this is a good starting point. I'll try it and will post the results.

If you want to see images and a video of my game, check this urls (sorry, they are in spanish but the game is both in spanish and english).

http://computeremuzone.com/forum/viewtopic.php?p=122583#p122583
http://www.youtube.com/watch?v=26WZ5DpWVXg

http://cezgs.computeremuzone.com/?l=en
http://computeremuzone.com/?l=en

The game will be released soon.

Thanks again.

tomb

The byte buffer needs to contain one byte for red, green, blue and alpha for each pixel in the icon. You could load the icon as a BufferedImage using ImageIO. Then use getRGB() to unpack it into a ByteBuffer. A 32x32 icons would then have 32*32*4 bytes.

paco

Quote from: tomb on July 31, 2008, 13:02:35
The byte buffer needs to contain one byte for red, green, blue and alpha for each pixel in the icon. You could load the icon as a BufferedImage using ImageIO. Then use getRGB() to unpack it into a ByteBuffer. A 32x32 icons would then have 32*32*4 bytes.

Thanks! I'll try this way, it seems very easy. Thanks again ;-)