diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/StarboundClient.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/StarboundClient.kt index 734efddb..d6fcd528 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/StarboundClient.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/StarboundClient.kt @@ -8,11 +8,14 @@ import org.lwjgl.BufferUtils import org.lwjgl.glfw.Callbacks import org.lwjgl.glfw.GLFW import org.lwjgl.glfw.GLFWErrorCallback +import org.lwjgl.glfw.GLFWImage import org.lwjgl.opengl.GL import org.lwjgl.opengl.GL45.* import org.lwjgl.opengl.GLCapabilities +import org.lwjgl.stb.STBImage import org.lwjgl.system.MemoryStack import org.lwjgl.system.MemoryUtil +import org.lwjgl.system.MemoryUtil.memAddressSafe import ru.dbotthepony.kstarbound.util.MailboxExecutorService import ru.dbotthepony.kstarbound.world.PIXELS_IN_STARBOUND_UNIT import ru.dbotthepony.kstarbound.world.PIXELS_IN_STARBOUND_UNITf @@ -238,7 +241,7 @@ class StarboundClient : Closeable { } } - val stack = MemoryStack.stackPush() + var stack = MemoryStack.stackPush() try { val pWidth = stack.mallocInt(1) @@ -261,6 +264,28 @@ class StarboundClient : Closeable { stack.close() } + stack = MemoryStack.stackPush() + + try { + val pWidth = stack.mallocInt(1) + val pHeight = stack.mallocInt(1) + val pChannels = stack.mallocInt(1) + + val readFromDisk = readInternalBytes("starbound.png") + val buff = ByteBuffer.allocateDirect(readFromDisk.size) + buff.put(readFromDisk) + buff.position(0) + + val data = STBImage.stbi_load_from_memory(buff, pWidth, pHeight, pChannels, 4) ?: throw IllegalStateException("Unable to decode starbound.png") + val img = GLFWImage.malloc() + img.set(pWidth[0], pHeight[0], data) + + GLFW.nglfwSetWindowIcon(window, 1, memAddressSafe(img)) + img.free() + } finally { + stack.close() + } + // vsync GLFW.glfwSwapInterval(0) @@ -1068,5 +1093,10 @@ class StarboundClient : Closeable { read } } + + @JvmStatic + fun readInternalBytes(file: String): ByteArray { + return ClassLoader.getSystemClassLoader().getResourceAsStream(file)!!.readAllBytes() + } } } diff --git a/src/main/resources/starbound.png b/src/main/resources/starbound.png new file mode 100644 index 00000000..adceefc5 Binary files /dev/null and b/src/main/resources/starbound.png differ