Qt5 OpenGL sanity check
-
just started updating all my OpenGL demos to Qt 5 and want to check a few things I can't find documented.
In Qt4 the initializeGL function is called once after the ctor, and I usually use this to setup my basic GL state. In the new version we have some code that checks if the state has been created then calls the init function (as in "this":http://qt-project.org/doc/qt-5.0/qtgui/openglwindow.html example)
I'm trying to create a simpler version as an example for my students and it seems that we don't have a valid OpenGL context until the .show() method is called for the window which means I either have to use an if statement in the render function to setup my basic GL state or do something like this
@ OpenGLWindow window;
// and set the OpenGL format
window.setFormat(format);
// set the window size
window.resize(1024, 720);
// and finally show
window.show();
// the context is only active once we show so now we can setup GL stuff
window.initialize();
@The code in the Window ctor is
@
setSurfaceType(QWindow::OpenGLSurface);m_context = new QOpenGLContext(this);
m_context->setFormat(requestedFormat());
m_context->create();
m_context->makeCurrent(this);
@I would assume that create would have a valid context and the make current would allow me to do (in immediate mode GL) something like
@ glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
int w=this->size().width();
int h=this->size().height();
gluPerspective(45,(float)w/h,0.5,100);
glMatrixMode(GL_MODELVIEW);
gluLookAt(2,2,2,0,0,0,0,1,0);
@However unless I do a show() this is not accepted, also if I do a show() followed by a call to my initialise() function that does the lookAt code I get a brief flash of the old window then the lookat version.
hope this all makes sense if anyone can tell me the proper way of doing things (I was hoping of avoiding the branch shown in the demo and having the needsInitialize code)
jon