[Qt-interest] View JPEG in QGLWidget

Brilliantov Kirill Vladimirovich brilliantov at byterg.ru
Mon Jul 25 13:55:11 CEST 2011


Hello!
I need view JPEG from IP-camera and I select QGLWidget for this.
I use Qt 4.7.

My code:
QByteArray jpg;
QImage image;
GLuint texture;

initializeGL()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glDisable(GL_DEPTH_TEST);
glGenTextures(1, &texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glEnable(GL_TEXTURE_2D);
}

resizeGL(int width, int height)
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
image = QGLWidget::convertToGLFormat(QImage::fromData(jpg));
if (1 == frame_number)
	glTexImage2D(GL_TEXTURE_2D, 0, 4, image.width(), image.height(),
							 0, GL_RGBA, GL_UNSIGNED_BYTE, image.bits());
else
	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, image.width(),
								image.height(),	GL_RGBA, GL_UNSIGNED_BYTE,
								image.bits());
}

paintGL()
{
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(-image.width()/2, -image.height()/2, 0.0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 1.0);
glVertex3f(0.0, image.height(), 0.0);
glTexCoord2f(0.0, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glTexCoord2f(1.0, 0.0);
glVertex3f(image.width(), 0.0, 0.0);
glTexCoord2f(1.0, 1.0);
glVertex3f(image.width(), image.height(), 0.0);
glEnd();
//glDrawPixels(image.width(), image.height(), GL_RGBA,
//		 GL_UNSIGNED_BYTE, image.bits());
}

I don't get any error, but I don't view image:
- if I comment glDrawPixels I see white rectangle
- if I use glDrawPixels I view static image

How can I solve this problem?
Thank you and excuse me for my bad english.



More information about the Qt-interest-old mailing list