vendredi 8 mai 2015

Setting up GLEW with QOpenGLWidget

community,

I have a Problem Setting up GLEW in Qt. Here is my class

#ifndef MYQOPENGLWIDGET_H
#define MYQOPENGLWIDGET_H

#define QT_NO_OPENGL_ES_2

#define GLEW_STATIC
#include <GL/glew.h>
#include <QOpenGLWidget>
#include <QMessageBox>

#include <iostream>


class MyQOpenGLWidget : public QOpenGLWidget{

public:
MyQOpenGLWidget(QWidget *parent = 0): QOpenGLWidget(parent){}

void initializeGL()
{



    GLenum err = glewInit();

    if(err != GLEW_OK)
    {
        QMessageBox::information(0, "Error!", QString("Failed to initialize GLEW ") + reinterpret_cast<const char*>(glewGetErrorString(err)), QMessageBox::Yes );
        exit(1);
    }
    else
    {
        QMessageBox::information(0, "Success!", QString("Succeded to initialize GLEW! "), QMessageBox::Yes );

    }

    glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    glEnable(GL_DEPTH_TEST);

    std::cout << "Leaving initializeGL" << std::endl;
}

void paintGL()
{
    std::cout << "paintGL()" << std::endl;
}


void resizeGL(int w, int h)
{
    if(h == 0)
      h=1;
    glViewport(0,0,w,h);

    std::cout << "resizeGL()" << std::endl;

    glOrtho(-1, 1, -1, 1, -1, 1);

}

};

#endif // MYQOPENGLWIDGET_H

In my pro-file I succesfully link to GLEW (which is included in gltools.lib which Comes form the OpenGLSuperbible )

QT       += core gui widgets

QT += opengl

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = untitled2
TEMPLATE = app

INCLUDEPATH += "C:/Users/fin/Documents/GLEWTEst/include"
LIBS += "C:/Users/fin/Documents/GLEWTEst/lib/gltools.lib"

SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h \
    myqopenglwidget.h

FORMS    += mainwindow.ui

DISTFILES += \
    ../build-untitled2-Desktop_Qt_5_4_1_MSVC2012_OpenGL_32bit-Debug/debug/untitled2.exe

Now what happens is, the Programm starts, and initializes GLEW correctly and calls initializeGL(), resizeGL() and then paintGL() Then it says the Programm was terminated with Exit code 1. So just a program Crash without any error message. Can anyone help me solve this?

Aucun commentaire:

Enregistrer un commentaire