Correct usage of QOpenGLContext??? [SOLVED]
-
Hi there everybody,
I want to create a simple example for using a QOpenGLContext in QT5.
I have found "this":http://www.youtube.com/watch?v=VxsS7u-vgc8 YouTube example and followed the steps exactly.
One cannot see everything especially not the main function.I have written a simple class deriving from QWindow (as you can see in the video).
@
//header file
class Window: public QWindow
{
private:
QOpenGLContext *_glContext;
public:
Window(QScreen *screen=0);
}@@
//.cpp fileWindow::Window(QScreen *screen): QWindow(screen)
{
setSurfaceType(OpenGLSurface);QSurfaceFormat fmt;
fmt.setMajorVersion(4);
fmt.setMinorVersion(2);
fmt.setProfile(QSurfaceFormat::CoreProfile); //whatever this isthis->setFormat(fmt);
create();
resize(300, 300);
_glContext = new QOpenGLContext();
_glContext->setFormat(fmt);_glContext->create();
if(!_glContext->isValid())
qCritical()<<"The OpenGL context is invalid!"; //I allways get this message//now another test:
//the next line prints: "Window format version is: 4.2" which is correct
qDebug()<<"Window format version is: "<<this->format().majorVersion()<<"."<<this->format().minorVersion();
//the next line prints: "Context format version is: 2.0" Which is ofcourse not correct! WTF?
qDebug()<<"Context format version is: "<<_glContext->format().majorVersion()<<"."<<_glContext->format().minorVersion();
}
@As you can see, the format of the Window does not match the format of the context!!??!??
Is this a bug or am i missing something?? Maybe i do it wrong in the main, already?@
#include "window.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);a.setApplicationName("test");
a.setApplicationVersion("0.1");Window w; //do i have to create a QScreen first to give it to the Window?
w.show(); //A white window of size 300x300 appears
}@I need to have a OpenGL 4.2 context!
Any help would be nice!
-
I also found this "example":http://qt-project.org/doc/qt-5.0/qtgui/openglwindow.html. It is one of the view QT5 examples delivered with the QT5.0.0 framework
But this seems to be an example for OpenGL ES2. If i set the format version of the window to anything >2.9 the whole example crashes!
I wish i had the example from the youtube video as code! He used 3.3 by the way which is not working in my case, either.I mean can i somehow setup my QT project by telling it to use OpenGL desktop version?
Or do I have to recompile the whole framework and setting the open gl module with configure?Does nobody know anything about that?
-
Ah in that case, have a read of this "post":http://qt-project.org/forums/viewthread/22821/#107114 which explains the issue and solution. Please do vote on the linked bug report.
-
Hi again. I did compile the framework in windows and Ubuntu 12.
Now in windows i get a 4.2 context!
But in Ubuntu it is still the same. But now i only get a 2.0 window format and a 2.1 context??? What is the right command to start the configure skript?I used:
@./configure -prefix $PWD/qtbase -opensource -nomake tests -opengl desktop -developer-build@
And then
@make -j 4@???
By the way, our graphics driver supports OpenGL 4.2! The context in our QT 4.8.4 version of our project returned 4.2 and was able to use at least Shaders of version 3.3
-
OK. It's me again. I just builded an example with rendering part and i recognized that the created context is perfectly rendering and using shaders of version 3.3 !!!!! (didn't test any higher shader version, but i guess it would also work)
So maybe that is a bug?? The context format returns 2.1 right after creating it but it renders 3.3 shaders without any problem!
In Windows the same code returns 4.2 and it is also rendering without problems!Merry X Mas and a happy end of the world (today the maya calendar ends! :D )
-
This my post is my own correct usage.Working perfectly.
it is HOWTO using "QOpenGLFunctions_3_3_Core" class.
There is no need Q_OBJECT macro.
There is no need to define custom signal or slot.
There is no need to define any connections.
I put it as be reference:)http://qt-project.org/wiki/Using-QOpenGLFunctions-and-QOpenGLContext