pygame double buffering
- by BaldDude
I am trying to use double buffering in pygame. What I'm trying to do is display a red then green screen, and switch from one to the other. Unfortunately, all I have is a black screen. I looked through many sites, but have been unable to find a solution. Any help would be appreciated.
import pygame, sys
from pygame.locals import *
RED = (255, 0, 0)
GREEN = ( 0, 255, 0)
bob = 1
pygame.init()
#DISPLAYSURF = pygame.display.set_mode((500, 400), 0, 32)
DISPLAYSURF = pygame.display.set_mode((1920, 1080), pygame.OPENGL | pygame.DOUBLEBUF | pygame.HWSURFACE | pygame.FULLSCREEN)
glClear(GL_COLOR_BUFFER_BIT)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
running = True
while running:
if bob==1:
#pygame.draw.rect(DISPLAYSURF, RED, (0, 0, 1920, 1080))
#pygame.display.flip()
glBegin(GL_QUADS)
glColor3f(1.0, 0.0, 0.0)
glVertex2f(-1.0, 1.0)
glVertex2f(-1.0, -1.0)
glVertex2f(1.0, -1.0)
glVertex2f(1.0, 1.0)
glEnd()
pygame.dis
bob = 0
else:
#pygame.draw.rect(DISPLAYSURF, GREEN, (0, 0, 1920, 1080))
#pygame.display.flip()
glBegin(GL_QUADS)
glColor3f(0.0, 1.0, 0.0)
glVertex2f(-1.0, 1.0)
glVertex2f(-1.0, -1.0)
glVertex2f(1.0, -1.0)
glVertex2f(1.0, 1.0)
glEnd()
pygame.dis
bob = 1
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == KEYDOWN:
if event.key == K_ESCAPE:
running = False
pygame.quit()
sys.exit()
I'm using Python 2.7 and my code need to be os independent.
Thanks for your help.