Hi,
1)I would like to know if a light isn't in the space created by glFrustum or gluPerspective, will it light the meshes which them are in the space ?
2)I have a problem of black screen what do you recommend me to do ?
Hi,
1)I would like to know if a light isn't in the space created by glFrustum or gluPerspective, will it light the meshes which them are in the space ?
2)I have a problem of black screen what do you recommend me to do ?
1) I believe that light can be directional or "omni-present" [points at all direction, don't have the terminology]. in the latter case, your mesh should be illuminated UNLESS your mesh is too far from your light source.
2) I once had a problem similar to yours and somebody told me to [programmatically or mathematically] create a bounding box of the scene and make sure that your mesh[es] and your light source[s] are within the bounding box.
hope that gets you in the right direction.
:regards:
1)with 3d studio max i have put an omni light next to the meshes, i have also checked the normals of just one sub-mesh of the scene (there are right) and i have no lighting![]()
can you help me ?
Have you created any Light Sources ?
Does you 3ds Loader create Opengl Light sources for any lights it finds in you file ?
____________________
Gordon.
www.3dscenegraph.com
Vega FAQ/Samples
SceneGraph Forums
Did you ensure your light has well been placed with opengl ? Did you also ensure you light up the right faces (front ones) ?
Try a light model of two faces and draw polygons with front and back faces on. Try also to put a high illuminated light.
Cannot help you anymore cause I never played with 3DS lights.
yes lighting works for some files, i try to display files which have just one light.Originally posted by UrbanLegend:
Have you created any Light Sources ?
Does you 3ds Loader create Opengl Light sources for any lights it finds in you file ?
____________________
Gordon.
www.3dscenegraph.com
Vega FAQ/Samples
SceneGraph Forums
in fact i have just noticed that lighting works just when there is one material for one sub-mesh.Originally posted by jide:
Did you ensure your light has well been placed with opengl ? Did you also ensure you light up the right faces (front ones) ?
Try a light model of two faces and draw polygons with front and back faces on. Try also to put a high illuminated light.
Cannot help you anymore cause I never played with 3DS lights.
So for example i have a file in which there are 3 sub-meshes and just one material : so i get no lighting for all the scene![]()
but when i delete two sub-meshes of this file to let just one(=one mesh for one material), it works !
i have nevertheless made a little function which is supposed to attribute the right material to the right mesh, i've searched an error in this part and in the ones associate to it but i have found nothing.
i've also made a cout by displaying "myLoader->getMatInfo(i)" and "i" values and it seems to be good...i don't know where to search.
here is the code (please take a look) :
the constructor which read the materials (at the end the little program which associate meshes to their materials:
the chunk which read the material color :Code :while (!file.eof()) { file.read((char*) &(chunk), sizeof (unsigned short int)); cout<<hex<<"chunk "<<chunk<<endl ; //cout<<sizeof (unsigned int)<<endl ; file.read((char*)&chunkSize, sizeof(unsigned int)); //cout<<dec<<"chunkSize "<<chunkSize<<endl ; switch(chunk) { case 0x4D4D: break; case 0x3D3D: break; case 0xafff: counterObjMat++ ; myObjects[counterObjMat].textureNames[0]='\0' ; break ; case 0xa000: //prend le nom des materials i=0 ; do { file.read(&tempChar, sizeof (char)); myObjects[counterObjMat].materialNames[i]=tempChar ; cout<<myObjects[counterObjMat].materialNames[i] ; i++ ; } while(tempChar != '\0'); /* if(tempChar == '\0') myObjects[counterObjMat].materialNames[i]= '\0' ;*/ break ; case 0xA010: break ; case 0xA020: break ; case 0x0010: loadColors2() ; break ; case 0x0011: loadColors() ; break ; case 0xa200: break ; case 0xa300: //myObjects[counterObjMat].textureNames[counterMat][0]= '\0' ; i=0 ;//prend le nom des textures do { file.read(&tempChar, sizeof (char)); myObjects[counterObjMat].textureNames[i]=tempChar ; // cout<<myObjects[counterObjMat].textureNames[i]; i++ ; } while(tempChar != '\0'); //cout<<"numéro obj et material "<<dec<<counterMat<<" " ; /* if(tempChar == '\0') myObjects[counterObjMat].textureNames[i]= '\0' ;*/ // counterObjMat++ ; break ; case 0x4000: do { file.read(&tempChar , sizeof (char)); //cout<<tempChar<<endl ; } while(tempChar != '\0'); break; case 0x4100: break; case 0x4110: //counterMat2= -1 ; counterObj++ ; cout<<"counterObj "<<dec<<counterObj<<endl ; loadVertices(); break ; case 0x4120: loadIndices() ; break ; case 0x4130: //counterMat2++ ; unsigned short int tmp ; //cout<<dec<<"chunkSize "<<chunkSize<<endl ; i=0 ; do { file.read(&tempChar, sizeof (char)); myObjects[counterObj].matNamesInsideChunkObject[i]=tempChar ; cout<<myObjects[counterObj].matNamesInsideChunkObject[i] ; i++ ; } while(tempChar != '\0'); /* if(tempChar == '\0') myObjects[counterObj].matNamesInsideChunkObject[i]= '\0' ;*/ /***lit le reste du chunk***/ file.read((char*) &(myObjects[counterObj].nbPoly), sizeof (short int)); for (polyCounter = 0 ; polyCounter < myObjects[counterObj].nbPoly ; polyCounter++) { file.read((char*) &(tmp), sizeof (unsigned short int)); } break ; case 0x4140: loadMapping() ; break ; case 0x4160: localAxis() ; break ; case 0x4600: lightPos() ; break ; case 0x4610: spotLight() ; break ; case 0x4700: camera() ; break ; /*case 0x2: case 0x100 :break ;*/ default: chunkSize -= 6 ; file.seekg(chunkSize, ios::cur); break ; } } for(j=0 ; j <= counterObj ; j++ ) { for(k=0 ; k <= counterObjMat ; k++)//!!! il n'y a pas forcément de texture(s) associée(s) a un matérial !!! { if(strcmp(myObjects[k].materialNames, myObjects[j].matNamesInsideChunkObject)==0) { matInfo.matIndices[j]=k ;//contient le n°du material correspondant a l'objet j cout<<dec<<"mat "<< matInfo.matIndices[j] << "avec objet"<<j<<endl ; //cout<<"texture "<<myObjects[k].textureNames<<" avec objet "<< k <<endl ; } } } file.close() ; }
a getter which return the value read in the little program at the end of the constructor :Code :void loader3ds::loadColors()//couleur ambiente { unsigned char red, green, blue ; file.read((char*) &red, sizeof (unsigned char)); file.read((char*) &green, sizeof (unsigned char)); file.read((char*) &blue, sizeof (unsigned char)); myObjects[counterObjMat].RGB[0] =(float) red / 255.0 ; myObjects[counterObjMat].RGB[1] =(float) green / 255.0 ; myObjects[counterObjMat].RGB[2] =(float) blue / 255.0 ; //!!!!voir si l'erreur ne vient pas de counterObjMat, le mettre a 0 quand on arrive dans le bloc 0x4000 cout<<"red " <<myObjects[counterObjMat].RGB[0] <<" green "<<myObjects[counterObjMat].RGB[1] <<" blue " <<myObjects[counterObjMat].RGB[2]<<endl ; }
the opengl part (display function)(please check glMaterialfv ):Code :int loader3ds::getMatInfo(int f) { return matInfo.matIndices[f] ; }
Code :for (i=0 ; i<=myLoader->getCounterObj() ; i++) { //glColor3f(1.0, 0.0, 0.0) ; glVertexPointer (3, GL_FLOAT, 0, &(myLoader->myObjects[i].myVertices[0][0])); glNormalPointer (GL_FLOAT, 0, &myLoader->myObjects[i].perVertexNormals[0][0]); glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, myLoader->myObjects[ myLoader->getMatInfo(i) ].RGB ) ; glDrawElements (GL_TRIANGLES, (myLoader->myObjects[i].nbPoly*3), GL_UNSIGNED_SHORT, &(myLoader->myObjects[i].myIndices[0][0])) ; }
Didn't seen all your post, it's quiete huge, and I'll have a deeper look surely later on this day.
The problem you stippled makes me remember one thing: you can find on the net many 3DS models, but much of them don't have materials. For avoiding this problem I decided to make a default material if needed. I know this is not the best advice but as long as 3DS files allow meshes without material (it means for ever) you'll have to find out any solution.
Also, I recently discovered there are two main ways a 3DS file is made: whether it uses hierarchical meshes, or whether it uses simple linked list for them (without childhood). I noticed that when trying wings3d.
Finally, and if I remember well as usual, 3ds materials don't take care of transparency but GL does. So have a look at that if everything's well.
PS: try also to avoid using hard id like 0x400. Just define a comprehensive data with that value. Don't see what purpose this value is, but let's say it's material:
#define material_id 0x400
Another thing, there's lib3ds, a very good library for loading and alterating 3ds files. It's pretty, and I've been using it for several years now (like four years). Have a look at it, it's free and might can help you.
Hope that helps.
ok thanks.