Automatic Scaling

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Message
Author
Dennis
Newbie
Posts: 11
Joined: Sun Jul 08, 2007 4:37 pm
Location: Esslingen, Germany
Contact:

Re: Automatic Scaling

#16 Post by Dennis »

PyTom wrote:Hm... I think xminimum (and xmaximum) need to be an absolute number of pixels, not a relative size.
I tried with an absolute size. It works fine for buttons, but not for the frame around them, meaning they extend beyond the frame's borders.

Code: Select all

$ style.prefs_button.xminimum = 300
works!

Code: Select all

$ style.prefs_frame.xminimum = 300
$ style.prefs_pref_frame.xminimum = 300
doesn't work.

Maybe I'm attaching xminimum to the wrong thing here?

But the columns are not windows, so xminimum shouldn't work with them, right? All I can do is set their positions:

Code: Select all

$ style.prefs_left.xpos = 0.1
$ style.prefs_center.xpos = 0.35
$ style.prefs_right.xpos = 0.6
My question is actually quite simple: How to increase the width of a preferences column?

If someone has a simple solution, it would be great! If not, it's not so important. Solving the thumbnail problem would have bigger impact :)
PyTom wrote:I'll look into the thumbnails issue.
Thanks! :)

@DaFool: 4 years are fine. Since it's a VN, what you don't get from the text, you'll get from the pictures. I'm glad we'll have some readers here then! Also looking forward to Nettestadt Troll - nice title :)

Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: Automatic Scaling

#17 Post by Jake »

Dennis wrote: @DaFool: 4 years are fine. Since it's a VN, what you don't get from the text, you'll get from the pictures.
You say that, but I've studied German for around four years as well and I still totally misinterpret one in every four or five sentences, and my grammar's atrocious. So bad that I didn't dare try and write that last sentence in German 'cause it'd probably have been unreadable. ;-)
Server error: user 'Jake' not found

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Automatic Scaling

#18 Post by PyTom »

Haven't had a chance to look into the preferences thing yet, but there's one thing you should know about the mode picking code. Right now, you're just picking the first mode you can get. On my computer, that's an xinerama mode... it's something like 2560x1024, split across 2 screens.

You should probably sanity check the screens, making sure they have an aspect ration of between 2 and 1.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Florian

Re: Automatic Scaling

#19 Post by Florian »

@PyTom: There is already a little - though not perfect - sanity check in place. Most xinerama modes produce higher resolutions than 1920*x, so the scaling factor locks back to 1. I must admit, there is room for improvement, though. :) I'll try to implement an ratio check.

But there is a more important question that strikes me: Which resolution does the game choose for the fullscreen mode? I just noticed that although the scaling works fine on my laptop monitor, it tries to change to a higher resolution (probably full HD) when I'm using my CRT monitor instead... which does produce an image, but my CRT doesn't handle that resolution very well.

Is my assumption correct, that it tries to set the resolution to config.screen_width/height, if this mode is available?

Is there any way to detect the current desktop resolution? (erm... which kinda leads back to my first question in this thread*g*)


Anyway, many many many thanks for your great support! :)

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Automatic Scaling

#20 Post by PyTom »

Florian wrote:@PyTom: There is already a little - though not perfect - sanity check in place. Most xinerama modes produce higher resolutions than 1920*x, so the scaling factor locks back to 1. I must admit, there is room for improvement, though. :) I'll try to implement an ratio check.
Yeah, but even at 1.0, it will still be bigger then any single screen. That's a problem. (You also probably want to check the y-height as well, to be sure you fit on the screen that way.)
But there is a more important question that strikes me: Which resolution does the game choose for the fullscreen mode? I just noticed that although the scaling works fine on my laptop monitor, it tries to change to a higher resolution (probably full HD) when I'm using my CRT monitor instead... which does produce an image, but my CRT doesn't handle that resolution very well.
Hm... Basically, the scaling code will ask pygame for (screen_width * factor, screen_height * factor). Pygame will then pick the first mode it can find that's bigger (or equal to) what's asked for.
Is there any way to detect the current desktop resolution? (erm... which kinda leads back to my first question in this thread*g*)
I don't know of a portable way to do this, sorry.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Florian

Re: Automatic Scaling

#21 Post by Florian »

This is getting more tricky than I though... :)

That's what I'm doing now (with screen_width/height set to 1920x1080):

Code: Select all

# get a list of display modes, sorted by resolution
import pygame
pygame.display.init()
modes = pygame.display.list_modes()

# find the appropriate scaling factor, 1 being the default
factor = 1 #default
for i in range(len(modes)):
  aspect_ratio = modes[i][0] / modes[i][1]
  # if the aspect ratio is somewhat reasonable set the scale factor to
  # scale to this resolution => the highest resolution should be chosen
  if 1.3 < aspect_ratio < 1.8: 
    factor = modes[0][0] / 1920.0
    break

if 'RENPY_SCALE_FACTOR' in os.environ:
    factor = float(os.environ['RENPY_SCALE_FACTOR'])
I left the last bit (if 'RENPY_SCALE[...]) in, because I don't really know what it does. Should I let it be, or should I better remove it, or should I modify it somehow?
PyTom wrote:(You also probably want to check the y-height as well, to be sure you fit on the screen that way.)
We have 16:9 pictures, so as long as the aspect ratio isn't higher than 1.8, it should always fit on the screen, shouldn't it?
Is there any way to detect the current desktop resolution? (erm... which kinda leads back to my first question in this thread*g*)
I don't know of a portable way to do this, sorry.
Do you know a non-portable way?

The problem seems to be that there are some modes available, that just don't make sense (like 1920x1200 on a 4:3 CRT). And at the moment I don't see a way to distinguish these from the sane modes.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Automatic Scaling

#22 Post by PyTom »

Florian wrote:Do you know a non-portable way?

The problem seems to be that there are some modes available, that just don't make sense (like 1920x1200 on a 4:3 CRT). And at the moment I don't see a way to distinguish these from the sane modes.
Unfortunately, no. I just give pygame a video mode, and let it do the work. I haven't dealt much with querying the mode.

(Well, I know how to do it on Linux, but that doesn't count.)
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Guest

Re: Automatic Scaling

#23 Post by Guest »

PyTom wrote:(Well, I know how to do it on Linux, but that doesn't count.)
If I get my win32api based approach to work, this would already be two platforms. :)

Is it possible to include win32api hassle-free, or is it complicated? Can I just copy a dll in the right directory and it works?


If this is not possible, I think we need a kind of "save-mode". Is it possible to change the resolution at runtime? We could then offer the user the option to change the resolution if it looks awkward.

Another alternative would be to give renpy a command-line option (sys.argv, right?) which triggers a resolution. We could then make one or more save-mode-shortcuts which delivers these options.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Automatic Scaling

#24 Post by PyTom »

You should be able to just drop the win32api files into the directory with the Ren'Py exe file, and I _think_ they will be picked up by default.

There isn't support for changing the resolution at runtime, sorry. I didn't see a need to add it in.

Hm... there isn't a way to give command line arguments to the game proper. I'm planning a 6.3.1b release anyway, so I'll add that.

Perhaps the best way to do this would be to offer the user several executable files (or shortcuts), each giving a different resolution, and then he can run the one he wants.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Florian

Re: Automatic Scaling

#25 Post by Florian »

I managed to add the module. Dropping the right file into the renpy directory did indeed work. (finding the right file was a lot more difficult for someone unfamiliar with python, though... *g*)

So far for the good news. The bad news: The scaling still doesn't work. Even if I choose a smaller scaling factor, the fullscreen mode switches to the large resolution... and displays a downscaled game surrounded by black.

So I went back to my original approach: Dynamically setting the game size and scaling the images. After some more annoying problems (my system is really good in providing awkward display modes... *sigh*), it finally seems to work with only one problem left:

I'm now displaying a 1280x720 image in the center of a 1280x1024 screen (I need to keep the original aspect ratio of the screen, or renpy will choose a bad fullscreen mode). The text is displayed below the image in the blackness. The problem is, that the text leaves gray traces behind when it changes. Every letter kinda burns into the background.

Do you know what might causing this? And more important: How do I fix this?

For everyone who's interested, here my current size-calculation-function:

Code: Select all

      # get_target_resolution(source_x, source_y)
      #   Function for retrieving scaling data for the images.
      #
      # Parameters:
      #   - horizontal size of the source images
      #   - vertical size of the source images
      # 
      # Returns:
      #   - horizontal resolution
      #   - vertical resolution
      #   - scale factor
      #   - aspect ratio of the original system resolution
      #       if the system resolution cannot be found, the ratio of the source
      #       image is used
      def get_target_resolution(source_x, source_y):
      
      
          # default return values (change nothing)
          factor = 1
          target_x = source_x
          target_y = source_y
          screen_factor = float(source_x) / float(source_y)
          
          source_factor = float(source_x) / float(source_y)
          
          # get a list of display modes, sorted by resolution
          import pygame
          pygame.display.init()
          modes = pygame.display.list_modes()
          
          # find the appropriate scaling factor, 1 being the default
          factor = 1 #default
          for i in range(len(modes)):
            aspect_ratio = modes[i][0] / modes[i][1]
            # if the aspect ratio is somewhat reasonable (not some multi-screen setup which
            # *should* be recognizable by unusal aspect ratios) set the scale factor to
            # scale to this resolution => the highest resolution should be chosen
            if 1.25 <= aspect_ratio < 1.8: 
              factor = modes[0][0] / float(source_x)
              target_x = modes[0][0]
              target_y = int(float(target_x) / source_factor)
              break
          
          # the "optimal resolution" that we found above can be awkward on
          # some systems (ie: mine). If we can query the current system resolution
          # try to use that one instead - if it seems reasonable.
          import os
          if os.name == 'nt':
            from win32api import GetSystemMetrics
            if 1.25 <= (float(GetSystemMetrics(0)) / float(GetSystemMetrics(1))) < 1.8:
              factor = float(GetSystemMetrics(0)) / float(source_x)
              target_x = GetSystemMetrics(0)
              target_y = int(float(GetSystemMetrics(0)) / source_factor)
              screen_factor = float(GetSystemMetrics(0)) / float(GetSystemMetrics(1))
              
          return target_x, target_y, factor, screen_factor
If you tell me the way to query the system resolution on linux, I can add that too... but I have no way of testing it.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Automatic Scaling

#26 Post by PyTom »

Florian wrote:The text is displayed below the image in the blackness. The problem is, that the text leaves gray traces behind when it changes. Every letter kinda burns into the background.
Basically, that's because the black is really transparent. You need to put something opaque there, underneath the text, to replace what's already there.
If you tell me the way to query the system resolution on linux, I can add that too... but I have no way of testing it.
Hm... the only way I know is parsing the output of the xrandr command, which looks like:

Code: Select all

 SZ:    Pixels          Physical       Refresh
*0   2560 x 1024   ( 747mm x 270mm )  *50  
 1   1024 x 768    ( 298mm x 203mm )   51  
 2    800 x 600    ( 233mm x 158mm )   52  
 3    640 x 480    ( 186mm x 127mm )   53  
Current rotation - normal
Current reflection - none
Rotations possible - normal 
Reflections possible - none
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Florian

Re: Automatic Scaling

#27 Post by Florian »

Hello again ^_^

I'm sorry, but I think we currently can't write the code for parsing the xrand output. My knowledge of Python is still limited especially in combination with Linux.

Maybe someone else will some day stumble upon this thread while creating a scalable visual novel and add the linux-only or even mac-parts.

Till then, I hope the default scaling will work all right on these systems.

Thanks for all your support!

Greetings,
Florian

P.S.: Fortunately, with the new way of scaling, the thumbnail-problem, which Dennis mentioned earlier, vanished. We now have thumbnails which adjust themselves to the screen size. :)

Criptych
Regular
Posts: 87
Joined: Sat Jun 23, 2007 9:19 am
Projects: ALICE.NET
Location: The other end of the internet.
Contact:

Re: Automatic Scaling

#28 Post by Criptych »

Florian wrote:I'm sorry, but I think we currently can't write the code for parsing the xrand output. My knowledge of Python is still limited especially in combination with Linux.
I'm not sure how you'd acquire the output-- I'm still settling into Python too-- but I think I can help you with parsing.

Code: Select all

# this should all be in a "python:" block or a .py file (Ren'Py supports that, right?)

import re # if you haven't already

def get_linux_video_modes():
    """
    Queries supported video modes and returns a list of 2-tuples (resx, resy).
    """
    modes = []
    while <more lines to read>:
        <get "line" from output>
        m = re.match(r'\*?[0-9]+ +([0-9]+) x ([0-9]+) +\([^)]+\) +\*?([0-9]+)', line)
        if m is not None: # found a mode string, add it to the list
            modes.append( ( int(m.group(1)), int(m.group(2)) ) )
    return modes
"Help," mind you. I make no guarantees.
Computers are useless. They can only give you answers. —Pablo Picasso

Image

Florian

Re: Automatic Scaling

#29 Post by Florian »

For the case that anyone else wants to do create an automatically scaling visual novel, I wrote a "few" summarizing instructions:

» Automatic Scaling in Ren'Py

I hope it helps someone... :)

If anyone extends this, just drop me a comment and I'll update the article.

Dennis
Newbie
Posts: 11
Joined: Sun Jul 08, 2007 4:37 pm
Location: Esslingen, Germany
Contact:

Re: Automatic Scaling

#30 Post by Dennis »

Just a note, for people who are interested in our VN, but haven't stumbled over the corresponding thread somewhere else.

Felix, Gaijin is released now and can be found at

http://www.kreativrauschen.de/felix/

and

http://www.serik.de/felix

and also one day at my German-language visual novel blog

http://www.storyautor.de/vn-blog
Jake wrote:
Dennis wrote: @DaFool: 4 years are fine. Since it's a VN, what you don't get from the text, you'll get from the pictures.
You say that, but I've studied German for around four years as well and I still totally misinterpret one in every four or five sentences, and my grammar's atrocious. So bad that I didn't dare try and write that last sentence in German 'cause it'd probably have been unreadable. ;-)
Since you don't have to write anything and will still get the story by understanding "only" 4 out of 5 sentences, you'll be fine :)

Post Reply

Who is online

Users browsing this forum: No registered users