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

  FORUM HardWare.fr
  Programmation
  C

  [OpenGL] les textures ne s'affichent pas

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[OpenGL] les textures ne s'affichent pas

n°1960922
cityhunter​xyz
100111011010010011 bip!
Posté le 27-01-2010 à 16:40:04  profilanswer
 

Bonjour,
je débute en OpenGL et je voulais faire un carré texturé à base de vertex array. je crèe bien le carré mais il n'est pas texturé. si j'assigne des couleurs au vertex, cela se passe bien. voici les parties de code correspondantes :
 

Code :
  1. //////////////////// Third VO creation
  2. ///Set*Array sont des méthodes de l'objet pour stocker les informations et le tableau de données
  3. /// le premier argument est les type, le second le nombre de composantes par entrée, le 3ième  
  4. // c'est le tableau lui mm et le 4ième le nombre d'élements
  5.                                         rectangleTextureVO =  new VertexObject();
  6.                                         GLfloat Vertices3[4][3] = { {  0.0,   0.0, 0.0}, //0
  7.                                                 {    w,   0.0, 0.0}, //1
  8.                                                 {    w,     h, 0.0}, //2
  9.                                                 {  0.0,     h, 0.0}};//3
  10.                                         rectangleTextureVO->SetVerticesArray(DataArray::FLOAT, 3, Vertices3, 4);
  11.                                         GLubyte indices3[] = {
  12.                                                 0, 1, 2, 3
  13.                                                 };
  14.                                         rectangleTextureVO->SetFaceIndicesArray (DataArray::UINT8_T, 4, indices, 1);
  15.                                         rectangleTextureVO->AddTexture(texture);
  16. ///////////////////// drawing part
  17.                                         glLoadIdentity();
  18.                                         glTranslatef(100.0f,100.0f,-60.0f);
  19.                                         glRotatef(45.0f, 1.0f, 1.0f, 1.0f);
  20.                                         rectangleTextureVO->draw();


draw() se décompose comme suit :

Code :
  1. int VertexObject::draw()
  2. {
  3.     IN("\n" );
  4.     glPushClientAttrib(0);
  5.     if (this->Colors != NULL)
  6.     {
  7.         glEnableClientState(GL_COLOR_ARRAY);
  8.         printf("%d %d %d\n" ,Colors->ComponentsCount, Colors->datatype_t,  Colors->array.all);
  9.         glColorPointer(Colors->ComponentsCount, Colors->datatype_t, 0, Colors->array.all);
  10.     }
  11.     if (this->Normals != NULL)
  12.     {
  13.         glEnableClientState(GL_NORMAL_ARRAY);
  14.         glNormalPointer(Normals->datatype_t, 0, Normals->array.all);
  15.     }
  16.     if (this->TextureData != NULL)
  17.     {
  18.             this->TextureData->ClientActiveTexture(GL_TEXTURE0);
  19.     }
  20.     if (this->Vertices != NULL && this->Indices != NULL)
  21.     {
  22.         glEnableClientState(GL_VERTEX_ARRAY);
  23.         printf("%d %d %d\n" ,Vertices->ComponentsCount, Vertices->datatype_t,  Vertices->array.all);
  24.         glVertexPointer(Vertices->ComponentsCount, Vertices->datatype_t, 0, Vertices->array.all);
  25.         //go through our index array and draw our vertex array
  26.         GLenum mode;
  27.         if ( Indices->ComponentsCount == 3 ) mode = GL_TRIANGLES;
  28.         else mode = GL_QUADS;
  29.         glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_color);
  30.         glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  31.         glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  32.         glMaterialf(GL_FRONT, GL_SHININESS, high_shininess);
  33.         glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
  34.         //Indices->count has allready the right count of Indices (Indices->ComponentsCount*nbfaces)
  35.         glDrawElements(mode,
  36.                         this->Indices->count * this->Indices->ComponentsCount,
  37.                         this->Indices->datatype_t,
  38.                         this->Indices->array.all);
  39.     }
  40.     if (this->TextureData != NULL)
  41.     {
  42.             this->TextureData->ReleaseTecture();
  43.             /* for multitexturing
  44.             //unbind the texture occupying the first texture unit
  45.             glActiveTextureARB( GL_TEXTURE0_ARB );
  46.             glDisable( GL_TEXTURE_2D );
  47.             glBindTexture( GL_TEXTURE_2D, 0 );
  48.             */
  49.     }
  50.     glPopClientAttrib();
  51.     debug::Instance()->FlushGL();
  52.     OUT("\n" );
  53.     return 0;
  54. }


et this->TextureData->ClientActiveTexture(GL_TEXTURE0); fait ceci  

Code :
  1. void Texture::ClientActiveTexture( GLenum texture )
  2. {
  3.         if (ID == 0)
  4.         {
  5.                 glGenTextures(1,&(this->ID));
  6.                 glBindTexture(TextureType,ID);
  7.                 glTexImage2D (
  8.                         TextureType,
  9.                         0,
  10.                         this->ComponentsCount,
  11.                         this->width,
  12.                         this->height,
  13.                         0,
  14.                         this->format,
  15.                         this->type,
  16.                         pdata
  17.                      );
  18.                  glTexParameteri(TextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  19.                  glTexParameteri(TextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  20.         }
  21.         texturePipeID = texture;
  22.         glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  23.         glDisable( GL_BLEND );
  24.         glClientActiveTexture(texturePipeID);
  25.         glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  26.         glTexCoordPointer(TexCoord->ComponentsCount,
  27.                         (GLenum)*(TexCoord),
  28.                         0,
  29.                         TexCoord->array.all);
  30.         //bind the primary texture to the first texture unit
  31.         glActiveTextureARB( texturePipeID );
  32.         glEnable( TextureType );
  33.         glBindTexture( TextureType, ID);
  34. }


 
j'ai un doute sur la partie glBindTexture.... je ne suis pas sur qu'elle soit bien placée
merci d'avance
cordialement
JLM

mood
Publicité
Posté le 27-01-2010 à 16:40:04  profilanswer
 

n°1960951
bjone
Insert booze to continue
Posté le 27-01-2010 à 19:05:40  profilanswer
 

Sont où les UVs ?

n°1961010
cityhunter​xyz
100111011010010011 bip!
Posté le 27-01-2010 à 21:49:27  profilanswer
 

bjone a écrit :

Sont où les UVs ?


ah oui j'oubliais :

Code :
  1. NCRC_AutoPtr<Texture> texture(new PPMTexture(texturename));
  2. GLint TexCoord[8][2] =
  3. { { texture->Width()    , 0}, // 0
  4.          { texture->Width()*2/3, 0 }, //1
  5.          { texture->Width()*2/3, texture->Height() }, //2
  6.          { texture->Width()    , texture->Height() }, //3
  7.          { 0                   , 0 }, //4
  8.          { texture->Width()/3  , 0 }, //5
  9.          { texture->Width()/3  , texture->Height() }, //6
  10.          { 0                   , texture->Height() }}; //7
  11. NCRC_AutoPtr<DataArray> texcoord(new DataArray(8, 2, DataArray::FLOAT, TexCoord));
  12. texture->SetTexCoord(texcoord);

n°1961204
bjone
Insert booze to continue
Posté le 28-01-2010 à 12:56:03  profilanswer
 

t'as essayé avec gDEBugger voir si il pouvait t'aider ?

n°1961260
cityhunter​xyz
100111011010010011 bip!
Posté le 28-01-2010 à 14:57:36  profilanswer
 

je suis en train d'obtenir une license d'évaluation, je suis derrière un proxy et donc ne peut utiliser les moyens livrés....  
en attendant je continue à chercher.... merci

n°1961420
cityhunter​xyz
100111011010010011 bip!
Posté le 28-01-2010 à 23:06:12  profilanswer
 

bon il m'a aidé à trouver un pb qui n'avait pas de relation (indirect rendering sous X)... mais maintenant il ne fait que se bloquer... il ne rends jamais la main, ne répond pas au clavier... bref je suis obligé de le tuer... personne ne connaitrait plutôt une lib permettant de tracer les appel OpenGL?

n°1962675
cityhunter​xyz
100111011010010011 bip!
Posté le 03-02-2010 à 16:05:16  profilanswer
 
n°1962809
bjone
Insert booze to continue
Posté le 04-02-2010 à 01:50:44  profilanswer
 

Exact pour le int/float, j'avais pas vu pourtant c'était dans ton post.

n°1962819
cityhunter​xyz
100111011010010011 bip!
Posté le 04-02-2010 à 08:26:04  profilanswer
 

au fait merci, gDEBugger m'a aidé à trouver un autre potentiel problème : le contexte n'était pas créé dans le mm thread, il semble que cela affectait le chargement des textures


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

  [OpenGL] les textures ne s'affichent pas

 

Sujets relatifs
Vertex Buffer Object - OpenGLQt + Extensions OpenGL
OpenGL, réccupération d'un rendu offscreen[Débutant][OpenGL ES] Problème affichage textures
java et opengl , une histoire de haine ?Thread concurrency ? (OpenGL vs STK)
Besoin d'aide OpenGL/GLUT[C / OpenGL] Comment faire un deplacement libre (si possible: freefly
[GLSL OPENGL] Light Culling pour une maison 
Plus de sujets relatifs à : [OpenGL] les textures ne s'affichent pas


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