How to use glBufferData() in PyOpenGL?

前端 未结 2 1938
长发绾君心
长发绾君心 2021-01-19 21:12

How do you use glBufferData() in the PyOpenGL python bindings to OpenGL?

When I run the following code

import sys
from OpenGL.GL import *
from PySide         


        
相关标签:
2条回答
  • 2021-01-19 21:26

    You can also use the array object of the array module:

    from array import array
    vert=[0.0,0.0,0.0,
          1.0,0.0,0.0,
          1.0,1.0,0.0,
          0.0,1.0,0.0]
    
    ar=array("f",vert)
    glBufferData(GL_ARRAY_BUFFER, ar.tostring(), GL_STATIC_DRAW)
    

    https://docs.python.org/2/library/array.html

    0 讨论(0)
  • 2021-01-19 21:30

    As a workaround, until lists are supported, pass the vertices as a numpy array:

    vertices = numpy.array([0.5, 0.5, -0.5, 0.5, -0.5, -0.5, 0.5, -0.5], 
                           dtype='float32')
    

    The glVertexPointer call should be glVertexPointer(2, GL_FLOAT, 0, None)

    0 讨论(0)
提交回复
热议问题