PDA

View Full Version : What element of Qlgwidget I'd pass to a class only to draw ?



tonnot
14th July 2011, 14:23
I have a Qglwidget and I have a class that wants to draw itself in the 3dWorld.
I can pass the 'this' reference to my_class_auto_draw_3d, but I dont want to use any other methods of the Qglwidget not related with opengl operations.
That is to say, I have no interest to know or do nothing at the Qglwidget from my_class_auto_draw_3d.
So, what object-element of Qglwidget can I use ?


Thanks.

mcosta
14th July 2011, 14:33
IMO I suggest this



class My3DObject
{
...
public:
virtual void draw ();
};


class MyGLWidget: public QGLWidget
{
...
public:
void addObject (My3DObject *obj) { objects.push_back(obj);}

protected:
void paintGL()
{
....

Q_FOREACH (My3DObject* obj, objects)
obj->draw();
}

private:
QVector<My3DObject*> objects;
};


In this way each Object draw itself;

tonnot
14th July 2011, 17:29
Yes it can be a solution.
In my case, I'd prefer the against proccess.
And, in your opinion, what can be faster ?
my_object.draw
draw(my_object).
(or it is the same ?)
Thanks

mcosta
14th July 2011, 18:51
Yes it can be a solution.
In my case, I'd prefer the against proccess.
And, in your opinion, what can be faster ?
my_object.draw
draw(my_object).
(or it is the same ?)
Thanks

IMO both have the same speed.
the main difference is that


my_object.draw: each object knows how draw itself;

draw(my_object): the object that execute this has to know my_object data to draw it.

in OO style I prefer the first one.

tonnot
14th July 2011, 21:26
So, we return to the first question.
I have to pass the QGLwidget object to the objects constructor to let them can be drawed. Can I pass another "light" object ? In example QGLWidget.the_gl_engine ?
(I dont see any tip at documentation )
Thanks

mcosta
15th July 2011, 08:45
wrong,

the OpenGL painting must be done in paintGL method or in a method called inside it.

tonnot
15th July 2011, 17:45
Ok. But as you can create a Qpainter using QPainter painter(this); it could be appropiate to create a 'QGLPiainter' (If exists. ) .
Do you think as me ?

mcosta
15th July 2011, 17:57
The problem is that QGLPainter doesn't exist.

tonnot
15th July 2011, 21:02
Ja ja, Do you think that it can be a future feature ?
Good weekend

Dong Back Kim
5th August 2011, 04:09
Ja ja, Do you think that it can be a future feature ?
Good weekend

Sounds like you are trying to implement overpainting by using QGLWidget. You can override paintEvent() instead of paintGL(). There is a famouse tutorial about 2D drawing/3D rendering by using a single QGLWidget. Search "Qt overpainting".

One thing I found a difficulty of using it is when you do QPainter within the paintEvent() you need to reset OpenGL machine states (i.e. no depth buffer). I think those should have been handled by QGLWidget internally. Other than that it works very well.

Now since you can use normal QPainter in QGLWIdget, why would you need QGLPainter? =)

Regards,
Dong Back Kim