On Sun, Feb 24, 2008 at 5:21 PM, Alex <[EMAIL PROTECTED]> wrote:
>
>  Hello!
>
>  After learning Python for a while, I started experimenting with pyglet
>  and converting some projects from jogl.
>
>  And now I get some errors with the code for shaders.  It seems it has
>  something to do with ctypes, but I haven't looked into them yet. And
>  they look pretty complicated.
>
>  Code:
>
>         vertex = glCreateShader(GL_VERTEX_SHADER)
>         fragment = glCreateShader(GL_FRAGMENT_SHADER)
>
>         vsource = 'void main()\n{\ngl_FrontColor = vec4(1.0, 1.0, 1.0,
>  1.0);\ngl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n}'
>         glShaderSource(vertex, 1, vsource, 0)
>         glCompileShader(vertex)
>
>         fsource = 'void main()\n{\ngl_FragColor = gl_Color;\n}'
>         glShaderSource(fragment, 1, fsource, 0)
>         glCompileShader(fragment)
>
>         self.program = glCreateProgram()
>         glAttachShader(self.program, vertex)
>         glAttachShader(self.program, fragment)
>         glLinkProgram(self.program)
>         glValidateProgram(self.program)
>
>  error:
>
>  glShaderSource(vertex, 1, vsource, 0)
>  ctypes.ArgumentError: argument 3: <type 'exceptions.TypeError'>:
>  expected LP_LP_c_char instance instead of str
>

You need to convert the string to the protype C type, like:

def _shaderSource(text, shader_type=GL_VERTEX_SHADER):
    buff = c.create_string_buffer(text)
    c_text = c.cast(c.pointer(c.pointer(buff)), c.POINTER(c.POINTER(GLchar)))
    shader = glCreateShader(shader_type)
    glShaderSource(shader, 1, c_text, None)
    return shader




-- 
\\\\\/\"/\\\\\\\\\\\
\\\\/ // //\/\\\\\\\
\\\/  \\// /\ \/\\\\
\\/ /\/ / /\/ /\ \\\
\/ / /\/ /\  /\\\ \\
/ /\\\  /\\\ \\\\\/\
\/\\\\\/\\\\\/\\\\\\
               d.p.s

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to