I am using qt 5.0.2 (Windows x64) . The problem is that qt only supports OpenGl 3 functions and for example I can't use glBegin(), glortho() etc. Do you have any idea how I can use OpenGL 1.x within qt?
-
Did you built QT yourself or get a pre-packaged version (for MSVC2010 or such)? – Hydronium Apr 30 '13 at 20:10
-
Is there any particular reason you are mixing brand new (Qt 5) and ancient technology (OpenGL 1.x)? – cmannett85 Apr 30 '13 at 20:58
2 Answers
Where did you get the (wrong) idea that Qt 5 supports Only OpenGL >= 3.0? Qt on its own supports all current Desktop OpenGL versions and profiles (from 1.1 to 4.3, Core/Compability) as well as OpenGL ES (1.1 to 3.0).
By any chance, are you using the binary OpenGL ES 2 downloads (through ANGLE) for Windows? If so, download the Desktop GL version (or build it yourself passing -opengl desktop
to configure).
Note that, in general,
- you need drivers that support the version you ask for (f.i. OS X 10.8 supports up to 3.2)
- you need a Qt build matching the GL version you are going to use
- certain parts of Qt require certain GL versions: QtQuick2 requires OpenGL >= 2.0 or ES 2.0 (and in case of OpenGL >= 3.2, a compatibility profile must be used)

- 21,934
- 4
- 55
- 70
I use this included as a header, "gl.h", in my Qt applications where I want to call OpenGL functions:
#ifndef GL_H
#define GL_H
#ifdef __APPLE__
#include <GL/glew.h>
#include <GLUT/glut.h>
#else
#include <GL/glew.h>
#include <GL/glut.h>
#endif
#endif // GL_H
Note, you need to have installed the correct builds of OpenGL, GLEW and GLUT for this include to work correctly. If you use MinGW, build GLEW and GLUT to use MinGW. If you use Visual C++ 2010, build them to support Visual C++ 2010.
Part of my mainwindow.cpp:
#include "gl.h"
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "about.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_glWidget = new GLWidget();
this->setCentralWidget(m_glWidget);
}
MainWindow::~MainWindow()
{
delete ui;
}
Take a look at this code here to get the full context: https://bitbucket.org/pcmantinker/csc-4356/src/2843c59fa06d0f99d1ba90bf8e328cbb10b1cfb2/project2?at=master
My code is Qt 4.x but should be easy enough to port to Qt 5. Also, here is a reference to the class web page that I took in the fall of 2012: http://csc.lsu.edu/~kooima/csc4356/index.html
It includes pre-built dlls for Windows environments for both Visual C++ 2010 and MinGW.

- 9,634
- 10
- 46
- 85