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!
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. :)