3 questions regarding fullscreen

greetings y’all, i’m new to Panda3D and Python in general, so i’ve been experimenting with the two, but now i have 3 things i want to figure out:

  1. how can i get panda to use the native resolution when switching to fullscreen? i’ve found some threads but i think they used a function that doesn’t work on Windows

  2. how can i toggle fullscreen during runtime?

from direct.showbase.ShowBase import ShowBase as Panda
from panda3d.core import loadPrcFile, WindowProperties

loadPrcFile('config.prc')

engine = Panda()

is_fullscreen = False

properties = WindowProperties()

def set_fullscreen():
    global is_fullscreen
    global properties
    is_fullscreen = not is_fullscreen

    if is_fullscreen:
      properties.setFullscreen(1)
      print("Fullscreen")

    if not is_fullscreen: 
      properties.setFullscreen(0)
      print("Not fullscreen")

engine.accept("alt-enter", set_fullscreen)
engine.run()

^^ i’ve tried using this but doesn’t seem to work

  1. is it possible to get fullscreen to render at the desired window size but upscaled to the native resolution?

any help would be appreciated!

Maybe this can help you. I show you a simple example.

Here are some links that may be useful to you.

https://docs.panda3d.org/1.10/python/reference/panda3d.core.GraphicsWindow
https://docs.panda3d.org/1.10/python/reference/panda3d.core.WindowProperties

Example

import direct.directbase.DirectStart
from direct.showbase.ShowBase import ShowBase
from panda3d.core import loadPrcFile, WindowProperties

wp = WindowProperties()
ScreenWidth = 1280
ScreenHeight = 720
wp.setSize(ScreenWidth,ScreenHeight)
base.win.requestProperties(wp)

def change():
    if not base.win.isFullscreen():
        wp.setSize(ScreenWidth,ScreenHeight)
        wp.setFullscreen(True)
    else:
        wp.setFullscreen(False)
        wp.setSize(ScreenWidth,ScreenHeight)
        screenx = int(base.pipe.getDisplayWidth()/2) - int(ScreenWidth/2)
        screeny = int(base.pipe.getDisplayHeight()/2) - int(ScreenHeight/2)
        wp.setOrigin(screenx,screeny)
    base.win.requestProperties(wp)
    
base.accept("alt-enter", change)
base.run()

Regards!

seems to work fine, thanks, but doesn’t answer my other two questions

Regarding the change in real time, I think you have already been answered.

from direct.showbase.ShowBase import ShowBase
from panda3d.core import WindowProperties

class MyApp(ShowBase):

    def __init__(self):
        ShowBase.__init__(self)

        base.accept("f", self.fullscreen)

    def fullscreen(self):
        wp = WindowProperties()
        wp.set_fullscreen(True)
        base.win.request_properties(wp)

app = MyApp()
app.run()

As for the size of the desired resolution of the game with fullscreen, I guess it does not depend on the panda, but depends on the hardware of your computer.

Add:

However, panda is a flexible engine, in theory you can render to a hidden buffer in any resolution and scale it yourself, taking into account the size of the window.

thanks for the response i did eventually find the answers to questions 1 and 2 but the third one wasn’t a necessity, just wondering if that was possible

To keep the desktop resolution, and not change to another resolution, you need to pass base.pipe.getDisplayWidth(), base.pipe.getDisplayHeight() as the size parameter. Panda will recognize these values and not switch resolutions when they are used.

yeah, i figured this out, problem being that you can’t enter fullscreen when the window is maximized, getting the error:

:display:windisplay(error): Videocard has no supported display resolutions at specified res (1920 x 991 x 32)
:display:windisplay(warning): Switching to fullscreen mode failed!

The problem is that you should only use the screen resolution that the video card supports.

from direct.showbase.ShowBase import ShowBase
import pprint

class MyApp(ShowBase):

    def __init__(self):
        ShowBase.__init__(self)

        display_modes = {}

        pipe = base.pipe.get_display_information()

        for i in range(pipe.get_total_display_modes()):
            width  = pipe.get_display_mode_width(i)
            height = pipe.get_display_mode_height(i)
            rate = pipe.get_display_mode_refresh_rate(i)

            if not (width, height) in display_modes:
                display_modes[(width, height)] = [rate]
            else:
                display_modes[(width, height)].append(rate)

        pp = pprint.PrettyPrinter()
        pp.pprint(display_modes)

app = MyApp()
app.run()

Result {(resolution): [frequency]}

{(640, 480): [59, 60, 67, 72, 75],
 (720, 400): [59, 60, 59, 60, 59, 60, 70],
 (720, 480): [59, 60],
 (720, 576): [50, 56, 60, 72, 75],
 (800, 480): [56, 60, 72, 75],
 (800, 600): [56, 60, 72, 75],
 (832, 624): [59, 60, 59, 60, 59, 60, 75],
 (1024, 600): [60, 70, 75],
 (1024, 768): [60, 70, 75],
 (1152, 864): [59, 60, 59, 60, 59, 60, 75],
 (1280, 720): [50, 59, 60],
 (1280, 768): [60],
 (1280, 960): [60],
 (1280, 1024): [60, 75],
 (1360, 768): [60],
 (1366, 768): [60],
 (1400, 1050): [60],
 (1440, 900): [60],
 (1600, 900): [60],
 (1680, 1050): [60],
 (1920, 1080): [50, 59, 60]}

thing is tho, this only happens when the window is maximized, when just windowed it works fine

and i didn’t specify a specific resolution to use, i used base.pipe.getDisplayWidth(), base.pipe.getDisplayHeight() to get the native resolution

maybe there is a way to restore the window first before going into fullscreen?

Now I see, it looks quite strange.

It seems that when the window is expanded, the size of the header is not taken into account.
Two steps are required.

from direct.showbase.ShowBase import ShowBase
from panda3d.core import WindowProperties

class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        base.accept("f", self.fullscreen)     
        base.accept("g", self.gfullscreen)

    def fullscreen(self):
        wp = WindowProperties()
        wp.undecorated = True
        base.win.request_properties(wp)

    def gfullscreen(self):
        wp = WindowProperties()
        wp.fullscreen = True
        wp.size = (base.pipe.get_display_width(), base.pipe.get_display_height())
        base.win.request_properties(wp)

app = MyApp()
app.run()

You need to get rid of the decorated window, and then turn on fullscreen mode.

There is obviously a bug here. But it can be circumvented by such a hack.

from direct.showbase.ShowBase import ShowBase
from panda3d.core import WindowProperties

class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        base.accept("f", self.fullscreen)

    def fullscreen(self):
        wp = WindowProperties()
        wp.undecorated = True
        base.win.request_properties(wp)

        base.graphicsEngine.render_frame()

        wp.fullscreen = True
        wp.size = (base.pipe.get_display_width(), base.pipe.get_display_height())
        base.win.request_properties(wp)

app = MyApp()
app.run()

ah, i was wondering how you force panda to render a frame, thanks!

If you think you have found a bug, then please file it on the issue tracker!

1 Like