changeset 604:aca9551ee8b4

Fix compiling issues with Cython 0.20 ; don't pretend to concat shader sources
author Thibaut Girka <thib@sitedethib.com>
date Tue, 11 Nov 2014 15:46:31 +0100
parents e9300aae4b24
children d6ead6f0ba80
files pytouhou/lib/sdl.pyx pytouhou/ui/opengl/shader.pyx pytouhou/ui/opengl/shaders/eosd.py
diffstat 3 files changed, 20 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/lib/sdl.pyx
+++ b/pytouhou/lib/sdl.pyx
@@ -95,7 +95,8 @@ class SDL(object):
 
 cdef class Window:
     def __init__(self, str title, int x, int y, int w, int h, Uint32 flags):
-        self.window = SDL_CreateWindow(title.encode(), x, y, w, h, flags)
+        title_bytes = title.encode()
+        self.window = SDL_CreateWindow(title_bytes, x, y, w, h, flags)
         if self.window == NULL:
             raise SDLError()
 
@@ -241,7 +242,8 @@ cdef class Chunk:
 
 cdef class Font:
     def __init__(self, str filename, int ptsize):
-        self.font = TTF_OpenFont(filename.encode(), ptsize)
+        path = filename.encode()
+        self.font = TTF_OpenFont(path, ptsize)
         if self.font == NULL:
             raise SDLError()
 
@@ -341,7 +343,8 @@ cdef int mix_volume_music(float volume) 
 
 cdef Music load_music(str filename):
     music = Music()
-    music.music = Mix_LoadMUS(filename.encode())
+    path = filename.encode()
+    music.music = Mix_LoadMUS(path)
     if music.music == NULL:
         raise SDLError()
     return music
--- a/pytouhou/ui/opengl/shader.pyx
+++ b/pytouhou/ui/opengl/shader.pyx
@@ -27,8 +27,6 @@ class GLSLException(Exception):
 
 
 cdef class Shader:
-    # vert and frag take arrays of source strings the arrays will be
-    # concattenated into one string by OpenGL
     def __init__(self, vert=None, frag=None):
         if use_debug_group:
             glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "Program creation")
@@ -42,9 +40,12 @@ cdef class Shader:
         self.location_cache = {}
 
         # create the vertex shader
-        self.create_shader(vert[0].encode(), GL_VERTEX_SHADER)
+        vert_src = vert.encode()
+        self.create_shader(vert_src, GL_VERTEX_SHADER)
+
         # create the fragment shader
-        self.create_shader(frag[0].encode(), GL_FRAGMENT_SHADER)
+        frag_src = frag.encode()
+        self.create_shader(frag_src, GL_FRAGMENT_SHADER)
 
         #TODO: put those elsewhere.
         glBindAttribLocation(self.handle, 0, 'in_position')
--- a/pytouhou/ui/opengl/shaders/eosd.py
+++ b/pytouhou/ui/opengl/shaders/eosd.py
@@ -18,7 +18,7 @@ from ..shader import Shader
 
 class GameShader(Shader):
     def __init__(self):
-        Shader.__init__(self, ['''
+        Shader.__init__(self, '''
             attribute vec3 in_position;
             attribute vec2 in_texcoord;
             attribute vec4 in_color;
@@ -34,7 +34,7 @@ class GameShader(Shader):
                 texcoord = in_texcoord;
                 color = in_color;
             }
-        '''], ['''
+        ''', '''
             varying vec2 texcoord;
             varying vec4 color;
 
@@ -44,12 +44,12 @@ class GameShader(Shader):
             {
                 gl_FragColor = texture2D(color_map, texcoord) * color;
             }
-        '''])
+        ''')
 
 
 class BackgroundShader(Shader):
     def __init__(self):
-        Shader.__init__(self, ['''
+        Shader.__init__(self, '''
             attribute vec3 in_position;
             attribute vec2 in_texcoord;
             attribute vec4 in_color;
@@ -65,7 +65,7 @@ class BackgroundShader(Shader):
                 texcoord = in_texcoord;
                 color = in_color;
             }
-        '''], ['''
+        ''', '''
             varying vec2 texcoord;
             varying vec4 color;
 
@@ -81,12 +81,12 @@ class BackgroundShader(Shader):
                 float fog_density = clamp((fog_end - depth) * fog_scale, 0.0, 1.0);
                 gl_FragColor = vec4(mix(fog_color, temp_color, fog_density).rgb, temp_color.a);
             }
-        '''])
+        ''')
 
 
 class PassthroughShader(Shader):
     def __init__(self):
-        Shader.__init__(self, ['''
+        Shader.__init__(self, '''
             attribute vec2 in_position;
             attribute vec2 in_texcoord;
 
@@ -99,7 +99,7 @@ class PassthroughShader(Shader):
                 gl_Position = mvp * vec4(in_position, 0.0, 1.0);
                 texcoord = in_texcoord;
             }
-        '''], ['''
+        ''', '''
             varying vec2 texcoord;
 
             uniform sampler2D color_map;
@@ -108,4 +108,4 @@ class PassthroughShader(Shader):
             {
                 gl_FragColor = texture2D(color_map, texcoord);
             }
-        '''])
+        ''')