Add window resizing handling
This commit is contained in:
@@ -94,6 +94,7 @@ void
|
||||
evtman_init ()
|
||||
{
|
||||
#define KEY(k) GINT_TO_POINTER(k)
|
||||
evtman_add_handler (2, SDL_EVENT_WINDOW_RESIZED, NULL, NULL, graphics_cb_window_resize, NULL);
|
||||
/* The UI effectively eats most SDL events, as it needs it for it's
|
||||
own calculations. */
|
||||
evtman_add_handler (1, SDL_EVENT_KEY_DOWN, evt_pred_flag, "ui_has_focus", uiman_cb_key_down, NULL);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "handler.h"
|
||||
#include "../util.h"
|
||||
#include "../flags.h"
|
||||
#include "../graphics.h"
|
||||
#include "../ui/uiman.h"
|
||||
|
||||
typedef struct CompositePredicate
|
||||
|
||||
+14
-6
@@ -8,13 +8,12 @@ int render_distance = 2;
|
||||
|
||||
static SDL_GLContext gl_context;
|
||||
|
||||
static int window_w = 800, window_h = 600;
|
||||
|
||||
static uint64_t last_check_perf = 0;
|
||||
static int avg_counter = 0;
|
||||
static double avg_elapsed = 0;
|
||||
|
||||
#define WINDOW_WIDTH 800
|
||||
#define WINDOW_HEIGHT 600
|
||||
|
||||
void
|
||||
graphics_init ()
|
||||
{
|
||||
@@ -23,7 +22,7 @@ graphics_init ()
|
||||
g_error ("Couldn't initialize SDL: %s", SDL_GetError ());
|
||||
}
|
||||
|
||||
sdl_window = SDL_CreateWindow (GAME_NAME, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_OPENGL);
|
||||
sdl_window = SDL_CreateWindow (GAME_NAME, window_w, window_h, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
|
||||
|
||||
if (!sdl_window)
|
||||
{
|
||||
@@ -53,7 +52,7 @@ graphics_init ()
|
||||
g_info ("GLSL version: %s", glGetString (GL_SHADING_LANGUAGE_VERSION));
|
||||
g_info ("Max vertex attributes: %d", GL_MAX_VERTEX_ATTRIBS);
|
||||
|
||||
glViewport (0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||
glViewport (0, 0, window_w, window_h);
|
||||
glClearColor (0, 0.3, 0.8, 1);
|
||||
|
||||
glEnable (GL_CULL_FACE);
|
||||
@@ -71,7 +70,7 @@ graphics_render ()
|
||||
uint64_t freq = SDL_GetPerformanceFrequency ();
|
||||
|
||||
mat4 projection, view;
|
||||
camera_get_projection (WINDOW_WIDTH / WINDOW_HEIGHT, projection);
|
||||
camera_get_projection ((float) window_w / (float) window_h, projection);
|
||||
camera_get_view (view);
|
||||
|
||||
resources_programs_set_mat4 ("projection", &projection);
|
||||
@@ -129,3 +128,12 @@ graphics_free ()
|
||||
SDL_GL_DestroyContext (gl_context);
|
||||
SDL_DestroyWindow (sdl_window);
|
||||
}
|
||||
|
||||
gboolean
|
||||
graphics_cb_window_resize (SDL_Event *event, void *data)
|
||||
{
|
||||
UNUSED (event, data);
|
||||
SDL_GetWindowSize (sdl_window, &window_w, &window_h);
|
||||
glViewport (0, 0, window_w, window_h);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -24,3 +24,4 @@
|
||||
void graphics_init ();
|
||||
void graphics_render ();
|
||||
void graphics_free ();
|
||||
gboolean graphics_cb_window_resize ();
|
||||
|
||||
Reference in New Issue
Block a user