PDA

View Full Version : QGraphicsView, OpenGL & rotated text



anthon
3rd December 2009, 21:01
Hi,
I use a QGraphicsView, and I want to put some OpenGL on it, so I set a QGLWidget as the view port. Then I add some text in the scene. The problem is, if I set any rotation on the text, the text looks ugly (see attachement 1), as if there were no antialiasing. Everything looks fine if I set a no OpenGL view port (see attachement 2). So I would like to know what I am doing wrong... I add a small code example.


#include <QApplication>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGLWidget>
#include <QLabel>
#include <QGraphicsProxyWidget>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QLabel* label = new QLabel("Example Text");
label->setFont(QFont("Arial", 24));

QGraphicsScene scene;

QGraphicsProxyWidget *proxy = scene.addWidget(label);
proxy->rotate(2);

QGraphicsView view;
QGLWidget* viewport = new QGLWidget(QGLFormat(QGL::SampleBuffers));

view.setRenderHints(QPainter::Antialiasing
| QPainter::SmoothPixmapTransform
| QPainter::TextAntialiasing);
view.setViewport(viewport);
view.setGeometry(100, 100, 320, 60);
view.setScene(&scene);
view.show();

return app.exec();
}

wysota
4th December 2009, 00:23
Does your hardware and software support sample buffers? Try passing QPainter::HighQualityAntialiasing as a render hint, if your card supports fragment programs, it should make it use them for antialiasing.

anthon
4th December 2009, 12:00
Thanks for your reply. Unfortunatly, QPainter::HighQualityAntialiasing didn't help.
How could I know if my hardware and software support sample buffer? My car is a decent Nvidia 8400gm and I use the 190.42 drivers on linux.

wysota
4th December 2009, 15:25
You can use QGLContext::format() to query for the resulting format. Your card should be supporting sample buffers though.

By the way, your code provides antialiased text on my system. It's not as pretty as without OpenGL of course but it is definitely antialiased.

direct rendering: Yes
OpenGL renderer string: GeForce 8400M GS/PCI/SSE2/3DNOW!
OpenGL version string: 3.2.0 NVIDIA 190.32

anthon
4th December 2009, 16:32
Interesting: If I open the NVIDIA X Server Settings configuration panel, and set Antialiasing > "override application settings", I get the antialiasing. If I set to "use application settings", then I loose it. There is something here. wysota, can you tell me which setting you use on your system please?

wysota
4th December 2009, 16:40
Defaults - "use application settings".

anthon
4th December 2009, 17:13
There seems to be something wrong with my installation (debian sid), because it works fine on my ubuntu box. Maybe the drivers? (180.44 on ubuntu). I'll investigate a little bit more, and I'll let you know what I find.
Anyway, thank you!

wysota
4th December 2009, 17:38
Check with glxinfo if you have direct rendering and all NVidia's extensions available.

anthon
5th December 2009, 18:05
So the problem was that I was using qt4.6 rc1 :o. Upgrading to 4.6 final fixed this...