comparison pytouhou/ui/opengl/backend.pyx @ 553:8f51e34d911c

Refactor graphics backend selection, to make them fallbackable and optional.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 29 May 2014 12:31:55 +0200
parents
children 653a9f087673
comparison
equal deleted inserted replaced
552:aad758aef26d 553:8f51e34d911c
1 from pytouhou.lib cimport sdl
2 from pytouhou.lib.sdl cimport Window
3
4 from pytouhou.lib.opengl cimport \
5 (glEnable, glHint, glEnableClientState, GL_TEXTURE_2D, GL_BLEND,
6 GL_PERSPECTIVE_CORRECTION_HINT, GL_FOG_HINT, GL_NICEST,
7 GL_COLOR_ARRAY, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY)
8
9 IF USE_GLEW:
10 from pytouhou.lib.opengl cimport glewInit
11
12
13 GameRenderer = None
14
15
16 def init(options):
17 global flavor, version, major, minor, double_buffer, is_legacy, GameRenderer
18
19 flavor = options['flavor']
20 assert flavor in ('core', 'es', 'compatibility', 'legacy')
21
22 version = options['version']
23 major = int(version)
24 minor = <int>(version * 10) % 10
25
26 double_buffer = options['double-buffer']
27 is_legacy = flavor == 'legacy'
28
29 #TODO: check for framebuffer/renderbuffer support.
30
31 from pytouhou.ui.opengl.gamerenderer import GameRenderer
32
33
34 def create_window(title, x, y, width, height):
35 sdl.gl_set_attribute(sdl.GL_CONTEXT_MAJOR_VERSION, major)
36 sdl.gl_set_attribute(sdl.GL_CONTEXT_MINOR_VERSION, minor)
37 sdl.gl_set_attribute(sdl.GL_DOUBLEBUFFER, double_buffer)
38 sdl.gl_set_attribute(sdl.GL_DEPTH_SIZE, 24)
39
40 flags = sdl.WINDOW_SHOWN | sdl.WINDOW_OPENGL
41
42 #TODO: legacy can support one of the framebuffer extensions.
43 if not is_legacy:
44 flags |= sdl.WINDOW_RESIZABLE
45
46 window = Window(title, x, y, width, height, flags)
47 window.gl_create_context()
48
49 if USE_GLEW:
50 if glewInit() != 0:
51 raise Exception('GLEW init fail!')
52
53 # Initialize OpenGL
54 glEnable(GL_BLEND)
55 if is_legacy:
56 glEnable(GL_TEXTURE_2D)
57 glHint(GL_FOG_HINT, GL_NICEST)
58 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
59 glEnableClientState(GL_COLOR_ARRAY)
60 glEnableClientState(GL_VERTEX_ARRAY)
61 glEnableClientState(GL_TEXTURE_COORD_ARRAY)
62
63 return window