opengl moment #1
@ -62,6 +62,8 @@ typedef struct context {
|
|||||||
bool debug;
|
bool debug;
|
||||||
bool is_running;
|
bool is_running;
|
||||||
bool resync_flag;
|
bool resync_flag;
|
||||||
|
|
||||||
|
bool window_size_has_changed;
|
||||||
} t_ctx;
|
} t_ctx;
|
||||||
|
|
||||||
extern t_ctx ctx;
|
extern t_ctx ctx;
|
||||||
|
@ -54,7 +54,6 @@ struct action_hash_item {
|
|||||||
|
|
||||||
struct input_state {
|
struct input_state {
|
||||||
struct action_hash_item *action_hash;
|
struct action_hash_item *action_hash;
|
||||||
SDL_Renderer *renderer; /* some input relates to the screen in some way */
|
|
||||||
const uint8_t *keyboard_state; /* array of booleans indexed by scancode */
|
const uint8_t *keyboard_state; /* array of booleans indexed by scancode */
|
||||||
uint32_t mouse_state; /* SDL mouse button bitmask */
|
uint32_t mouse_state; /* SDL mouse button bitmask */
|
||||||
t_vec2 mouse_window_position;
|
t_vec2 mouse_window_position;
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
static void poll_events(void) {
|
static void poll_events(void) {
|
||||||
SDL_Event e;
|
SDL_Event e;
|
||||||
|
|
||||||
|
ctx.window_size_has_changed = false;
|
||||||
|
|
||||||
while (SDL_PollEvent(&e)) {
|
while (SDL_PollEvent(&e)) {
|
||||||
switch (e.type) {
|
switch (e.type) {
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
@ -37,6 +39,7 @@ static void poll_events(void) {
|
|||||||
case SDL_WINDOWEVENT_RESIZED:
|
case SDL_WINDOWEVENT_RESIZED:
|
||||||
ctx.window_w = e.window.data1;
|
ctx.window_w = e.window.data1;
|
||||||
ctx.window_h = e.window.data2;
|
ctx.window_h = e.window.data2;
|
||||||
|
ctx.window_size_has_changed = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,8 +141,8 @@ static void render_space(void) {
|
|||||||
void render(void) {
|
void render(void) {
|
||||||
textures_update_atlas(&ctx.texture_cache);
|
textures_update_atlas(&ctx.texture_cache);
|
||||||
|
|
||||||
/* TODO: only do this when needed */
|
|
||||||
/* fit rendering context onto the resizable screen */
|
/* fit rendering context onto the resizable screen */
|
||||||
|
if (ctx.window_size_has_changed) {
|
||||||
if ((float)ctx.window_w / (float)ctx.window_h > RENDER_BASE_RATIO) {
|
if ((float)ctx.window_w / (float)ctx.window_h > RENDER_BASE_RATIO) {
|
||||||
float ratio = (float)ctx.window_h / (float)RENDER_BASE_HEIGHT;
|
float ratio = (float)ctx.window_h / (float)RENDER_BASE_HEIGHT;
|
||||||
int w = (int)((float)RENDER_BASE_WIDTH * ratio);
|
int w = (int)((float)RENDER_BASE_WIDTH * ratio);
|
||||||
@ -162,6 +162,7 @@ void render(void) {
|
|||||||
h
|
h
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
glClearColor((1.0f / 255) * 230,
|
glClearColor((1.0f / 255) * 230,
|
||||||
(1.0f / 255) * 230,
|
(1.0f / 255) * 230,
|
||||||
|
Loading…
Reference in New Issue
Block a user