[Qt-interest] View JPEG in QGLWidget
Constantin Makshin
cmakshin at gmail.com
Tue Jul 26 20:08:34 CEST 2011
1) check your video card capabilities — not all video cards support non-power-of-two textures (and the camera is likely to produce NPOT images);
2) put calls to glGetError() into your resizeGL() function (at least after the glTex[Sub]Image() call) and check the returned values.
On Monday, July 25, 2011 03:55:11 PM Brilliantov Kirill Vladimirovich wrote:
> 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.
-------------- 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/20110726/e5a8fa34/attachment.bin
More information about the Qt-interest-old
mailing list