Full screen and screen size

I’ve searched the forums and the manual, but I couldn’t find how to do the following in C++:

  1. Set full screen mode (assuming such a thing exists)

  2. Get the screen dimenisons (position, length, and width)

Same way you do it in Python. Either set:

fullscreen 1

in your Config.prc file, or when you create your window at runtime, call set_fullscreen(true) on the WindowProperties structure you pass to create the window.

To query the existing window’s size, query window->get_properties() for the WindowProperties structure. You can query get_size() and get_origin() on this. If you’re asking about the desktop size, you can get this from the GraphicsPipe.

David

Thanks. That looks like what I need. I didn’t know to look at the configuration stuff, but now I do!

Follow-up question:

Is there a way to restrict the mouse to the game window, or at least to the display that the game is fullscreened in? I have two displays, and when I go full screen, the mouse can wander into another display.

I know I can get it working by hiding the real cursor (well, I’m assuming that’s not a problem), locking it to the center of the screen, and then putting up a fake cursor, based on its movements, but I’m hoping there’s an easier solution.

Is there?

In general, no. In fact, certain operating systems (e.g. Mac OSX) explicitly disallow this kind of behavior; Apple considers it a violation of contract for an application to try to take control of the mouse like that–it makes it hard for a user to interact with other applications.

Do you have any other fullscreen applications that lock the mouse to their window? Seems a little unusual to me.

David

You mean locking the mouse to the center, measuring the distance it moves, and re-centering it? I’d always assumed that’s how games like FPS’s operated. Otherwise, you couldn’t turn all the way around. The mouse would eventually hit the right border of the screen, or it would stray into another display.

What do you suggest, instead?

Oh, sure. You can do that, but only if you set WindowProperties::set_cursor_hidden(true) and WindowProperties::set_mouse_mode(WindowProperties::M_relative). This will hide the mouse and allow you to reset it to the center of the window each frame, and this is legal behavior on any operating system, including Apple, because it’s a special mode in which the mouse pointer is hidden, so the user is supposed to understand that he shouldn’t be able to take the mouse pointer to the other desktop.

But you’d said you didn’t want to hide the mouse pointer. :slight_smile:

David

How involved would it be to toggle fullscreen/windowed (say it is an in-game config window or hotkey activated eg: ALT+ENTER) without requiring a game restart?

From what I can tell using the config file method requires restarting the game.

You can currently do that like this:

wp = WindowProperties()
wp.setFullscreen(True)
base.win.requestProperties(wp)
from panda3d.core import WindowProperties,GraphicsPipe
gp=GraphicsPipe
deskSize=(gp.getDisplayWidth(),gp.getDisplayHeight())
print deskSize

(I also noticed gp=GraphicsPipe() complains about trying to instance a constant class so it is not done like wp=WindowProperties() is done)

This code to get the desktop size complains:
TypeError: descriptor ‘getDisplayWidth’ of ‘libpanda.GraphicsPipe’ object needs an argument

From reference/1.8.1/python/classpanda3d.core.GraphicsPipe.php:
"int getDisplayHeight ()
Returns the height of the entire display, if it is known. "
“int getDisplayWidth ()
Returns the width of the entire display, if it is known.”

These should not need arguments?

Use this:

gp = base.win.getPipe()

Thanks.
Incredibly helpful since the documentation for much of ShowBase’s members are empty.