IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

OpenGL Discussion :

probleme avec affichage de texture, glTexCoordPointer


Sujet :

OpenGL

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre chevronné

    Inscrit en
    Août 2007
    Messages
    302
    Détails du profil
    Informations forums :
    Inscription : Août 2007
    Messages : 302
    Par défaut probleme avec affichage de texture, glTexCoordPointer
    Bonjour,

    Je suis debutant en OpenGL et j'ai un petit soucis pour mapper une texture sur une surface. Elle refuse tout simplement de s'afficher (la surface s'affiche tout en blanc)... Comme ca fait des heures que je tourne en rond sans trouver la source du probleme.... je m'en remets a vous! j'ai essaye de mettre autant d'information que possible ci-dessous.

    Merci d'avance!

    Greg

    mon code d'initialisation:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
        void initOpenGL(void)
        {
          glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
          glutInitWindowSize(500,500);
          glutInitWindowPosition(100,100);
          glutCreateWindow("Close me to terminate");
          glClearColor(0.3, 0.3, 0.5, 0.0);
          glMatrixMode(GL_PROJECTION);
          glLoadIdentity();
        }
    initialisation de ma texture:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
     
         int s = 256; // 256*256 texture
         Vector<Point3D<unsigned char> > tex(s*s, true); // RGB texture 
         Vector<pair<float, float> > texMap(M*N, true); // mapping vertex->texture
     
          // fill texture with dummy values
          int k = 0;
          for (int i = 0; i < s; ++i){
            for (int j = 0; j < s; ++j) {
              tex[k].x = 255*float(i) / s;
              tex[k].y = 255*float(i) / s;
              tex[k].z = 255*float(i) / s;
              k ++;
            }
          }
          for (int i = 0; i < M; ++i) {
            for (int j = 0; j < N; ++j)
            {
              texMap[k].first = float(i) / M;
              texMap[k].second = float(j) / N;
     
              k ++;
            }
          }
     
          glEnable (GL_TEXTURE_2D);
          GL_CHECK_ERROR();
     
          glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
          GL_CHECK_ERROR();
          glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
          GL_CHECK_ERROR();
          glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
          GL_CHECK_ERROR();
          glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
          GL_CHECK_ERROR();
          glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
          GL_CHECK_ERROR();
     
          // generate one new identifier for the texture
          glGenTextures(1, &textureHandle);
          GL_CHECK_ERROR();
     
          // bind it to a 2d texture, therearfter GL_TEXTURE_2D will refer to 'textureHandle'
          glBindTexture(GL_TEXTURE_2D, textureHandle);
          GL_CHECK_ERROR();
     
          // specifiy the texture to OpenGL
          glTexImage2D(GL_TEXTURE_2D,     // refers to textureHandle, as it was bound before
            0,                 // level op mipmap (not used for now...)
            GL_RGB,            // texture internal format is RGB (what will be in the GPU)
            s,s,
            //Mtex, Ntex,        // size of the texture
            0,                 // border size, color can be set with GL_TEXTURE_BORDER_COLOR parameter
            GL_RGB,            // format of the array passed in parameter below is RGB
            GL_UNSIGNED_BYTE,// texture are passed in 8 bits per channel
            tex.getInternalData()
            );
          GL_CHECK_ERROR();
    et, finalement le code d'affichage...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
     
        virtual void draw(const Camera& cam)
        {          
          glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
          glMatrixMode(GL_PROJECTION);
          glLoadIdentity();
          gluPerspective(90.0, // <- Y camera field-of-view, in degrees 
    	      glutGet(GLUT_WINDOW_WIDTH)/(float)glutGet(GLUT_WINDOW_HEIGHT), // viewport's aspect ratio 
    	      0.001, // Near clipping plane depth 
    	      200000.0 // Far clipping plane depth 
          ); 
          lookAt(cam_);
     
          static bool textureEnabled = true;
          static bool colorEnabled = false;
     
          glEnable (GL_TEXTURE_2D);
     
          // we'll draw an array of vertices
          glEnableClientState(GL_VERTEX_ARRAY);
          GL_CHECK_ERROR();
     
          // with textures...
          if (textureEnabled) {
            glEnableClientState(GL_TEXTURE_COORD_ARRAY);
            GL_CHECK_ERROR();
          }
     
          // and colors
          if (colorEnabled) {
            glEnableClientState(GL_COLOR_ARRAY);
            GL_CHECK_ERROR();
          }
     
          // give OpenGL a pointer to the vertices
          glVertexPointer(3, GL_FLOAT, 0, vertices.getInternalData());
          GL_CHECK_ERROR();
     
          // give OpenGL a pointer to the texture
          if (textureEnabled) {
            glTexCoordPointer(2, GL_FLOAT, 0, texMap.getInternalData() ); 
            GL_CHECK_ERROR();
          }
     
          // give OpenGL a pointer to the colors
          if (colorEnabled) {
            glColorPointer( 3, GL_UNSIGNED_BYTE, 0, tex.getInternalData() );
            GL_CHECK_ERROR();
          }
     
          glDrawElements(GL_TRIANGLE_STRIP, indices.size(), GL_UNSIGNED_INT, indices.getInternalData() );
          GL_CHECK_ERROR();
          //glDrawArrays(GL_POINTS, 0, vertices.size());
     
          if (colorEnabled) {
            glDisableClientState( GL_COLOR_ARRAY );        
            GL_CHECK_ERROR();
          }
     
          if (textureEnabled) {      
            glDisableClientState(GL_TEXTURE_COORD_ARRAY);
            GL_CHECK_ERROR();
          }
     
          glDisableClientState(GL_VERTEX_ARRAY);
          GL_CHECK_ERROR();
        }
    Ceci est suivit d'un swapBuffer().
    notez que ca fonctionne si j'utilise "glColorPointer". GL_CHECK_ERROR() juste teste glGetError(), dans mon cas glGetError vaut toujours GL_NO_ERROR.
    Help

  2. #2
    Membre expérimenté
    Homme Profil pro
    Inscrit en
    Mars 2005
    Messages
    249
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Bas Rhin (Alsace)

    Informations forums :
    Inscription : Mars 2005
    Messages : 249
    Par défaut
    J'ai l'impression que le problème est au chargement de la texture... pas sûr de comprendre exactement tout ce que tu fais, et je ne sais pas si ta fonction "tex.getInternalData()" applique une transformation quelconque aux texels, mais j'ai l'impression que tes infos RGB sont données en int 0->255 , alors qu'à ma connaissance OpenGl veut du float 0->1 , ce qui expliquerait pourquoi la texture est blanche.
    [edit] : ah non, j'ai rien dit, le GL_UNSIGNED_BYTE indique que c'est passé en unsigned char comme tu fais...

Discussions similaires

  1. problem avec affichage de text
    Par dmichel dans le forum GLUT
    Réponses: 2
    Dernier message: 27/02/2007, 09h50
  2. [Configuration] probleme avec affichage photo
    Par arti2004 dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 3
    Dernier message: 17/06/2006, 23h23
  3. Réponses: 3
    Dernier message: 01/06/2006, 19h45
  4. Probleme avec affichage de date
    Par Wongmaster dans le forum Access
    Réponses: 27
    Dernier message: 24/12/2004, 20h51
  5. Probleme d affichage de texture
    Par venomelektro dans le forum OpenGL
    Réponses: 1
    Dernier message: 27/09/2004, 15h07

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo