[Qt-interest] View JPEG in QGLWidget
Constantin Makshin
cmakshin at gmail.com
Fri Aug 19 14:05:24 CEST 2011
1. Does your application use OpenGL by default? I.e. is mode == GL_MODE_NATIVE when the widget is initialized? If it isn't, the texture object won't be created with obvious consequences.
2. Does your videocard support the "GL_ARB_texture_non_power_of_two" OpenGL extension? If it doesn't, that may be the cause and you have to use fallback methods:
2.1) "GL_ARB_texture_rectangle" OpenGL extension if it's supported — no impact on performance or image quality, easy to implement (just use special texture type and texture coordinates);
2.2) scale the image (*before* calling QGLWidget::convertToGLFormat()) to make its dimensions be powers of two — scaling reduces image quality and affects performance;
2.3) resize image "canvas", i.e. put your non-power-of-two image on a larger power-of-two background (e.g. paint a 654x321 image over a 1024x512 background) — no loss of image quality, but inefficient memory usage, reduced performance due to this additional paint operation, a bit tricky texture coordinate calculation.
Also your resizeGL() function looks weird — why do you want to move the image anywhere? And again, that glTranslatef() moves your image quad out of view.
On Friday, August 19, 2011 09:18:02 AM Brilliantov Kirill Vladimirovich wrote:
> >
> > 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);
> > }
> >
>
> Hello Constantin and thank for your reply!
> I comment glTranslate() in paintGL, my resizeGL function:
> void Image::resizeGL(int width, int height)
> {
> if (width < frame_resolution.width() || height < frame_resolution.height())
> setMinimumSize(frame_resolution);
> else {
> /*(switch (mode) {
> case GL_MODE_NATIVE:
> glTranslatef(-(width - frame_resolution.width()) / 2,
> -(height - frame_resolution.height()) / 2,
> 0.0);
> break;
> case GL_MODE_PAINTER:
> QPainter paint(this);
> paint.setWindow((width - frame_resolution.width()) / 2,
> (height - frame_resolution.height()) / 2,
> frame_resolution.width(),
> frame_resolution.height());
> break;
> }*/
> glViewport(0, 0, width, height);
> }
> }
>
> Now I see white rectangle ;)
> Any ideas?
-------------- 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/20110819/420ad8f4/attachment.bin
More information about the Qt-interest-old
mailing list