Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.display.flip()
    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.display.flip()
    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.

share|improve this question
    
Ok, I got it, but it seems that I can't answer my quetion yet. I had to use pyopengl calls to draw on the surface. But now, the problem is that it doesn't seem to flip on vsync... the question is why? –  BaldDude Jul 3 '13 at 15:59
1  
Your indentation is messed up. –  monkey Jul 20 '13 at 4:13
    
Does it work if you take off "FULLSCREEN"? –  jsbueno Jul 15 at 1:08
    
The project went in another direction. I no longer use Pygame, so I did not keep up with this question. –  BaldDude Jul 15 at 11:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.