ofMaterial problem:can't apply in ofMesh and ofDrawTriangle

Hello,everyone~~

i use “ofPlanePrimitive” to draw the plane,use “ofDrawTriangle” to draw the triangle.and i make a material and apply on it.But I found the triangle is has not effected.

the same things happend when i use ofMesh.

    materialPlane.begin();
    ofPoint a,b,c;
    a.set(-400,80,-200);
    b.set(300,80,100);
    c.set(-200,80,400); 
    ofDrawTriangle(a, b, c);      
    plane.draw();
    materialPlane.end();

i use OF 0.9

in order to calculate lighting you need to have normals in your mesh which ofDrawTriangle doesn’t add. If you create your own mesh you’ll need to calculate the normals for each face

Thanks,arturo.A lot of help :slight_smile:

Strange, I replace the ofDrawTriangle by ofMesh.But still not ok, the material color always be gray~

    materialPlane.begin();
    
    plane.draw();
//        ofPoint a,b,c;
//        a.set(-400,80,-200);
//        b.set(300,80,100);
//        c.set(-200,80,400);     
//        ofDrawTriangle(a, b, c);
    
    ofPoint a,b,c;
    ofMesh mesh;
    a.set(-400,80,-200);
    b.set(300,80,100);
    c.set(-200,80,400);
    mesh.addVertex(a);
    mesh.addVertex(b);
    mesh.addVertex(c);
    
    setNormals(mesh);
    mesh.draw();    
    materialPlane.end();

void ofApp::setNormals( ofMesh &mesh ){
//The number of the vertices
int nV = mesh.getNumVertices();
//The number of the triangles
int nT = mesh.getNumIndices() / 3;
vector<ofPoint> norm( nV ); //Array for the normals
//Scan all the triangles. For each triangle add its
//normal to norm's vectors of triangle's vertices
for (int t=0; t<nT; t++) {
    //Get indices of the triangle t
    int i1 = mesh.getIndex( 3 * t );
    int i2 = mesh.getIndex( 3 * t + 1 );
    int i3 = mesh.getIndex( 3 * t + 2 );
    //Get vertices of the triangle
    const ofPoint &v1 = mesh.getVertex( i1 );
    const ofPoint &v2 = mesh.getVertex( i2 );
    const ofPoint &v3 = mesh.getVertex( i3 );
    //Compute the triangle's normal
    ofPoint dir = ( (v2 - v1).crossed( v3 - v1 ) ).normalized();
    //Accumulate it to norm array for i1, i2, i3
    norm[ i1 ] += dir;
    norm[ i2 ] += dir;
    norm[ i3 ] += dir;
}

//Normalize the normal's length
for (int i=0; i<nV; i++) {
    norm[i].normalize();
}
//Set the normals to mesh
mesh.clearNormals();
mesh.addNormals( norm );
}

can you post a small example that demos the problem so i can test it? also can you try using OF 0.9.1? i fixed there some problems with materials and lights so this might be related

HI,arturo.I build a lightSystem to test it.Here is the example.

I found that in OF 0.9.2 has the same problem~~