@@ -2059,13 +2059,12 @@ void gl_model_draw(const gl_model_t *model, const gl_camera_t *camera) {
2059
2059
* GUI
2060
2060
*****************************************************************************/
2061
2061
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
+ }
2069
2068
2070
2069
void gui_keyboard_callback (GLFWwindow * window ,
2071
2070
int key ,
@@ -2141,8 +2140,8 @@ void gui_cursor_position_callback(GLFWwindow *window, double x, double y) {
2141
2140
} else if (gui -> last_cursor_set ) {
2142
2141
gl_camera_pan (& gui -> camera , gui -> mouse_sensitivity , dx , dy );
2143
2142
}
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);
2146
2145
} else {
2147
2146
// Reset cursor
2148
2147
gui -> left_click = 0 ;
@@ -2188,6 +2187,7 @@ void gui_setup(gui_t *gui) {
2188
2187
}
2189
2188
glfwMakeContextCurrent (gui -> window );
2190
2189
glfwSetWindowUserPointer (gui -> window , gui );
2190
+ glfwSetWindowSizeCallback (gui -> window , gui_window_size_callback );
2191
2191
glfwSetKeyCallback (gui -> window , gui_keyboard_callback );
2192
2192
glfwSetCursorPosCallback (gui -> window , gui_cursor_position_callback );
2193
2193
glfwSetMouseButtonCallback (gui -> window , gui_mouse_button_callback );
@@ -2202,7 +2202,7 @@ void gui_setup(gui_t *gui) {
2202
2202
gl_camera_setup (& gui -> camera , & gui -> window_width , & gui -> window_height );
2203
2203
gui -> camera .position [0 ] = 0 ;
2204
2204
gui -> camera .position [1 ] = 1 ;
2205
- gui -> camera .position [2 ] = -1 ;
2205
+ gui -> camera .position [2 ] = -2 ;
2206
2206
gui -> movement_speed = 50.0f ;
2207
2207
gui -> mouse_sensitivity = 0.02f ;
2208
2208
@@ -2262,12 +2262,12 @@ void gui_loop(gui_t *gui) {
2262
2262
2263
2263
// Update
2264
2264
glfwSwapBuffers (gui -> window );
2265
+ glfwSetWindowAspectRatio (gui -> window , 16 , 9 );
2265
2266
glfwPollEvents ();
2267
+ gl_camera_update (& gui -> camera );
2266
2268
}
2267
2269
2268
2270
gl_cube_cleanup (& cube );
2269
- // gl_cube_cleanup(&cube2);
2270
- // gl_cube_cleanup(&cube3);
2271
2271
gl_camera_frame_cleanup (& cf );
2272
2272
gl_grid_cleanup (& grid );
2273
2273
gl_model_free (model );
0 commit comments