QT & raw OpenGL with glew not working
-
It's been 2 days now that I'm trying to setup a working window where I can issue raw openGL commands with glew, but all I can see on screen is just a white empty window while my glClearColor is set to red
So here's glwindow.h :
#ifndef GLWINDOW_H #define GLWINDOW_H #include <QWindow> #include <QOpenGLContext> class GLWindow : public QWindow { QOpenGLContext* context; public: GLWindow(const QSurfaceFormat& format); void initGL(); void resize(int w, int h); }; #endif // GLWINDOW_Hglwindow.cpp:
#define GLEW_STATIC #include <glew.h> #include "glwindow.h" #include <QDebug> GLWindow::GLWindow(const QSurfaceFormat& format) : context(0) { setSurfaceType( OpenGLSurface ); setFormat(format); create(); context = new QOpenGLContext(this); context->setFormat(format); context->create(); context->makeCurrent(this); glViewport(0,0,500,500); glClearColor(1.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); context->swapBuffers(this); } void GLWindow::resize(int w, int h) { } void GLWindow::initGL() { }main.cpp:
#include <QGuiApplication> #include <glwindow.h> #include <QSurfaceFormat> int main(int argc, char *argv[]) { QGuiApplication a(argc, argv); QSurfaceFormat format; format.setMajorVersion( 3 ); #if !defined(Q_OS_MAC) format.setMinorVersion( 3 ); #else format.setMinorVersion( 2 ); #endif format.setDepthBufferSize( 24 ); format.setSamples( 4 ); format.setProfile( QSurfaceFormat::CoreProfile ); GLWindow window(format); window.show(); return a.exec(); }Lastly here's the .pro file:
QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = Tentativo5 TEMPLATE = app SOURCES += main.cpp\ glwindow.cpp HEADERS += \ glwindow.h INCLUDEPATH += "C:/....../OpenGL/headers/GL" LIBS += "C:/......./OpenGL/lib/glew32s.lib" LIBS += opengl32.libI'm pretty desperate at this point so feel free to ask anything about the setup, I'm really not suited to set all the mess that qt apparently need to have a working opengl window
-
Hi and welcome to devnet,
With Qt 5 you don't need glew at all, you can use QOpenGLFunctions and derived class.
-
Hi and welcome to devnet,
With Qt 5 you don't need glew at all, you can use QOpenGLFunctions and derived class.
-
The OpenGL window example might be a good starting point.
-
The OpenGL window example might be a good starting point.
-
renderLater is used to trigger an update of the scene while exposeEvent will trigger it when the window exposure changed.
-
renderLater is used to trigger an update of the scene while exposeEvent will trigger it when the window exposure changed.
@SGaist
Last question, I found a working example here: https://wiki.qt.io/Using-QOpenGLFunctions-and-QOpenGLContext
which I blindly implemented and played a bit around till I finally rendered a triangle on screen, the problem is that as with QGLWidget, if I resize fast enough I start to see white flickering as shown in this screenshot: http://oi63.tinypic.com/11wgi9t.jpg
what could be causing it?Fun thing is that I switched from qglwidget since I thought the performance impact could have caused it
-
I can't say from the top of my head. However, QGLWidget is old tech, you should move to the new QOpenGLWidget class directly.
-
I can't say from the top of my head. However, QGLWidget is old tech, you should move to the new QOpenGLWidget class directly.