From 214ef9399d9537d301d6701b72aa27e2d6aea5cc Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Tue, 24 Sep 2019 20:22:07 +0200 Subject: [PATCH] [GTK3] Fix integer scaling --- gtk3/main.c | 28 +++++++++++++++++----------- gtk3/shader.c | 8 ++++---- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/gtk3/main.c b/gtk3/main.c index 8d253ff..bc8dd47 100644 --- a/gtk3/main.c +++ b/gtk3/main.c @@ -92,10 +92,10 @@ static void vblank(GB_gameboy_t *gb) { } static void update_viewport(void) { - int win_width = gtk_widget_get_allocated_width(GTK_WIDGET(gl_area)); + int win_width = gtk_widget_get_allocated_width(GTK_WIDGET(gl_area)); int win_height = gtk_widget_get_allocated_height(GTK_WIDGET(gl_area)); - double x_factor = win_width / (double) GB_get_screen_width(&gb); + double x_factor = win_width / (double) GB_get_screen_width(&gb); double y_factor = win_height / (double) GB_get_screen_height(&gb); if (true /*configuration.scaling_mode == GB_SDL_SCALING_INTEGER_FACTOR*/) { @@ -103,19 +103,24 @@ static void update_viewport(void) { y_factor = (int)(y_factor); } - /*if (configuration.scaling_mode != GB_SDL_SCALING_ENTIRE_WINDOW) { - if (x_factor > y_factor) { - x_factor = y_factor; + if (true /*configuration.scaling_mode != GB_SDL_SCALING_ENTIRE_WINDOW*/) { + if (x_factor > y_factor) { + x_factor = y_factor; + } + else { + y_factor = x_factor; + } } - else { - y_factor = x_factor; - } - }*/ - unsigned new_width = x_factor * GB_get_screen_width(&gb); + unsigned new_width = x_factor * GB_get_screen_width(&gb); unsigned new_height = y_factor * GB_get_screen_height(&gb); - rect = (Rect){(win_width - new_width) / 2, (win_height - new_height) / 2, new_width, new_height}; + rect = (Rect){ + (win_width - new_width) / 2, + (win_height - new_height) / 2, + new_width, + new_height + }; glViewport(rect.x, rect.y, rect.w, rect.h); } @@ -283,6 +288,7 @@ static void startup(GApplication *app, gpointer user_data_gptr) { g_signal_connect(gl_area, "render", G_CALLBACK(gl_draw), NULL); g_signal_connect(gl_area, "resize", G_CALLBACK(gl_resize), NULL); g_signal_connect(gl_area, "unrealize", G_CALLBACK(gl_finish), NULL); + gtk_container_add(GTK_CONTAINER(main_window), GTK_WIDGET(gl_area)); // Handle the whole menubar situation … diff --git a/gtk3/shader.c b/gtk3/shader.c index e7da2e4..a6bd860 100644 --- a/gtk3/shader.c +++ b/gtk3/shader.c @@ -129,8 +129,8 @@ bool init_shader_with_name(shader_t *shader, const char *name) glBindTexture(GL_TEXTURE_2D, shader->texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glBindTexture(GL_TEXTURE_2D, 0); shader->texture_uniform = glGetUniformLocation(shader->program, "image"); @@ -138,8 +138,8 @@ bool init_shader_with_name(shader_t *shader, const char *name) glBindTexture(GL_TEXTURE_2D, shader->previous_texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glBindTexture(GL_TEXTURE_2D, 0); shader->previous_texture_uniform = glGetUniformLocation(shader->program, "previous_image");