PDA

View Full Version : QGLWidget's PaintGl Method



beginQT
25th September 2011, 11:35
Hello,

I have started my new project with QT Eclipse, as I told in my previois thread I have Mainwindow and opengl window which is child to it called GLWidget inherited from QGLwidget.What I want to know is..

In my GL window i need to place different artifacts like I have to place multiple textures and along with that i need to draw some primitives(ex:polygons) over that textures using opengl core libraries(GLUT). Problem that I found currently is, any drawing on the opengl window is possible only through PaintGL() method, Looks like I cannot use my own methods to draw some textures, everything must be through PaintGL.
If that is the case How do i draw a different textures and at the same time depending on the some inputs I need to change textures as well as primiives..basically its an kind of scene changes dynamically.

Hope readers understand what I mean, If not please let me know I will try to eloberate it!
Please sugget me how to use it!

Thanks in Advance!

stampede
25th September 2011, 11:59
Thats right, all painting must be done from painGL method, but you can call other drawing methods from paintGL. Simple example, you can have a boolean values to control what to draw, like this:


void MyGlWidget::paintGL(){
if( this->_drawPolygon ){ // boolean value to control visibility of a polygon
this->drawPolygon();
}
if( this->_drawTexture1 ){ // same for visibility of a texture
this->drawTexture1();
}
if( this->_drawSomethingElse ) ...
}

// some methods to control what should be rendered
void MyGlWidget::setDrawPolygon( bool draw ){
this->_drawPolygon = draw;
this->updateGL();
}
void MyGlWidget::setDrawTexture1( bool draw ){
this->_drawTexture1 = draw;
this->updateGL();
}
void MyGlWidget::setDrawSomethingElse( ... etc.

beginQT
25th September 2011, 12:33
Thanks for the response!

So, it means userdefined functions must also be called from PaintGL and in that functions we can still use our core opengl commands to draw the polygons and the textures and stuff like that..Is it correct?

Thanks!

stampede
25th September 2011, 13:08
userdefined functions must also be called from PaintGL and in that functions we can still use our core opengl commands to draw the polygons and the textures and stuff like that..Is it correct?
Yes. You can also use standard QPainter 2D drawing on the QGlWidget, if you reimplement paintEvent.

beginQT
25th September 2011, 13:14
Ok..
I dont know much about QPainter and stuff like that..I am an beginner and looking for something most specific to our project requirements..I still have to read some stuff to get more exposure towards that..
Any suggestions or links of the tutorials are most welcome!

And, Could you please drop some code snippet to draw a texture in opengl window by using QT API's?
Earlier i was using only pure opengl commands to do that in my previous environment..I heard that there is simple ways to do this using QT API functions.

Thanks!

stampede
25th September 2011, 13:48
You can start here: http://doc.qt.nokia.com/latest/examples-opengl.html