Re: [PyOpenGL-Users] Shader doesn't compile with Python 3
Brought to you by:
mcfletch
|
From: Gabriele L. <gab...@gm...> - 2013-05-29 18:49:32
|
@Chris yes, that's basically the issue. The function glShaderSource in py3
wants an 'str' object instead of a 'bytes' one. If you pass a 'bytes' you
have to convert it to 'str'. And in the non-bzr version there is probably
some code that doesn't correctly handles bytes strings.
I was able to solve the problem by backporting the function compileshader.
In this way it works with both py2 and py3:
def compileShader( source, shaderType ):
"""Compile shader source of given type
source -- GLSL source-code for the shader
shaderType -- GLenum GL_VERTEX_SHADER, GL_FRAGMENT_SHADER, etc,
returns GLuint compiled shader reference
raises RuntimeError when a compilation failure occurs
"""
if isinstance(source, str):
source = [source]
elif isinstance(source, bytes):
source = [source.decode('utf-8')]
shader = glCreateShader(shaderType)
glShaderSource(shader, source)
glCompileShader(shader)
result = glGetShaderiv(shader, GL_COMPILE_STATUS)
if not(result):
# TODO: this will be wrong if the user has
# disabled traditional unpacking array support.
raise RuntimeError(
"""Shader compile failure (%s): %s"""%(
result,
glGetShaderInfoLog( shader ),
),
source,
shaderType,
)
return shader
On Wed, May 29, 2013 at 9:23 AM, Chris Barker - NOAA Federal <
chr...@no...> wrote:
> On Tue, May 28, 2013 at 10:53 PM, Gabriele Lanaro
> <gab...@gm...> wrote:
> > I'm having the same problem in python 3 (not being able to compile the
> > shaders because it gets an invalid literal). Did you find any actual
> > workaround for that?
>
> IIUC shaders have to be written in ASCII, perhaps with Py3, you are
> passing unicode in -- ty encoding it to ascii and passing the bytes
> object instead.
>
> Or maybe I totally mis-understand the issue!
>
> -Chris
>
>
>
> --
>
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R (206) 526-6959 voice
> 7600 Sand Point Way NE (206) 526-6329 fax
> Seattle, WA 98115 (206) 526-6317 main reception
>
> Chr...@no...
>
|