Getting the display width/height BEFORE import DirectStart

base.pipe.getDisplayWidth()
base.pipe.getDisplayHeight()

Is there a way to use this before importing DirectStart (opening the window)? I want to use this code so I can set my game to fullscreen at the users resolution.

I can acomplish this on Windows using pyWin and the folowing code:

from win32api import GetSystemMetrics

width = GetSystemMetrics(0)
height = GetSystemMetrics(1)

print width+' '+height

but I want to make it cross platform and not Windows Only.

Here’s roughly what I’m doing:

from pandac.PandaModules import loadPrcFileData, WindowProperties
loadPrcFileData("", "window-type none")
from direct.showbase.ShowBase import ShowBase

ShowBase()
base.makeDefaultPipe()
wprops = WindowProperties.getDefault()

# Now set 'props' with whatever properties you want.
# At this point you can use base.pipe.getDisplayInformation()
# and base.pipe.getDisplayWidth/Height() if you need.

base.openDefaultWindow(props = wrops)

nice trick, but the

from direct.showbase.ShowBase import ShowBase
ShowBase()

may be confusing for newbies. it’s actually exactly the same as

from direct.directbase.DirectStart

:wink:

Thanks, but when I try to use that method I get this:

Traceback (most recent call last):
  File "main.py", line 1, in <module>
    from pandac.Config import *                     # Import Configuration file
  File "C:\Panda3D-1.6.2\pandac\Config.py", line 6, in <module>
    base.makeDefaultPipe() 
  File "C:\Panda3D-1.6.2\direct\showbase\ShowBase.py", line 460, in makeDefaultPipe
    assert self.pipe == None
AssertionError

I’m using a custom Config.py file to simplify some things:

from pandac.PandaModules import *
from win32api import GetSystemMetrics
from direct.showbase.ShowBase import ShowBase

ShowBase() 
base.makeDefaultPipe() 
wprops = WindowProperties.getDefault() 

screenWidth = base.pipe.getDisplayWidth()
screenHeight = base.pipe.getDisplayHeight()

class Mouse():
    def removeCursor(self):
        props = WindowProperties() 
        props.setCursorHidden(True) 
        base.win.requestProperties(props) 
    
    def showCursor(self):
        props = WindowProperties()
        props.setCursorHidden(False)
        base.win.requestProperties(props)

    
class Window():
    def makeFullscreen(self, width, height):
        loadPrcFileData('','win-size '+str(width)+' '+str(height))
        loadPrcFileData('','fullscreen 1')
    
    def setTitle(self, title):
        loadPrcFileData('','window-title '+title)
        
    def setSize(self, width, height):
        loadPrcFileData('','win-size '+str(width)+' '+str(height))
        
    def setPos(self, widthPos, heightPos):
        loadPrcFileData('','win-origin '+str(widthPos)+' '+str(heightPos))
        
window = Window()
mouse = Mouse()

I know the code is kinda sloppy :slight_smile:

Looks like there already was a pipe when you tried to open one. Maybe you didn’t specify “win-type none” correctly, or maybe that code is called twice, accidentally?

No, I did it on purpose, to avoid inline imports and keep them at module-level, since you’ll want to put the part that starts with “ShowBase()” in a function or class… There’s a reason why it’s possible this way, too.

Secondly, this is rather less confusing, I think. Importing a class and instancing it is IMO less confusing than a magic import line that does who-knows-what.

agree with pro_r - that Directstart is not quite a pythonic way to go
I guess I start to use the other way, unless somebody’ll find a strong reason to use the former one

Pro_rsoft, I put the code you suggested into a file without anything to interfere with it and it works but it seems like the loadPrcFileData() lines I added aren’t taking effect before the window opens

from pandac.PandaModules import loadPrcFileData, WindowProperties 
loadPrcFileData("", "window-type none") 
from direct.showbase.ShowBase import ShowBase 

ShowBase()
base.makeDefaultPipe() 
wprops = WindowProperties.getDefault() 

width = base.pipe.getDisplayWidth()
height = base.pipe.getDisplayHeight()

loadPrcFileData("","fullscreen 1")
loadPrcFileData("","win-size "+str(width)+" "+str(height))

base.openDefaultWindow(props = wprops)

run()

The window just opens at the default size

You forgot the ShowBase() call to open the window and initialize “base”. But the fact that it didn’t error there means the window got already opened way before this code happened.

Before this file is loaded/imported, are you sure there is no other file importing DirectStart or opening a window?

Yeah I realized Just as you posted that ShowBase() wasn’t in the copied code. It somehow got removed when I copied from PyPE.

I’m pretty sure there’s no files importing DirectStart. The code I posted is all that’s in the file.

I might just have to have the window open then switch it to fullscreen using one of the methods on the forums.

Well, there must be something that’s opening the window before that code executes, otherwise it would’ve worked.

From the ShowBase() class:

        # Open the default rendering window.
        if self.windowType != 'none':
            props = WindowProperties.getDefault()
            if (self.config.GetBool('read-raw-mice', 0)):
                props.setRawMice(1)
            self.openDefaultWindow(startDirect = False, props=props)

This code might be executing, but the win-type is set to none in my file :confused:

I tried putting your code from a few posts above in a python file, I ran it, and it worked for me.

Hmm. It might be some conflict with Windows Vista then. I get that issue a lot :frowning:

If only my new rig was ready.

Well, I’d strongly doubt it. I’d check and retrace your imports again, or debug it by uncommenting your import lines, it’s probably something silly.

I tossed around some print functions and everything is working right

PandaModules Imported
Window Type set to none
ShowBase Imported
ShowBase() Initialized
Known pipe types:
  wglGraphicsPipe
(all display modules loaded.)
Default Pipe Created
wprops Defined
Got the width and height of the screen
Set to fullscreen
Resolution set to: 1440x900
:display:gsg:glgsg(warning): Buffers advertised as supported by OpenGL runtime, but could not get pointers to extension functions.
:display:gsg:glgsg(warning): Occlusion queries advertised as supported by OpenGL runtime, but could not get pointers to extension functions.
Main window opened

It doesn’t look like anything is opening the window beforehand.