Bonjour,
je suis en train d'apprendre openGl avec Qt, J'ai fait un cube et j'ai voulu le texturer. seulement mon cube apparaît blanc (comme si la texture n'avait pas été chargée). ma texture est bien de dimension 2^n.
Je met le code
glWidget.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
28
#define _GLWIDGET_H
 
#include <QtGui>
#include <QtOpenGL/QGLWidget>
#include <iostream>
 
class GLWidget : public QGLWidget {
 
    Q_OBJECT // must include this if you use Qt signals/slots
 
public:
    GLWidget(QWidget *parent = NULL);
 
protected:
    void initializeGL();
    void resizeGL(int w, int h);
    void paintGL();
    void chargerTextures();
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void keyPressEvent(QKeyEvent *event);
 
    GLuint texture[1];
 
 
};
 
#endif  /* _GLWIDGET_H */
glWidget.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
#include <QtGui/QMouseEvent>
#include <iostream>
#include "glWidget.h"
 
GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent) {
    setMouseTracking(true);
}
 
void GLWidget::initializeGL()
{
    void chargerTextures();
    glEnable(GL_CULL_FACE);
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_BLEND);
    glEnable(GL_POLYGON_SMOOTH);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glClearColor(0, 0, 0, 0);
}
 
void GLWidget::chargerTextures()
{
    QImage buf_vitrail;
 
    QImage vitrail;
 
    buf_vitrail.load("vitrail.bmp");
    vitrail = QGLWidget::convertToGLFormat(buf_vitrail);
 
    glGenTextures(1, &texture[0]);
    glTexImage2D(GL_TEXTURE_2D, 0, 3, vitrail.width(), vitrail.height(), 0, GL_RGB, GL_BITMAP, &texture[0]);
 
 
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
 
 
 
}
 
void GLWidget::resizeGL(int w, int h) {
    int side = qMin(w, h);
         glViewport((w - side) / 2, (h - side) / 2, side, side);
 
         glMatrixMode(GL_PROJECTION);
         glLoadIdentity();
         glOrtho(-0.5, +0.5, -0.5, +0.5, 4.0, 15.0);
         glMatrixMode(GL_MODELVIEW);
}
 
 
void GLWidget::paintGL() {
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective(90.f, 1.f, 1.f, 500.f);
 
 
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity( );
 
    glBindTexture(GL_TEXTURE_2D, texture[0]);
 
    gluLookAt(3,4,2,0,0,0,0,0,1);
 
 
 
    glBegin(GL_QUADS);
 
                    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
                    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
                    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad
                    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad
                    // Back Face
                    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad
                    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
                    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
                    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad
                    // Top Face
                    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
                    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
                    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
                    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
                    // Bottom Face
                    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Top Right Of The Texture and Quad
                    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Top Left Of The Texture and Quad
                    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
                    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
                    // Right face
                    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad
                    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
                    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad
                    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
                    // Left Face
                    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad
                    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
                    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad
                    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
 
        glEnd();
 
 
}
 
void GLWidget::mousePressEvent(QMouseEvent *event) {
 
}
void GLWidget::mouseMoveEvent(QMouseEvent *event) {
}
 
void GLWidget::keyPressEvent(QKeyEvent* event) {
    switch(event->key()) {
    case Qt::Key_Escape:
        close();
        break;
    default:
        event->ignore();
        break;
    }
}
Voilà, si quelu'un pouvait me dire ce qui cloche dans mon code ce serait bien sympa. Moi je ne vois pas d'où ça peut venir, en plus je n'ai aucune erreur au compilo.

(avant de poster je me suis renseigné)

Merci d'avance.