[Qt-interest] View JPEG in QGLWidget

Constantin Makshin cmakshin at gmail.com
Thu Aug 18 21:40:16 CEST 2011


Try to remove the "glTranslate()" line — it moves the quad out of view. You shouldn't apply any transformations at all as the [-1, -1]–[1, 1] rectangle already covers the whole viewport.

And override the QGLWidget::resizeGL() function with something like this:

void Image::resizeGL (int width, int height)
{
    glViewport(0, 0, width, height);
}

On Thursday, August 18, 2011 03:20:39 PM Brilliantov Kirill Vladimirovich wrote:
> >
> > OK, I think I've found the source of the problem ? incorrect vertex coordinates.
> 
> Hello, Constantin!
> Your sample correct work with static image, but with dinamic image 
> (images from IP-camera) I get only black screen.
> 
> My code:
> bool mode = isValid();
> 
> enum gl_mode_e {
> 	GL_MODE_PAINTER, ///< use QPainter
> 	GL_MODE_NATIVE	///< use OpenGL
> };
> 
> void Image::initializeGL()
> {
> 	if (GL_MODE_NATIVE == mode) {
> 		glClearColor(0.0, 0.0, 0.0, 0.0);
> 		glDisable(GL_DEPTH_TEST);
> 		glEnable(GL_TEXTURE_2D);
> 		glGenTextures(1, &texture);
> 		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
> 		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
> 		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);
> 	}
> }
> void Image::paintGL()
> {
> 	switch (mode) {
> 		case GL_MODE_NATIVE:
> 			glClear(GL_COLOR_BUFFER_BIT);
> 			glTranslatef(-image.width()/2, -image.height()/2, 0.0);
> 			glBindTexture(GL_TEXTURE_2D, texture);
> 			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());
> 			glBegin(GL_QUADS);
> 				//top left
> 				glTexCoord2f(0.0, 1.0);
> 				glVertex2f(-1.0, 1.0);
> 				//bottom left
> 				glTexCoord2f(0.0, 0.0);
> 				glVertex2f(-1.0, -1.0);
> 				//bottom right
> 				glTexCoord2f(1.0, 0.0);
> 				glVertex2f(1.0, -1.0);
> 				//top right
> 				glTexCoord2f(1.0, 1.0);
> 				glVertex2f(1.0, 1.0);
> 			glEnd();
> 			break;
> 		case GL_MODE_PAINTER:
> 			QPainter paint(this);
> 			paint.drawImage(0, 0, QImage::fromData(jpg));
> 			break;
> 	}
> 	show();
> }
> 
> I see image when I use GL_MODE_PAINTER, but with GL_MODE_NATIVE I see 
> only black screen;
> 
> Can your help me?
> Thank you and excuse me for my bad english.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110818/1c2e62a4/attachment.bin 


More information about the Qt-interest-old mailing list