Module Video
[hide private]
[frames] | no frames]

Source Code for Module Video

 1  ##################################################################### 
 2  # -*- coding: iso-8859-1 -*-                                        # 
 3  #                                                                   # 
 4  # Frets on Fire                                                     # 
 5  # Copyright (C) 2006 Sami Kyöstilä                                  # 
 6  #                                                                   # 
 7  # This program is free software; you can redistribute it and/or     # 
 8  # modify it under the terms of the GNU General Public License       # 
 9  # as published by the Free Software Foundation; either version 2    # 
10  # of the License, or (at your option) any later version.            # 
11  #                                                                   # 
12  # This program is distributed in the hope that it will be useful,   # 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of    # 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     # 
15  # GNU General Public License for more details.                      # 
16  #                                                                   # 
17  # You should have received a copy of the GNU General Public License # 
18  # along with this program; if not, write to the Free Software       # 
19  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,        # 
20  # MA  02110-1301, USA.                                              # 
21  ##################################################################### 
22   
23  import pygame 
24  import os 
25  from OpenGL.GL import * 
26  from OpenGL.GL.ARB.multisample import * 
27  import Log 
28   
29 -class Video:
30 - def __init__(self, caption = "Game"):
31 self.screen = None 32 self.caption = caption 33 self.fullscreen = False 34 self.flags = True
35
36 - def setMode(self, resolution, fullscreen = False, flags = pygame.OPENGL | pygame.DOUBLEBUF, 37 multisamples = 0):
38 if fullscreen: 39 flags |= pygame.FULLSCREEN 40 41 self.flags = flags 42 self.fullscreen = fullscreen 43 44 try: 45 pygame.display.quit() 46 except: 47 pass 48 49 pygame.display.init() 50 51 pygame.display.gl_set_attribute(pygame.GL_RED_SIZE, 8) 52 pygame.display.gl_set_attribute(pygame.GL_GREEN_SIZE, 8) 53 pygame.display.gl_set_attribute(pygame.GL_BLUE_SIZE, 8) 54 pygame.display.gl_set_attribute(pygame.GL_ALPHA_SIZE, 8) 55 56 if multisamples: 57 pygame.display.gl_set_attribute(pygame.GL_MULTISAMPLEBUFFERS, 1); 58 pygame.display.gl_set_attribute(pygame.GL_MULTISAMPLESAMPLES, multisamples); 59 60 try: 61 self.screen = pygame.display.set_mode(resolution, flags) 62 except Exception, e: 63 Log.error(str(e)) 64 if multisamples: 65 Log.warn("Video setup failed. Trying without antialiasing.") 66 pygame.display.gl_set_attribute(pygame.GL_MULTISAMPLEBUFFERS, 0); 67 pygame.display.gl_set_attribute(pygame.GL_MULTISAMPLESAMPLES, 0); 68 multisamples = 0 69 self.screen = pygame.display.set_mode(resolution, flags) 70 else: 71 Log.error("Video setup failed. Make sure your graphics card supports 32 bit display modes.") 72 raise 73 74 pygame.display.set_caption(self.caption) 75 pygame.mouse.set_visible(False) 76 77 if multisamples: 78 try: 79 glEnable(GL_MULTISAMPLE_ARB) 80 except: 81 pass 82 83 return bool(self.screen)
84
85 - def toggleFullscreen(self):
86 assert self.screen 87 88 return pygame.display.toggle_fullscreen()
89
90 - def flip(self):
91 pygame.display.flip()
92
93 - def getVideoModes(self):
94 return pygame.display.list_modes()
95