#Weird vertex attribute bug

11 messages · Page 1 of 1 (latest)

frosty prawn
#

The vertex attributes aren't set correctly. This is my code

glGenVertexArrays(1, &border_vao);
glBindVertexArray(border_vao);

glGenBuffers(1, &border_vbo);
glBindBuffer(GL_ARRAY_BUFFER, border_vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * border_vertices.size(), &border_vertices[0], GL_STATIC_DRAW);

glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float)));
glEnableVertexAttribArray(1);

glBindVertexArray(0);
#version 430 core
layout (location = 0) in vec2 vertex_position;
layout (location = 1) in vec2 direction;

void main() {
    gl_Position = vec4(
        ((2. * vertex_position.x) - 1.f) * zoom,
        ((2. * vertex_position.y) - 1.f) * zoom,
        0.0, 1.0);
    tex_coord = vertex_position;
}
#

The read order is wrong for location = 0 but not for location = 1

noble nest
#

Nothing jumps out at me from the code. You should run your app through RenderDoc

frosty prawn
#

vertex_position is vertices[0], vertices[1], vertices[2], vertices[3], vertices[4], vertices[5]
direction is vertices[1], vertices[3], vertices[5]

frosty prawn
noble nest
#

That should be your first option. Always

frosty prawn
#

Not really sure what to look for, everything looks quite alright I guess

#

Except this

#

Not sure what happens here

frosty prawn
#

I was just being stupid

glBindVertexBuffer(0, border_vbo, 0, sizeof(GLfloat) * 2);

should be

glBindVertexBuffer(0, border_vbo, 0, sizeof(GLfloat) * 4);

I didn't realise that I needed to edit that too

sage jewel
#

if you turned your floats into an actual vertex construct, those things are easier to read