How to connect OpenGL 3-4 to OpenGLWidget?
-
Hi everyone! I had a one annoying problem. I'm trying connect a modern OpenGL to QOpenGLwidget which appeared in the modern version of Qt. Nothing happens. Yes, I can create an OpenGL window but unfortunately without ui elements. All you do is add turns QOpenGLWidget an empty window. Then I just have no idea how to work with it.
I am writing on Windows 8, Qt 5.5.
Before the question of how to set the I walk around almost the entire Internet, but to no avail. Nowhere is rising this topic. The documentation did not help, since I am not an expert on Qt.
I would be very grateful for any help. I think this question quite a few worries.
-
I have not written any code. I just added the OpenGLwidget to MainWindow.
An example of an interesting, but it does not contain the ui elements.
My problem is that I can't work with the built-in ui interface. If there are any interesting examples of implementation I will be very happy.
-
Hi and welcome to devnet,
Something's not clear, what are you expecting from QOpenGLWidget ?
-
@SGaist said:
Hi and welcome to devnet,
Something's not clear, what are you expecting from QOpenGLWidget ?
I just need to move on OpenGL to Qt platform. I do not understand how to do it. OpenGLWidget it seems to be a component for working with OpenGL? But I had no ideas how to use it.
-
What OpenGL code do you already have ?
-
This is part of my code. I don't think what it help to somebody. I'm still no understand how to attach OpenGL to OpenGLWidget.
#ifndef OPENGLRENDER_H
#define OPENGLRENDER_H
#include <QOpenGLFunctions>class OpenGLrender : public QOpenGLWidget, protected QOpenGLFunctions
{
public:
OpenGLrender(QWidget *parent) : QOpenGLWidget(parent) { }protected:
void initializeGL()
{
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
f->glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
}void resizeGL(int w, int h) { m_projection.setToIdentity(); m_projection.perspective(45.0f, w / float(h), 0.01f, 100.0f); } void paintGL() { QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); f->glClear(GL_COLOR_BUFFER_BIT); }
};
#endif // OPENGLRENDER_H
-
You should take a look at the OpenGL examples in the Qt sources, you'll have a better understanding of how it works