Bonjour,

J'attaque l'OpenGL 3, et j'ai un souci avec mon premier programme. Impossible de comprendre pourquoi, j'ai ma scène 3D, mais mon supppppper triangle ne daigne s'afficher. Voici le code de ma scène, si quelqu'un a une petite idée :

Main.cpp :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
MapEditor::MapEditor(QWidget *parent) : QMainWindow(parent), ui(new Ui::MapEditor)
{
    ui->setupUi(this);
 
    // Specify an OpenGL 3.3 format using the Core profile.
    // That is, no old-school fixed pipeline functionality
    QGLFormat glFormat;
    glFormat.setVersion( 3, 3 );
    glFormat.setProfile( QGLFormat::CoreProfile ); // Requires >=Qt-4.8.0
    glFormat.setSampleBuffers( true );
 
    _3Dscene = new GLScene(this, glFormat);
}
GLScene.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
#include <iostream>
#include "GLScene.h"
 
using namespace std;
 
GLScene::GLScene(QMainWindow *parent, QGLFormat & glformat) : QGLWidget(glformat, parent)
{
    // Necessary ?
    glInit();
    this->setGeometry(0,0,parent->width(),parent->height());
}
 
GLScene::~GLScene()
{
}
 
void GLScene::initializeGL()
{
   // makeCurrent();
 
    GLenum initialisationGLEW(glewInit());
 
    if(initialisationGLEW != GLEW_OK)
        std::cout << "Erreur d'initialisation de GLEW : " << glewGetErrorString(initialisationGLEW) << std::endl;
 
    glClearColor(1.0, 0.0, 0.0, 0.0);
    //glEnable(GL_DEPTH_TEST);
}
 
void GLScene::paintGL()
{
    draw();
}
 
void GLScene::draw()
{
    float vertices[] = {-0.5, -0.5, 0.0, 0.5, 0.5, -0.5};
 
    glClear(GL_COLOR_BUFFER_BIT);
    glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,0, vertices);
    glEnableVertexAttribArray(0);
    glDrawArrays(GL_TRIANGLES,0,3);
    glDisableVertexAttribArray(0);
    swapBuffers();
}
Théoriquement, ca doit mafficher un triangle blanc sur fond rouge, banalement, en 2D.

Merci d'avance !