Bonjour,

Je dois générer une texture à partir d'un pointeur sur un tableau de byte que l'on me passe en paramètre. Pour celà j'utilise glTexImage2D.

Quand je fais le chargement dans initializeGL() tout ce passe bien

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
 
 
QWindowOGL::QWindowOGL(int timerInterval, QWidget *parent, GLvoid* texture ) : QGLWidget( parent )
{
	m_zoneAffichage = QRect(0,0,1080,1920);
	m_reticule = false;
	m_RGB = true;
	m_rotation = true;
	m_buffer = texture;
	glInit();
	m_timer = new QTimer();
	m_timer->start(timerInterval);
	connect( m_timer, SIGNAL(timeout()), this, SLOT(updateGL()) );
}
 
void QWindowOGL::loadGLTextures()
{
 
	glGenTextures( 1, &m_texture[0] );
	glBindTexture( GL_TEXTURE_2D, m_texture[0] );
	glTexImage2D( GL_TEXTURE_2D, 0, 4, 4, 4, 0, GL_RGB, GL_FLOAT, (GLvoid*)m_buffer );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
}
 
void QWindowOGL::initializeGL()
{
	loadGLTextures();
 
	glEnable(GL_TEXTURE_2D);
 
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClearDepth(1.0f);
 
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
 
}
 
 
void QWindowOGL::paintGL()
{
 
    glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glOrtho(m_zoneAffichage.left(), m_zoneAffichage.right(), m_zoneAffichage.bottom(), m_zoneAffichage.top(), 0.1f, 10.0f);
 
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
 
	glClearColor(1.0,1.0,1.0, 1.0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
 
	glTranslatef(0.0f,0.0f,-5.0f);
 
	glColor3f(1.0, 1.0, 1.0);
	glBindTexture(GL_TEXTURE_2D, m_texture[0]);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex2f( 0.0f,  0.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex2f( 1080.0f,  0.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex2f( 1080.0f,  1920.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex2f( 0.0f,  1920.0f);
	glEnd();
 
}
Le problème c'est que mon tableau change au cours du temps, et donc que je dois régénérer ma texture au cours du temps. Pour cela je pensais appeler le glTexImage2D dans le paintGL pour que la texture soit générer "en live" mais là, je n'ai plus de texture qui s'affiche :

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
QWindowOGL::QWindowOGL(int timerInterval, QWidget *parent) : QGLWidget( parent )
{
	m_zoneAffichage = QRect(0,0,1080,1920);
	m_reticule = false;
	m_RGB = true;
	m_rotation = true;
	m_buffer = texture;
	glInit();
	m_timer = new QTimer();
	m_timer->start(timerInterval);
	connect( m_timer, SIGNAL(timeout()), this, SLOT(updateGL()) );
}
 
void QWindowOGL::initializeGL()
{
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
 
	glEnable(GL_TEXTURE_2D);
 
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClearDepth(1.0f);
 
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
 
}
 
void QWindowOGL::setTexture(GLvoid* pTexture, int width, int height, bool RGB, bool rotation)
{
	m_buffer = pTexture;
	m_textureWidth = width;
	m_textureHeight = height;
	m_RGB = RGB;
	m_rotation = rotation;
}
 
void QWindowOGL::paintGL()
{
 
    glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glOrtho(m_zoneAffichage.left(), m_zoneAffichage.right(), m_zoneAffichage.bottom(), m_zoneAffichage.top(), 0.1f, 10.0f);
 
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
 
	glClearColor(1.0,1.0,1.0, 1.0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
 
	glGenTextures( 1, &m_texture[0] );
	glBindTexture( GL_TEXTURE_2D, m_texture[0] );
	glTexImage2D( GL_TEXTURE_2D, 0, 4, 4, 4, 0, GL_RGB, GL_FLOAT, m_buffer );
 
	glTranslatef(0.0f,0.0f,-5.0f);
 
	glColor3f(1.0, 1.0, 1.0);
	glBindTexture(GL_TEXTURE_2D, m_texture[0]);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex2f( 0.0f,  0.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex2f( 1080.0f,  0.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex2f( 1080.0f,  1920.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex2f( 0.0f,  1920.0f);
	glEnd();
}
Sauriez-vous s'il est possible de générer la texture "en live" comme je le veut ou est-ce impossible (et la ben je suis dans la merde )

Merci d'avance