Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Mesh stange glitch

$
0
0

@Gallo wrote:

hello,

i am facing a strange glitch when i manipulate my mesh. I don't know if it is an issue with normals, or maybe bad indices or whatever.

Do you have an idea about the symptoms ?

http://gph.is/29NUEEw

here i am creating the mesh :

mesh.enableColors();
mesh.enableIndices();
glPointSize(pointSize);
glDisable(GL_POINT_SMOOTH);

int width = scaledImage.getWidth();
int height = scaledImage.getHeight();
for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) {
        ofColor c = scaledImage.getColor(x, y);
        float brightness = ofMap(c.getBrightness(), 0, 255, -displacement, displacement);
        ofPoint p(x * MAP_SCALE, y * MAP_SCALE, brightness);
        mesh.addVertex(p);
        mesh.addColor(image.getColor(x * MAP_SCALE, y * MAP_SCALE));
    }
}

//add indices
for (int y = 0; y < height - 1; y++){
    for (int x=0; x < width - 1; x++){
        mesh.addIndex(x+y*width);               // 0
        mesh.addIndex((x+1)+y*width);           // 1
        mesh.addIndex(x+(y+1)*width);           // 10

        mesh.addIndex((x+1)+y*width);           // 1
        mesh.addIndex((x+1)+(y+1)*width);       // 11
        mesh.addIndex(x+(y+1)*width);           // 10
    }
}

And i draw it like that :

void ofApp::draw(){
    cam.begin();
    ofPushMatrix();
    ofTranslate(-ofGetWidth() / 2, -ofGetHeight() / 2);
    mesh.draw();
    ofPopMatrix();
    cam.end();
}

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles