# Constructing VBO

**URL:** <https://discourse.libcinder.org/t/constructing-vbo/278>\
**Category:** Using Cinder\
**Created:** [September 21, 2016, 8:20am UTC](https://discourse.libcinder.org/t/constructing-vbo/278 "2016-09-21T08:20:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrea](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/andrea/32/193_2.png) [@Andrea](https://discourse.libcinder.org/u/Andrea)\
**Post date:** [September 21, 2016, 8:20am UTC](https://discourse.libcinder.org/t/constructing-vbo/278/1 "2016-09-21T08:20:37Z")

</div>

Hi,

it’s been a while since I used Cinder and it looks like many things have changed.

I’m trying to construct a vbo manually, but I must be doing something wrong as I can’t see anything on screen. Regardless the actual geometry(random points atm) I’m creating a simple vbo with static points, indices and colors.

```
const int numVerts = 9;
std::vector<vec3> positions;
std::vector<ColorA> colors;
std::vector<uint32_t> indices;

for( size_t k=0; k < numVerts; k++ )
{
    indices.push_back( k );
    positions.push_back( vec3( randFloat(-10.0f, 10.0f), randFloat(-10.0f, 10.0f), randFloat(-10.0f, 10.0f) ) );
    colors.push_back( ColorA(1.0,0.0,0.0,1.0) );
}

vector<gl::VboMesh::Layout> layout = {
    gl::VboMesh::Layout().usage( GL_STATIC_DRAW ).attrib( geom::Attrib::POSITION, 3 ),
    gl::VboMesh::Layout().usage( GL_STATIC_DRAW ).attrib( geom::Attrib::COLOR, 4 )
};

mVboMesh = gl::VboMesh::create( numVerts, GL_TRIANGLES, { layout }, numVerts );

mVboMesh->bufferAttrib<vec3>( geom::POSITION, positions );
mVboMesh->bufferAttrib<ColorA>( geom::COLOR, colors );
mVboMesh->bufferIndices( numVerts, indices.data() );

mBatch = gl::Batch::create( mVboMesh, gl::getStockShader( gl::ShaderDef().color() ) );

```

this is my draw()

gl::ScopedGlslProg scpGlslProg(gl::getStockShader(gl::ShaderDef().color()));  
gl::draw( mVboMesh );  
OR  
mBatch-\>draw();

---

<div class="post-metadata">

**Author:** ![lithium](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/lithium/32/38_2.png) [@lithium](https://discourse.libcinder.org/u/lithium)\
**Post date:** [September 21, 2016, 8:47am UTC](https://discourse.libcinder.org/t/constructing-vbo/278/2 "2016-09-21T08:47:04Z")

</div>

Two options, firstly, since in this case your indices match your vertices, you can just remove the “numIndices” argument you provided to `VboMesh::create()` and remove the call to `->bufferIndices()`

Going forward though, you will need to allocate a `Vbo` as an index buffer and pass that to the `VboMesh` constructor, it’s not enough to simply tell the function how many indices there are. First of all, remove the call to `->bufferIndices()`, and create your IBO and `VboMesh` thus:

```auto
gl::VboRef ibo = gl::Vbo::create ( GL_ELEMENT_ARRAY_BUFFER, indices, GL_STATIC_DRAW );
mVboMesh = gl::VboMesh::create( numVerts, GL_TRIANGLES, { layout }, indices.size(), GL_UNSIGNED_INT, ibo );

```

A.

---

<div class="post-metadata">

**Author:** ![Andrea](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/andrea/32/193_2.png) [@Andrea](https://discourse.libcinder.org/u/Andrea)\
**Post date:** [September 21, 2016, 9:03am UTC](https://discourse.libcinder.org/t/constructing-vbo/278/3 "2016-09-21T09:03:31Z")

</div>

I’ve managed to draw points and triangles using the method above and also by streaming the data on each frame(GL\_ARRAY\_BUFFER / GL\_STREAM\_DRAW ), however the GL\_QUADS doesn’t seem to work.

---

<div class="post-metadata">

**Author:** ![gabor\_papp](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gabor_papp/32/769_2.png) [@gabor\_papp](https://discourse.libcinder.org/u/gabor_papp)\
**Post date:** [September 21, 2016, 9:52am UTC](https://discourse.libcinder.org/t/constructing-vbo/278/4 "2016-09-21T09:52:54Z")

</div>

`GL_QUADS` were [removed](https://www.opengl.org/wiki/Primitive#Quads) in OpenGL 3.1.

---

<div class="post-metadata">

**Author:** ![Andrea](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/andrea/32/193_2.png) [@Andrea](https://discourse.libcinder.org/u/Andrea)\
**Post date:** [September 21, 2016, 10:18am UTC](https://discourse.libcinder.org/t/constructing-vbo/278/5 "2016-09-21T10:18:30Z")

</div>

makes sense.  
so the last thing I need to do is to buffer my indices, to draw quads I usually use 6 indices and 4 vertices. I’m doing something like this but it doesn’t seem to work.

// create indices and verts  
indices.push\_back( cellsCount \* 4 );  
indices.push\_back( cellsCount \* 4 + 1 );  
indices.push\_back( cellsCount \* 4 + 2 );

indices.push\_back( cellsCount \* 4 );  
indices.push\_back( cellsCount \* 4 + 2 );  
indices.push\_back( cellsCount \* 4 + 3 );

mVerts.push\_back( { vec3(randFloat(),randFloat(),randFloat()), ColorA( 1.0f, 1.0f, 1.0f, 1.0f ) } );  
mVerts.push\_back( { vec3(randFloat(),randFloat(),randFloat()), ColorA( 1.0f, 1.0f, 1.0f, 0.7f ) } );  
mVerts.push\_back( { vec3(randFloat(),randFloat(),randFloat()), ColorA( 1.0f, 1.0f, 1.0f, 0.2f ) } );  
mVerts.push\_back( { vec3(randFloat(),randFloat(),randFloat()), ColorA( 1.0f, 1.0f, 1.0f, 0.1f ) } );

…

// buffer indices  
mVbo = gl::Vbo::create( GL\_ARRAY\_BUFFER, mVerts, GL\_STREAM\_DRAW );

```
geom::BufferLayout layout;
layout.append( geom::Attrib::POSITION, 3, sizeof( Vert ), offsetof( Vert, pos ) );
layout.append( geom::Attrib::COLOR, 4, sizeof( Vert ), offsetof( Vert, color ) );

auto mesh = gl::VboMesh::create( mVerts.size(), GL_TRIANGLES, { { layout, mVbo } }, indices.size() );
mesh->bufferIndices( indices.size(), indices.data() );
```

---

<div class="post-metadata">

**Author:** ![lithium](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/lithium/32/38_2.png) [@lithium](https://discourse.libcinder.org/u/lithium)\
**Post date:** [September 21, 2016, 2:16pm UTC](https://discourse.libcinder.org/t/constructing-vbo/278/6 "2016-09-21T14:16:59Z")

</div>

When you say it doesn’t work, do you mean you aren’t seeing anything, or you aren’t seeing what you want? I pasted your code into a sample app and it produced this:

 ![](https://canada1.discourse-cdn.com/flex030/uploads/libcinder/original/1X/db0dbf1b278d7680c4eacc0b5e76c31ddd13b0a3.png)

Is that what you’re expecting to see?

---

<div class="post-metadata">

**Author:** ![ryanbartley](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/ryanbartley/32/5_2.png) [@ryanbartley](https://discourse.libcinder.org/u/ryanbartley)\
**Post date:** [September 24, 2016, 2:36am UTC](https://discourse.libcinder.org/t/constructing-vbo/278/7 "2016-09-24T02:36:46Z")

</div>

That looks pretty cool.
