Python PyOpenGL如何设置VertexAttribute指针

Python PyOpenGL如何设置VertexAttribute指针,python,opengl,pyopengl,vao,Python,Opengl,Pyopengl,Vao,在上的教程之后,我正在尝试用Python构建一个顶点数组对象,经过一点研究,大部分代码都很容易翻译成Python,但是我有点困惑,我不知道应该如何为一个包含顶点、颜色和纹理坐标的对象构建VertexAttributePointer。本教程中给出的代码如下: GLfloat vertices[] = { // Positions // Colors // Texture Coords 0.5f, 0.5f, 0.0f, 1.0f, 0

在上的教程之后,我正在尝试用Python构建一个顶点数组对象,经过一点研究,大部分代码都很容易翻译成Python,但是我有点困惑,我不知道应该如何为一个包含顶点、颜色和纹理坐标的对象构建VertexAttributePointer。本教程中给出的代码如下:

 GLfloat vertices[] = {
    // Positions          // Colors           // Texture Coords
     0.5f,  0.5f, 0.0f,   1.0f, 0.0f, 0.0f,   1.0f, 1.0f, // Top Right
     0.5f, -0.5f, 0.0f,   0.0f, 1.0f, 0.0f,   1.0f, 0.0f, // Bottom Right
    -0.5f, -0.5f, 0.0f,   0.0f, 0.0f, 1.0f,   0.0f, 0.0f, // Bottom Left
    -0.5f,  0.5f, 0.0f,   1.0f, 1.0f, 0.0f,   0.0f, 1.0f  // Top Left 
};

glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

// Position attribute
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)0);
glEnableVertexAttribArray(0);
// Color attribute
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
glEnableVertexAttribArray(1);
// TexCoord attribute
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(6 * sizeof(GLfloat)));
glEnableVertexAttribArray(2);
然后将其馈送到着色器:

顶点着色器:

#version 330 core
layout (location = 0) in vec3 position;
layout (location = 1) in vec3 color;
layout (location = 2) in vec2 texCoord;

out vec3 ourColor;
out vec2 TexCoord;

void main()
{
    gl_Position = vec4(position, 1.0f);
    ourColor = color;
    TexCoord = texCoord;
}
片段着色器:

#version 330 core
in vec3 ourColor;
in vec2 TexCoord;

out vec4 color;

uniform sampler2D ourTexture;

void main()
{
    color = texture(ourTexture, TexCoord);
}

现在,这是教程中让我困惑的部分。我找不到如何在Python中构建VertexAttributePointer来保存此数据的源代码,也找不到如何在Python的着色器中访问此数据的源代码。我找到的大多数PyOpenGL教程都是传统的OpenGL,甚至根本不使用VertexAttributeArray,因此我不知道如何正确使用它。

小问题:在着色器中,您引用了
ourColor
,但从未在片段着色器的输出中实际使用它。我猜你想看看有纹理和没有纹理的代码作为两个不同的着色器和程序的示例?你读过和写过吗?