Bonsoir,

Après quelques heures passées à essayer d'afficher une image en arrière-plan fixe dans une fenêtre OpenGl, je viens demander votre aide.

Après une lecture des techniques de Skybox, de FBO, de quad avec texture, mes essais ne m'ont pas mené à bout.

J'obtiens une texture incomplète et qui s'affiche trop grand.

La texutre à une résolution de 1384*893 (je n'ai pas le choix), et l'affichage se fait dans la même résolution.

Voici, ce que j'ai déjà fait... je n'y vois plus rien, merci de bien vouloir y jeter un oeil :

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
void GLWidget::initializeGL()
{
 
 
    if (m_displayStyle)
        m_displayStyle->initGL(); 
 
    glGenTextures(1, &texture);
    glBindTexture(GL_TEXTURE_2D, texture);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mBackgroundGL.width(), mBackgroundGL.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, static_cast<GLubyte*>(mBackgroundGL.bits()));
 
}
 
 
void GLWidget::paintGL()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
 
   // draw background
   glEnable(GL_TEXTURE_2D);
   glMatrixMode(GL_PROJECTION);
   glPushMatrix();
   glOrtho(0, 1, 0, 1, 0, 1);
   glMatrixMode(GL_MODELVIEW);
   glPushMatrix();
   glLoadIdentity();
   glDisable(GL_DEPTH_TEST);
   glBindTexture(GL_TEXTURE_2D, texture);
   glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex2f( 0.0f, 0.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex2f( 0.0f, 1.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex2f( 1.0f, 1.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex2f( 1.0f, 0.0f);
    glEnd();
 
    glEnable(GL_DEPTH_TEST);
    glPopMatrix();
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
 
   /*glRasterPos2i (-50, 0);
   glDrawPixels (mBackgroundGL.width(), mBackgroundGL.height(), GL_RGBA,
                 GL_UNSIGNED_BYTE,
                 static_cast<GLubyte*>(mBackgroundGL.bits()));
    glEnable(GL_DEPTH_TEST);*/
 
    //QPainter p(this);
 
    //p.drawImage(0,0,mBackground);
 
    //p.end();
 
    if (m_displayStyle)
        m_displayStyle->draw();
 
}
 
void GLWidget::resizeGL(int width, int height)
{
    int side = qMin(width, height);
    glViewport(0, 0, width, height);
    //glViewport(0, 0, 1384, 893);
    //mBackground = mBackground.scaled(QSize(width, height));
 
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
    glMatrixMode(GL_MODELVIEW);
}
P.S : j'aime utiliser QT, mais j'ai l'impression que mon problème se situe chez openGL dans les transformations.

Merci encore,

G