Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Creating DPI aware programs  (Read 2984 times)

0 Members and 1 Guest are viewing this topic.

dassie

  • Newbie
  • *
  • Posts: 13
    • View Profile
Creating DPI aware programs
« on: September 01, 2017, 02:25:36 am »
So it seems that SFML does not adjust window sizes and such based on the system's DPI settings.

I'm looking for a strategy wherein I can make my SFML program DPI-aware myself (a game boy emulator). I'm able to calculate the scaling factor that is required and now I'm wondering how to account for it.

I could so something as simple as scaling my window size and number of screen pixels per emulator pixel by the same scaling factor. E.g. if the factor is 2, then I'll double the window dimensions, and draw 4 pixels for everyone 1 pixel computed by the emulator.

But I also saw a post where someone suggested using a view and setting the zoom setting on the view object. Is that more efficient? Can the view also scale window dimensions?

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Creating DPI aware programs
« Reply #1 on: September 01, 2017, 11:05:32 pm »
Using a view would require you to still scale the window size yourself but allows you to keep the same 'size' of view which would automatically apply the "draw 4 pixels for everyone 1 pixel".

Basically, set the window to the size you wish and set the view to match the 'emulator screen resolution'. This way it automatically streches (or shrinks) to fit the window.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

dassie

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Creating DPI aware programs
« Reply #2 on: September 02, 2017, 04:32:45 am »
Thank for the response, I actually already went ahead and coded something up.

You're right, I had to set the window size my self based on the scale factor.

To scale the emulation frame buffer, I opted to use a sf::Transform rather than bitmap scaling myself by drawing more pixels. Basically, I copy my emulator's frame buffer to a VertexArray of points, then I draw it to the window using an scale transform.

« Last Edit: September 02, 2017, 10:38:29 am by Laurent »

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Creating DPI aware programs
« Reply #3 on: September 02, 2017, 04:27:29 pm »
Yeah, that'd work.
However, that requires you to re-calculate the scale of the buffer everytime the window size changes.
A view, though, wouldn't need updating; it's automatic, saves duplicating work and effectively does the same thing (transforms all positions when drawing).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

dassie

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Creating DPI aware programs
« Reply #4 on: September 03, 2017, 07:38:27 am »
Yeah, that'd work.
However, that requires you to re-calculate the scale of the buffer everytime the window size changes.
A view, though, wouldn't need updating; it's automatic, saves duplicating work and effectively does the same thing (transforms all positions when drawing).

I didn't know that. For now I'm making the window non-resizeable (even if the DPI changes) - I'm planning to make it resizeable at some point in the future so I'll keep that in mind for that happens.

 

anything