comparison pytouhou/ui/opengl/backend.pyx @ 556:c34b23e29d16

Make the OpenGL flavor and version options work.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 30 May 2014 16:40:36 +0200
parents 98380e4a0ee5
children 0f2af7552462
comparison
equal deleted inserted replaced
555:98380e4a0ee5 556:c34b23e29d16
11 11
12 12
13 def init(options): 13 def init(options):
14 global flavor, version, major, minor, double_buffer, is_legacy, GameRenderer 14 global flavor, version, major, minor, double_buffer, is_legacy, GameRenderer
15 15
16 flavor = options['flavor'] 16 flavor_name = options['flavor']
17 assert flavor in ('core', 'es', 'compatibility', 'legacy') 17 assert flavor_name in ('core', 'es', 'compatibility', 'legacy')
18 flavor = (sdl.GL_CONTEXT_PROFILE_CORE if flavor_name == 'core' else
19 sdl.GL_CONTEXT_PROFILE_ES if flavor_name == 'es' else
20 sdl.GL_CONTEXT_PROFILE_COMPATIBILITY)
18 21
19 version = options['version'] 22 version = str(options['version'])
20 major = int(version) 23 assert len(version) == 3 and version[1] == '.'
21 minor = <int>(version * 10) % 10 24 major = int(version[0])
25 minor = int(version[2])
22 26
23 maybe_double_buffer = options['double-buffer'] 27 maybe_double_buffer = options['double-buffer']
24 double_buffer = maybe_double_buffer if maybe_double_buffer is not None else -1 28 double_buffer = maybe_double_buffer if maybe_double_buffer is not None else -1
25 29
26 is_legacy = flavor == 'legacy' 30 is_legacy = flavor_name == 'legacy'
27 31
28 #TODO: check for framebuffer/renderbuffer support. 32 #TODO: check for framebuffer/renderbuffer support.
29 33
30 from pytouhou.ui.opengl.gamerenderer import GameRenderer 34 from pytouhou.ui.opengl.gamerenderer import GameRenderer
31 35
32 36
33 def create_window(title, x, y, width, height): 37 def create_window(title, x, y, width, height):
38 sdl.gl_set_attribute(sdl.GL_CONTEXT_PROFILE_MASK, flavor)
34 sdl.gl_set_attribute(sdl.GL_CONTEXT_MAJOR_VERSION, major) 39 sdl.gl_set_attribute(sdl.GL_CONTEXT_MAJOR_VERSION, major)
35 sdl.gl_set_attribute(sdl.GL_CONTEXT_MINOR_VERSION, minor) 40 sdl.gl_set_attribute(sdl.GL_CONTEXT_MINOR_VERSION, minor)
36 sdl.gl_set_attribute(sdl.GL_DEPTH_SIZE, 24) 41 sdl.gl_set_attribute(sdl.GL_DEPTH_SIZE, 24)
37 if double_buffer >= 0: 42 if double_buffer >= 0:
38 sdl.gl_set_attribute(sdl.GL_DOUBLEBUFFER, double_buffer) 43 sdl.gl_set_attribute(sdl.GL_DOUBLEBUFFER, double_buffer)