Menu

#248 Glut VC++ Windows QT5 not working glutGameModeGet segmentation fault

open
nobody
None
2
2019-08-28
2019-08-28
Gust
No

Hello,
I am trying to make freeglut work in a qt5 project and have reported this to qt forums but it now seems like a glut problem also im trying to use freeglut to draw opengl within qt but the moment i start my qt program within 3 seconds it crashes saying the program ended unexpectedly i'm using qglwidget from qt and drawing with glut inside there following a youtube tutorial

i tried using debugger and it seems glutinit internally is causing memory leak
or seg fault or something and prog dies in function glutgamemodeget

Main.cpp

#include "mainwindow.h"
#include "glwidget.h"
#include <QApplication>
#include <GL/glut.h>

int main(int argc, char *argv[])
{
    glutInit(&argc,argv);
    QApplication a(argc, argv);
    MainWindow w;
//    GLWidget w;
    w.show();

    return a.exec();
}

glwidget.h

#ifndef GLWIDGET_H
#define GLWIDGET_H

#include <QGLWidget>

class GLWidget : public QGLWidget
{
    Q_OBJECT
public:
  //  GLWidget();
    explicit GLWidget(QWidget * parent = 0);
    void initializeGL();
    void paintGL();
    void resizeGL(int w,int h);
    //explicit GLWidget( QWidget * parent = 0 );
};

#endif // GLWIDGET_H

glwidget.cpp

#include "glwidget.h"
#include <GL/glut.h>

GLWidget::GLWidget(QWidget *parent):QGLWidget(parent)
{

}

//GLWidget::GLWidget()
//{

//}

void GLWidget::initializeGL()
{
    glClearColor(0.2,0.2,0.2,1);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHTING);
    glEnable(GL_COLOR_MATERIAL);
}

void GLWidget::paintGL()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//    glMatrixMode(GL_MODELVIEW);
//    glLoadIdentity();![](http://)
//    gluLookAt(0,0,5,0,0,0,0,1,0);
    glColor3f(1,0,0);
    glutSolidSphere(1,20,20);
}

void GLWidget::resizeGL(int w, int h)
{
    glViewport( 0, 0, (GLint)w, (GLint)h );
}
1 Attachments

Discussion


Log in to post a comment.

MongoDB Logo MongoDB