11package uno.glfw
22
33import glm_.bool
4+ import glm_.f
45import glm_.vec2.Vec2
56import glm_.vec2.Vec2d
67import glm_.vec2.Vec2i
@@ -89,7 +90,7 @@ open class GlfwWindow(var handle: Long) {
8990 val x = appBuffer.int
9091 val y = appBuffer.int
9192 nglfwGetWindowPos(handle, x, y)
92- return field(x, y )
93+ return field(memGetInt(x), memGetInt(y) )
9394 }
9495 set(value) = glfwSetWindowPos(handle, value.x, value.y)
9596
@@ -98,7 +99,7 @@ open class GlfwWindow(var handle: Long) {
9899 val x = appBuffer.int
99100 val y = appBuffer.int
100101 nglfwGetWindowSize(handle, x, y)
101- return field(x, y )
102+ return field(memGetInt(x), memGetInt(y) )
102103 }
103104 set(value) = glfwSetWindowSize(handle, value.x, value.y)
104105
@@ -114,7 +115,7 @@ open class GlfwWindow(var handle: Long) {
114115 val x = appBuffer.int
115116 val y = appBuffer.int
116117 nglfwGetFramebufferSize(handle, x, y)
117- return field(x, y )
118+ return field(memGetInt(x), memGetInt(y) )
118119 }
119120
120121 val frameSize = Vec4i ()
@@ -124,7 +125,7 @@ open class GlfwWindow(var handle: Long) {
124125 val z = appBuffer.int
125126 val w = appBuffer.int
126127 nglfwGetWindowFrameSize(handle, x, y, z, w)
127- return field(x, y, z, w )
128+ return field(memGetInt(x), memGetInt(y), memGetInt(z), memGetInt(w) )
128129 }
129130
130131 fun iconify () = glfwIconifyWindow(handle)
@@ -160,14 +161,12 @@ open class GlfwWindow(var handle: Long) {
160161 handle = NULL
161162 }
162163
163- fun present () = glfwSwapBuffers(handle)
164-
165164 var cursorPos = Vec2d ()
166165 get() {
167- val x = appBuffer.doubleBuffer
168- val y = appBuffer.doubleBuffer
169- glfwGetCursorPos (handle, x, y)
170- return field(x[ 0 ], y[ 0 ] )
166+ val x = appBuffer.double
167+ val y = appBuffer.double
168+ nglfwGetCursorPos (handle, x, y)
169+ return field(memGetDouble(x), memGetDouble(y) )
171170 }
172171 set(value) = glfwSetCursorPos(handle, value.x, value.y)
173172
@@ -225,7 +224,7 @@ open class GlfwWindow(var handle: Long) {
225224 field = value
226225 }
227226 val scrollCallbacks = sortedMapOf<String , ScrollCallbackT >()
228- val nScrollCallback = GLFWScrollCallbackI { _, xOffset, yOffset -> scrollCallbacks.values.forEach { it(Vec2 (xOffset, yOffset)) } }
227+ val nScrollCallback = GLFWScrollCallbackI { _, xOffset, yOffset -> scrollCallbacks.values.forEach { it(Vec2d (xOffset, yOffset)) } }
229228
230229
231230 var windowCloseCallback: WindowCloseCallbackT ? = null
@@ -240,15 +239,15 @@ open class GlfwWindow(var handle: Long) {
240239 val defaultKeyCallback: KeyCallbackT = { key, _, _, mods -> onKeyPressed(key, mods) }
241240 val defaultMouseButtonCallback: MouseButtonCallbackT = { button, action, mods -> onMouseButtonEvent(button, action, mods) }
242241 val defaultCursorPosCallback: CursorPosCallbackT = { pos -> onMouseMoved(pos) }
243- val defaultScrollCallback: ScrollCallbackT = { scroll -> onMouseScrolled(scroll.y) }
242+ val defaultScrollCallback: ScrollCallbackT = { scroll -> onMouseScrolled(scroll.y.f ) }
244243 val defaultWindowCloseCallback: WindowCloseCallbackT = ::onWindowClosed
245244 val defaultFramebufferSizeCallback: FramebufferSizeCallbackT = { size -> onWindowResized(size) }
246245
247246 //
248247 // Event handlers are called by the GLFW callback mechanism and should not be called directly
249248 //
250249
251- open fun onWindowResized (newSize : Vec2i ) {}
250+ open fun onWindowResized (newSize : Vec2i ) = appBuffer.reset()
252251 open fun onWindowClosed () {}
253252
254253 // Keyboard handling
@@ -299,16 +298,21 @@ open class GlfwWindow(var handle: Long) {
299298 fun getJoystickButtons (joystickId : Int ): ByteBuffer ? = glfwGetJoystickButtons(joystickId)
300299 fun getJoystickAxes (joystickId : Int ): FloatBuffer ? = glfwGetJoystickAxes(joystickId)
301300
301+ var autoSwap = true
302+
302303 inline fun loop (block : () -> Unit ) {
303304 while (isOpen) {
304305 glfwPollEvents()
305306 block()
307+ if (autoSwap)
308+ glfwSwapBuffers(handle)
306309 appBuffer.reset()
307310 }
308311 }
309312
310313 infix fun createSurface (instance : VkInstance ) = glfw.createWindowSurface(handle, instance)
311314
315+ fun present () = glfwSwapBuffers(handle)
312316 fun swapBuffers () = glfwSwapBuffers(handle)
313317}
314318
@@ -317,5 +321,5 @@ typealias CursorPosCallbackT = (pos: Vec2) -> Unit
317321typealias FramebufferSizeCallbackT = (size: Vec2i ) -> Unit
318322typealias KeyCallbackT = (key: Int , scanCode: Int , action: Int , mods: Int ) -> Unit
319323typealias MouseButtonCallbackT = (button: Int , action: Int , mods: Int ) -> Unit
320- typealias ScrollCallbackT = (scroll: Vec2 ) -> Unit
324+ typealias ScrollCallbackT = (scroll: Vec2d ) -> Unit
321325typealias WindowCloseCallbackT = () -> Unit
0 commit comments