2015-12-09 4 views
0

Je voulais vous poser des questions sur la texture et l'éclairage. J'utilise un objet 3ds dans OpenGL et une texture BITMAP. Cela fonctionne parfaitement. Quand j'utilise l'éclairage, il ne reflète pas la lumière. Pendant que je cherchais, je viens de commenter la ligne: glEnable(GL_TEXTURE_2D); et la texture était partie, mais l'éclairage fonctionne!GL_TEXTURE_2D Problèmes d'éclairage?

Existe-t-il une possibilité de laisser TEXTURE et d'ajouter de l'éclairage? Pourquoi cela arrive-t-il? Quelqu'un a une idée?

ÉDITÉ

cela est en fonction INIT() fonction

void initialize(){ 
glEnable(GL_DEPTH_TEST); // We enable the depth test (also called z buffer) 
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // Polygon rasterization mode (polygon filled) 

glEnable(GL_TEXTURE_2D); // This Enable the Texture mapping 

    glEnable(GL_LIGHTING); 
    glEnable(GL_LIGHT0); 
    glEnable(GL_NORMALIZE); 

    // Light model parameters: 
    // ------------------------------------------- 

    GLfloat lmKa[] = {0.0, 0.0, 0.0, 0.0 }; 
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmKa); 

    glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, 1.0); 
    glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 0.0); 

    // ------------------------------------------- 
    // Spotlight Attenuation 

    GLfloat spot_direction[] = {1.0, -1.0, -1.0 }; 
    GLint spot_exponent = 30; 
    GLint spot_cutoff = 180; 

    glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spot_direction); 
    glLighti(GL_LIGHT0, GL_SPOT_EXPONENT, spot_exponent); 
    glLighti(GL_LIGHT0, GL_SPOT_CUTOFF, spot_cutoff); 

    GLfloat Kc = 1.0; 
    GLfloat Kl = 0.0; 
    GLfloat Kq = 0.0; 

    glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION,Kc); 
    glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, Kl); 
    glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, Kq); 


    // ------------------------------------------- 
    // Lighting parameters: 

    GLfloat light_pos[] = {0.0f, 5.0f, 5.0f, 1.0f}; 
    GLfloat light_Ka[] = {1.0f, 0.5f, 0.5f, 1.0f}; 
    GLfloat light_Kd[] = {1.0f, 0.1f, 0.1f, 1.0f}; 
    GLfloat light_Ks[] = {1.0f, 1.0f, 1.0f, 1.0f}; 

    glLightfv(GL_LIGHT0, GL_POSITION, light_pos); 
    glLightfv(GL_LIGHT0, GL_AMBIENT, light_Ka); 
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_Kd); 
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_Ks); 

    // ------------------------------------------- 
    // Material parameters: 

    GLfloat material_Ka[] = {0.5f, 0.0f, 0.0f, 1.0f}; 
    GLfloat material_Kd[] = {0.4f, 0.4f, 0.5f, 1.0f}; 
    GLfloat material_Ks[] = {0.8f, 0.8f, 0.0f, 1.0f}; 
    GLfloat material_Ke[] = {0.1f, 0.0f, 0.0f, 0.0f}; 
    GLfloat material_Se = 20.0f; 

    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, material_Ka); 
    glMaterialfv(GL_FRONT, GL_DIFFUSE, material_Kd); 
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material_Ks); 
    glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, material_Ke); 
    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material_Se); 
} 

, cet état est() (J'utilise QT)

void pointGL(){ 
    if(change) 
    { 
     ThreeDModels objectClass; 

     objectClass.SpaceShip(); 
     change = false; 
    } 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    glLoadIdentity(); 
    glPushMatrix(); 
    glScalef(0.05, 0.05, 0.05); 

    ThreeDModels objectiModel; 
    objectiModel.objectCreation(l_index); 

    glPopMatrix(); 

} 

Méthode quelle autre méthode pour Lo Ading 3ds objet et ajouter de la texture

void ThreeDModels::SpaceShip() 
{ 
    Load3DS(&objecti, "C:/Users/Documents/3DModelRendering/3DModels/Spaceship/spaceship.3ds"); 
    int a =  LoadBitmap2("C:/Users/Documents/3DModelRendering/3DModels/Spaceship/spaceshiptexture.bmp"); 
} 


void ThreeDModels::objectCreation(int l_index) 
{ 
glBegin(GL_TRIANGLES); // glBegin and glEnd delimit the vertices that define a primitive (in our case triangles) 

for (l_index = 0; l_index<objecti.polygons_qty; l_index++) 
{ 
    //----------------- FIRST VERTEX ----------------- 
    // Texture coordinates of the first vertex 
    glTexCoord2f(objecti.mapcoord[objecti.polygon[l_index].a].u, 
     objecti.mapcoord[objecti.polygon[l_index].a].v); 
    // Coordinates of the first vertex 
    glVertex3f(objecti.vertex[objecti.polygon[l_index].a].x, 
     objecti.vertex[objecti.polygon[l_index].a].y, 
     objecti.vertex[objecti.polygon[l_index].a].z); //Vertex definition 

    //----------------- SECOND VERTEX ----------------- 
    // Texture coordinates of the second vertex 
    glTexCoord2f(objecti.mapcoord[objecti.polygon[l_index].b].u, 
     objecti.mapcoord[objecti.polygon[l_index].b].v); 
    // Coordinates of the second vertex 
    glVertex3f(objecti.vertex[objecti.polygon[l_index].b].x, 
     objecti.vertex[objecti.polygon[l_index].b].y, 
     objecti.vertex[objecti.polygon[l_index].b].z); 

    //----------------- THIRD VERTEX ----------------- 
    // Texture coordinates of the third vertex 
    glTexCoord2f(objecti.mapcoord[objecti.polygon[l_index].c].u, 
     objecti.mapcoord[objecti.polygon[l_index].c].v); 
    // Coordinates of the Third vertex 
    glVertex3f(objecti.vertex[objecti.polygon[l_index].c].x, 
     objecti.vertex[objecti.polygon[l_index].c].y, 
     objecti.vertex[objecti.polygon[l_index].c].z); 
    } 
    glEnd(); 
} 
+0

Texture et éclairage doivent travailler ensemble sans frais supplémentaires. Mais sans voir le code, il est impossible de vous aider. – BDL

+0

@BDL, j'ai édité ma question et ajouté le code que j'utilise pour charger l'objet et pour ajouter l'éclairage – user3774470

+0

BTW, le chargement et l'ajout de la texture fonctionne parfaitement. La Lumière fonctionne aussi très bien. Mais lorsque Combiné l'objet ne reflète pas la lumière comme il se doit :( – user3774470

Répondre

-1

J'ai trouvé les gars de réponse:

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); WAS dans la méthode LoadBitmap(), juste enlever celui-ci, et cela a fonctionné; D