OpenGL: Shader using wrong layout location

by Alex Weavers   Last Updated July 11, 2019 06:13 AM

It's actually taking the color vector instead of the vertex vector. I noticed because I set the colors to random(), and the triangle clusterfudge that is my cube keeps changing shape when I reload the program.

I'm in the process of updating my code to match OpenGL3/4 standards and use PyGLM instead of numpy. Unfortunately it looks like my pointers are getting scrambled by the VAO.

I checked my view, perspective, and model matricies and they appear to be correct. I have also tried transposing them to no avail. Here's the VBO:

   vector                               color (random)
 [[-0.25       -0.25        0.25        0.4582803   0.8329993   0.36713707]
 [-0.25        0.25        0.25        0.7530541   0.87386566  0.07133926]
 [ 0.25        0.25        0.25        0.2536045   0.34725097  0.5796058 ]
 [-0.25       -0.25        0.25        0.4582803   0.8329993   0.36713707]
 [ 0.25        0.25        0.25        0.2536045   0.34725097  0.5796058 ]

Here's my shader code:

#version 420
layout (location=0) in vec3 vertex_attrib;
// in vec3 texcoord_attrib;
// layout (location=1) in vec3 normal_attrib;
layout (location=2) in vec3 color_attrib;
out vec3 vertex;
// out vec3 normal;
out vec3 color;

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

void main() {
    gl_Position = projection * view * model * vec4(vertex_attrib, 1.0f);
    vertex =;
    // normal = normal_attrib;
    color = color_attrib;

Commenting/uncommenting the normal location appears to do nothing.

VAO code where it binds the pointers for the VBO:

        for args in self.vptr_args:

# args for the two calls of glVertexAttribPointer: (result of the print)
# index=0, size=3, typ=GL_FLOAT, normalized=GL_FALSE, stride=0, pointer=None
# index=2, size=3, typ=GL_FLOAT, normalized=GL_FALSE, stride=0, pointer=c_void_p(12)

I'm terribly confused. The only thing I can think of is that PyGLM says it's using high-precision floats which is messing up the offset?

enter image description here

Tags : opengl vbo vao

Related Questions

OpenGL ES 2.0 2D-Image displaying

Updated April 21, 2015 21:05 PM

OpenGL ES God Ray Precision error

Updated July 25, 2015 13:05 PM

Playstation 4 OpenGL ES support (or Xbox)

Updated May 18, 2017 17:13 PM

Optimizing performance of a heavy fragment shader

Updated December 16, 2016 08:05 AM