sunLoadingImage
whowedImag
decoration left 1
decoration left 2
transhome
transprojects
transgallery
transarticles
decoration rigth
English

Show/Hide search bar
black cat logo variable logo
[04.12.2012]

Qt and OpenGL Core Profile

How to use last versions of OpenGL in Qt without help of QGL wrapper? You require Qt 4.8+ version. For automatic initialization of OpenGL functions you can use GLEW library.

Take any sample project for QGLWidget and modify it a bit. For initialization of last version of OpenGL: create rendering context format (1), set required version of OpenGL (2), set usage of OpenGL Core Profile (3). Pass created format to QGLWidget (4): #include "coreglwidget.h"
int main( int argc, char* argv[] )
{
   QApplication a( argc, argv );
   QGLFormat glFormat;                            // 1
   glFormat.setVersion( 4, 2 );                   // 2
   glFormat.setProfile( QGLFormat::CoreProfile ); // 3
   CoreGLWidget w( glFormat );                    // 4
   w.show();
   return a.exec();
}

Declaration of class based on QGLWidget class:
class CoreGLWidget : public QGLWidget
{
Q_OBJECT
public:
   CoreGLWidget( const QGLFormat& format, QWidget* parent = 0 );
protected:
   virtual void initializeGL();
   virtual void resizeGL( int w, int h );
   virtual void paintGL();
};

Constructor of widget and initialization of OpenGL rendering context with passed format:
CoreGLWidget::CoreGLWidget( const QGLFormat& format, QWidget* parent )
   : QGLWidget( format, parent )
{
}

Implement initializeGL(), resizeGL() and paintGL() as usual.




Sun and Black Cat- Igor Dykhta (igor dykhta email) 2007-2014