Skip to content

Commit

Permalink
attempt to do nicer DPI scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
atsb committed Jun 9, 2023
1 parent 14cbf4d commit 4a0aa6b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/engine/gl_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,17 @@ void GL_Init(void) {
glEnable(GL_LINE_SMOOTH);
glEnable(GL_POLYGON_SMOOTH);

dglViewport(0, 0, video_width, video_height);
float scalingForDPI = GetDPIDisplayScale();

glViewport(0, 0, video_width * scalingForDPI, video_height * scalingForDPI);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, video_width * scalingForDPI, video_height * scalingForDPI, 0, -1, 1);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

dglClearDepth(1.0f);
dglDisable(GL_TEXTURE_2D);
dglEnable(GL_CULL_FACE);
Expand Down
21 changes: 17 additions & 4 deletions src/engine/i_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ boolean window_focused;
int mouse_x = 0;
int mouse_y = 0;

/* Get the Current DPI Scaling */

float GetDPIDisplayScale(void)
{
float diag, hori, vert;
SDL_GetDisplayDPI(0, &diag, &hori, &vert);
return hori / 96.0f;
}

//
// I_InitScreen
//
Expand Down Expand Up @@ -150,12 +159,16 @@ void I_InitScreen(void) {
flags |= SDL_WINDOW_BORDERLESS;
}

/* DPI Scale */
float scalingForDPI = GetDPIDisplayScale();
I_Printf("DPI Factor: %f\n", scalingForDPI);

sprintf(title, "Doom64EX+ - Version Date: %s", version_date);
window = SDL_CreateWindow(title,
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
video_width,
video_height,
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
video_width * scalingForDPI,
video_height * scalingForDPI,
flags);

if (window == NULL) {
Expand Down
1 change: 1 addition & 0 deletions src/engine/i_video.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

extern SDL_Surface* screen;
extern SDL_Window* window;
float GetDPIDisplayScale(void);
void I_InitVideo(void);
void I_InitScreen(void);
void I_ShutdownVideo(void);
Expand Down

0 comments on commit 4a0aa6b

Please sign in to comment.