[openGL with Qt] updating of screen when paintGL is updated
Hello all,
I have a problem with the display in OpenGL. Currently I have a program that plot little by little some things in an openGL window.
=> i want to update screen each time that i go in the method "plotGL" but i don't know how i can do that :confused:
=> I noticed that openGL screen is updated if I increase the size of the openGL window but this update of the display is not automatically :p
So, How can I update my screen each time that i go in the paintGL function?
thank you in advance for your help
ps: I tried repaint () and updateGL () but it does not work then call these methods paintGL, it makes me so all block
this is my code:
Code:
void myGLWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1.0f,1.0f,1.0f,1.0f);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity( );
gluLookAt( 1.2, 1.7, 1.0, 0, 0, 0, 0, 0, 1);
glBegin(GL_LINES);
//plot
glEnd();
// updateSCREEN();
}
i have tried to decomment the line "updateSCREEN();" and put this method
Code:
void myGLWidget::updateSCREEN()
{
updateGL();
//repaint(); //i have tried this too
}
but it don't works, it creates a general blocage of alls my windows :mad:
Can you help me please? thanks a lot :rolleyes:
Re: [openGL with Qt] updating of screen when paintGL is updated
Hi
First, you can put glClearColor(1.0f,1.0f,1.0f,1.0f) in your initializeGL() method, no need to keep calling it in paintGL().
Second, if you use updateGL() inside paintGL(), you are creating a infinite loop, since, updateGL() keeps calling paintGL(), thats why your windows block.
You have to put updateGL() some where else possibly inside your plotGL method
Re: [openGL with Qt] updating of screen when paintGL is updated
thank for your help i think my problem it's soon resolve
regards
EDIT:
i have already a problem: my GL object was defined in the constructor of an other class, so now i can acces to this object to do:
Code:
myWidgetGL->updateScreen()
so i want to make a method in the GLWidget class that is tell without this syntaxe....
do you know how i can do that ?
Re: [openGL with Qt] updating of screen when paintGL is updated
I don't need the updateScreen() method
you can call directly myWidgetGL->updateGL();
You have to find a logic in your program, that when a user does some input that change the drawing, you call the updateGL().
For example some method like keypress event, where the user updates the scale, or the translation of the drawing. Than, in that method, you call updateGL() to fire the update in the drawing.
Re: [openGL with Qt] updating of screen when paintGL is updated
yes i use keypresse event so i update my openGL at this moment and it works.
but i have a problem:
=> i have defined my GL widget in the constructor of one window, so i can't access to this widget in a other place
for example:
=> in my main.cpp i can't do this:
Code:
myGlWidget->updateGL();
because this widget is defined in the constructor of my main windows...
so it's my problem to update the screen now...
Re: [openGL with Qt] updating of screen when paintGL is updated
In the constructor where you defined your glwidget add the following:
Code:
setFocusPolicy(Qt::StrongFocus);
than implement a method for the keypressevent and in that method add
Code:
void somewidget
::keyPressEvent(QKeyEvent *event
) {
myGlWidget->->keyPressEvent(event);
}
That way you'll be passing the event to the glwidget.
ALso do you realize you can use qglwidget as a standalone window without making a child of another widget ? That way you wouldnt have this problem.
Re: [openGL with Qt] updating of screen when paintGL is updated
thank for your help
Quote:
Originally Posted by
john_god
ALso do you realize you can use qglwidget as a standalone window without making a child of another widget ? That way you wouldnt have this problem.
yes i think have to do this.
thanks for all
regards :-)