Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rendering): Don't try to set window icon on macOS #5066

Merged
merged 2 commits into from
Aug 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.terasology.engine.rendering.ShaderManager;
import org.terasology.engine.rendering.ShaderManagerLwjgl;
import org.terasology.engine.rendering.nui.internal.LwjglCanvasRenderer;
import org.terasology.engine.utilities.OS;
import org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager;
import org.terasology.nui.canvas.CanvasRenderer;

Expand Down Expand Up @@ -156,23 +157,26 @@ private void initWindow() {
GLFW.glfwSwapInterval(0);
}

try {
String root = "org/terasology/engine/icons/";
ClassLoader classLoader = getClass().getClassLoader();

BufferedImage icon16 = ImageIO.read(classLoader.getResourceAsStream(root + "gooey_sweet_16.png"));
BufferedImage icon32 = ImageIO.read(classLoader.getResourceAsStream(root + "gooey_sweet_32.png"));
BufferedImage icon64 = ImageIO.read(classLoader.getResourceAsStream(root + "gooey_sweet_64.png"));
BufferedImage icon128 = ImageIO.read(classLoader.getResourceAsStream(root + "gooey_sweet_128.png"));
GLFWImage.Buffer buffer = GLFWImage.create(4);
buffer.put(0, LwjglGraphicsUtil.convertToGLFWFormat(icon16));
buffer.put(1, LwjglGraphicsUtil.convertToGLFWFormat(icon32));
buffer.put(2, LwjglGraphicsUtil.convertToGLFWFormat(icon64));
buffer.put(3, LwjglGraphicsUtil.convertToGLFWFormat(icon128));
GLFW.glfwSetWindowIcon(window, buffer);

} catch (IOException | IllegalArgumentException e) {
logger.warn("Could not set icon", e);
if (OS.get() != OS.MACOSX) {
try {
String root = "org/terasology/engine/icons/";
ClassLoader classLoader = getClass().getClassLoader();

BufferedImage icon16 = ImageIO.read(classLoader.getResourceAsStream(root + "gooey_sweet_16.png"));
BufferedImage icon32 = ImageIO.read(classLoader.getResourceAsStream(root + "gooey_sweet_32.png"));
BufferedImage icon64 = ImageIO.read(classLoader.getResourceAsStream(root + "gooey_sweet_64.png"));
BufferedImage icon128 = ImageIO.read(classLoader.getResourceAsStream(root + "gooey_sweet_128.png"));
GLFWImage.Buffer buffer = GLFWImage.create(4);
buffer.put(0, LwjglGraphicsUtil.convertToGLFWFormat(icon16));
buffer.put(1, LwjglGraphicsUtil.convertToGLFWFormat(icon32));
buffer.put(2, LwjglGraphicsUtil.convertToGLFWFormat(icon64));
buffer.put(3, LwjglGraphicsUtil.convertToGLFWFormat(icon128));
// Not supported on Mac: Code: 65548, Description: Cocoa: Regular windows do not have icons on macOS
GLFW.glfwSetWindowIcon(window, buffer);

} catch (IOException | IllegalArgumentException e) {
logger.warn("Could not set icon", e);
}
}

lwjglDisplay.setDisplayModeSetting(config.getDisplayModeSetting(), false);
Expand Down