I'm currently working on a game engine written in pygame and I wanted to add OpenGL support.
I wrote a test to see how to make pygame and OpenGL work together, and when it's running in windowed mode, it runs between 150 and 200 fps. When I run it full screen (all I did was add the FULLSCREEN flag when I set up the window), it drops down to 60 fps. I added a lot more drawing functions to see if it was just a huge performance drop, but it always ran at 60 fps.
Is there something extra I need to do to tell OpenGL that it's running fullscreen or is this a limitation of OpenGL?
(I am running in Windows XP)
As frou pointed out, this would be due to Pygame waiting for the vertical retrace when you update the screen by calling display.flip(). As the Pygame display documentation notes, if you set the display mode using the HWSURFACE or the DOUBLEBUF flags, display.flip() will wait for the vertical retrace before swapping buffers.
To be honest, I don't see any good reason (aside from benchmarking) to try to achieve a frame rate that's faster than the screen's refresh rate. You (and the people playing your game) won't be able to notice any difference in speed or performance, since the display can only draw 60 fps anyways. Plus, if you don't sync with the vertical retrace, there's a good chance that you'll get screen tearing.
Is this a V-Sync issue? Something about the config or your environment may be limiting maximum frame rate to your monitor's refresh rate.
If you are not changing your clock.tick() when you change between full screen and windowed mode this is almost certainly a vsync issue. If you are on an LCD then it's 100% certain.
Unfortunately v-sync can be handled in many places including SDL, Pyopengl, your display server and your video drivers. If you are using windows you can adjust the vsync toggle in the nvidia control panel to test, and there's more than likely something in nvidia-settings for linux as well. I'd guess other manufacturers drivers have similar settings but that's a guess.
Related
Recently, I’ve been using pygame and found out when I create a window using pygame.display.set_mode((0, 0), pygame.FULLSCREEN), it's shown in the wrong resolution. I have a 2560 × 1600 monitor, but the window is at 1440 × 900 (It's still fullscreen, but the image quality has been reduced).
It's been shown in the docs for pygame.display, I believe that the problem is caused by stretching:
Some display environments have an option for automatically stretching all windows. When this option is enabled, this automatic stretching distorts the appearance of the pygame window. In the pygame examples directory, there is example code (prevent_display_stretching.py) which shows how to disable this automatic stretching of the pygame display on Microsoft Windows (Vista or newer required).
and this answer to a similar question, shown that in windows the problem can be solved using the code below:
ctypes.windll.user32.SetProcessDPIAware()
true_res = (windll.user32.GetSystemMetrics(0),windll.user32.GetSystemMetrics(1))
screen = pygame.display.set_mode(true_res,pygame.Fullscreen)
Sadly, I don't know how to do a similar job in macOS.
I've been able to work this problem out in the fullscreen mode using the code below:
screen = pygame.display.set_mode((2560, 1600), pygame.FULLSCREEN | pygame.SCALE)
Still don't know how to solve this under other circumstances, so I remain the question open.
you can maybe ask the user what his resolution is from a drop-down menu and save that variable in a text file then set the screen width and height to the contexts of that text file
Came across a problem which google searches could not help me with. I have a little SDL application that runs at 60 fps. Everything is working fine, however, it pauses/stops running when the window is dragged ( 640 X 480 window ). Is there a flag or something that can be set in the SDL window to prevent this from happening? Or is this unavoidable?
Windows uses a modal event loop for dragging windows, which blocks your main UI thread.
More discussion (and suggested workarounds, such as drawing from a second thread): http://www.sfml-dev.org/forum/viewtopic.php?p=8384&sid=632116a07a569edee43331076e028071
OpenTk apparently has code designed to address this, maybe you can reuse some of it: http://www.opentk.com/node/1218
Sorry right off the bat, my English is bad. I use google translate.
Faced such a problem:
On my laptop, the interface scale is 125%. The maximum resolution of the monitor is 1920x1080, and I work with it.
While creating the Pyglet application window, with a resolution of 1280x720, I noticed that the window is clearly larger than what I expected. Having changed the resolution to the maximum one available to me - 1920x1080, using the second monitor, I realized that it is clearly larger than the main monitor.
For a long time and painfully, I figured out the cause of the problem, but found it out. When I set the interface scaling to 100%, instead of 125% that was comfortable for me, everything fell into place. The windows began to work as intended.
But this is not the way to solve the problem. Therefore, I have come to you with a question. How do I ignore the zoomed-in laptop interface in my application? Also, an alternative solution could be to change the scale of the interface while the application is running, and with this I would also like to contact you. Can someone suggest how to implement one of the solutions?
I should have guessed that the same problem could be with Pygame.
Solution:
import ctypes
ctypes.windll.user32.SetProcessDPIAware()
https://gamedev.stackexchange.com/questions/105750/pygame-fullsreen-display-issue
My goal is to take screenshots off an application while the laptop screen is off, but instead the screenshot will always be the same as just before turning off the screen. It does not redraw itself once the screen is off, and remains frozen.
I'm obtaining a screenshot using printwindow from Python (using method described here: Python Screenshot of inactive window PrintWindow + win32gui
This method works nicely as long as I have my laptop screen on, but if I turn it off, it simply returns the last image before the screen turned off. I've tried using win32gui.RedrawWindow, hoping that this would force a redraw, but I haven't gotten it to work, even trying all the different flags. I've also tried getting screenshots via pyautogui, but this also has the same problem. Is there any way to redraw the application while the laptop screen is off?
It would be nice if there were a straightforward way to do what you want to do, but unfortunately it's just not possible without some convoluted low-level work.
In the underlying WinAPI, native windows redraw themselves only when they receive WM_PAINT messages, and they only receive WM_PAINT messages if they are visible. They don't get the messages if they're behind another window, or if they're dragged off screen, or minimized, or their visibility is set to False. They also aren't visible when the screen is off. Since they aren't visible, they simply never get told to redraw themselves. That's why the screen capture image doesn't change after the screen is turned off.
There is no command you can issue that will override this -- it is implemented as a fundamental part of the windowing paradigm.
One solution is to have the application paint itself in something that's not a window (e.g., a dialog box) and capture that rather than capturing the screen. You could also modify the application by overriding OnPaint and using a timer to invalidate and call your OnPaint function periodically (since WM_PAINT messages won't be received).
If it were me I'd override OnPaint, make my application draw itself to a background context bitmap rather than the normal window, then use a timer to invalidate and redraw periodically and just take the bitmap of the background context whenever I wanted to capture the output.
If you don't own the code for the applications that are running, you may still be able to get applications to redraw themselves by running everything in a virtual machine. I've done that successfully for headless computing in the past, but it was many OS versions ago and things may be different now, so YMMV...
Information on manual screenshots under VMWare is here.
Information on programmatic screenshots under Hyper-V is here.
I am developing an application that will run on Linux to run fullscreen all the time (no menus or trays or anything will be visible).
The application is going to be developed in Python, not that that matters as far as the window manager, but what I am having a hard time with is choosing a window manager.
I need something with the smallest possible footprint, that will let me run a graphical Python app and have an mplayer window at the same time, at widescreen resolutions (widescreen, 16:10,16:9, etc). Other than that, it doesn't need a lot of features, but the end footprint size is the most important thing I'll be looking at.
What window manager would you recommend?
EDIT: There won't be any interaction with the application needed.
You don't actually need any window manager or display manager. All you need to do is open your initial window with the same geometry as the root window. I suppose you could even draw directly into the root window if you wanted.
If you are using some display library it probably has an easy way to open a full screen window. For example using a recent enough version of SDL through pygame you can do
pygame.display.init()
surface = pygame.display.set_mode((0,0),pygame.FULLSCREEN,0)
to get a window that fills the entire screen. This will work even if there is no window manager running.
As for mplayer, it accepts the -geometry flag, so you can use something like mplayer -geometry 640x480+20+20 to display the mplayer window 20 pixels from the top 20 pixels from the left and with a size of 640x480 pixels.
You probably meant window manager. Display manages are KDM, GDM and the like. Windoe managers, to name, GNOME, Xfce, KDE, ratpoison, fvwm, twm, blackbox are a few. ratpoison gives full screen to the application that is in the foreground but demands heavy keyboard interaction (hence the name ratpoison) and no mouse interaction at all.
I assume you'll be running both your python GUI and mplayer in some sort of geometries combination that shows both at the same time, filling the screen.
As commented, you should not need a window manager to achieve that. You could have your python GUI app get command-line parameters for setting its window geometry and also call fullscreen mplayer with the -geometry parameter. That should fill the screen as expected, without any window decorations.
Now you could have the startx script called for the user running it all and have a custom ~/.xinitrc script doing something like:
#!/bin/sh
exec python my_gui_app --whatever-sets-geom &
exec mplayer -fs video.avi
If yout pyhon app will instead be launching mplayer then just leave the first 'exex' call (remove the '&') and have it call mplayer as desired with the expected dimensions in '-fs' mode.
Please note you may need to use something like the 'xset' program to disable monitor blanking due to energy savings, hide the cursor (although IIRC that's something mplayer does for its own window), and things like that.
Also, somethimes running, for example, GTK apps on a bare X display may end up using an "ugly" theme, so you may need to have the toolkit style configuration taken care of someway.
I am doing something similar on my "set-top box" and I don't use any window manager.
It boots debian, and from inittab I auto-login the user that runs the display. That user's .profile starts X, which runs .xinitrc, which starts my python app that runs as a network server in front of mplayer (running mplayer in -slave mode).
My python app does not have a GUI element - only mplayer runs on the X display. But in your case, it should be no different. As I mentioned in a comment to another answer, you may want to look into how you can reparent mplayer's window to give you greater control over its placement and/or movement/size.
Doing it this way avoided a display manager and a window manager. This simplifies the solution, boots faster and uses a smaller footprint (it runs of an SD card, with heaps of room to spare).
I realize this is an old question, but I use openbox on my system, I have created a custom config file that disables all mouse keyboard shortcuts, and removes borders etc on the applications.
In the openbox config i even created some secret shortcuts that can run fx. an xterm for debugging live on the box.
The openbox documentation was very helpful in figuring everything out, I did the config in about 30 minutes.