Skip to content

Commit b3ea5ca

Browse files
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # build.gradle
2 parents 29a4fb4 + 527bfab commit b3ea5ca

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ dependencies {
3737

3838
ext.kx = "com.github.kotlin-graphics"
3939
implementation "$kx:gln:b6f92bf107aa87046bccb5d35edcccb50e767770"
40-
implementation "$kx:vkk:b68d74bddc44e4b372354f7a085d26eadb7ca8f2"
40+
implementation "$kx:vkk:a5176a1f51734ef62571a1674713948e91d35fc6"
4141

4242
testImplementation 'io.kotlintest:kotlintest:2.0.7'
4343
testImplementation 'io.kotlintest:kotlintest-runner-junit5:3.0.6'

src/main/kotlin/uno/glfw/GlfwWindow.kt

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package uno.glfw
22

33
import glm_.bool
4+
import glm_.f
45
import glm_.vec2.Vec2
56
import glm_.vec2.Vec2d
67
import 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
317321
typealias FramebufferSizeCallbackT = (size: Vec2i) -> Unit
318322
typealias KeyCallbackT = (key: Int, scanCode: Int, action: Int, mods: Int) -> Unit
319323
typealias MouseButtonCallbackT = (button: Int, action: Int, mods: Int) -> Unit
320-
typealias ScrollCallbackT = (scroll: Vec2) -> Unit
324+
typealias ScrollCallbackT = (scroll: Vec2d) -> Unit
321325
typealias WindowCloseCallbackT = () -> Unit

0 commit comments

Comments
 (0)