rendering: window icon

This commit is contained in:
Bixilon 2021-11-18 16:40:33 +01:00
parent e6fd5d5f54
commit 1c61ffb440
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 28 additions and 0 deletions

View File

@ -150,6 +150,7 @@ class RenderWindow(
val stopwatch = Stopwatch()
window.init()
window.setDefaultIcon(connection.assetsManager)
inputHandler.camera.init(this)

View File

@ -15,8 +15,13 @@ package de.bixilon.minosoft.gui.rendering.system.window
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.config.StaticConfiguration
import de.bixilon.minosoft.data.assets.AssetsManager
import de.bixilon.minosoft.util.KUtil.toResourceLocation
import de.matthiasmann.twl.utils.PNGDecoder
import glm_.vec2.Vec2
import glm_.vec2.Vec2i
import org.lwjgl.BufferUtils
import java.nio.ByteBuffer
interface BaseWindow {
var size: Vec2i
@ -61,6 +66,18 @@ interface BaseWindow {
fun setOpenGLVersion(major: Int, minor: Int, coreProfile: Boolean)
fun setIcon(size: Vec2i, buffer: ByteBuffer)
fun setDefaultIcon(assetsManager: AssetsManager) {
val decoder = PNGDecoder(assetsManager.readAssetAsStream("minosoft:textures/icons/window_icon.png".toResourceLocation()))
val data = BufferUtils.createByteBuffer(decoder.width * decoder.height * PNGDecoder.Format.RGBA.numComponents)
decoder.decode(data, decoder.width * PNGDecoder.Format.RGBA.numComponents, PNGDecoder.Format.RGBA)
data.flip()
setIcon(Vec2i(decoder.width, decoder.height), data)
}
companion object {
val DEFAULT_WINDOW_SIZE: Vec2i
get() = Vec2i(900, 500)

View File

@ -35,7 +35,9 @@ import glm_.vec2.Vec2i
import org.lwjgl.glfw.Callbacks.glfwFreeCallbacks
import org.lwjgl.glfw.GLFW.*
import org.lwjgl.glfw.GLFWErrorCallback
import org.lwjgl.glfw.GLFWImage
import org.lwjgl.system.MemoryUtil
import java.nio.ByteBuffer
class GLFWWindow(
@ -280,6 +282,14 @@ class GLFWWindow(
eventMaster.fireEvent(MouseScrollEvent(offset = Vec2d(xOffset, yOffset)))
}
override fun setIcon(size: Vec2i, buffer: ByteBuffer) {
val images = GLFWImage.malloc(1)
val image = GLFWImage.malloc()
image.set(size.x, size.y, buffer)
images.put(0, image)
glfwSetWindowIcon(window, images)
}
companion object {
val CursorModes.glfw: Int
get() {