Bonjour,

je travaille en ce moment sous opengl et qt. J'ai fait un petit programme qui met en mouvement deux textures. Le problème c'est que le programme rame dans les 5s.
Je travaille sous Qt et j'utilise une fonction de Qt qui gére un timer. Lorsque ce top arrive,
l'inclinaison et la translation de l'objet change. Pour le moment j'ai mis 1s de rafraichissement et ca rame déja.

Voici mon code:

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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
 
#include <iostream>
using namespace std;
 
#include <QtGui/QMouseEvent>
#include <glwidget.h>
#include <QtOpenGL/QGLWidget>
 
#include <QtOpenGL>
#include "GL/glu.h"
 
 
double fovy = 45.0;
double znear = 0.5,zfar = 100;
double ratio = 1;
double pitch = 0;
double roll  = 0;
 
 
GLWidget::GLWidget(QWidget *parent):
    QGLWidget(parent)
{
    rquad =25;
    setMouseTracking(true);
 
    startTimer(1);
 
}
 
void GLWidget::initializeGL()
{
    loadTexture("./images/test.png");
    glEnable(GL_TEXTURE_2D);
    glShadeModel(GL_SMOOTH);
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClearDepth(1.0f);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
 
}
void initializeGL2()
{
    glShadeModel(GL_SMOOTH);
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClearDepth(1.0f);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
 
 
void GLWidget::resizeGL(int width, int height)
{
    if(height == 0)
        height = 1;
 
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(fovy, ratio, znear, zfar);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
 
}
 
void GLWidget::paintGL()
{
    initializeGL();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
 
 
    double translation = (1.0/tan(fovy/2.0*M_PI/180.0)*1.125);
 
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glRotatef(roll, 0, 0, 1);
 
    cout << "translation :" << -pitch/(fovy/2)*1.125 << endl;
    glTranslatef(0,-pitch/(fovy/2)*1.125, -translation);
    glEnable(GL_ALPHA_TEST);
    glAlphaFunc(GL_EQUAL, 255);
    glBegin(GL_QUADS);
    // Face Avant
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(-1.0f, -4.0f,  0.0f);
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f( 1.0f, -4.0f,  0.0f);
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f( 1.0f,  4.0f,  0.0f);
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(-1.0f,  4.0f,  0.0f);
    glEnd();
    //    initializeGL2();
    /* Dessin du sprite avec transparence */
    glDisable(GL_ALPHA_TEST);
    glDisable (GL_TEXTURE_2D);
 
 
        glLoadIdentity();
        glTranslatef(0.0f, 0.0f, -translation-0.1);
 
        glBegin(GL_QUADS);
        // Face Avant
        glColor3f(0.2f, 1.0f, 1.0f);
        //   glTexCoord2f(0.0f, 0.0f);
        glVertex3f(-1, -1,  0.0f);
        //       glColor3f(1.0,0.0,0.0);
        glVertex3f( 1, -1,  0.0f);
        //       glColor3f(1.0,0.0,0.0);
        glVertex3f( 1,  0.0f,  0.0f);
        //       glColor3f(1.0,0.0,0.0);
        glVertex3f(-1,  0.0f,  0.0f);
 
        glEnd();
 
}
 
void GLWidget::loadTexture(QString textureName)
{
    QImage qim_Texture;
    QImage qim_TempTexture;
    qim_TempTexture.load(textureName);
    qim_Texture = QGLWidget::convertToGLFormat( qim_TempTexture );
    glGenTextures( 1, &texture[0] );
    glBindTexture( GL_TEXTURE_2D, texture[0] );
    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, qim_Texture.width(), qim_Texture.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, qim_Texture.bits() );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
 
}
 
void GLWidget::keyPressEvent(QKeyEvent *event)
{
 
    switch( event->key() )
      {
      case Qt::Key_Left:
        roll -=1;
        break;
 
    case Qt::Key_Right:
        roll +=1;
      break;
 
    case Qt::Key_Up:
        pitch += 1;
      break;
 
    case Qt::Key_Down:
      pitch-= 1;
 
      break;
    }
 
//    paintGL();
    cout << "roll :"  << roll << "pitch" << pitch << endl;
    event->accept();
}
 
void GLWidget::timerEvent( QTimerEvent *e )
{
    if(mod)
    {
        pitch +=1;
        roll  +=1;
        if(pitch>40)
            mod=0;
    }else
    {
        pitch -=1;
        roll -=1;
 
        if(pitch < -40)
            mod=1;
    }
 
    pitch +=1;
//    pitch = pitch%40.0;
    roll  +=1;
//    roll  = roll%40.0;
    updateGL();
 
}

J'ai oublié de faire quelquechose dans le code. Genre une mémoire qui se sature?
Si quelqu'un pouvait m'aider.
D'avance merci.