Hello,
I made a litle project in order to apply what I learned in Python :
you are a player in a 3D maze where you can meet other connected players (through a server).
I use OpenGl for the 3D maze rendering.
During the game, if you press the ESC key, I display an option menu and after, I go back to the game.
My problem : I have to do a pygame.display.quit() and reinitialize the display mode by pygame.display.set_mode before switching to the maze or option menu otherwize, the program crashes.
So the window close and reopen <-- not really beautiful
Do you have a solution to avoid the close and open window ?
I think that this problem comes from the pygame.display.set_mode parameters
I know that I’m not so clear on my problem description so I’ve created a small program showing my problem : my option menu is implemented by a black window with a red square and the maze in implemented as a black window with a white shape.
When the ‘c’ key is pressed, the switch is made between the two windows.
import pygame
from pygame.locals import *
from OpenGL.GLU import *
from OpenGL.GL import *
class testMode():
def __init__(self):
self.windowWidth=800
self.windowHeight=600
self.modeOpenGpl = False
pygame.init()
self.withoutOpenGpl()
def withOpenGpl(self):
pygame.display.quit()
pygame.display.set_mode((self.windowWidth,self.windowHeight), DOUBLEBUF|OPENGL|OPENGLBLIT)
glMatrixMode(GL_PROJECTION); glLoadIdentity()
gluPerspective(45, (self.windowWidth/self.windowHeight), 0.1, 200.0)
glMatrixMode(GL_MODELVIEW); glLoadIdentity()
glScalef(0.01,0.01,0.01)
gluLookAt(0,0,0, 0,0,-1, 0,1,0)
glBegin(GL_QUADS)
glTexCoord2f(0.0, 0.0); glVertex3f(0.0, -50.0, -1000.0)
glTexCoord2f(1.0, 0.0); glVertex3f(0.0, -50.0, 100.0)
glTexCoord2f(1.0, 1.0); glVertex3f(100.0, -50.0, 1000.0)
glTexCoord2f(0.0, 1.0); glVertex3f(100.0, -50.0, -1000.0)
glEnd()
pygame.display.flip()
def withoutOpenGpl(self):
pygame.display.quit()
self.windowInit = pygame.display.set_mode((self.windowWidth,self.windowHeight))
carre = pygame.Surface((100,100))
carre.fill((255,0,0))
self.windowInit.blit(carre,(10,10))
pygame.display.flip()
tMode = testMode()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit(); import sys; sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
pygame.quit(); import sys; sys.exit()
elif event.key == pygame.K_c:
tMode.modeOpenGpl = not tMode.modeOpenGpl
if tMode.modeOpenGpl: tMode.withOpenGpl()
else: tMode.withoutOpenGpl()
key = pygame.key.get_pressed()
pygame.quit()
Many thanks in advance for your replies.