C语言 未使用物料履行目标[已关闭]

3okqufwl  于 2023-01-08  发布在  其他
关注(0)|答案(1)|浏览(125)

**已关闭。**此问题需要debugging details。当前不接受答案。

编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
2天前关闭。
Improve this question
我开始写代码的材料在我的类项目,这是我有作为一个初步测试:

glEnable(GL_COLOR_MATERIAL);
        glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,_selected_object->material.ambient);
        glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,_selected_object->material.diffuse);
        glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,_selected_object->material.specular);
        _selected_object->material.shininess=128.0f;
        glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,_selected_object->material.shininess);

And this is the result in the object
为什么这些脸没有被材料完全填满?
我确实有一个具有以下值的光源:

l->A1[0]=0.0;
    l->A1[1]=0.0;
    l->A1[2]=0.0;
    l->A1[3]=1.0;
    l->RDifusa[0]=1.0;
    l->RDifusa[1]=1.0;
    l->RDifusa[2]=1.0;
    l->RDifusa[3]=1.0;
    l->REspecular[0]=1.0;
    l->REspecular[1]=1.0;
    l->REspecular[2]=1.0;
    l->REspecular[3]=1.0;
    l->position[0]=1.0;
    l->position[1]=1.0;
    l->position[2]=1.0;
    l->position[3]=0.0;

我在这里显示(在我的init函数中):

glEnable(GL_LIGHTING);
    glLightfv(GL_LIGHT0, GL_AMBIENT, l->A1);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, l->RDifusa);
    glLightfv(GL_LIGHT0, GL_SPECULAR, l->REspecular);
    glLightfv(GL_LIGHT0, GL_POSITION, l->position);
    glEnable(GL_LIGHT0);

这是绘制对象的代码部分:

while (aux_obj != 0) {

        glPushMatrix();
       // glLoadIdentity();
        glMultMatrixd(aux_obj->mtptr->M);

        /* Select the color, depending on whether the current object is the selected one or not */
        if (aux_obj == _selected_object){
            glColor3f(KG_COL_SELECTED_R,KG_COL_SELECTED_G,KG_COL_SELECTED_B);
        }else{
            glColor3f(KG_COL_NONSELECTED_R,KG_COL_NONSELECTED_G,KG_COL_NONSELECTED_B);
        }
    

        /* Draw the object; for each face create a new polygon with the corresponding vertices */
        //glLoadIdentity();
        for (f = 0; f < aux_obj->num_faces; f++) {
            glBegin(GL_POLYGON);
            vector3 N,A,B,C,ABAC;

            for (v = 0; v < aux_obj->face_table[f].num_vertices; v++) {
                v_index = aux_obj->face_table[f].vertex_table[v];
                glVertex3d(aux_obj->vertex_table[v_index].coord.x,
                aux_obj->vertex_table[v_index].coord.y,
                aux_obj->vertex_table[v_index].coord.z);
            }
        }
        glEnd();
        glEnable(GL_COLOR_MATERIAL);
        glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,_selected_object->material.ambient);
        glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,_selected_object->material.diffuse);
        glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,_selected_object->material.specular);
        


        //Draw vertex normal vectors->
        for(v=0;v<aux_obj->num_vertices;v++){
            glBegin(GL_LINE);
            glVertex3d(aux_obj->vertex_table[v].coord.x,aux_obj->vertex_table[v].coord.y,aux_obj->vertex_table[v].coord.z);
            //Point A= vertex
            //Point B = A - 10000*D
            glVertex3d(aux_obj->vertex_table[v].coord.x+(aux_obj->vertex_table[v].normal.x),aux_obj->vertex_table[v].coord.y+(aux_obj->vertex_table[v].normal.y),aux_obj->vertex_table[v].coord.z+(aux_obj->vertex_table[v].normal.z));
            glEnd();
        } 
        

        //Set object material values->
        
        glPopMatrix();
        aux_obj = aux_obj->next;
    }
c3frrgcw

c3frrgcw1#

基元GL_POLYGON将基元的所有顶点连接到一个多边形。您为每个面创建一个多边形,并且必须对每个单独的多边形执行glEnd()。必须在遍历所有面的循环中调用glEnd(),但不能在循环之后调用:

for (f = 0; f < aux_obj->num_faces; f++) {
    glBegin(GL_POLYGON);
    vector3 N,A,B,C,ABAC;

    for (v = 0; v < aux_obj->face_table[f].num_vertices; v++) {
        v_index = aux_obj->face_table[f].vertex_table[v];
        glVertex3d(aux_obj->vertex_table[v_index].coord.x,
        aux_obj->vertex_table[v_index].coord.y,
        aux_obj->vertex_table[v_index].coord.z);
    }
    glEnd();                                             // <--- INSERT
}
//glEnd();                                                  <--- DELETE

相关问题