#[SOLVED] how to fix this glfw window resize bug
10 messages · Page 1 of 1 (latest)
Could you send some code?
People probably wont answer the question if its "how do i fix da issue?" and nothing else.
yea sure, thats the whole source code :)
its written in odin tho
this part is most suspect
CursorPosCallback :: proc "c" (window: glfw.WindowHandle, xpos, ypos: f64) {
context = g_ctx
@(static) firstMouse := true;
@(static) lastX: f32;
@(static) lastY: f32;
@(static) sensitivity: f32 = 0.1;
if firstMouse {
lastX = f32(xpos);
lastY = f32(ypos);
firstMouse = false;
}
xoffset := (f32(xpos) - lastX) * sensitivity;
yoffset := (lastY - f32(ypos)) * sensitivity; // reversed since y-coordinates go from bottom to top
lastX = f32(xpos);
lastY = f32(ypos);
camera.yaw += xoffset;
camera.pitch += yoffset;
update_camera_rotation(&camera)
}
setup_callbacks :: proc(window: glfw.WindowHandle) {
FramebufferSizeCallback :: proc "c" (window: glfw.WindowHandle, width, height: c.int) {
gl.Viewport(0,0,width, height);
}
KeyCallback :: proc "c" (window: glfw.WindowHandle, key, scancode, action, mods: i32) {
if key == glfw.KEY_ESCAPE && action == glfw.PRESS {
should_exit = true
}
}
glfw.SetFramebufferSizeCallback(window, FramebufferSizeCallback);
glfw.SetKeyCallback(window, KeyCallback);
glfw.SetCursorPosCallback(window, CursorPosCallback);
}
...
FramebufferSizeCallback :: proc "c" (window: glfw.WindowHandle, width, height: c.int) {
gl.Viewport(0,0,width, height);
}
FINALLY i sovled it
[SOLVED] how to fix this glfw window resize bug
i had to do this
....
frame_buffer_changed := false // global flag
FramebufferSizeCallback :: proc "c" (window: glfw.WindowHandle, width, height: c.int) {
frame_buffer_changed = true;
context = g_ctx
gl.Viewport(0,0,width, height);
}
cursor_pos_changed := false // global flag
xpos, ypos: f64 // global mouse cursor position set
CursorPosCallback :: proc "c" (window: glfw.WindowHandle, _xpos, _ypos: f64) {
cursor_pos_changed = true;
xpos = _xpos
ypos = _ypos
}
...
glfw.SetFramebufferSizeCallback(window, FramebufferSizeCallback);
glfw.SetCursorPosCallback(window, CursorPosCallback);
...
cursor_pos_handle :: proc (window: glfw.WindowHandle) {
@(static) firstMouse := true;
@(static) lastX: f32;
@(static) lastY: f32;
@(static) sensitivity: f32 = 0.1;
if frame_buffer_changed {
frame_buffer_changed = false
return
}
if firstMouse {
lastX = f32(xpos);
lastY = f32(ypos);
firstMouse = false;
}
xoffset := (f32(xpos) - lastX) * sensitivity;
yoffset := (lastY - f32(ypos)) * sensitivity; // reversed since y-coordinates go from bottom to top
lastX = f32(xpos);
lastY = f32(ypos);
fmt.println(xpos, ypos)
camera.yaw += xoffset;
camera.pitch += yoffset;
update_camera_rotation(&camera)
}
...
// IN MAIN LOOP
if cursor_pos_changed {
cursor_pos_handle(window)
cursor_pos_changed = false;
}
this makes it so mouse cursor movement is synchronous idk if its a good idea but yea, that fixed that problem