# HG changeset patch # User Michael Pavone # Date 1679979322 25200 # Node ID 5e34369ed6bef9bf883ca79b9052df9d2a5dcd9e # Parent b7768c58f0daf3dd4304bd46cbcfa901e82f110e Fix DPI scaling when OpenGL is enabled diff -r b7768c58f0da -r 5e34369ed6be nuklear_ui/nuklear_sdl_gles2.h --- 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);