<p>Look good to me.</p>

<p>And yes you can use different datatypes for different attributes in a vao, that's the entire point of having the type parameter there in the first place.</p>

CC BY-SA 3.0
2017-02-28T19:58:18.517Z
what I have a problem with is the "stride" value in glVertexAttribPointer. Why would you not tightly pack an array?
l'arbre
CC BY-SA 3.0
2017-02-28T20:46:17.737Z
when interleaving data by using a array of structs then the stride is the sizeof the struct.
ratchet freak
CC BY-SA 3.0
2017-02-28T13:55:13.977Z
2017-02-28T13:55:13.977Z
ratchet freak
<p>It's been a long time since I last used OpenGL and I can't figure out VAOs anymore... I want to make a simple voxel engine using geometry shaders. This is what I want to do: </p>

<p>vbo1: array of GLfloat for the positions (3 floats per vertex)</p>

<p>vbo2: array of GLfloat for the size of the cube (1 float per vertex)</p>

<p>vbo3: array of GLbyte for the type of voxel (1 byte per vertex)</p>

<p>-> vao: GLfloat x, GLfloat y, GLfloat z, GLfloat size, GLbyte type</p>

<p>Here's my code:</p>

<pre><code>    float *positions = new GLfloat[size * 3];

    positions[0] = 0.5;
    positions[1] = 0.5;
    positions[2] = 0;

    glGenBuffers(1, &amp;positionsId);
    glBindBuffer(GL_ARRAY_BUFFER, positionsId);
    glBufferData(GL_ARRAY_BUFFER, size * 3 * sizeof(GLfloat), positions, GL_STATIC_DRAW);

    byte * voxelValues = new GLubyte[size];


    voxelValues[0] = 0;

    glGenBuffers(1, &amp;voxelValuesId);
    glBindBuffer(GL_ARRAY_BUFFER, voxelValuesId);
    glBufferData(GL_ARRAY_BUFFER, size * sizeof(GLubyte), voxelValues, GL_STATIC_DRAW);

    float * sizes = new GLfloat[size];


    sizes[0] = 1;

    glGenBuffers(1, &amp;sizesId);
    glBindBuffer(GL_ARRAY_BUFFER, sizesId);
    glBufferData(GL_ARRAY_BUFFER, size * sizeof(GLfloat), sizes, GL_STATIC_DRAW);

    glGenVertexArrays(1, &amp;vao);

    glBindVertexArray(vao);
    glBindBuffer(GL_ARRAY_BUFFER, positionsId);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    glBindBuffer(GL_ARRAY_BUFFER, sizesId);
    glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, NULL);
    glBindBuffer(GL_ARRAY_BUFFER, voxelValuesId);
    glVertexAttribPointer(2, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, NULL);

    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);
    glEnableVertexAttribArray(2);
</code></pre>

<p>Is the code even doing what I want it to do? And is it even possible to use different datatypes in the vao? </p>

<opengl><rendering>
Need help with VBO/VAO
l'arbre
# Need help with VBO/VAO

(Asked by: username_0 on 2017-02-28)

It's been a long time since I last used OpenGL and I can't figure out VAOs anymore... I want to make a simple voxel engine using geometry shaders. This is what I want to do:

vbo1: array of GLfloat for the positions (3 floats per vertex)

vbo2: array of GLfloat for the size of the cube (1 float per vertex)

vbo3: array of GLbyte for the type of voxel (1 byte per vertex)

-> vao: GLfloat x, GLfloat y, GLfloat z, GLfloat size, GLbyte type

Here's my code:

```
    float *positions = new GLfloat[size * 3];

    positions[0] = 0.5;
    positions[1] = 0.5;
    positions[2] = 0;

    glGenBuffers(1, &positionsId);
    glBindBuffer(GL_ARRAY_BUFFER, positionsId);
    glBufferData(GL_ARRAY_BUFFER, size * 3 * sizeof(GLfloat), positions, GL_STATIC_DRAW);

    byte * voxelValues = new GLubyte[size];

    voxelValues[0] = 0;

    glGenBuffers(1, &voxelValuesId);
    glBindBuffer(GL_ARRAY_BUFFER, voxelValuesId);
    glBufferData(GL_ARRAY_BUFFER, size * sizeof(GLubyte), voxelValues, GL_STATIC_DRAW);

    float * sizes = new GLfloat[size];

    sizes[0] = 1;

    glGenBuffers(1, &sizesId);
    glBindBuffer(GL_ARRAY_BUFFER, sizesId);
    glBufferData(GL_ARRAY_BUFFER, size * sizeof(GLfloat), sizes, GL_STATIC_DRAW);

    glGenVertexArrays(1, &vao);

    glBindVertexArray(vao);
    glBindBuffer(GL_ARRAY_BUFFER, positionsId);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    glBindBuffer(GL_ARRAY_BUFFER, sizesId);
    glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, NULL);
    glBindBuffer(GL_ARRAY_BUFFER, voxelValuesId);
    glVertexAttribPointer(2, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, NULL);

    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);
    glEnableVertexAttribArray(2);

```

Is the code even doing what I want it to do? And is it even possible to use different datatypes in the vao?

**Tags:** opengl, rendering


---

## 1 answers

### Answer by username_1 on 2017-02-28. Score: 2 | Accepted answer

Look good to me.

And yes you can use different datatypes for different attributes in a vao, that's the entire point of having the type parameter there in the first place.

> **Comments:**
> **username_0**: what I have a problem with is the "stride" value in glVertexAttribPointer. Why would you not tightly pack an array?  
> **username_1**: when interleaving data by using a array of structs then the stride is the sizeof the struct.  

---

