mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-01 02:56:43 +01:00
make windowed display resizable and try to fix flickering border around the viewport
This commit is contained in:
parent
2e1a7e73fd
commit
96a33c1a37
4 changed files with 14 additions and 5 deletions
|
@ -92,7 +92,7 @@ SYMBOL_INTERNAL void Console_Load(struct Game *game) {
|
|||
game->_priv.font_bsod = al_load_ttf_font(GetDataFilePath(game, "fonts/DejaVuSansMono.ttf"), al_get_display_height(game->display)*0.025,0 );
|
||||
}
|
||||
int width = (al_get_display_width(game->display) / game->viewport.width) * game->viewport.width;
|
||||
if (game->viewport.allow_non_integer) {
|
||||
if (!game->viewport.integer_scaling) {
|
||||
width = (al_get_display_width(game->display) / (float)game->viewport.width) * game->viewport.width;
|
||||
}
|
||||
game->_priv.console = al_create_bitmap(width, al_get_font_line_height(game->_priv.font_console)*5);
|
||||
|
|
|
@ -119,8 +119,8 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char*
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (game->config.fullscreen) al_set_new_display_flags(ALLEGRO_PROGRAMMABLE_PIPELINE | ALLEGRO_FULLSCREEN_WINDOW | ALLEGRO_OPENGL);
|
||||
else al_set_new_display_flags(ALLEGRO_PROGRAMMABLE_PIPELINE | ALLEGRO_WINDOWED | ALLEGRO_OPENGL);
|
||||
if (game->config.fullscreen) al_set_new_display_flags(ALLEGRO_PROGRAMMABLE_PIPELINE | ALLEGRO_FULLSCREEN_WINDOW | ALLEGRO_OPENGL );
|
||||
else al_set_new_display_flags(ALLEGRO_PROGRAMMABLE_PIPELINE | ALLEGRO_WINDOWED | ALLEGRO_RESIZABLE | ALLEGRO_OPENGL);
|
||||
al_set_new_display_option(ALLEGRO_VSYNC, 2-atoi(GetConfigOptionDefault(game, "SuperDerpy", "vsync", "1")), ALLEGRO_SUGGEST);
|
||||
al_set_new_display_option(ALLEGRO_OPENGL, atoi(GetConfigOptionDefault(game, "SuperDerpy", "opengl", "1")), ALLEGRO_SUGGEST);
|
||||
#ifdef ALLEGRO_WINDOWS
|
||||
|
@ -378,6 +378,10 @@ SYMBOL_EXPORT int libsuperderpy_run(struct Game *game) {
|
|||
else if(ev.type == ALLEGRO_EVENT_DISPLAY_FOUND) {
|
||||
SetupViewport(game, game->viewport_config);
|
||||
}
|
||||
else if(ev.type == ALLEGRO_EVENT_DISPLAY_RESIZE) {
|
||||
al_acknowledge_resize(game->display);
|
||||
SetupViewport(game, game->viewport_config);
|
||||
}
|
||||
#ifdef ALLEGRO_MACOSX
|
||||
else if ((ev.type == ALLEGRO_EVENT_KEY_DOWN) && (ev.keyboard.keycode == 104)) { //TODO: report to upstream
|
||||
#else
|
||||
|
|
|
@ -51,7 +51,7 @@ struct libsuperderpy_viewport {
|
|||
int width; /*!< Actual available width of the drawing canvas. */
|
||||
int height; /*!< Actual available height of the drawing canvas. */
|
||||
float aspect;
|
||||
bool allow_non_integer;
|
||||
bool integer_scaling;
|
||||
};
|
||||
|
||||
/*! \brief Main struct of the game. */
|
||||
|
|
|
@ -289,11 +289,16 @@ SYMBOL_EXPORT void SetupViewport(struct Game *game, struct libsuperderpy_viewpor
|
|||
}
|
||||
}
|
||||
|
||||
al_set_target_backbuffer(game->display);
|
||||
al_identity_transform(&game->projection);
|
||||
al_use_transform(&game->projection);
|
||||
al_set_clipping_rectangle(0, 0, al_get_display_width(game->display), al_get_display_height(game->display));
|
||||
|
||||
al_clear_to_color(al_map_rgb(0,0,0));
|
||||
|
||||
float resolution = al_get_display_width(game->display) / (float)game->viewport.width;
|
||||
if (al_get_display_height(game->display) / game->viewport.height < resolution) resolution = al_get_display_height(game->display) / (float)game->viewport.height;
|
||||
if (!game->viewport.allow_non_integer) {
|
||||
if (game->viewport.integer_scaling) {
|
||||
resolution = floor(resolution);
|
||||
}
|
||||
if (resolution < 1) resolution = 1;
|
||||
|
|
Loading…
Reference in a new issue