Hi,
I’m trying to draw a cube with ofMesh and ofVbo. Although the cube is drawn I get a little weird results. From different points of view it seems some sides of the cube aren’t drawn and/or some sides are somehow transparent and sides that shouldn’t be visible are seen trough them from a the specific perspective.
I thought maybe culling was a problem so I turned it off but that doesn’t seem to make any difference though.
This screenshot shows an example of the cube. All blue and pink colors are the same, so that darker blue area doesn’t make sense.
the code:
//--------------------------------------------------------------
void testApp::setup(){
ofBackground(255);
ofSetFrameRate(24);
ofSetVerticalSync(true);
truck = 0;
mesh_fill_cube();
}
//--------------------------------------------------------------
void testApp::update(){
cbe_vbo.setMesh(cbe_mesh, GL_DYNAMIC_DRAW);
}
//--------------------------------------------------------------
void testApp::draw(){
easycam.begin();
glDisable(GL_CULL_FACE);
cbe_vbo.draw(GL_QUADS, 0, 24);
easycam.end();
}
void testApp::mesh_fill_cube() {
for (int i=0; i<1; i++) { // amount of cubes
for (int j=0; j<1; j++) {
vector<ofVec3f> vec;
// front face coordinates
vec.push_back(ofVec3f(-50,50,50));
vec.push_back(ofVec3f(50,50,50));
vec.push_back(ofVec3f(50,-50,50));
vec.push_back(ofVec3f(-50,-50,50));
// back face coordinates
vec.push_back(ofVec3f(-50,50,-50));
vec.push_back(ofVec3f(50,50,-50));
vec.push_back(ofVec3f(50,-50,-50));
vec.push_back(ofVec3f(-50,-50,-50));
// back plane
for (int i=0, idx[4] = {4,5,6,7}; i<4; i++) {
cbe_mesh.addVertex(vec[idx[i]]);
cbe_mesh.addColor(ofFloatColor(1,0.2,1,1));
}
// front plane
for (int i=0, idx[4] = {0,1,2,3}; i<4; i++) {
cbe_mesh.addVertex(vec[idx[i]]);
cbe_mesh.addColor(ofFloatColor(0.1,0.1,1,1));
}
// bottom plane
for (int i=0, idx[4] = {2,3,7,6}; i<4; i++) {
cbe_mesh.addVertex(vec[idx[i]]);
cbe_mesh.addColor(ofFloatColor(1,0.4,1));
}
// top plane
for (int i=0, idx[4] = {0,1,5,4}; i<4; i++) {
cbe_mesh.addVertex(vec[idx[i]]);
cbe_mesh.addColor(ofFloatColor(0.3,0.3,1));
}
// left plane
for (int i=0, idx[4] = {0,4,7,3}; i<4; i++) {
cbe_mesh.addVertex(vec[idx[i]]);
cbe_mesh.addColor(ofFloatColor(1,0.4,1));
}
// right plane
for (int i=0, idx[4] = {1,5,6,2}; i<4; i++) {
cbe_mesh.addVertex(vec[idx[i]]);
cbe_mesh.addColor(ofFloatColor(0.3,0.3,1));
}
}
}
}