Search code examples
pythonopenglpygletopengl-compat

expected LP_c_float instance instead of list


I need to put an array in the function

material_diffuse = [1.0, 1.0, 1.0, 1.0]
pgl.glMaterialfv(pgl.GL_FRONT_AND_BACK, pgl.GL_DIFFUSE, material_diffuse) 

or 

material_diffuse = [1.0, 1.0, 1.0, 1.0]
pgl.glMaterialfv(pgl.GL_FRONT_AND_BACK, 
pgl.GL_DIFFUSE,ctypes.c_float(material_diffuse))

In the first case i get: expected LP_c_float instance instead of list In the second: TypeError: must be real number, not list


Solution

  • Based on [MS.Docs]: glMaterialfv function (that pyglet wraps via [Python 3.Docs]: ctypes - A foreign function library for Python), you should use:

    pgl.glMaterialfv(pgl.GL_FRONT_AND_BACK, pgl.GL_DIFFUSE, (pgl.GLfloat * len(material_diffuse))(*material_diffuse))
    

    Other reference: [searchcode]: pyglet - /experimental/buffer/torus.py.