PDA

View Full Version : [openGL with Qt] updating of screen when paintGL is updated



21did21
6th July 2011, 01:21
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:


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

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:

john_god
6th July 2011, 04:12
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

21did21
6th July 2011, 14:23
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:


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 ?

john_god
6th July 2011, 17:34
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.

21did21
6th July 2011, 18:04
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:

myGlWidget->updateGL();
because this widget is defined in the constructor of my main windows...

so it's my problem to update the screen now...

john_god
6th July 2011, 18:28
In the constructor where you defined your glwidget add the following:


setFocusPolicy(Qt::StrongFocus);

than implement a method for the keypressevent and in that method add



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.

21did21
6th July 2011, 19:07
thank for your help



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 :-)