简体   繁体   English

pyOpenGL无法创建顶点缓冲区对象

[英]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. 我只是从OpenGL开始,尝试使用Python 2.7,pygame和pyOpenGL创建一个基本的“ hello world”类型的OpenGL应用程序,以使用GPU渲染某些2D形状。 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 . vbo.VBOOpenGL.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. 编辑:我想我会包括在此VBO调用之前执行的代码。

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() . 在此init()之后,立即调用来自追溯的vbo.VBO(...)行。

Solved myself. 解决了自己。 vbo.VBO wants numpy-type arrays ( numpy.array ), not normal lists. vbo.VBO想要numpy类型的数组( numpy.array ),而不是普通列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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