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 visualisation cubemap (OpenGL4.X + Qt5) [OpenGL 4.x]


Sujet :

OpenGL

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2012
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2012
    Messages : 22
    Par défaut Problème visualisation cubemap (OpenGL4.X + Qt5)
    Bonjour à tous,
    Nom : Sélection_006.png
Affichages : 308
Taille : 176,5 Ko
    J'ai un petit soucis au niveau de la visualisation de mon cubemap avec Qt. Je désactive mon depth buffer pour pouvoir afficher le cubemap en fond. Le problème est que je visualise quand même mon cube avec les bonnes textures...
    Je ne sais pas où j'ai loupé un truc? Si vous avez une idée, j'en serais heureux que vous puissiez m'aider et je vous remercie d'avance. Voici mon code de construction et de rendu avec les shaders.
    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
    void CubeMapMaterial::init(const std::string &path)
    {
        QOpenGLFunctions_4_3_Core *f = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_4_3_Core>();
        GLfloat vertices[] = {
        // Positions          
        -1.0f,  1.0f, -1.0f,
        -1.0f, -1.0f, -1.0f,
         1.0f, -1.0f, -1.0f,
         1.0f, -1.0f, -1.0f,
         1.0f,  1.0f, -1.0f,
        -1.0f,  1.0f, -1.0f,
        -1.0f, -1.0f,  1.0f,
        -1.0f, -1.0f, -1.0f,
        -1.0f,  1.0f, -1.0f,
        -1.0f,  1.0f, -1.0f,
        -1.0f,  1.0f,  1.0f,
        -1.0f, -1.0f,  1.0f,
         1.0f, -1.0f, -1.0f,
         1.0f, -1.0f,  1.0f,
         1.0f,  1.0f,  1.0f,
         1.0f,  1.0f,  1.0f,
         1.0f,  1.0f, -1.0f,
         1.0f, -1.0f, -1.0f,
        -1.0f, -1.0f,  1.0f,
        -1.0f,  1.0f,  1.0f,
         1.0f,  1.0f,  1.0f,
         1.0f,  1.0f,  1.0f,
         1.0f, -1.0f,  1.0f,
        -1.0f, -1.0f,  1.0f,
        -1.0f,  1.0f, -1.0f,
         1.0f,  1.0f, -1.0f,
         1.0f,  1.0f,  1.0f,
         1.0f,  1.0f,  1.0f,
        -1.0f,  1.0f,  1.0f,
        -1.0f,  1.0f, -1.0f,
        -1.0f, -1.0f, -1.0f,
        -1.0f, -1.0f,  1.0f,
         1.0f, -1.0f, -1.0f,
         1.0f, -1.0f, -1.0f,
        -1.0f, -1.0f,  1.0f,
         1.0f, -1.0f,  1.0f
        };
        m_vao.create();
        m_vbo = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
        m_vbo->create();
        if (m_vao.isCreated())
        {
            m_vao.bind();
            m_vbo->bind();
            m_vbo->allocate(vertices, sizeof(vertices));
            m_vbo->setUsagePattern(QOpenGLBuffer::StaticDraw);
            f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
            f->glEnableVertexAttribArray(0);
            m_vao.release();
        }
     
        QImage sidePosX = QImage(QString::fromStdString(path)+ "/xpos.png").mirrored().convertToFormat(QImage::Format_RGBA8888);
        QImage sidePosY = QImage(QString::fromStdString(path)+ "/ypos.png").mirrored().convertToFormat(QImage::Format_RGBA8888);
        QImage sidePosZ = QImage(QString::fromStdString(path)+ "/zpos.png").mirrored().convertToFormat(QImage::Format_RGBA8888);
        QImage sideNegX = QImage(QString::fromStdString(path)+ "/xneg.png").mirrored().convertToFormat(QImage::Format_RGBA8888);
        QImage sideNegY = QImage(QString::fromStdString(path)+ "/yneg.png").mirrored().convertToFormat(QImage::Format_RGBA8888);
        QImage sideNegZ = QImage(QString::fromStdString(path)+ "/zneg.png").mirrored().convertToFormat(QImage::Format_RGBA8888);
     
        m_textureCubeMap = new QOpenGLTexture(QOpenGLTexture::TargetCubeMap);
        m_textureCubeMap->create();
        m_textureCubeMap->bind();
        m_textureCubeMap->setSize(sidePosX.width(), sidePosX.height(), sidePosX.depth());
        m_textureCubeMap->setFormat(QOpenGLTexture::RGBA8_UNorm);
        m_textureCubeMap->allocateStorage();
        m_textureCubeMap->setData(0, 0, QOpenGLTexture::CubeMapPositiveX, QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, (const void*)sidePosX.constBits(), 0);
        m_textureCubeMap->setData(0, 0, QOpenGLTexture::CubeMapPositiveY, QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, (const void*)sidePosY.constBits(), 0);
        m_textureCubeMap->setData(0, 0, QOpenGLTexture::CubeMapPositiveZ, QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, (const void*)sidePosZ.constBits(), 0);
        m_textureCubeMap->setData(0, 0, QOpenGLTexture::CubeMapNegativeX, QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, (const void*)sideNegX.constBits(), 0);
        m_textureCubeMap->setData(0, 0, QOpenGLTexture::CubeMapNegativeY, QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, (const void*)sideNegY.constBits(), 0);
        m_textureCubeMap->setData(0, 0, QOpenGLTexture::CubeMapNegativeZ, QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, (const void*)sideNegZ.constBits(), 0);
        m_textureCubeMap->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear);
        m_textureCubeMap->setWrapMode(QOpenGLTexture::DirectionS, QOpenGLTexture::ClampToEdge);
        m_textureCubeMap->setWrapMode(QOpenGLTexture::DirectionT, QOpenGLTexture::ClampToEdge);
        m_textureCubeMap->setWrapMode(QOpenGLTexture::DirectionR, QOpenGLTexture::ClampToEdge);
        m_textureCubeMap->release();
    }
    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
    void CubeMapMaterial::render()
    {
        QOpenGLFunctions_4_3_Core *f = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_4_3_Core>();
    	if(m_program)
    	{
            m_program->bind();
            f->glDepthMask(GL_FALSE);
    	mat4 mat = Engine::currentCamera->getProjectionMatrix() * Engine::currentCamera->getViewMatrix();
    	QMatrix4x4 VP = mat4ToMatrix4x4(mat);
            m_program->setUniformValue(m_locations[0], VP);
        	m_program->setUniformValue(m_locations[1], 0);
     
            m_vao.bind();
            m_textureCubeMap->bind();
            m_vao.release();
        	m_program->release();
            f->glDepthMask(GL_TRUE);
    	}
    }
    Les shaders
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    #version 430 core
     
    layout (location = 0) in vec3 position;
     
    uniform mat4 VP;
    out vec3 texCoords;
     
    void main()
    {
        gl_Position = (VP * vec4(position.xyz, 1.0));//.xyww;
        texCoords = position;
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    #version 430 core
     
    out vec4 color;
    in vec3 texCoords;
    uniform samplerCube cubemap;
     
    void main()
    {
        color = texture(cubemap, texCoords);
    }

  2. #2
    Expert confirmé

    Avatar de dragonjoker59
    Homme Profil pro
    Software Developer
    Inscrit en
    Juin 2005
    Messages
    2 034
    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 034
    Billets dans le blog
    12
    Par défaut
    Salut!
    Dans ton shader, tu as commenté le .xyww.
    C'est nécessaire pour le rendu de skybox, essaie de le réactiver ?
    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).

  3. #3
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2012
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2012
    Messages : 22
    Par défaut
    Je l'ai fait, mais je n'obtiens qu'un fond blanc. Cela ne vient pas de mon depth buffer?

  4. #4
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2012
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2012
    Messages : 22
    Par défaut
    Alors j'ai réussis à trouver mon erreur. Je n'avais pas enlevé la partie translation de la matrice de vue (matrice de transformation du repère monde vers le repère caméra).
    Par contre j'ai un autre problème, cette fois-ci visuelle.
    Nom : Sélection_007.png
Affichages : 285
Taille : 385,5 Ko
    Est-ce un problème de précision du depth buffer? Ou est-ce un problème d'aliasing?

  5. #5
    Expert confirmé

    Avatar de dragonjoker59
    Homme Profil pro
    Software Developer
    Inscrit en
    Juin 2005
    Messages
    2 034
    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 034
    Billets dans le blog
    12
    Par défaut
    J'aurais dit qu'il faut utiliser le clamp to edge, mais c'est déjà ce que tu fais, alors vérifie que les images que tu as n'ont pas de bordure.
    Et vérifie aussi que les texture Qt n'ont pas par défaut une bordure de définie
    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).

  6. #6
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2012
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2012
    Messages : 22
    Par défaut
    Merci pour tout, j'avais changé de paramètre pour la texture. J'ai remis en mode CLAMP_TO_EDGE. Tout fonctionne, nickel!

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

Discussions similaires

  1. problème visualisation cellules
    Par breva64 dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 26/01/2009, 12h12
  2. Problème Visualisation Code
    Par slopez dans le forum BOUML
    Réponses: 12
    Dernier message: 08/12/2008, 09h00
  3. Problème visualisation DIV et combo
    Par nicotine dans le forum Balisage (X)HTML et validation W3C
    Réponses: 2
    Dernier message: 20/03/2007, 15h17
  4. [C#]Problème visualisation focus
    Par guiguesba dans le forum Windows Forms
    Réponses: 3
    Dernier message: 14/12/2006, 14h55
  5. problème visualisation d'images avec wampserver
    Par oli-ola dans le forum Apache
    Réponses: 8
    Dernier message: 29/08/2006, 23h26

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