comparison pytouhou/ui/window.pyx @ 460:ec327e58b477

Add a context manager to initialize and shut down SDL outside of Window.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 06 Sep 2013 23:29:19 +0200
parents 1b56d62250ab
children 11708a1d0a1a
comparison
equal deleted inserted replaced
459:6e733ed817bd 460:ec327e58b477
79 bint fixed_pipeline=False, bint sound=True): 79 bint fixed_pipeline=False, bint sound=True):
80 self.fps_limit = fps_limit 80 self.fps_limit = fps_limit
81 self.use_fixed_pipeline = fixed_pipeline 81 self.use_fixed_pipeline = fixed_pipeline
82 self.runner = None 82 self.runner = None
83 83
84 IF UNAME_SYSNAME == "Windows":
85 sdl.set_main_ready()
86 sdl.init(sdl.INIT_VIDEO)
87 sdl.img_init(sdl.INIT_PNG)
88 sdl.ttf_init()
89 if sound:
90 sdl.mix_init(0)
91
92 sdl.gl_set_attribute(sdl.GL_CONTEXT_MAJOR_VERSION, 2) 84 sdl.gl_set_attribute(sdl.GL_CONTEXT_MAJOR_VERSION, 2)
93 sdl.gl_set_attribute(sdl.GL_CONTEXT_MINOR_VERSION, 1) 85 sdl.gl_set_attribute(sdl.GL_CONTEXT_MINOR_VERSION, 1)
94 sdl.gl_set_attribute(sdl.GL_DOUBLEBUFFER, int(double_buffer)) 86 sdl.gl_set_attribute(sdl.GL_DOUBLEBUFFER, int(double_buffer))
95 sdl.gl_set_attribute(sdl.GL_DEPTH_SIZE, 24) 87 sdl.gl_set_attribute(sdl.GL_DEPTH_SIZE, 24)
96 88
113 glHint(GL_FOG_HINT, GL_NICEST) 105 glHint(GL_FOG_HINT, GL_NICEST)
114 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) 106 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
115 glEnableClientState(GL_COLOR_ARRAY) 107 glEnableClientState(GL_COLOR_ARRAY)
116 glEnableClientState(GL_VERTEX_ARRAY) 108 glEnableClientState(GL_VERTEX_ARRAY)
117 glEnableClientState(GL_TEXTURE_COORD_ARRAY) 109 glEnableClientState(GL_TEXTURE_COORD_ARRAY)
118
119 # Initialize sound
120 if sound:
121 sdl.mix_open_audio(44100, sdl.DEFAULT_FORMAT, 2, 4096)
122 sdl.mix_allocate_channels(26) #TODO: make it dependent on the SFX number.
123 110
124 self.clock = Clock(self.fps_limit) 111 self.clock = Clock(self.fps_limit)
125 112
126 113
127 cdef void set_size(self, int width, int height) nogil: 114 cdef void set_size(self, int width, int height) nogil:
151 return running 138 return running
152 139
153 140
154 cpdef double get_fps(self): 141 cpdef double get_fps(self):
155 return self.clock.get_fps() 142 return self.clock.get_fps()
156
157
158 def __dealloc__(self):
159 sdl.mix_close_audio()
160 sdl.mix_quit()
161 sdl.ttf_quit()
162 sdl.img_quit()
163 sdl.quit()