Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1310 connectés 

  FORUM HardWare.fr
  Programmation

  [OpenGL] Pb chargement textures avec fichier 3ds ! Venez voir pliz !

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[OpenGL] Pb chargement textures avec fichier 3ds ! Venez voir pliz !

n°179117
WhitePoney
Moi ! Moi m'sieur !
Posté le 20-07-2002 à 11:22:50  profilanswer
 

Dans mon programme j'utilise le tutorial de digiben, http://www.gametutorials.com/Tutor [...] GL_Pg4.htm , le 3ds file loader.
 
Mais voilà je n'arrive absolument pas à avoir les textures de mes meshes 3ds (le meshe s'affiche parfaitement quand même). Pour ceux qui jetterons un oeil aux fichiers du tutorial, je pense que le problème vient des fonctions Init() et CreateTextures(), et draw().
 
 
Je pense aussi que il y a une merde au niveau des ids des textures, non ? Et je ne sais pas, lors du dessin de l'objet,  comment déterminer quelle texture charger pour le triangle en cours...
 
 
Bon ok je suis une grosse brèle mais j'ai vraiment besoin de résoudre ce problème de textures qui me bloque carrément :cry: !
 
 
:hello:


Message édité par WhitePoney le 21-07-2002 à 14:49:18
mood
Publicité
Posté le 20-07-2002 à 11:22:50  profilanswer
 

n°179149
WhitePoney
Moi ! Moi m'sieur !
Posté le 20-07-2002 à 14:21:22  profilanswer
 

eupeuuuu !
 
un exemple de chargeur serait le bienvenue, que je puisse méditer dessus !

n°179280
bjone
Insert booze to continue
Posté le 20-07-2002 à 20:30:02  profilanswer
 

très interressant comme question...
 
mais comme c'est pas du code que tu as fait toi, t'as un peu de mal à cerner le problème, et tout le monde aurra du mal aussi....
il peut y avoir 50 raison au blem...
 
1) est-tu sûr que l'image est bien chargée ? (problème de chemin d'accès, etc etc....)
 
2) as-tu pas un opérateur qui fout le bordel (c très vite fait)....

n°179284
bjone
Insert booze to continue
Posté le 20-07-2002 à 20:41:04  profilanswer
 

je viens de parcourir le loader et le reste
 
postes ton code ou tu utilises le loader....

n°179394
WhitePoney
Moi ! Moi m'sieur !
Posté le 21-07-2002 à 11:49:35  profilanswer
 

Voilà le bout de code où est peut-être le pb :
/////////////////////////// MAIN.CPP /////////////////////////
 
UINT gamesession_textures[30];
 
 
 
///////////////////////////// GAMESESSION.CPP /////////////////////
 
void GameSession::init()  
{
 
 glEnable(GL_TEXTURE_2D);
 glShadeModel(GL_SMOOTH);
 glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
 glClearDepth(1.0f);
 glEnable(GL_DEPTH_TEST);
 glDepthFunc(GL_LEQUAL);
 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);  
 
 glEnable(GL_LIGHT0);    
 glEnable(GL_LIGHTING);  
 glEnable(GL_COLOR_MATERIAL);    
 
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 gluPerspective(45.0f, 4/3, 0.1f, 200.0f);
 
}
 
 
 
 
 
///////////////////////////// 3DS.H ///////////////////////////////////////////:
 
 void load_textures(t3DModel *pModel)
 {
  // Go through all the materials
  for(int i = 0; i < pModel->numOfMaterials; i++)
  {
   // Check to see if there is a file name to load in this material
   if(strlen(pModel->pMaterials[i].strFile) > 0)
   {
    CreateTexture(gamesession_textures, pModel->pMaterials[i].strFile, i);    
   }
   // Set the texture ID for this material
   pModel->pMaterials[i].texureId = i;
 
  }
 
  // Here, we turn on a lighting and enable lighting.  We don't need to
  // set anything else for lighting because we will just take the defaults.
  // We also want color, so we turn that on
 
  glEnable(GL_LIGHT0);   // Turn on a light with defaults set
  glEnable(GL_LIGHTING);  // Turn on lighting
  glEnable(GL_COLOR_MATERIAL); // Allow color
 }
 
 
 
 
 
 
 
 void CreateTexture(UINT textureArray[], LPSTR strFileName, int textureID)
 {
  char ouca [20];
 
  AUX_RGBImageRec *pBitmap = NULL;
  FILE *pFile = NULL;
 
  if(!strFileName) return;
 
  strcpy(ouca,"data/" );
  strcat(ouca,strFileName);
  pFile = fopen(ouca,"r" );
 
  if(pFile)
  {
   pBitmap = auxDIBImageLoad(ouca);
  }
  else
  {
   MessageBox(NULL, "Couldn't find a texture!", "Error!", MB_OK);
   exit(0);
  }
 
  glGenTextures(1, &textureArray[textureID]);
 
  glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
 
  glBindTexture(GL_TEXTURE_2D, textureArray[textureID]);
 
  gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitmap->sizeX, pBitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data);
 
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);  
 
  if (pBitmap)
  {
   if (pBitmap->data)
   {
    free(pBitmap->data);
   }
 
   free(pBitmap);
  }
 }
 
 
 
 
 
 
 
 
 
void draw()
{
 int i;
 
 for( i = 0; i < theobject->numOfObjects; i++)
 {
  if(theobject->pObject.size() <= 0) break;
 
  t3DObject *pObject = &theobject->pObject[i];  
  if(pObject->bHasTexture) {
   // Turn on texture mapping and turn off color
   glEnable(GL_TEXTURE_2D);
 
   // Reset the color to normal again
   glColor3ub(255, 255, 255);
 
   // Bind the texture map to the object by it's materialID
   glBindTexture(GL_TEXTURE_2D, gamesession_textures[pObject->materialID]);
 
  } else {
 
   // Turn off texture mapping and turn on color
   glDisable(GL_TEXTURE_2D);
 
   // Reset the color to normal again
   glColor3ub(255, 255, 255);
 
  }
 
  // This determines if we are in wireframe or normal mode
  glBegin(GL_TRIANGLES);  // Begin drawing with our selected mode (triangles or lines)
 
   // Go through all of the faces (polygons) of the object and draw them
   for(int j = 0; j < pObject->numOfFaces; j++)
   {
    // Go through each corner of the triangle and draw it.
    for(int whichVertex = 0; whichVertex < 3; whichVertex++)
    {
     // Get the index for each point of the face
     int index = pObject->pFaces[j].vertIndex[whichVertex];
 
     // Give OpenGL the normal for this vertex.
     glNormal3f(pObject->pNormals[ index ].x, pObject->pNormals[ index ].y, pObject->pNormals[ index ].z);      
 
     // If the object has a texture associated with it, give it a texture coordinate.
     if(pObject->bHasTexture) {
 
      // Make sure there was a UVW map applied to the object or else it won't have tex coords.
      if(pObject->pTexVerts) {
       glTexCoord2f(pObject->pTexVerts[ index ].x, pObject->pTexVerts[ index ].y);
      }
     } else {
 
      // Make sure there is a valid material/color assigned to this object.
      // You should always at least assign a material color to an object,  
      // but just in case we want to check the size of the material list.
      // if the size is at least one, then we have a valid material.
 
      if(theobject->pMaterials.size() < pObject->materialID)  
 
      {
       // Get and set the color that the object is, since it must not have a texture
       BYTE *pColor = theobject->pMaterials[pObject->materialID].color;
 
       // Assign the current color to this model
       glColor3ub(pColor[0], pColor[1], pColor[2]);
       }
      }
     glVertex3f(pObject->pVerts[ index ].x , pObject->pVerts[ index ].y, pObject->pVerts[ index ].z);
    }
   }
 
  glEnd();  
 }
 
 
}
 
 
 
 
 
 
Voilà les bouts de code (très semblables  à ceux du tutorial ^^) ; a mon avis, dans la boucle de la  fonction  load_textures() il ne faudrait pas utiliser i comme index mais plutôt un indice général qui ne reviens pas  à 0 à chaque fois (j'ai essayé mais ça ne marche pas non plus :/ ). A noter que glGenTexture me renvoie 0 à chaque fois. J'ai essayé en n'utilisant pas cette fonction mais en mettant "à la main" un entier unique dans gamesession_textures mais ça ne marche pas non plus.  
 
Si mon objet à plusieurs matériaux, il faudrait que j'ajoute une variable dans la structure t3DObject qui indique où commencer à chercher les matériaux ? Mais comment savoir quelle texture utiliser à quel moment, si mon objet en à plusieurs ? Et comment savoir comment les "épingler" ?
 
Voilà, j'attends vos expliquations :hello: !


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation

  [OpenGL] Pb chargement textures avec fichier 3ds ! Venez voir pliz !

 

Sujets relatifs
comment faire un saut de ligne dans un txt a partir dun fichier php?Placer un fichier .exe dans son executable ! et la compression???
[OpenGL] calcul normal[VBA] Comment créer un boite de dialogue fichier/parcourir ?
[ PHP ] fOrcer le téléchargement d'un fichier .txtHELP !!! exécution d'un fichier batch sur 1 serveur distant
Pb avec Listview et chargement avec ACCESS[php][mail] attachement de fichier pb quand c superieur a 10 ko
[openGL]comment fait on pour importer des objet 3ds?[opengl] probleme avec la fonction glcolor3d
Plus de sujets relatifs à : [OpenGL] Pb chargement textures avec fichier 3ds ! Venez voir pliz !


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR