PDA

View Full Version : Solution for render text in some low-level class



deedw
19th April 2010, 12:45
Hello,

I don't have exactly a Qt problem but more a general programming problem while using Qt. ;) Currently I write a little OpenGL viewer (derived from QGLWidget) for an application. The design is (at least an abstraction of it):



viewer-----+
|
+---scene-----+
| |
geometry rendering object


The scene takes the information from the geometry (like points and lines) and store them in some rendering object. Later the viewer will be activated with
makeCurrent() and all rendering objects will be called with the method
render(). In these methods the corresponding OpenGL commands are implemented (draw line or draw points).

My problem is that I want to show some text in the viewer. For example I want to show the distance to (0,0,0) for every geometric point. Currently I use gluProject and QGLWidget::renderText for it. But therefore I need the viewer in the rendering object.

This is a bad design (I think) and I want to find a better solution. So my question is how you would solve the problem?

My two ideas are:

1. Only use a reference to the QGLWidget in the rendering object for the text and not the complete viewer. Pro: Easy to implement. Contra: The low-level class has access to some GUI methods from QWidget.

2. Create a container in in the viewer for point and string information that is passed downwards and filled by the rendering objects. Then the viewer can render the text in this container. Pro: Good design. Contra: I need to pass the container all the way down when construction an object or when I want to render it. (The way from the viewer to the rendering object is a little bit more complicated than shown above.) Further it could be time consuming and I need to hold some information several times in the memory (at least pointers).

I'm looking for your answers and ideas.

Greetings Dee