glDrawElements可在Linux下运行,但不能在Windows下运行

时间:2018-08-31 20:29:00

标签: c++ qt opengl rendering qtopengl

我只想渲染一个四边形。我在渲染类中使用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);
}

0 个答案:

没有答案