[Qt-interest] View JPEG in QGLWidget
Brilliantov Kirill Vladimirovich
brilliantov at byterg.ru
Thu Aug 18 13:20:39 CEST 2011
>
> 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.
More information about the Qt-interest-old
mailing list