[solved] Qt and OpenGL
-
Hi Guys!
I'm trying to use the power of the OpenGL on a Colibri T20 from Toradex. The card is running Linux (Angstrom) with X11 (Xorg).
I've developped a small piece of code (which is running fine on Windows) with both QWidget and QGLWidget. It's a simple animation on a picture (fade-in/fade-out) When I'm running the version with the QWidget I can see my processor up to 20% and when I'm running it with the QGLWidget, the processor activity looks like the ECG from a reality TV star, so I concluded that my usage of the QGLWidget is correct. :-)
The problem is when I'm running the code on the card: the animation I've created is sloooooooooooooooooow (with both QGLWidget and QWidget)
So my question is: Am I really using the hardware accelaration or not? How can I test it? Should I have receive an error from my project during the compilation if OpenGL wasn't installed on the card? Or, is my code optimized? (my opinion: my code is not optimised at all :-) )
Here is the code of my test widget:
@#include "glwidget.h"
#include "QDebug"GLWidget::GLWidget(Helper *helper, QWidget *parent)
: QGLWidget(QGLFormat(QGL::SampleBuffers), parent), helper(helper)
{
elapsed = 1;
reverse = false;
}void GLWidget::animate()
{
//elapsed = (elapsed + qobject_cast<QTimer*>(sender())->interval()) % 1000;
if(reverse)
elapsed = elapsed + 0.01;
else
elapsed = elapsed - 0.01;if(elapsed <= 0 && reverse == false) reverse = true; else if(elapsed >= 1 && reverse == true) reverse = false; repaint();
}
void GLWidget::paintEvent(QPaintEvent *event)
{
QPainter painter;
painter.begin(this);
painter.setOpacity(elapsed);
painter.setRenderHint(QPainter::Antialiasing);
helper->paint(&painter, event, elapsed);painter.end();
}@
And here the repaint's call
@GLWidget *openGL = new GLWidget(&helper, this);
this->setCentralWidget(openGL);
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), openGL, SLOT(animate()));
timer->start(10);@Thanks a looooooot!
-
Hi and welcome to devnet,
I'm not sure I'm following you right. Since you want to do OpenGL why are you using paintEvent ?
Also, you are trying to update at 100fps which might be a bit optimistic for an embedded board.
-
Hi,
Thanks for welcoming me on the forum and for your answer!
I followed a tutorial on line to create this widget because I've never worked with OpenGL and paint functions. Should I use paintGL and QGLPainter instead?
I've try to turn down to 10fps, the result seems the same... For my fade-in/out functions, I'm using the painter's setOpacity function, is it the right way?
What I want to do is simple, just a smooth fade-in/out on a picture :-)
Thanks for you answer!
-
Then you might be overcomplicating things, what about this:
- QLabel -> for your image
- QGraphicsOpacityEffect -> self-explaining
- QPropertyAnimation -> to animate the QGraphicsOpacityEffect
This way everything is automated for you
-
Thanks, but actually I've started to use OpenGL directly because my first try was QPropertyAnimation and QGraphicsOpacityEffect and the result wasn't good too.
But, good news! I've found a solution... The problem was the picture it self... I used a too big one and because i'm lazy i downscaled the picture to see it entirely on the screen... So I've changed the picture by a picture of 1920x1080 and... Wow, at 100fps, it's smooth as hell! And it use only 5 to 8 percent of the processor!
Sorry for this thread... My fault... But I've learned a lot and maybe my code will be usefull for somebody else :-)
Thanks again!
-
You're welcome !
Don't be afraid to ask question :)
Since you have it working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)