Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何让VBOs使用Python和PyOpenGL_Python_Opengl_Pygame_Vbo_Vertex Buffer - Fatal编程技术网

如何让VBOs使用Python和PyOpenGL

如何让VBOs使用Python和PyOpenGL,python,opengl,pygame,vbo,vertex-buffer,Python,Opengl,Pygame,Vbo,Vertex Buffer,下面的Python程序应该在窗口的右上象限绘制一个白色三角形 import pygame from OpenGL.GL import * from ctypes import * pygame.init () screen = pygame.display.set_mode ((800,600), pygame.OPENGL|pygame.DOUBLEBUF, 24) glViewport (0, 0, 800, 600) glClearColor (0.0, 0.5, 0.5, 1.0) g

下面的Python程序应该在窗口的右上象限绘制一个白色三角形

import pygame
from OpenGL.GL import *
from ctypes import *

pygame.init ()
screen = pygame.display.set_mode ((800,600), pygame.OPENGL|pygame.DOUBLEBUF, 24)
glViewport (0, 0, 800, 600)
glClearColor (0.0, 0.5, 0.5, 1.0)
glEnableClientState (GL_VERTEX_ARRAY)

vertices = [ 0.0, 1.0, 0.0,  0.0, 0.0, 0.0,  1.0, 1.0, 0.0 ]
vbo = glGenBuffers (1)
glBindBuffer (GL_ARRAY_BUFFER, vbo)
glBufferData (GL_ARRAY_BUFFER, len(vertices)*4, (c_float*len(vertices))(*vertices), GL_STATIC_DRAW)

running = True
while running:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    glClear (GL_COLOR_BUFFER_BIT)

    glBindBuffer (GL_ARRAY_BUFFER, vbo)
    glVertexPointer (3, GL_FLOAT, 0, 0)

    glDrawArrays (GL_TRIANGLES, 0, 3)

    pygame.display.flip ()
它不会抛出任何错误,但不幸的是它没有画出三角形

我还尝试将缓冲区数据作为NumPy数组提交:

glBufferData (GL_ARRAY_BUFFER, len(vertices)*4, np.array (vertices, dtype="float32"), GL_STATIC_DRAW)
也没有画三角形。PyOpenGL。。。你没有画VBO吗

我的系统:Python 2.7.3;opengl4.2.0;Linux Mint Maya 64位

好的,我刚找到它:

glvertexinter
调用的第四个参数必须是表示空指针的
None

glVertexPointer (3, GL_FLOAT, 0, None)

我发誓,我昨晚搜索了好几个小时都没发现。

第二次在谷歌上搜索“哦”,这让我从灰白的头发中解脱出来。这与
GL.glvertexattributepointer(0,4,GL.GL\u FLOAT,GL.GL\u FALSE,0,None)相同。
。将
0
作为最后一个参数传递可能适用于C/C++代码,但显然不适用于PyOpenGL。它必须是
None
。我花了几个小时调试才找到这个。我已经疯了。你救了我,非常感谢!最后一个参数的类型为GLvoid*,必须转换为ctypes.c_void_p(偏移量),请参阅