How to connect OpengL 3-4 to Qt?
Hi everyone! I'm trying to connect to the new OpenGL. But success is not achieved.
All I managed to do is create a new project and will place on it OpenGLWidget. What to do next I don't know.
In example on opengl entire interface is created from the code without the use Qt designer. This option is not suitable for me. I'm placed OpenGLWidget and some buttons then I want to draw triangles or other primitives. No success. How to initialize OpenGL? Where I can place draw functions?
I would be grateful for any help.
Re: How to connect OpengL 3-4 to Qt?
Quote:
Originally Posted by
NewQTUser777
This option is not suitable for me.
What is suitable for you then?
Quote:
I'm placed OpenGLWidget and some buttons then I want to draw triangles or other primitives. No success. How to initialize OpenGL? Where I can place draw functions?
Did you read the docs on QOpenGLWidget? What methods did you reimplement?
Re: How to connect OpengL 3-4 to Qt?
Quote:
Originally Posted by
wysota
What is suitable for you then?
I started using Qt as an alternative to Window API.
Create a project, added OpenGLWidget, placed buttons and menu. And then ... I do not know what to do. I have no idea how to work with the ui elements from code.
Quote:
Originally Posted by
wysota
Did you read the docs on QOpenGLWidget? What methods did you reimplement?
Yes. I tried to implement the initializeGL(), paintGL(), resizeGL(), but unfortunately. There is an opinion that in fact these functions are called not for my placed openGLWidget.
Re: How to connect OpengL 3-4 to Qt?
Did you implement them in a class you then use to instantiate the GL widget? Did you promote the widget you placed on the form to that class?
Re: How to connect OpengL 3-4 to Qt?
Quote:
Originally Posted by
wysota
Did you implement them in a class you then use to instantiate the GL widget? Did you promote the widget you placed on the form to that class?
I'm added new class OpenGLrender:
Code:
#ifndef OPENGLRENDER_H
#define OPENGLRENDER_H
class OpenGLrender : public QOpenGLWidget
{
public:
OpenGLrender();
};
#endif // OPENGLRENDER_H
Before that, I placed OpengLWidget on the form. What's next?
Re: How to connect OpengL 3-4 to Qt?
Nothing is "next". If you implement a class and never use it then why are you surprised its methods are not called? You have to instantiate that class either by doing it explicitly or by promoting an existing widget on a form to that class.
Re: How to connect OpengL 3-4 to Qt?
Quote:
class OpenGLrender : public QOpenGLWidget
{
// ...
}
And beyond what wysota told you, if you derive a class from anything in the QObject hierarchy, you need to include the Q_OBJECT macro in the class definition.
Re: How to connect OpengL 3-4 to Qt?
You don't have to do that however usually you want to do that.
Re: How to connect OpengL 3-4 to Qt?
Check the following blog. It may help.
http://openglrevisited.blogspot.se/
Re: How to connect OpengL 3-4 to Qt?
Quote:
You don't have to do that however usually you want to do that.
True, if you don't need to use the metainformation system in the class. But for newbies, sometimes it's good to get a habit started so that later we don't have to reply to the posts asking "why don't my slots work?"