Bonjour à tous,
Nom : Sélection_006.png
Affichages : 307
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);
}