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 :

Problème de texture [OpenGL 1.x]


Sujet :

OpenGL

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2012
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2012
    Messages : 5
    Par défaut Problème de texture
    Bonjour à tous je viens vers vous, car j'ai un ptit gros problème et que cela fait plus de 3 jours que j'y suis dessus, sans résultat !
    Voila en ce moment, je développe un outil pédagogique pour OpenGL, j'utilise Qt/OpenGL sur QtCreator et j'ai un gros soucis de texture. J'ai beau bien faire tout ce qui est demandé mon Quad apparaît blanc (Pas de warning n'y rien)!!! (Et au passage j'active bien GL_TEXTURE_2D).

    Voila
    ma classe (glGridLight)->(glWidget->QGLWidget)

    glGridLight.h:
    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
     
    #include "glwidget.h"
    #include "gridlight.h"
    #include <qstring.h>
    #include <GL/glu.h>
    #include "figure.h"
     
    class LearningGrid;
     
    class GLGridLight : public GLWidget
    {
    private:
        GridLight* m_grid1;
        float m_x;
        float inc;
        GLuint Texture [1];
     
    public:
        GLGridLight ( QWidget* parent = 0 );
     
    private:
        virtual void draw();
        friend class LearningGridLight;
     
    };
     
    #endif // GLQUADBLENDINGLIGHT_H
    Et glGridLight.cpp

    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
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    #include "glgridlight.h"
    #include "gllight4p.h"
    #include "gllight3p.h"
    #include "gllight1p.h"
    #include "glmaterial4p.h"
    #include "glmaterial3p.h"
    #include "glmaterial1p.h"
    #include <qstring.h>
     
    extern int m_nbrQuad;
     
    GLGridLight::GLGridLight(QWidget* parent): GLWidget(parent)
    {
        m_nbrQuad=10000;
     
        GLlight4P* m_GLLight4P=new GLlight4P(QString("GL_LIGHT0"),QString("GL_AMBIENT"),1.0,0.0,0.0,1.0);
        GLlight4P* m_GLLight24P=new GLlight4P(QString("GL_LIGHT0"),QString("GL_DIFFUSE"),1.0,0.0,0.0,1.0);
        GLlight4P* m_GLLight34P=new GLlight4P(QString("GL_LIGHT0"),QString("GL_SPECULAR"),1.0,0.0,0.0,1.0);
        GLlight4P* m_GLLight44P=new GLlight4P(QString("GL_LIGHT0"),QString("GL_POSITION"),0.0,0.0,20.0,1.0);
     
        GLlight3P* m_GLLight3P=new GLlight3P(QString("GL_LIGHT0"),QString("GL_SPOT_DIRECTION"),0.0,0.0,-1.0);
     
        GLlight1P* m_GLLight1P=new GLlight1P(QString("GL_LIGHT0"),QString("GL_SPOT_EXPONENT"),0.0);
        GLlight1P* m_GLLight21P=new GLlight1P(QString("GL_LIGHT0"),QString("GL_SPOT_CUTOFF"),180.0);
        GLlight1P* m_GLLight31P=new GLlight1P(QString("GL_LIGHT0"),QString("GL_CONSTANT_ATTENUATTION"),1.0);
        GLlight1P* m_GLLight41P=new GLlight1P(QString("GL_LIGHT0"),QString("GL_LINEAR_ATTENUATTION"),0.0);
        GLlight1P* m_GLLight51P=new GLlight1P(QString("GL_LIGHT0"),QString("GL_QUADRATIC_ATTENUATTION"),0.0);
     
        GLmaterial4P* m_GLMaterial4P=new GLmaterial4P(QString("GL_FRONT_AND_BACK"),QString("GL_AMBIENT"),1.0,1.0,1.0,1.0);
        GLmaterial4P* m_GLMaterial24P=new GLmaterial4P(QString("GL_FRONT_AND_BACK"),QString("GL_DIFFUSE"),1.0,1.0,1.0,1.0);
        GLmaterial4P* m_GLMaterial34P=new GLmaterial4P(QString("GL_FRONT_AND_BACK"),QString("GL_SPECULAR"),1.0,1.0,1.0,1.0);
        GLmaterial4P* m_GLMaterial44P=new GLmaterial4P(QString("GL_FRONT_AND_BACK"),QString("GL_EMISSION"),0.0,0.0,0.0,1.0);
     
        GLmaterial3P* m_GLMaterial3P=new GLmaterial3P(QString("GL_FRONT_AND_BACK"),QString("GL_COLOR_INDEXES"),0.0,1.0,1.0);
     
        GLmaterial1P* m_GLMaterial1P=new GLmaterial1P(QString("GL_FRONT_AND_BACK"),QString("GL_SHININESS"),0.0);
     
        m_grid1=new GridLight(m_GLLight4P,
                              m_GLLight24P,
                              m_GLLight34P,
                              m_GLLight44P,
                              m_GLLight3P,
                              m_GLLight1P,
                              m_GLLight21P,
                              m_GLLight31P,
                              m_GLLight41P,
                              m_GLLight51P,
                              m_GLMaterial4P,
                              m_GLMaterial24P,
                              m_GLMaterial34P,
                              m_GLMaterial44P,
                              m_GLMaterial3P,
                              m_GLMaterial1P,false,false,false,true,true,true
                              );
    }
     
    void GLGridLight::draw()
    {
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
     
        glRotatef(rotationX, 1.0, 0.0, 0.0);
        glRotatef(rotationY, 0.0, 1.0, 0.0);
        glRotatef(rotationZ, 0.0, 0.0, 1.0);
     
        glEnable(GL_TEXTURE_2D);
        glEnable(GL_DEPTH_TEST);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     
        QImage buf_vitrail;
        QImage vitrail;
        buf_vitrail.load("Basketweave-texture.png");
        vitrail = QGLWidget::convertToGLFormat(buf_vitrail);
        glGenTextures(1, &Texture[0]);
        glBindTexture( GL_TEXTURE_2D, Texture[0] );
        glTexImage2D(GL_TEXTURE_2D, 0, 3, vitrail.width(), vitrail.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, vitrail.bits());
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
     
        glNormal3i(0,0,1);
        inc=20.0;
     
        glTranslatef(-10.5,-10.5,-45.0);
        switch(m_nbrQuad)
        {
            case 100:
            {
                m_x = 10;
            }
            break;
            case 400:
            {
                m_x = 20;
            }
            break;
            case 1600:
            {
                m_x = 40;
            }
            break;
            case 6400:
            {
                m_x = 80;
            }
            break;
            case 10000:
            {
                m_x = 100;
            }
            break;
        }
     
        for(float i=0;i<inc;i=i+(inc/m_x))
        {
            for(float j=0;j<inc;j=j+(inc/m_x))
            {
                glBindTexture(GL_TEXTURE_2D, Texture[0]);
                glBegin(GL_QUADS);
                glTexCoord2d(0,0);glVertex3f(GLfloat(i),GLfloat(j),0.0);
                glTexCoord2d(1,0);glVertex3f(GLfloat(i+(inc/m_x)),GLfloat(j),0.0);
                glTexCoord2d(1,1);glVertex3f(GLfloat(i+(inc/m_x)),GLfloat(j+(inc/m_x)),0.0);
                glTexCoord2d(0,1);glVertex3f(GLfloat(i),GLfloat(j+(inc/m_x)),0.0);
                glEnd();
            }
        }
        m_grid1->drawFigure();
    }
    Si jamais vous ciblez mon erreur je vous en serez bien reconnaissant

  2. #2
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2011
    Messages
    129
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

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

    Informations forums :
    Inscription : Novembre 2011
    Messages : 129
    Par défaut
    Bonjour,

    Quand tu souhaites charger ton image : assures toi de prendre le path entier car la fonction QImage::load(QString absolutePath) prend un chemin absolu.

    Tu pourrais donc faire quelques chose du style (dans la mesure où ton image est bien dans le répertoire courant):

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    QString vitrailpath = QDir::currentPath()+"/Basketweave-texture.png";
    if(QFile::exists(textpath)) {
        buf_vitrail.load(vitrailpath);
        vitrail = QGLWidget::convertToGLFormat(buf_vitrail);
     
        ...
    }
    Ensuite, tu as du PNG donc le format doit être GL_RGBA et non GL_RGB puis, dans la fonction glTexImage2D(...), tu dois passer le troisième paramètre à 4 puisque tu as 4 composantes couleurs : R (red), G(green), B(blue) et A : alpha


    Je ne sais pas si cela va fonctionner, mais cela devrait être mieux.

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2012
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2012
    Messages : 5
    Par défaut
    Salut,

    merci pour tes remarques, du coup j'ai pu identifié mon problème mais je ne l'ai malheureusement tjrs pas résolu.
    En effet en fessant le test pour savoir si mon fichier.png existait, je remarque que non !!!

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    QString vitrailpath = QDir::currentPath()+"/Basketweave-texture.png";
    if(QFile::exists(vitrailpath)) { ...
    Bizarre, pourtant quand je vérifie dans le dossier du projet, il y est belle et bien et mes fichiers sources sont au même niveau.

    Je comprend pas

  4. #4
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2011
    Messages
    129
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

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

    Informations forums :
    Inscription : Novembre 2011
    Messages : 129
    Par défaut
    Que donne l'affichage de vitrailpath ?

    cout << vitrailpath.toStdString() << endl;

    Fais attention : Le répertoire courant n'est pas celui de tes sources si tu as déclaré tes ressources dans un dossier à part !
    Je te conseille de mettre tes images dans un dossiers "resources" qui se trouve dans ton dossier de projet.

    Tu aurais donc plutôt un truc du genre :

    virailpath = QDir::currentPath() + "/resources/mon_image.png";

    Au final, si tes sources sont directement dans le dossier de ton projet, c'est probablement une histoire de "/" en plus ou en moins quelque part.

  5. #5
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2012
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2012
    Messages : 5
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    "/home/etudiant/Dropbox/Projet/QGLLearning-build-desktop-Qt_4_8_1_dans_le_PATH__Syst_me__Release/Basketweave.png"
    Ce qui veut bien dire que mon fichier existe belle et bien, mais alors pourquoi il respecte pas la condition de:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    if(QFile::exists(vitrailpath))
        {

    ???

  6. #6
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2012
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2012
    Messages : 5
    Par défaut
    C'est bon, problème résolu.
    J'avais juste pas mis le fichier dans le bon répertoire

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 10
    Dernier message: 08/06/2009, 11h30
  2. Problème de texture (ça rame !)
    Par Alex63 dans le forum OpenGL
    Réponses: 3
    Dernier message: 30/06/2006, 09h23
  3. [GLScene] Problème de textures
    Par Leobaillard dans le forum Composants VCL
    Réponses: 2
    Dernier message: 28/11/2005, 18h06
  4. Problème de texture GLscène
    Par [Silk] dans le forum Langage
    Réponses: 2
    Dernier message: 22/11/2005, 18h29
  5. Problème de texture
    Par filousnt dans le forum OpenGL
    Réponses: 4
    Dernier message: 26/06/2004, 20h11

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