diff options
Diffstat (limited to 'src/pig.c')
-rw-r--r-- | src/pig.c | 100 |
1 files changed, 1 insertions, 99 deletions
@@ -45,104 +45,6 @@ static inline float randf(void) } -void pig_canvas_size(pig_t *pig, int *res_width, int *res_height) -{ - assert(pig); - assert(res_width); - assert(res_height); - - SDL_GL_GetDrawableSize(pig->window, res_width, res_height); -} - - -void pig_canvas_to_ndc(pig_t *pig, int x, int y, float *res_x, float *res_y) -{ - int w, h; - - assert(pig); - assert(res_x); - assert(res_y); - - pig_canvas_size(pig, &w, &h); - - *res_x = (float)x / (float)w * 2.f - 1.f; - *res_y = (1.f - (float)y / (float)h) * 2.f - 1.f; -} - - -void pig_canvas_from_ndc(pig_t *pig, float x, float y, int *res_x, int *res_y) -{ - int w, h; - - assert(pig); - assert(res_x); - assert(res_y); - - pig_canvas_size(pig, &w, &h); - - *res_x = roundf(x * (float)w * .5f + .5f * (float)w); - *res_y = roundf(y * (float)h * .5f + .5f * (float)h); -} - - -void pig_viewport_size(pig_t *pig, int *res_width, int *res_height) -{ - assert(pig); - assert(res_width); - assert(res_height); - - SDL_GetWindowSize(pig->window, res_width, res_height); -} - - -void pig_viewport_to_ndc(pig_t *pig, int x, int y, float *res_x, float *res_y) -{ - int w, h; - - assert(pig); - assert(res_x); - assert(res_y); - - pig_viewport_size(pig, &w, &h); - - *res_x = (float)x / (float)w * 2.f - 1.f; - *res_y = (1.f - (float)y / (float)h) * 2.f - 1.f; -} - - -void pig_viewport_from_ndc(pig_t *pig, float x, float y, int *res_x, int *res_y) -{ - int w, h; - - assert(pig); - assert(res_x); - assert(res_y); - - pig_viewport_size(pig, &w, &h); - - *res_x = roundf(x * (float)w * .5f + .5f * (float)w); - *res_y = roundf(y * (float)h * .5f + .5f * (float)h); -} - - -uint32_t pig_viewport_id(pig_t *pig) -{ - return SDL_GetWindowID(pig->window); -} - - -void pig_toggle_fullscreen(pig_t *pig) -{ - if (pig->windowed) { - if (!SDL_SetWindowFullscreen(pig->window, SDL_WINDOW_FULLSCREEN_DESKTOP)) - pig->windowed = 0; - } else { - if (!SDL_SetWindowFullscreen(pig->window, 0)) - pig->windowed = 1; - } -} - - static void randomize_color(v3f_t *color) { color->x = randf(); @@ -359,7 +261,7 @@ static void pig_dispatch(play_t *play, void *context, SDL_Event *event) /* on highdpi the window size and pixels are decoupled, so ignore what * the event contains and query the canvas size. */ - pig_canvas_size(pig, &w, &h); + SDL_GL_GetDrawableSize(pig->window, &w, &h); glViewport(0, 0, w, h); stage_dirty(pig->stage); } |