# \[solved\] Color of VboMesh

**URL:** <https://discourse.libcinder.org/t/solved-color-of-vbomesh/1175>\
**Category:** Using Cinder\
**Created:** [May 23, 2018, 4:46pm UTC](https://discourse.libcinder.org/t/solved-color-of-vbomesh/1175 "2018-05-23T16:46:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![t\_k](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@t\_k](https://discourse.libcinder.org/u/t_k)\
**Post date:** [May 23, 2018, 4:46pm UTC](https://discourse.libcinder.org/t/solved-color-of-vbomesh/1175/1 "2018-05-23T16:46:02Z")

</div>

It seems VboMesh doesn’t hold Layout color info.  
As code below, circles hold color info but Batch changing color each frame.  
Am I wrong usage of VboMesh::Layout?  
I would be very appreciate for any help!

```
class Aobj{
public:
    Aobj();
    vec2 pos, dir;
    ColorA col;
    gl::BatchRef batch;
    gl::VboMeshRef mesh;
    void update();
    void draw();
};

Aobj::Aobj(){
    vector<gl::VboMesh::Layout> layout = {gl::VboMesh::Layout().usage(GL_DYNAMIC_DRAW).attrib(geom::POSITION, 2).attrib(geom::COLOR, 4)};
    mesh = gl::VboMesh::create(3, GL_TRIANGLES, layout);
    batch = gl::Batch::create(mesh, gl::getStockShader(gl::ShaderDef().color()));
    pos = vec2(randFloat(app::getWindowWidth()),randFloat(app::getWindowHeight()));
    col = ci::ColorA(randFloat(),randFloat(),randFloat(),1);
    dir = randVec2();
    auto vertColorIter = mesh->mapAttrib4f(geom::COLOR);
    for (int i=0; i<3; i++) *vertColorIter++ = col;
    vertColorIter.unmap();
}

void Aobj::update(){
    auto vertPosIter = mesh->mapAttrib2f( geom::POSITION );
    *vertPosIter++ = vec2( pos+vec2(15,0) );
    *vertPosIter++ = vec2( pos+vec2(0,-20) );
    *vertPosIter++ = vec2( pos+vec2(-15,0) );
    vertPosIter.unmap();
    pos += dir;
};

void Aobj::draw(){
    gl::color(col);
    gl::drawSolidCircle(pos, 10);
    if(batch) batch->draw();
};

class mainApp : public App {
    vector<Aobj> mObj;
};

void mainApp::update(){
    for(int i=0; i<5; ++i) mObj.push_back(Aobj());
    for( auto p=mObj.begin(); p!=mObj.end();){
        p->update();
        if (randInt(50)==0) p = mObj.erase(p);
        else ++p;
    }
}

void mainApp::draw(){
    gl::clear();
    for(auto &p:mObj) p.draw();
}
```

---

<div class="post-metadata">

**Author:** ![t\_k](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@t\_k](https://discourse.libcinder.org/u/t_k)\
**Post date:** [May 23, 2018, 9:21pm UTC](https://discourse.libcinder.org/t/solved-color-of-vbomesh/1175/2 "2018-05-23T21:21:18Z")

</div>

just forgot to update color mapAttrib… thx
