How to include freeglut in a QWidget?
Unsolved
General and Desktop
-
How to include freeglut in a QWidget?
I know that there is a QOpenGLQWidget that can do more than freeglut. But I would like to be able to embed a freeglut window into a QWidget.
All code
main.cpp
#include "widgetglut.h" #include <QApplication> #include <QScreen> #include <QDebug> int main(int argc, char *argv[]) { QApplication a(argc, argv); WidgetGlut w; //выставляем подстройку к размеру экрана QSize screenSize = qApp->screens().at(0)->availableSize(); const int width = screenSize.width() / 2.5; const int height = screenSize.height() * 0.5; w.setGeometry((screenSize.width() - width) / 2.0, (screenSize.height() - height) / 2.0, width, height); w.setWindowTitle("куте + бесплатный глут"); w.setScale((float)width, (float)height); w.show(); return a.exec(); }
widgetglut.h
#ifndef WIDGETGLUT_H #define WIDGETGLUT_H #include <QWidget> #include "myfreeglut.h" class WidgetGlut : public QWidget { Q_OBJECT public: WidgetGlut(QWidget *parent = 0); ~WidgetGlut(); protected: private: protected: QGridLayout* gl_layaout; }; #endif // WIDGETGLUT_H
widgetglut.cpp
#include "widgetglut.h" WidgetGlut::WidgetGlut(QWidget *parent) : QWidget(parent) { gl_layaout = new QGridLayout(parent); MyFreeGlut * glutWindow = new MyFreeGlut (); glutWindow->Size(this->width,this->height); glutWindow->Position(this->x,this->y); QWidget *container = QWidget::createWindowContainer(glutWindow); gl_layaout->addWidget(container); this->setLayout(gl_layaout); } WidgetGlut::~WidgetGlut() { }
myfreeglut.h
#ifndef MYFREEGLUT_H #define MYFREEGLUT_H #include <GL/glew.h> #include <GLFW/glfw3.h> #include <GL/freeglut.h> class MyFreeGlut { public: MyFreeGlut() ; ~MyFreeGlut(); int Size(int x, int y); int Plaise(int x, int y); void Init(void); void LineSegment(void); private: int _size_x {0}; int _size_y {0}; int _position_x {0}; int _position_y {0}; }; #endif // MYFREEGLUT_H
myfreeglut.cpp
#include "myfreeglut.h" MyFreeGlut::MyFreeGlut() { glutInit(&argc, argv); // How to call it correctly! ? // glutInitContextVersion(4, 3); // glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(_size_x, _size_y); glutInitWindowPosition( _position_x, _position_y) ; glutCreateWindow("line"); MyFreeGlut::Init(); glutDisplayFunc(MyFreeGlut::LineSegment()); glutMainLoop(); } int MyFreeGlut::Size(int x, int y) { _size_x =x; _size_y =y; } int MyFreeGlut::Position(int x, int y) { _position_x =x; _position_y =y; } void MyFreeGlut::Init(void) { glClearColor(1.0, 1.0, 1.0, 0.0); glMatrixMode(GL_PROJECTION); gluOrtho2D(0.0, 200.0, 0.0, 160.0); } void MyFreeGlut::LineSegment(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 0.0, 0.0); glBegin(GL_LINES); glVertex2i (180, 15); glVertex2i (10, 145); glEnd(); glFlush(); }