[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Fullscreen vs Windowed Alpha Blit speed?
- To: pygame-users@xxxxxxxx
- Subject: [pygame] Fullscreen vs Windowed Alpha Blit speed?
- From: Fred Burton <flbl@xxxxxxxxxxxxxx>
- Date: Sat, 22 Jan 2005 12:24:23 -0800
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Sat, 22 Jan 2005 15:25:39 -0500
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
- User-agent: Mozilla Thunderbird 0.9 (Windows/20041103)
I was writing a simple slideshow program last night (which fades images
in and out),
and was wondering why for some reason bliting with alpha seems to run
much slower when in fullscreen than when not.
Can someone tell me how to make it run as fast in fullscreen as in a
window? (I tried a few things last night, but none of them seemed to help)
import pygame
import os
fade_time = 1000
hang_time = 10000
imgdir = 'images/'
fullscreen = 0
bgcolor = 0
# 20 minute software by Fred Burton: flbl@xxxxxxxxxxxxxx
files = os.listdir(imgdir)
pics = []
for pic in files:
if pic.lower()[-4:] == '.jpg':
pics.append(pic)
pics.sort()
class ErrorQuit:
pass
skip = '*'
def think():
global gamequit
global skip
remainingEvents = pygame.event.get()
for event in remainingEvents:
if event.type == pygame.QUIT:
raise ErrorQuit
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
raise ErrorQuit
if event.key == pygame.K_SPACE:
skip = 1
if event.key == pygame.K_n:
skip = 1
if event.key == pygame.K_p:
skip = -1
if event.key == pygame.K_b:
skip = -1
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
skip = 1
if event.button == 3:
skip = -1
def find_pred(name):
dl = pics
if len(dl) == 0:
return None
try:
i = dl.index(name)
except:
return dl[-1]
i -= 1
if i<0:
i = -1
return dl[i]
def find_succ(name):
dl = pics
if len(dl) == 0:
return None
try:
i = dl.index(name)
except:
return dl[0]
i += 1
if i>=len(dl):
i = 0
return dl[i]
try:
pygame.init()
if fullscreen:
screen = pygame.display.set_mode((1024,768), pygame.DOUBLEBUF | pygame.FULLSCREEN)
else:
screen = pygame.display.set_mode((1024,768), pygame.DOUBLEBUF)
ifname = pics[0]
while (1):
if skip == -1:
ifname = find_pred(ifname)
elif skip != '*':
ifname = find_succ(ifname)
skip = 0
img = pygame.image.load(imgdir+ifname)
# pos = (0,0)
pos = (0.5*(screen.get_width()-img.get_width()), 0.5*(screen.get_height()-img.get_height()))
t0 = pygame.time.get_ticks()
t1 = t0
while (t1-t0)<fade_time:
n = (255*(t1-t0))/fade_time
screen.fill(bgcolor)
img.set_alpha(int(n))
screen.blit(img, pos)
pygame.display.flip()
think()
pygame.time.wait(1)
t1 = pygame.time.get_ticks()
img.set_alpha(255)
screen.blit(img, pos)
pygame.display.flip()
t0 = pygame.time.get_ticks()
t1 = t0
while ((t1-t0)<hang_time) and (skip == 0):
n = (255*(t1-t0))/fade_time
think()
pygame.time.wait(10)
t1 = pygame.time.get_ticks()
t0 = pygame.time.get_ticks()
t1 = t0
while (t1-t0)<fade_time:
n = 255-((255*(t1-t0))/fade_time)
screen.fill(bgcolor)
img.set_alpha(int(n))
screen.blit(img, pos)
pygame.display.flip()
pygame.time.wait(1)
think()
t1 = pygame.time.get_ticks()
screen.fill(bgcolor)
pygame.display.flip()
finally:
pygame.quit()