Narrat1ve Narrat1ve - 1 year ago 245
Python Question

Pygame (Python) Scale Transform Slow

I'm writing a simple program in python which takes in data over the serial port and updates the screen.

Because I want this program to look the same on whatever computer it runs on, and it needs to be fullscreen, I had the idea that I wanted to draw everything in a small 640, 480 window, and then scale it to a fullscreen window every time I update the frame.

This allows me to keep all the offsets the same for text, etc. It also turns out this is really slow.

Here's about what the important part of the code looks like:

window = pygame.display.set_mode((1920, 1080),pygame.FULLSCREEN)


while iterations<400:
#Blit all the stuff to the prescaled surface here
screenPostscaled=pygame.transform.scale(screenPrescaled,(1920, 1080))

This runs a WHOLE lot slower than

Everything on the screen is either text or lines, there are no images loaded.
I suspect I'm doing something stupid.

I know I can update "dirty rectangles" only, but I wonder if I'm missing something more fundamental.

Thanks in advance!

Answer Source

You can save one blit by using window as destination surface:

pygame.transform.scale(screenPrescaled, (1920, 1080), window)

If it continues being too slow, you should use update rectangles, you can scale them using the same factor as you scale the image 1920/640 and 1080/480.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download