Bonjour à tous,

Je rencontre un problème dans un projet dans lequel j'essaye d'afficher pour le moment de simples points 2D stockés dans un VBO.
Puisque cela ne fonctionne pas, je me suis naturellement tourné vers un paterne "type exemple" trouvé sur internet, dans lequel on affiche un cube 3D. L'idée est de pouvoir afficher quelque chose au moins.
Jusqu'à là pas de soucis.

En revanche lorsque je l'implémente dans mon code l'exemple type du cube 3D, cela ne fonctionne pas . Pouvez-vous m'aiguiller ?

Voici l'architecture de la partie du projet qui nous intéresse :
1. Fichier mainwindow.cpp : Fenêtre d'accueil qui lance des threads, et qui contient le QOpenGLWidget dans sa partie mainwindow.ui
2. MyOpenGLWidget.cpp : Classe qui hérite du widget OpenGL intégré dans mainwindow.ui

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
#include "myopenglwidget.h"
#include <GL/glu.h>
#include <QGLWidget>
#include <QThread>
#include <QOpenGLFunctions>
 
MyOpenGLWidget::MyOpenGLWidget(QWidget *parent) : QOpenGLWidget (parent)
{
}
 
MyOpenGLWidget::~MyOpenGLWidget()
{
    delete pointShaderProgram;
}
 
void MyOpenGLWidget::initializeGL()
{
    initializeOpenGLFunctions();
    glClearColor(0.0f,0.0f,0.3f,1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
    pointShaderProgram = new QOpenGLShaderProgram(this);
    pointShaderProgram->addShaderFromSourceFile(QOpenGLShader::Fragment, "/home/rv/Bureau/Sniffer-master/src/fragmentshader.fsh");
    pointShaderProgram->addShaderFromSourceFile(QOpenGLShader::Vertex, "/home/rv/Bureau/Sniffer-master/src/pointshader.vsh");
    pointShaderProgram->link();
    pointShaderProgram->bind();
 
    //Initialize Cube3D
    cubeAlpha = 25;
    cubeBeta = -25;
    cubeDistance = 2.5;
    cubeVertices << QVector3D(-0.5, -0.5,  0.5) << QVector3D( 0.5, -0.5,  0.5) << QVector3D( 0.5,  0.5,  0.5) // Front
                 << QVector3D( 0.5,  0.5,  0.5) << QVector3D(-0.5,  0.5,  0.5) << QVector3D(-0.5, -0.5,  0.5)
                 << QVector3D( 0.5, -0.5, -0.5) << QVector3D(-0.5, -0.5, -0.5) << QVector3D(-0.5,  0.5, -0.5) // Back
                 << QVector3D(-0.5,  0.5, -0.5) << QVector3D( 0.5,  0.5, -0.5) << QVector3D( 0.5, -0.5, -0.5)
                 << QVector3D(-0.5, -0.5, -0.5) << QVector3D(-0.5, -0.5,  0.5) << QVector3D(-0.5,  0.5,  0.5) // Left
                 << QVector3D(-0.5,  0.5,  0.5) << QVector3D(-0.5,  0.5, -0.5) << QVector3D(-0.5, -0.5, -0.5)
                 << QVector3D( 0.5, -0.5,  0.5) << QVector3D( 0.5, -0.5, -0.5) << QVector3D( 0.5,  0.5, -0.5) // Right
                 << QVector3D( 0.5,  0.5, -0.5) << QVector3D( 0.5,  0.5,  0.5) << QVector3D( 0.5, -0.5,  0.5)
                 << QVector3D(-0.5,  0.5,  0.5) << QVector3D( 0.5,  0.5,  0.5) << QVector3D( 0.5,  0.5, -0.5) // Top
                 << QVector3D( 0.5,  0.5, -0.5) << QVector3D(-0.5,  0.5, -0.5) << QVector3D(-0.5,  0.5,  0.5)
                 << QVector3D(-0.5, -0.5, -0.5) << QVector3D( 0.5, -0.5, -0.5) << QVector3D( 0.5, -0.5,  0.5) // Bottom
                 << QVector3D( 0.5, -0.5,  0.5) << QVector3D(-0.5, -0.5,  0.5) << QVector3D(-0.5, -0.5, -0.5);
    glGenBuffers(1, &cubeVBO);
    glBindBuffer(GL_ARRAY_BUFFER, cubeVBO);
    glBufferData(GL_ARRAY_BUFFER, cubeVertices.size() * sizeof(QVector3D), cubeVertices.constData(), GL_STATIC_DRAW);
 
 
}
 
void MyOpenGLWidget::resizeGL(int width, int height)
{
    glViewport(0,0,width,height);
    cubeProjectionMatrix.setToIdentity();
    cubeProjectionMatrix.perspective(60.0, (float)width/(float)height, 0.001, 1000);
}
 
 
void MyOpenGLWidget::paintGL()
{
    //Part where we are supposed to display our 3D Cube
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
    pointShaderProgram->bind();
    pointShaderProgram->setUniformValue("isCube",true);
 
    cubeModelMatrix.setToIdentity();
    cubeViewMatrix.setToIdentity();
    cubeViewMatrix.lookAt(QVector3D(0,0,cubeDistance), QVector3D(0,0,0), QVector3D(0,1,0));
 
    cubeModelMatrix.rotate(cubeBeta,1,0,0);
    cubeModelMatrix.rotate(cubeAlpha,0,1,0);
 
    pointShaderProgram->setUniformValue("qt_ModelViewProjectionMatrix",cubeProjectionMatrix * cubeViewMatrix * cubeModelMatrix);
 
    glBindBuffer(GL_ARRAY_BUFFER, cubeVBO);
    glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,0,nullptr);
    glEnableVertexAttribArray(0);
 
    glDrawArrays(GL_TRIANGLES,0,cubeVertices.size());
 
    glDisableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER,0);
    pointShaderProgram->release();
 
}
VertexShader :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 
#version 130
attribute highp vec4 vertexPos;
uniform highp mat4 qt_ModelViewProjectionMatrix;
 
void main(void)
{
gl_Position = qt_ModelViewProjectionMatrix * vertexPos;
}
FragmentShader :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
#version 130
void main(void)
{
gl_FragColor = vec4(1.0,1.0,1.0,1.0);
}