Mercurial > touhou
comparison pytouhou/ui/window.pyx @ 510:64a72df88de5
Make Window able to not initialise OpenGL.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 05 Dec 2013 01:40:31 +0100 |
parents | c622eaf64428 |
children | b39ad30c6620 |
comparison
equal
deleted
inserted
replaced
509:292fea5c584e | 510:64a72df88de5 |
---|---|
85 | 85 |
86 | 86 |
87 | 87 |
88 cdef class Window: | 88 cdef class Window: |
89 def __init__(self, bint double_buffer=True, long fps_limit=-1, | 89 def __init__(self, bint double_buffer=True, long fps_limit=-1, |
90 bint fixed_pipeline=False, bint sound=True): | 90 bint fixed_pipeline=False, bint sound=True, bint opengl=True): |
91 self.fps_limit = fps_limit | 91 self.fps_limit = fps_limit |
92 self.use_fixed_pipeline = fixed_pipeline | 92 self.use_fixed_pipeline = fixed_pipeline |
93 self.runner = None | 93 self.runner = None |
94 | 94 |
95 sdl.gl_set_attribute(sdl.GL_CONTEXT_MAJOR_VERSION, 2) | 95 flags = sdl.WINDOW_SHOWN |
96 sdl.gl_set_attribute(sdl.GL_CONTEXT_MINOR_VERSION, 1) | |
97 sdl.gl_set_attribute(sdl.GL_DOUBLEBUFFER, int(double_buffer)) | |
98 sdl.gl_set_attribute(sdl.GL_DEPTH_SIZE, 24) | |
99 | 96 |
100 flags = sdl.WINDOW_OPENGL | sdl.WINDOW_SHOWN | 97 if opengl: |
98 sdl.gl_set_attribute(sdl.GL_CONTEXT_MAJOR_VERSION, 2) | |
99 sdl.gl_set_attribute(sdl.GL_CONTEXT_MINOR_VERSION, 1) | |
100 sdl.gl_set_attribute(sdl.GL_DOUBLEBUFFER, int(double_buffer)) | |
101 sdl.gl_set_attribute(sdl.GL_DEPTH_SIZE, 24) | |
102 | |
103 flags |= sdl.WINDOW_OPENGL | |
104 | |
101 if not self.use_fixed_pipeline: | 105 if not self.use_fixed_pipeline: |
102 flags |= sdl.WINDOW_RESIZABLE | 106 flags |= sdl.WINDOW_RESIZABLE |
103 | 107 |
104 self.win = sdl.Window('PyTouhou', | 108 self.win = sdl.Window('PyTouhou', |
105 sdl.WINDOWPOS_CENTERED, sdl.WINDOWPOS_CENTERED, | 109 sdl.WINDOWPOS_CENTERED, sdl.WINDOWPOS_CENTERED, |
106 640, 480, #XXX | 110 640, 480, #XXX |
107 flags) | 111 flags) |
108 self.win.gl_create_context() | |
109 | 112 |
110 IF USE_GLEW: | 113 if opengl: |
111 if glewInit() != 0: | 114 self.win.gl_create_context() |
112 raise Exception('GLEW init fail!') | |
113 | 115 |
114 # Initialize OpenGL | 116 IF USE_GLEW: |
115 glEnable(GL_BLEND) | 117 if glewInit() != 0: |
116 if self.use_fixed_pipeline: | 118 raise Exception('GLEW init fail!') |
117 glEnable(GL_TEXTURE_2D) | 119 |
118 glHint(GL_FOG_HINT, GL_NICEST) | 120 # Initialize OpenGL |
119 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) | 121 glEnable(GL_BLEND) |
120 glEnableClientState(GL_COLOR_ARRAY) | 122 if self.use_fixed_pipeline: |
121 glEnableClientState(GL_VERTEX_ARRAY) | 123 glEnable(GL_TEXTURE_2D) |
122 glEnableClientState(GL_TEXTURE_COORD_ARRAY) | 124 glHint(GL_FOG_HINT, GL_NICEST) |
125 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) | |
126 glEnableClientState(GL_COLOR_ARRAY) | |
127 glEnableClientState(GL_VERTEX_ARRAY) | |
128 glEnableClientState(GL_TEXTURE_COORD_ARRAY) | |
123 | 129 |
124 self.clock = Clock(self.fps_limit) | 130 self.clock = Clock(self.fps_limit) |
125 | 131 |
126 | 132 |
127 cdef void set_size(self, int width, int height) nogil: | 133 cdef void set_size(self, int width, int height) nogil: |
151 return running | 157 return running |
152 | 158 |
153 | 159 |
154 cdef double get_fps(self) nogil: | 160 cdef double get_fps(self) nogil: |
155 return self.clock.get_fps() | 161 return self.clock.get_fps() |
156 | |
157 | |
158 def del_runner(self): | |
159 self.runner = None |