Changing resolution while in game

Hi guys.

This is very simple question, I just want to be sure that I’m doing this right. I’m working on my menu right now and I want to offer an option to change resolution while in game. Here is the code I’m going to use:

def setResolution(self):
    wp = WindowProperties()
    wp.setSize(1024, 768) # there will be more resolutions
    wp.setFullscreen(True)
    base.win.requestProperties(wp)

When I run it, I see the change, but is this the right way to do this? Will it work on Windows? What about Mac?

Yes, that is the correct and recommended way to do it. As of 1.7.0, this should work fine on both Windows and Unix/X11, I don’t know about Mac OSX.
Note that you will also need to switch the origin and size back when you switch back from fullscreen.

Note that through the DisplayInformation interface (available through base.pipe.getDisplayInformation()) you can easily query a list of supported resolutions on the system.

With 1.7 it will work on Windows and on Linux. I don’t think anybody implemented runtime full-screen switching for Mac yet. However, that is the correct way to do it and someday it will work in Mac too with that method.

Thank you for answers. I forgot to mention that I ran this function in full screen mode, but I suppose it doesn’t matter?

I think I have found a bug. Take a look at this code:

from pandac.PandaModules import *

loadPrcFileData('', 'fullscreen 1')
loadPrcFileData('', 'win-size 1680 1050')

import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from direct.gui.DirectGui import *
import sys

class World(DirectObject):
  def __init__(self):
    self.accept("r", self.setResolution)
    self.initMenu()

  def initMenu(self):
    self.NewButton = DirectButton(frameColor = (0, 0, 0, 0), parent = base.aspect2d, text = ("Testing"), scale = 0.08, command = sys.exit)
    self.NewButton.setPos(base.a2dLeft + 0.3, 0, base.a2dTop - 0.3)

  def setResolution(self):
    wp = WindowProperties()
    wp.setSize(800, 600)
    wp.setFullscreen(True)
    base.win.requestProperties(wp)
    self.NewButton.destroy()
    self.initMenu()

World = World()
run()

It shows a button in top-left corner and tries to keep it in the same place even if you change resolution with a “R” key. It works fine in Windows XP SP3, I have tried various resolutions and Nvidia’s settings (Stretched, Aspect Ratio Scaled, Centered). But I have some problems with it in Kubuntu Linux 64-bit with latest stable Nvidia’s drivers. If I set starting resolution to 1024x768 and then change it (while in game) to 800x600, everything is okay, just like in Windows. However, if I set my starting resolution to 1680x1050 and then change it to (while in game) 800x600, my button won’t appear in the right place, it is barely visible, almost out of sight.

I think it has something to do with aspect ratio, since with 4:3 resolutions it works fine, but I haven’t tried all of them, yet. Is it a bug in Linux Nvidia’s drivers, Panda3D or my code?

Any Linux-Widescreen-Nvidia users here? If yes, when test my example and tell me if you have same problem, please. Panda3D pros, what do you think?

P.S. Maybe it has nothing to do with Nvidia, I cannot test it with other graphic cards, so I don’t know.

Some images:

1680x1050:

800x600:

Bump :unamused:

Try to parent it to any of base.a2dTopCenter, a2dBottomCenter, a2dLeftCenter, a2dRightCenter, a2dTopLeft, a2dTopRight, a2dBottomLeft, a2dBottomRight.

And you might want to use this :
discourse.panda3d.org/viewtopic.php?t=8518

Thanks, ynjh_jo. I have tried your example and it works fine.

I will post about my findings in 1.7.0 bugs thread.

I’m getting some problems on this issue: I can’t get this code working both on Windows and Linux. Consider this application:

import direct.directbase.DirectStart
from panda3d.core import WindowProperties
from direct.showbase.DirectObject import DirectObject
from direct.gui.OnscreenText import OnscreenText

class World( DirectObject ):

  def __init__( self ):
    self.accept( 'mouse1', self.setResolution, extraArgs = [ 1920, 1080 ] )
    OnscreenText( text = 'check resolution aid', scale = .05 )
    self.setResolution( 640, 480 )

  def setResolution( self, w, h ):
    wp = WindowProperties()
    wp.setSize( w, h )
    wp.setFullscreen( True )
    base.win.requestProperties( wp ) 
    
w = World()
run()

If I run it on Windows, it behaves correctly (clicking the left mouse button I can switch the resolution), but on Linux (Ubuntu 10.04, Panda 1.7.0) the Panda’s windows disappears and I see my desktop, magnified. Is my code wrong in some parts? Thanks!

This works on Windows/OSX/Linux (I hope this is the correct approach):

  def setResolution( self, w, h ):
    wp = WindowProperties()
    wp.setSize( w, h )
    wp.setFullscreen( True )
    import os
    if os.name == 'posix':
      base.openMainWindow()
      base.graphicsEngine.openWindows()
    base.win.requestProperties( wp )