Window icon

This commit is contained in:
DBotThePony 2023-12-02 15:38:00 +07:00
parent 19c3da7b8f
commit 8fe6da7218
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 31 additions and 1 deletions

View File

@ -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()
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB