我只是想渲染一个四边形。我将 QtOpengWindows 用于我的渲染类,这里是渲染四边形的代码:
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
float x0 = -(float)150.f, y0 = -(float)150.f;
float x1 = (float)150.f, y1 = (float)150.f;
// Set attributes
QVector3D vertices[4] = {
QVector3D( x0, y0, 0.0f),
QVector3D( x0, y1, 0.0f),
QVector3D( x1, y1, 0.0f),
QVector3D( x1, y0, 0.0f)
};
const QVector3D normals[4] = {
QVector3D(0.0f, 0.0f,1.0f),
QVector3D(0.0f, 0.0f,1.0f),
QVector3D(0.0f, 0.0f,1.0f),
QVector3D(0.0f, 0.0f,1.0f)
};
const unsigned int indices[4] = { 0, 1, 2, 3 };
shProgram.enableAttributeArray("vVertices");
shProgram.enableAttributeArray("vNormals");
shProgram.setAttributeArray("vVertices", vertices);
shProgram.setAttributeArray("vNormals", normals);
f->glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_INT, indices);
shProgram.disableAttributeArray("vVertices");
shProgram.disableAttributeArray("vNormals");
它在 Linux 下运行良好,但是当我尝试在 Windows 下运行它时,这部分代码不会呈现任何内容。这是我的顶点着色器:
#version 450
// Per vertex attributes
layout (location = 0)in vec3 vVertices;
layout (location = 1)in vec3 vNormals;
// Model View matrix, Normal matrix, and Model View Projection matrix
uniform mat4 M;
uniform mat4 MVP;
out vec3 interpolatedPosition;
out vec3 interpolatedNormal;
void main()
{
interpolatedPosition = vec3( M * vec4( vVertices, 1.0 ) );
interpolatedNormal = vNormals;
gl_Position = MVP * vec4(vVertices,1);
}