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 l'affichage de texture


Sujet :

OpenGL

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre du Club
    Inscrit en
    Octobre 2009
    Messages
    8
    Détails du profil
    Informations forums :
    Inscription : Octobre 2009
    Messages : 8
    Par défaut probleme avec l'affichage de texture
    bonjour tous le monde.
    j'ai un petit souci avec le placage d'une texture sur un cube simple.
    voila le code:
    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
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
     
     
    testGL1::testGL1(QWidget *parent) :  
        QGLWidget(parent)
    {
         clearColor = Qt::darkYellow;
        xRot = 0;
        yRot = 0;
        zRot = 0;
    }
     
    void testGL1::loadTexture()
    {
       texture[0] = bindTexture(QPixmap(QString(":/image.png")),  GL_TEXTURE_2D);
       glBindTexture( GL_TEXTURE_2D, texture[0] );
    }
     
    void testGL1::initializeGL()
    {
        loadTexture();
     
        glShadeModel(GL_SMOOTH);
        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        glClearDepth(1.0f);
        glEnable(GL_DEPTH_TEST);
        glDepthFunc(GL_LEQUAL);
        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
     
     
    }
     
    void testGL1::resizeGL(int width,int height)
    {
        if (height==0)			// Prevent A Divide By Zero By
            {
                    height=1;		// Making Height Equal One
            }
     
            glViewport(0,0,width,height);	// Reset The Current Viewport
     
            glMatrixMode(GL_PROJECTION);	// Select The Projection Matrix
            glLoadIdentity();		// Reset The Projection Matrix
     
            // Calculate The Aspect Ratio Of The Window
            gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
     
            glMatrixMode(GL_MODELVIEW);				// Select The Modelview Matrix
            glLoadIdentity();
    }
     
    void testGL1::paintGL()
    {
            qglClearColor(clearColor);
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
             glLoadIdentity();
     
             glEnable(GL_DEPTH_TEST);
             glTranslatef(0.0f,0.0f,-20.0F) ;
             glRotatef(-50.0F,1.0F,0.0F,0.0F);
     
             glRotatef(xRot/ 16.0f , 1.0f, 0.0f, 0.0f);
             glRotatef(yRot/ 16.0f , 0.0f, 1.0f, 0.0f);
             glRotatef(zRot/ 16.0f, 0.0f, 0.0f, 1.0f);
     
             for ( int i = 0 ; i < 6 ; i++ ) {
                 glPushMatrix();
                 glRotatef(i*360.0F/6,0.0F,0.0F,1.0F);
                 glTranslatef(6.0f,0.0f,0.0F) ;
                 SolidCube(1.0F) ;//
                 glPopMatrix(); }
     
              glDisable(GL_DEPTH_TEST);
              glFlush();
    }
     
     
    void testGL1::SolidCube(float c){
     
      glBindTexture(GL_TEXTURE_2D, texture[0]);
     
        c /= 1.0F;
      glBegin(GL_QUADS);
      glNormal3f(0.0F,0.0F,-1.0F);
      glTexCoord2f(0.0f, 0.0f); glVertex3f(c,c,-c);
      glTexCoord2f(1.0f, 0.0f); glVertex3f(c,-c,-c);
      glTexCoord2f(1.0f, 1.0f); glVertex3f(-c,-c,-c);
      glTexCoord2f(0.0f, 1.0f); glVertex3f(-c,c,-c);
      //glNormal3f(0.0F,0.0F,1.0F);
      glTexCoord2f(1.0f, 0.0f); glVertex3f(c,c,c);
      glTexCoord2f(1.0f, 1.0f); glVertex3f(-c,c,c);
      glTexCoord2f(0.0f, 1.0f); glVertex3f(-c,-c,c);
      glTexCoord2f(0.0f, 0.0f); glVertex3f(c,-c,c);
      //glNormal3f(-1.0F,0.0F,0.0F);
      glTexCoord2f(0.0f, 1.0f); glVertex3f(-c,c,-c);
      glTexCoord2f(0.0f, 0.0f); glVertex3f(-c,-c,-c);
      glTexCoord2f(1.0f, 0.0f); glVertex3f(-c,-c,c);
      glTexCoord2f(1.0f, 1.0f); glVertex3f(-c,c,c);
      //glNormal3f(1.0F,0.0F,0.0F);
      glTexCoord2f(1.0f, 1.0f); glVertex3f(c,c,c);
      glTexCoord2f(0.0f, 1.0f); glVertex3f(c,-c,c);
      glTexCoord2f(0.0f, 0.0f); glVertex3f(c,-c,-c);
      glTexCoord2f(1.0f, 0.0f); glVertex3f(c,c,-c);
      //glNormal3f(0.0F,-1.0F,0.0F);
     
      glTexCoord2f(1.0f, 0.0f); glVertex3f(-c,-c,c);
      glTexCoord2f(1.0f, 1.0f); glVertex3f(-c,-c,-c);
      glTexCoord2f(0.0f, 1.0f); glVertex3f(c,-c,-c);
      glTexCoord2f(0.0f, 0.0f); glVertex3f(c,-c,c);
      //glNormal3f(0.0F,1.0F,0.0F);
      glTexCoord2f(0.0f, 0.0f); glVertex3f(c,c,c);
      glTexCoord2f(1.0f, 0.0f); glVertex3f(c,c,-c);
      glTexCoord2f(1.0f, 1.0f); glVertex3f(-c,c,-c);
      glTexCoord2f(0.0f, 1.0f); glVertex3f(-c,c,c);
      glEnd();
     
    }
    ca compile sans probleme , mais la texture ne s'affiche pas, je vois plutot mes cubes en blanc.
    Merci d'avance

  2. #2
    Invité
    Invité(e)
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    glEnable(GL_TEXTURE_2D);

  3. #3
    Membre du Club
    Inscrit en
    Octobre 2009
    Messages
    8
    Détails du profil
    Informations forums :
    Inscription : Octobre 2009
    Messages : 8
    Par défaut
    merci de ta réponse.
    en fait, je l'ai mis a plusieurs endroits mais toujours rien, que du blanc.
    ou est ce ke je doit la mettre exactement

  4. #4
    Expert confirmé

    Avatar de dragonjoker59
    Homme Profil pro
    Software Developer
    Inscrit en
    Juin 2005
    Messages
    2 035
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Software Developer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2005
    Messages : 2 035
    Billets dans le blog
    12
    Par défaut
    normalement tu devrais pouvoir le mettre à l'initialisation d'OpenGL
    Si vous ne trouvez plus rien, cherchez autre chose...

    Vous trouverez ici des tutoriels OpenGL moderne.
    Mon moteur 3D: Castor 3D, presque utilisable (venez participer, il y a de la place)!
    Un projet qui ne sert à rien, mais qu'il est joli (des fois) : ProceduralGenerator (Génération procédurale d'images, et post-processing).

  5. #5
    Membre du Club
    Inscrit en
    Octobre 2009
    Messages
    8
    Détails du profil
    Informations forums :
    Inscription : Octobre 2009
    Messages : 8
    Par défaut
    j'ai deja éssayé, mais rien na changé.
    je veux éssayé maintenant avec un seul cube simplement, que je met directement dans paintGL(), voila le code.

    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
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
     
    testGL1::testGL1(QWidget *parent) :  //fenetrePrincipale *parent  int timerInterval,
        QGLWidget(parent)
    {
        clearColor = Qt::darkYellow;
        glInit() ;
    }
     
    testGL1::~testGL1()
    {
    }
     
    void testGL1::initializeGL()
    {
     
     
        glEnable(GL_TEXTURE_2D);
        loadTexture();
     
        glShadeModel(GL_SMOOTH);
        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        glClearDepth(1.0f);
     
        glEnable(GL_DEPTH_TEST);
        glDepthFunc(GL_LEQUAL);
        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
     
    }
     
    void testGL1::resizeGL(int width,int height)
    {
        if (height==0)			// Prevent A Divide By Zero By
            {
                    height=1;		// Making Height Equal One
            }
     
            glViewport(0,0,width,height);	// Reset The Current Viewport
     
            glMatrixMode(GL_PROJECTION);	// Select The Projection Matrix
            glLoadIdentity();		// Reset The Projection Matrix
     
            // Calculate The Aspect Ratio Of The Window
            gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
     
            glMatrixMode(GL_MODELVIEW);				// Select The Modelview Matrix
            glLoadIdentity();
    }
     
    void testGL1::paintGL()
    {
            qglClearColor(clearColor);
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer
     
            glLoadIdentity();
            glEnable(GL_TEXTURE_2D);
            glEnable(GL_DEPTH_TEST);
     
             glTranslatef(0.0f,0.0f,-20.0F) ;
     
     
            float  c = 1.0F;
           glPushMatrix();
          glGenTextures( 1, &texture );
          glBindTexture(GL_TEXTURE_2D, texture);
            glBegin(GL_QUADS);
            glTexCoord2f(0.0f, 0.0f); glVertex3f(c,c,-c);
            glTexCoord2f(1.0f, 0.0f); glVertex3f(c,-c,-c);
            glTexCoord2f(1.0f, 1.0f); glVertex3f(-c,-c,-c);
            glTexCoord2f(0.0f, 1.0f); glVertex3f(-c,c,-c);
     
            glTexCoord2f(1.0f, 0.0f); glVertex3f(c,c,c);
            glTexCoord2f(1.0f, 1.0f); glVertex3f(-c,c,c);
            glTexCoord2f(0.0f, 1.0f); glVertex3f(-c,-c,c);
            glTexCoord2f(0.0f, 0.0f); glVertex3f(c,-c,c);
     
            glTexCoord2f(0.0f, 1.0f); glVertex3f(-c,c,-c);
            glTexCoord2f(0.0f, 0.0f); glVertex3f(-c,-c,-c);
            glTexCoord2f(1.0f, 0.0f); glVertex3f(-c,-c,c);
            glTexCoord2f(1.0f, 1.0f); glVertex3f(-c,c,c);
     
            glTexCoord2f(1.0f, 1.0f); glVertex3f(c,c,c);
            glTexCoord2f(0.0f, 1.0f); glVertex3f(c,-c,c);
            glTexCoord2f(0.0f, 0.0f); glVertex3f(c,-c,-c);
            glTexCoord2f(1.0f, 0.0f); glVertex3f(c,c,-c);
     
            glTexCoord2f(1.0f, 0.0f); glVertex3f(-c,-c,c);
            glTexCoord2f(1.0f, 1.0f); glVertex3f(-c,-c,-c);
            glTexCoord2f(0.0f, 1.0f); glVertex3f(c,-c,-c);
            glTexCoord2f(0.0f, 0.0f); glVertex3f(c,-c,c);
     
            glTexCoord2f(0.0f, 0.0f); glVertex3f(c,c,c);
            glTexCoord2f(1.0f, 0.0f); glVertex3f(c,c,-c);
            glTexCoord2f(1.0f, 1.0f); glVertex3f(-c,c,-c);
            glTexCoord2f(0.0f, 1.0f); glVertex3f(-c,c,c);
            glEnd();
           glPopMatrix();
     
              glFlush();
    }
     
     
     
     
    void testGL1::loadTexture()
    {
     
      texture = bindTexture(QPixmap(QString(":/images/side1.png")),  GL_TEXTURE_2D);
     
      glGenTextures( 1, &texture );
       glBindTexture( GL_TEXTURE_2D, texture );
     
       glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
       glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
      deleteTexture(texture);
    }

  6. #6
    Invité
    Invité(e)
    Par défaut
    float c = 1.0F;
    glPushMatrix();
    glGenTextures( 1, &texture );
    glBindTexture(GL_TEXTURE_2D, texture);
    glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f); glVertex3f(c,c,-c);
    glTexCoord2f(1.0f, 0.0f); glVertex3f(c,-c,-c);
    Le glGenTextures( 1, &texture ) ici va te mettre une texture pas initialisée dans texture, que tu utilises à la place de celle que tu as chargé. Essaye plutôt de réutiliser l'id dans lequel tu as chargé quelque chose.

Discussions similaires

  1. [FLASH 8] Problème avec l'affichage sur le net
    Par bahabaha64 dans le forum Flash
    Réponses: 13
    Dernier message: 06/12/2006, 16h53
  2. Réponses: 5
    Dernier message: 27/09/2006, 14h07
  3. probleme avec l'affichage de donnés(statistique)
    Par The_Duck dans le forum Access
    Réponses: 1
    Dernier message: 12/07/2006, 14h19
  4. probleme avec l'affichage d'une de mes variables
    Par somatino dans le forum Langage
    Réponses: 12
    Dernier message: 02/03/2006, 15h39
  5. [CSS] Probleme avec l'affichage de mon site :
    Par vampyrx dans le forum Mise en page CSS
    Réponses: 1
    Dernier message: 28/08/2005, 23h23

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