Skip to content

Commit 3a75f43

Browse files
committed
Add window size callback
1 parent 663ac4f commit 3a75f43

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

proto/gui.h

+12-12
Original file line numberDiff line numberDiff line change
@@ -2059,13 +2059,12 @@ void gl_model_draw(const gl_model_t *model, const gl_camera_t *camera) {
20592059
* GUI
20602060
*****************************************************************************/
20612061

2062-
// void gui_window_callback(gui_t *gui, const SDL_Event event) {
2063-
// if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
2064-
// const GLsizei width = event.window.data1;
2065-
// const GLsizei height = (event.window.data2 > 0) ? event.window.data2 : 1;
2066-
// glViewport(0, 0, width, height);
2067-
// }
2068-
// }
2062+
void gui_window_size_callback(GLFWwindow *window, int width, int height) {
2063+
gui_t *gui = (gui_t *) glfwGetWindowUserPointer(window);
2064+
gui->window_width = width;
2065+
gui->window_height = height;
2066+
glViewport(0, 0, width, height);
2067+
}
20692068

20702069
void gui_keyboard_callback(GLFWwindow *window,
20712070
int key,
@@ -2141,8 +2140,8 @@ void gui_cursor_position_callback(GLFWwindow *window, double x, double y) {
21412140
} else if (gui->last_cursor_set) {
21422141
gl_camera_pan(&gui->camera, gui->mouse_sensitivity, dx, dy);
21432142
}
2144-
// } else if (event.wheel.type == SDL_MOUSEWHEEL && event.wheel.y) {
2145-
// gl_camera_zoom(&gui->camera, gui->mouse_sensitivity, 0, event.wheel.y);
2143+
// } else if (event.wheel.type == SDL_MOUSEWHEEL && event.wheel.y) {
2144+
// gl_camera_zoom(&gui->camera, gui->mouse_sensitivity, 0, event.wheel.y);
21462145
} else {
21472146
// Reset cursor
21482147
gui->left_click = 0;
@@ -2188,6 +2187,7 @@ void gui_setup(gui_t *gui) {
21882187
}
21892188
glfwMakeContextCurrent(gui->window);
21902189
glfwSetWindowUserPointer(gui->window, gui);
2190+
glfwSetWindowSizeCallback(gui->window, gui_window_size_callback);
21912191
glfwSetKeyCallback(gui->window, gui_keyboard_callback);
21922192
glfwSetCursorPosCallback(gui->window, gui_cursor_position_callback);
21932193
glfwSetMouseButtonCallback(gui->window, gui_mouse_button_callback);
@@ -2202,7 +2202,7 @@ void gui_setup(gui_t *gui) {
22022202
gl_camera_setup(&gui->camera, &gui->window_width, &gui->window_height);
22032203
gui->camera.position[0] = 0;
22042204
gui->camera.position[1] = 1;
2205-
gui->camera.position[2] = -1;
2205+
gui->camera.position[2] = -2;
22062206
gui->movement_speed = 50.0f;
22072207
gui->mouse_sensitivity = 0.02f;
22082208

@@ -2262,12 +2262,12 @@ void gui_loop(gui_t *gui) {
22622262

22632263
// Update
22642264
glfwSwapBuffers(gui->window);
2265+
glfwSetWindowAspectRatio(gui->window, 16, 9);
22652266
glfwPollEvents();
2267+
gl_camera_update(&gui->camera);
22662268
}
22672269

22682270
gl_cube_cleanup(&cube);
2269-
// gl_cube_cleanup(&cube2);
2270-
// gl_cube_cleanup(&cube3);
22712271
gl_camera_frame_cleanup(&cf);
22722272
gl_grid_cleanup(&grid);
22732273
gl_model_free(model);

0 commit comments

Comments
 (0)