Mercurial > repos > blastem
diff nuklear_ui/nuklear_sdl_gles2.h @ 2309:5e34369ed6be
Fix DPI scaling when OpenGL is enabled
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 27 Mar 2023 21:55:22 -0700 |
parents | b7768c58f0da |
children | 523ab225815b |
line wrap: on
line diff
--- a/nuklear_ui/nuklear_sdl_gles2.h Sun Mar 26 22:39:18 2023 -0700 +++ b/nuklear_ui/nuklear_sdl_gles2.h Mon Mar 27 21:55:22 2023 -0700 @@ -194,7 +194,6 @@ nk_sdl_render(enum nk_anti_aliasing AA, int max_vertex_buffer, int max_element_buffer) { struct nk_sdl_device *dev = &sdl.ogl; - int width, height; int display_width, display_height; struct nk_vec2 scale; GLfloat ortho[4][4] = { @@ -203,13 +202,12 @@ {0.0f, 0.0f,-1.0f, 0.0f}, {-1.0f,1.0f, 0.0f, 1.0f}, }; - SDL_GetWindowSize(sdl.win, &width, &height); SDL_GL_GetDrawableSize(sdl.win, &display_width, &display_height); - ortho[0][0] /= (GLfloat)width; - ortho[1][1] /= (GLfloat)height; + ortho[0][0] /= (GLfloat)display_width; + ortho[1][1] /= (GLfloat)display_height; - scale.x = (float)display_width/(float)width; - scale.y = (float)display_height/(float)height; + scale.x = 1.0f; + scale.y = 1.0f; /* setup global state */ glViewport(0,0,display_width,display_height); @@ -289,7 +287,7 @@ if (!cmd->elem_count) continue; glBindTexture(GL_TEXTURE_2D, (GLuint)cmd->texture.id); glScissor((GLint)(cmd->clip_rect.x * scale.x), - (GLint)((height - (GLint)(cmd->clip_rect.y + cmd->clip_rect.h)) * scale.y), + (GLint)((display_height - (GLint)(cmd->clip_rect.y + cmd->clip_rect.h)) * scale.y), (GLint)(cmd->clip_rect.w * scale.x), (GLint)(cmd->clip_rect.h * scale.y)); glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count, GL_UNSIGNED_SHORT, offset);