0

I simply want to render a quad. I'm using QtOpengWindows for my rendering class and here is the code for rendering a quad:

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");

It works well under Linux, but when I try to run it under Windows this part of the code doesn't render anything. Here is my vertex shader:

#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);
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
user3178756
  • 555
  • 1
  • 5
  • 17
  • 1
    Did you check the OpenGL version that is installed in Windows? If the shader doesn't compile (because the version paradigm is not fullfilled) there won't be any obvious error but you won't see anything. – Florian Blume Sep 01 '18 at 09:31
  • @FlorianBlume The shader compiles, but it just doesn't show anything. The OpenGL version on Windows is 3.3. I have two different shaders for rendering different objects, and one of them is working, it's only the one that renders a quad that doesn't work. My guess is there is something wrong with glDrawElements in the OpenGL version on Windows. – user3178756 Sep 01 '18 at 10:55
  • 1
    Amd the one you posted is the one for the quads? It's no surprise it doesn't work. You say the OpenGL version on Windows is 3.3 but the shader pragma requires version 4.5 (due to the `#version 450` pragma). – Florian Blume Sep 01 '18 at 11:40

0 Answers0