comparison pytouhou/ui/opengl/backend_glfw.pyx @ 636:4fa0a8e7d941

Add a GLFW implementation of gui.Window.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 14 May 2017 20:14:03 +0100
parents
children
comparison
equal deleted inserted replaced
635:80687f258001 636:4fa0a8e7d941
1 # -*- encoding: utf-8 -*-
2 ##
3 ## Copyright (C) 2016 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
4 ##
5 ## This program is free software; you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published
7 ## by the Free Software Foundation; version 3 only.
8 ##
9 ## This program is distributed in the hope that it will be useful,
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ## GNU General Public License for more details.
13 ##
14
15 from .backend cimport profile, major, minor, double_buffer, is_legacy
16
17 cimport pytouhou.lib.glfw as glfw
18
19
20 def create_glfw_window(title, width, height):
21 '''Create a window (using GLFW) and an OpenGL context.'''
22
23 glfw.init()
24
25 if profile == 'core':
26 glfw.window_hint(glfw.CLIENT_API, glfw.OPENGL_API)
27 glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
28 elif profile == 'es':
29 glfw.window_hint(glfw.CLIENT_API, glfw.OPENGL_ES_API)
30 glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, major)
31 glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, minor)
32 glfw.window_hint(glfw.ALPHA_BITS, 0)
33 glfw.window_hint(glfw.DEPTH_BITS, 24 if is_legacy else 0)
34 if double_buffer >= 0:
35 glfw.window_hint(glfw.DOUBLEBUFFER, double_buffer)
36
37 # Legacy contexts don’t support our required extensions for scaling.
38 if not is_legacy:
39 glfw.window_hint(glfw.RESIZABLE, True)
40
41 return glfw.Window(width, height, title)