changeset 450:2a352118c55a

Add back Windows support, using GLEW for OpenGL.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 30 Aug 2013 18:21:07 +0200
parents d56536ef28e8
children c034570ac785
files pytouhou/lib/opengl.pxd pytouhou/lib/sdl.pxd pytouhou/lib/sdl.pyx pytouhou/ui/window.pyx setup.py
diffstat 5 files changed, 30 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/lib/opengl.pxd
+++ b/pytouhou/lib/opengl.pxd
@@ -12,7 +12,13 @@
 ## GNU General Public License for more details.
 ##
 
-cdef extern from 'GL/gl.h':
+
+IF USE_GLEW:
+    cdef extern from 'GL/glew.h' nogil:
+        GLenum glewInit()
+
+
+cdef extern from 'GL/gl.h' nogil:
     ctypedef unsigned int GLuint
     ctypedef int GLint
     ctypedef float GLfloat
--- a/pytouhou/lib/sdl.pxd
+++ b/pytouhou/lib/sdl.pxd
@@ -23,6 +23,11 @@ cdef extern from "SDL.h":
     void SDL_Quit()
 
 
+IF UNAME_SYSNAME == "Windows":
+    cdef extern from "SDL_main.h":
+        void SDL_SetMainReady()
+
+
 cdef extern from "SDL_error.h":
     const char *SDL_GetError()
 
--- a/pytouhou/lib/sdl.pyx
+++ b/pytouhou/lib/sdl.pyx
@@ -147,6 +147,11 @@ def mix_init(int flags):
         raise SDLError(SDL_GetError())
 
 
+IF UNAME_SYSNAME == "Windows":
+    def set_main_ready():
+        SDL_SetMainReady()
+
+
 def quit():
     SDL_Quit()
 
--- a/pytouhou/ui/window.pyx
+++ b/pytouhou/ui/window.pyx
@@ -20,6 +20,9 @@ from pytouhou.lib.opengl cimport \
           GL_PERSPECTIVE_CORRECTION_HINT, GL_FOG_HINT, GL_NICEST,
           GL_COLOR_ARRAY, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY)
 
+IF USE_GLEW:
+    from pytouhou.lib.opengl cimport glewInit
+
 
 class Clock(object):
     def __init__(self, fps=None):
@@ -76,6 +79,8 @@ class Window(object):
         self.use_fixed_pipeline = fixed_pipeline
         self.runner = None
 
+        IF UNAME_SYSNAME == "Windows":
+            sdl.set_main_ready()
         sdl.init(sdl.INIT_VIDEO)
         sdl.img_init(sdl.INIT_PNG)
         if sound:
@@ -94,6 +99,10 @@ class Window(object):
                               sdl.WINDOW_OPENGL | sdl.WINDOW_SHOWN)
         self.win.gl_create_context()
 
+        IF USE_GLEW:
+            if glewInit() != 0:
+                raise Exception('GLEW init fail!')
+
         # Initialize OpenGL
         glEnable(GL_BLEND)
         if self.use_fixed_pipeline:
--- a/setup.py
+++ b/setup.py
@@ -49,8 +49,10 @@ for directory, _, files in os.walk('pyto
 try:
     from cx_Freeze import setup, Executable
 except ImportError:
+    is_windows = False
     extra = {}
 else:
+    is_windows = True
     extra = {'options': {'build_exe': {'includes': extension_names}},
              'executables': [Executable(script='eosd', base='Win32GUI')]}
 
@@ -65,6 +67,7 @@ setup(name='PyTouhou',
       ext_modules=cythonize(extensions, nthreads=4,
                             compiler_directives={'infer_types': True,
                                                  'infer_types.verbose': True},
-                            compile_time_env={'MAX_TEXTURES': 1024}),
+                            compile_time_env={'MAX_TEXTURES': 1024,
+                                              'USE_GLEW': is_windows}),
       scripts=['eosd', 'anmviewer'],
       **extra)