Reputation: 3066
I'm learning OpenGL by referencing KDAB's article part one. It is rather new and helpful. However, I get a compile error trying his code on the page.
There are three files in my Qt project: main.cpp, window.cpp and window.h.
window.h:
#ifndef WINDOW_H
#define WINDOW_H
#include <QWindow>
#include <QSurfaceFormat>
#include <QOpenGLContext>
#include <QOpenGLFunctions_4_3_Core>
class Window : public QWindow
{
Q_OBJECT
public:
Window(QScreen* screen);
signals:
private:
QOpenGLContext *m_context;
QOpenGLFunctions_4_3_Core* m_funcs;
};
#endif // WINDOW_H
window.cpp:
#include "window.h"
Window::Window(QScreen* screen) :
QWindow(screen)
{
setSurfaceType(OpenGLSurface);
QSurfaceFormat format;
format.setDepthBufferSize(24);
format.setMajorVersion(4);
format.setMinorVersion(3);
format.setSamples(4);
format.setProfile(QSurfaceFormat::CoreProfile);
setFormat(format);
create();
m_context = new QOpenGLContext;
m_context->setFormat(format);
m_context->create();
// Make the context current on this window
m_context->makeCurrent( this );
// Obtain a functions object and resolve all entry points
// m_funcs is declared as: QOpenGLFunctions_4_3_Core* m_funcs
m_funcs = m_context->versionFunctions();
if ( !m_funcs ) {
qWarning( "Could not obtain OpenGL versions object" );
exit( 1 );
}
m_funcs->initializeOpenGLFunctions();
// m_funcs->glVertexAttribDivisor();
}
main.cpp:
#include <QCoreApplication>
#include <QGLWidget>
int main(int argc, char *argv[]) {
QCoreApplication app(argc, argv);
return app.exec();
}
error: invalid conversion from 'QAbstractOpenGLFunctions*' to 'QOpenGLFunctions_4_3_Core*' [-fpermissive]
Upvotes: 3
Views: 539
Reputation: 3066
I found the solution in Qt's document. The statement should be
m_funcs = m_context->versionFunctions<QOpenGLFunctions_4_3_Core>();
then the error is eliminated.
Upvotes: 4