where did you put these code? gl***() could only be called in QGLWidet's members and is obvisouly cannot be there. i'm wondering what does painter do?
where did you put these code? gl***() could only be called in QGLWidet's members and is obvisouly cannot be there. i'm wondering what does painter do?
actually QGLWidget specialized methods that initialize GL context and render things using GL commands (I mean the methods where you can and are supposed to do this) are most likely called from the default paintEvent() which makes it possible to initialize a QPainter in them but, again, it is NOT the right thing(tm) to do...
If all you need is simple 2D drawing QGLWidget does all the needed GL calls under the hood when you simply use QPainter inside the paintEvent().
If you need some complex rendering to be done use these methods instead (do not touch the painEvent()) as recommended by the docs :
- paintGL() - Renders the OpenGL scene. Gets called whenever the widget needs to be updated.
- resizeGL() - Sets up the OpenGL viewport, projection, etc. Gets called whenever the the widget has been resized (and also when it is shown for the first time because all newly created widgets get a resize event automatically).
- initializeGL() - Sets up the OpenGL rendering context, defines display lists, etc. Gets called once before the first time resizeGL() or paintGL() is called.
And avoid mixing GL calls with QPainter. Even if it works it is USELESS and a clear design failure... Anything QPainter does is done using GL commands so if you're doing advanced GL rendering you certainly know how to do some simple 2D painting directly using GL or you use some of the convenience methods of QGLWidget (eg QGLWidget::renderText())
Last but not least, GL coordinates and windows coordinates are not the same : Windows use a right/down base whose origin is at the top left corner while GL use a right/up base whose origin is a the center of the rendering context. Going from one to another requires the composition of two basic transforms : translation and symetry of axe (Ox)
Current Qt projects : QCodeEdit, RotiDeCode
Hi fullmetalcoder,
Thank you for your detailed explanation.
> Anything QPainter does is done using GL commands so if you're
> doing advanced GL rendering you certainly know how to do some
> simple 2D painting
The basic requirement is to draw the text on the QGLWidget.
I have already done experiments on QGLWidget::renderText(), but it is tooooo slow, while performing rotation with text.
Then I looked into the internals of the renderText.
I looked into the Qt443 code and found that in renderText() it uses the QPainter::drawText(). So I am trying to simulate the same code in my program, but I am facing this problem.
Can you please let me know...
1) how can I optimize the performance of renderText()?
2) can I get better performance if I use QPainter::drawText on QGLWidget?
3) can I get still better performance if I use QPaintEngine::drawTextItem() on QGLWidget, pl. provide example.
And finally I don't won't to go with third-party libraries like FontGL/FTGL.
Thank you.
the performances of QLWidget depends of several factors that do not affect (or not as noticably) regular widgets :
- GPU
- OpenGL implementation/ GPU drivers
- AA settings
I don't have Qt source code on my box atm so I can't comment about renderText()/drawText() though there should not be a huge difference.
As for coordinate transform this should do :
Yes the two functions do exactly the same but having a different name might help to keep the code readable.Qt Code:
{ } { }To copy to clipboard, switch view to plain text mode
So I think the problem actually lies in this line or in any of the preceding lines that setp up the parameters of the function :
Qt Code:
gluProject(x, y, z, &m[0][0], &p[0][0], &v[0], &w_x, &w_y, &w_z);To copy to clipboard, switch view to plain text mode
Current Qt projects : QCodeEdit, RotiDeCode
Bookmarks