简体   繁体   中英

pyOpenGL failing to create a vertex buffer object

I'm just starting out with OpenGL and trying to create a basic "hello world"-type OpenGL app using Python 2.7, pygame and pyOpenGL to render some 2D shapes using the GPU. When trying to create a vertex buffer for the vertex data:

Traceback (most recent call last):
  File "test.py", line 126, in <module>
    main()
  File "test.py", line 59, in main
    vertexbuffer = vbo.VBO([[0, 0], [1, 0], [1, 1], [0, 1], [2.2, 2.2], [2.7, 2.7], [2.2, 3.2], [1.7, 2.7]])
  File "/usr/lib/python2.7/site-packages/OpenGL/arrays/vbo.py", line 180, in __init__
    self.set_array( data, size )
  File "/usr/lib/python2.7/site-packages/OpenGL/arrays/vbo.py", line 204, in set_array
     self.size = ArrayDatatype.arrayByteCount( self.data )
  File "/usr/lib/python2.7/site-packages/OpenGL/arrays/arraydatatype.py", line 176, in arrayByteCount
    return cls.getHandler(value).arrayByteCount( value )
AttributeError: 'ListHandler' object has no attribute 'arrayByteCount'

vbo.VBO is OpenGL.arrays.vbo.VBO .

Very confused by this. Searching for this error message yields absolutely nothing specific.

Any insights?

EDIT: I thought I'd include the code that is executed before this VBO call.

def init(screen_size):
    screen = pygame.display.set_mode(screen_size, HWSURFACE | OPENGL | DOUBLEBUF)

    glViewport(0, 0, screen_size[0], screen_size[1])

    glShadeModel(GL_SMOOTH)
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)

    viewport = glGetIntegerv(GL_VIEWPORT)

    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    glFrustum(-1.0, 1.0,  1.0, -1.0,  1, 10.0);

    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()

The vbo.VBO(...) line from the traceback is called immediately after this init() .

Solved myself. vbo.VBO wants numpy-type arrays ( numpy.array ), not normal lists.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM