Python VBO-PyOpenGL点

Python VBO-PyOpenGL点,python,glut,vbo,pyopengl,vao,Python,Glut,Vbo,Pyopengl,Vao,我现在正在使用PyOpenGL和GLUT,只想用VBO可视化屏幕上的一些点。 我对使用PyOpenGL编程相当陌生,所以可能代码一点也不好。但在我看来,这应该行得通。 但我总是只得到一分。谁有主意,为什么 谢谢你的帮助 import sys import random #for random numbers from OpenGL.GL import * #for definition of points from OpenGL.GLU import * from OpenGL.GLUT im

我现在正在使用PyOpenGL和GLUT,只想用VBO可视化屏幕上的一些点。 我对使用PyOpenGL编程相当陌生,所以可能代码一点也不好。但在我看来,这应该行得通。 但我总是只得到一分。谁有主意,为什么

谢谢你的帮助

import sys 
import random #for random numbers
from OpenGL.GL import * #for definition of points
from OpenGL.GLU import *
from OpenGL.GLUT import * #for visualization in a window
import numpy as np

AMOUNT = 10
DIMENSION = 3

def changePoints(points):
    for i in range(0, 3*AMOUNT):
        x = random.uniform(-1.0, 1.0)
        points[i]= points[i]*x
    print(points)
    return points

def displayPoints(points):
    vbo=GLuint(0) # init the Buffer in Python!
    glGenBuffers(1, vbo) # generate a buffer for the vertices
    glBindBuffer(GL_ARRAY_BUFFER, vbo) #bind the vertex buffer
    glBufferData(GL_ARRAY_BUFFER,sys.getsizeof(points), points, GL_STREAM_DRAW) 
    glBindBuffer(GL_ARRAY_BUFFER, vbo) #bind the vertex buffer

    glEnableClientState(GL_VERTEX_ARRAY) # enable Vertex Array
    glVertexPointer(DIMENSION, GL_FLOAT,0, ctypes.cast(0, ctypes.c_void_p))
    glBindBuffer(GL_ARRAY_BUFFER, vbo) #bind the vertex buffer
    glDrawArrays(GL_POINTS, 0, AMOUNT) 
    glDisableClientState(GL_VERTEX_ARRAY) # disable the Vertex Array
    glDeleteBuffers(1, vbo)

##creates Points 
def Point(): 

    points = np.arange(AMOUNT*3)
    np.ascontiguousarray(points, dtype = np.float32)

    points = changePoints(points)

    #Visualization
    displayPoints(points)


##clears the color and depth Buffer, call Point() and swap the buffers of the current window
def display():
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    Point()
    glutSwapBuffers() 

def main():
    ##initials GLUT
    glutInit(sys.argv) 
    #sets the initial display mode (selects a RGBA mode window; selects a double buffered window; selects a window with a depth buffer)
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH)
    #defines the size of the Window
    glutInitWindowSize(800, 1600) 
    #creates a window with title
    glutCreateWindow(b'Points') #!string as title is causing a error, because underneath the PyOpenGL call is an old-school C function expecting ASCII text. Solution: pass the string in byte format.
    glutDisplayFunc(display) #sets the display callback for the current window.
    glutMainLoop() #enters the GLUT event processing loop. 

main()

如果不使用任何投影矩阵,则必须在规格化设备空间中设置点的顶点坐标,即从(-1,-1,-1)到(1,1,1)。该体积将投影到视口

要解决您的问题,
必须是数据类型为
np的元素数组。float32

def Point(): 

    points = np.arange(AMOUNT*3, dtype = np.float32)
    points = changePoints(points)

    #Visualization
    displayPoints(points)
点的坐标必须在[-1.0,1.0]范围内:

def changePoints(points):
for i in range(len(points)):
    points[i] = random.uniform(-1.0, 1.0)
print(points)
return points