PDA

View Full Version : How to connect OpengL 3-4 to Qt?



NewQTUser777
14th July 2015, 23:34
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.

wysota
15th July 2015, 07:04
This option is not suitable for me.
What is suitable for you then?


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?

NewQTUser777
15th July 2015, 17:05
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.


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.

wysota
16th July 2015, 11:26
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?

NewQTUser777
16th July 2015, 16:29
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:



#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?

wysota
18th July 2015, 22:04
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.

d_stranz
19th July 2015, 16:54
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.

wysota
21st July 2015, 11:52
You don't have to do that however usually you want to do that.

sajis997
21st July 2015, 12:12
Check the following blog. It may help.

http://openglrevisited.blogspot.se/

d_stranz
21st July 2015, 23:15
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?"