comparison pytouhou/ui/opengl/backend_sdl.pyx @ 635:80687f258001

Make sdl.Window inherit from gui.Window, so we can swap implementations.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 14 Apr 2016 21:18:03 +0100
parents
children
comparison
equal deleted inserted replaced
634:5270c34b4c00 635:80687f258001
1 from .backend cimport profile, major, minor, double_buffer, is_legacy
2
3 cimport pytouhou.lib.sdl as sdl
4
5
6 def create_sdl_window(title, x, y, width, height):
7 '''Create a window (using SDL) and an OpenGL context.'''
8
9 profile_mask = (sdl.GL_CONTEXT_PROFILE_CORE if profile == 'core' else
10 sdl.GL_CONTEXT_PROFILE_ES if profile == 'es' else
11 sdl.GL_CONTEXT_PROFILE_COMPATIBILITY)
12
13 sdl.gl_set_attribute(sdl.GL_CONTEXT_PROFILE_MASK, profile_mask)
14 sdl.gl_set_attribute(sdl.GL_CONTEXT_MAJOR_VERSION, major)
15 sdl.gl_set_attribute(sdl.GL_CONTEXT_MINOR_VERSION, minor)
16 sdl.gl_set_attribute(sdl.GL_RED_SIZE, 8)
17 sdl.gl_set_attribute(sdl.GL_GREEN_SIZE, 8)
18 sdl.gl_set_attribute(sdl.GL_BLUE_SIZE, 8)
19 sdl.gl_set_attribute(sdl.GL_DEPTH_SIZE, 24 if is_legacy else 0)
20 if double_buffer >= 0:
21 sdl.gl_set_attribute(sdl.GL_DOUBLEBUFFER, double_buffer)
22
23 flags = sdl.WINDOW_SHOWN | sdl.WINDOW_OPENGL
24
25 # Legacy contexts don’t support our required extensions for scaling.
26 if not is_legacy:
27 flags |= sdl.WINDOW_RESIZABLE
28
29 window = sdl.Window(title, x, y, width, height, flags)
30 #window.create_gl_context()
31
32 #discover_features()
33
34 ## If we can’t use scaling but have previously created a resizable window,
35 ## recreate it unresizable.
36 #if not use_scaled_rendering and flags & sdl.WINDOW_RESIZABLE:
37 # flags &= ~sdl.WINDOW_RESIZABLE
38 # window = sdl.Window(title, x, y, width, height, flags)
39 # window.create_gl_context()
40
41 return window