Lwjgl3: glfwSetWindowIcon on Mac and Linux

Created on 12 May 2017  路  3Comments  路  Source: LWJGL/lwjgl3

The function glfwSetWindowIcon doesn't seem to be working on Linux and Mac. I have tested this on OSX 11 (virtualbox) and Ubuntu 16.04. Works fine on Windows.

Is that a known problem or am I just doing it wrong? This is how I read the program's icon:

try (MemoryStack stack = MemoryStack.stackPush()) {
    final int res = OSDetector.isWindows() ? 32 : 128;
    final ByteBuffer icon = IconLoader.loadImageIcon("/icon.png", res);
    GLFWImage.Buffer buf = GLFWImage.mallocStack(1, stack).width(res).height(res).pixels(icon);
    glfwSetWindowIcon(window, buf);         
} catch (Exception e) {
    e.printStackTrace();
}

And the IconLoader.loadImageIcon function:

public static ByteBuffer loadImageIcon(String resource, int size) {
    URL url = IconLoader.class.getResource(resource);

    try {
        BufferedImage img = ImageIO.read(url);
        return loadInstance(img, size);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

I know this is using ImageIO, but how would I read a file with a given URL with STBImage? I've already tried using url.getPath(), but that doesn't work in a packed jar file.

Thanks in advance!

Question

All 3 comments

Based on experience, any _window icon setting_ API never really work on OS X and Linux. For OS X, I usually create an application bundle (https://developer.apple.com/library/content/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html#//apple_ref/doc/uid/10000123i-CH101-SW1) and for linux, a desktop file (https://linuxcritic.wordpress.com/2010/04/07/anatomy-of-a-desktop-file/) usually does the trick.

I know this is using ImageIO, but how would I read a file with a given URL with STBImage? I've already tried using url.getPath(), but that doesn't work in a packed jar file.

This should help.

Thanks a lot. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

baileysostek picture baileysostek  路  4Comments

SpinyOwl picture SpinyOwl  路  3Comments

erikmartinessanches picture erikmartinessanches  路  3Comments

Theikon picture Theikon  路  5Comments

ShadowLordAlpha picture ShadowLordAlpha  路  3Comments