如何将顶点缓冲区数组合并到我的图形程序中?

How do I incorporate Vertex Buffer Array into my graphics program?

我正在使用 PyOpenGL 为 Python 和 PyQt5 编写 3d 图形工具包。如果有帮助的话,我正在编写自己的着色器来配合它。我想要做的是从使用 glBegin 到使用顶点缓冲区数组。我在使用 VBO 时发现了以下内容:

http://www.songho.ca/opengl/gl_vbo.html - 我只能从中收集一些信息,因为它在 C/C++.

How to get VBOs to work with Python and PyOpenGL - 这是在 Python2 中,因此相当有限。

但是,我无法拼凑我需要的每个形状对象的顶点并将它们编译到场景 VBO 中。我也不知道数组中的数据是如何布局的。下面是我的 initGL 和 paintGL 函数,以及我的顶点和片段着色器的 GLSL 代码。

    def initGL(self):
        self.vertProg = open(self.vertPath, 'r')
        self.fragProg = open(self.fragPath, 'r')
        self.vertCode = self.vertProg.read()
        self.fragCode = self.fragProg.read()
        self.vertShader = shaders.compileShader(self.vertCode, GL_VERTEX_SHADER)
        self.fragShader = shaders.compileShader(self.fragCode, GL_FRAGMENT_SHADER)
        self.shader = shaders.compileProgram(self.vertShader, self.fragShader)

#paintGL uses shape objects, such as cube() or mesh(). Shape objects require the following:
#a list named 'vertices'  - This list is a list of points, from which edges and faces are drawn.
#a list named 'wires'     - This list is a list of tuples which refer to vertices, dictating where to draw wires.
#a list named 'facets'    - This list is a list of tuples which refer to vertices, ditating where to draw facets.
#a bool named 'render'    - This bool is used to dictate whether or not to draw the shape.
#a bool named 'drawWires' - This bool is used to dictate whether wires should be drawn.
#a bool named 'drawFaces' - This bool is used to dictate whether facets should be drawn.

    def paintGL(self):
        shaders.glUseProgram(self.shader)
        glLoadIdentity()
        gluPerspective(45, self.sizeX / self.sizeY, 0.1, 110.0)    #set perspective?
        glTranslatef(0, 0, self.zoomLevel)    #I used -10 instead of -2 in the PyGame version.
        glRotatef(self.rotateDegreeV + self.vOffset, 1, 0, 0)    #I used 2 instead of 1 in the PyGame version.
        glRotatef(self.rotateDegreeH, 0, 0, 1)
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)

        for s in self.shapes:
            if s.drawWires:
                glBegin(GL_LINES)
                for w in s.wires:
                    for v in w:
                        glVertex3fv(s.vertices[v])
                glEnd()

            if s.drawFaces:
                glBegin(GL_QUADS)
                for f in s.facets:
                    for v in f:
                        glVertex3fv(s.vertices[v])
                glEnd()

顶点着色器:

#version 120    
void main() {
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}

片段着色器:

#version 120
void main() {
    gl_FragColor = vec4( 0, 1, 0, 1 );
}

在这个项目的最终形式中,我想在我的缓冲区中包含有关顶点位置、颜色甚至发光的信息。 (这将在我最终将其用于光线行进时实现。)我还需要一种方法来指定我是否应该绘制线和面。

如何设置和配置一个或多个 VBO 以将所有这些信息传输到 GPU 和 OpenGL?

Python3.7.6,Windows10

经过一段时间的研究,我决定尝试使用不太具体的搜索词。我最终偶然发现了这个网站:https://www.metamost.com/opengl-with-python/