Anwendung mit abgeleitetem OGLWidget wird fehlerhaft beendet
Verfasst: 23. Mai 2012 13:46
Hallo Qt-Gemeinde,
habe ein ganz merkwürdiges Problem.....
Ich habe ein eigenes OpenGLWidget (natürlich von dem OGLWidget abgeleitet). Wenn ich das Ding in meiner Hauptanwendung einbaue
und laufen lass ist zunächst alles prima....beende ich die Anwendung jedoch, bekomme ich einen Fehler (siehe Bild im Anhang)
Der Debuger schmeißt folgenden Fehler:
Hat irgend wer eine Ahnung woran das hängen könnte?
Hier noch der Code des OpenGlViewers:
habe ein ganz merkwürdiges Problem.....
Ich habe ein eigenes OpenGLWidget (natürlich von dem OGLWidget abgeleitet). Wenn ich das Ding in meiner Hauptanwendung einbaue
Code: Alles auswählen
this->m_glwidget=new OpenGlWidget(this);
this->setCentralWidget(m_glwidget);
Der Debuger schmeißt folgenden Fehler:
Code: Alles auswählen
ASSERT: "group->context() == q_ptr" in file qgl.cpp, line 1684
Invalid parameter passed to C runtime function.Hier noch der Code des OpenGlViewers:
Code: Alles auswählen
#include "openglviewer.h"
#ifndef GL_MULTISAMPLE
#define GL_MULTISAMPLE 0x809D
#endif
OpenGlView::OpenGlView(QWidget *parent): QGLWidget(parent)
{
this->m_background=new Background(QColor(89,133,255),QColor(225,225,225));
this->m_camera=new Camera(this->height(),
this->width(),
QVector3D(0.0,0.0,10),
QVector3D(0,0,0),
QVector3D(0,1,0),::PERSPECTIVE);
this->m_camera->setFarPlane(10000);
this->m_camera->setNearPlane(1);
this->m_camera->setFOV(90);
this->m_clear_color=QColor(114,114,114);
this->setFormat(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer | QGL::AlphaChannel));
}
OpenGlView::~OpenGlView()
{
delete this->m_background;
delete this->m_camera;
}
void OpenGlView::initializeGL()
{
qglClearColor(this->m_clear_color);
glDisable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glEnable(GL_CULL_FACE);
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_MULTISAMPLE);
glEnable(GL_COLOR_MATERIAL);
static GLfloat lightPosition[4] = { 0.5, 5.0, 7.0, 1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
}
void OpenGlView::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
draw();
}
void OpenGlView::resizeGL(int width, int height)
{
glViewport(0, 0, width , height);
this->m_camera->RenderTargetSizeChanged(height,width);
this->m_camera->Transform();
}
void OpenGlView::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() == Qt::LeftButton)
{
if (this->m_camera->getCameraMode() == PAN)
{
this->m_camera->Pan(event->x(), event->y());
updateGL();
}
else if (this->m_camera->getCameraMode() == ROTATE)
{
this->m_camera->Rotate(event->x(), event->y());
updateGL();
}
}
else if (event->buttons() == Qt::RightButton)
{
this->m_camera->Pan(event->x(), event->y());
updateGL();
}
else if (event->buttons() == Qt::MidButton)
{
this->m_camera->Rotate(event->x(), event->y());
updateGL();
}
}
void OpenGlView::wheelEvent(QWheelEvent *event)
{
if (event->delta() < 0)
this->m_camera->ZoomOut();
else if (event->delta() > 0)
this->m_camera->ZoomIn();
updateGL();
}
void OpenGlView::mousePressEvent(QMouseEvent *event)
{
if (event->button()==Qt::LeftButton)
{
if (this->m_camera->getCameraMode() == PAN)
{
this->m_camera->StartPan(event->x(), event->y());
}
else if (this->m_camera->getCameraMode() ==ROTATE)
{
this->m_camera->StartRotation(event->x(), event->y());
}
}
else if (event->button()==Qt::RightButton)
{
this->m_camera->StartPan(event->x(), event->y());
}
else if (event->button()==Qt::MidButton)
{
this->m_camera->StartRotation(event->x(), event->y());
}
}
void OpenGlView::draw()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
//Background zeichnen
this->m_background->draw();
this->m_camera->Transform();
//Trihedron zeichnen
this->drawAxis3D();
glPushMatrix();
//Hier wird gezeichnet!!!
glPopMatrix();
}
void OpenGlView::drawAxis3D()
{
GLUquadricObj *pObj; // Temporary, used for quadrics
// Measurements
float fAxisRadius = 0.025f;
float fAxisHeight = 1.0f;
float fArrowRadius = 0.06f;
float fArrowHeight = 0.1f;
// Setup the quadric object
pObj = gluNewQuadric();
gluQuadricDrawStyle(pObj, GLU_FILL);
gluQuadricNormals(pObj, GLU_SMOOTH);
gluQuadricOrientation(pObj, GLU_OUTSIDE);
gluQuadricTexture(pObj, GLU_FALSE);
///////////////////////////////////////////////////////
// Draw the blue Z axis first, with arrowed head
glColor4f(0.0f, 0.0f, 1.0f,1.0f);
gluCylinder(pObj, fAxisRadius, fAxisRadius, fAxisHeight, 10, 1);
glPushMatrix();
glTranslatef(0.0f, 0.0f, 1.0f);
gluCylinder(pObj, fArrowRadius, 0.0f, fArrowHeight, 10, 1);
glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
gluDisk(pObj, fAxisRadius, fArrowRadius, 10, 1);
glPopMatrix();
///////////////////////////////////////////////////////
// Draw the Red X axis 2nd, with arrowed head
glColor4f(1.0f, 0.0f, 0.0f,1.0f);
glPushMatrix();
glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
gluCylinder(pObj, fAxisRadius, fAxisRadius, fAxisHeight, 10, 1);
glPushMatrix();
glTranslatef(0.0f, 0.0f, 1.0f);
gluCylinder(pObj, fArrowRadius, 0.0f, fArrowHeight, 10, 1);
glRotatef(180.0f, 0.0f, 1.0f, 0.0f);
gluDisk(pObj, fAxisRadius, fArrowRadius, 10, 1);
glPopMatrix();
glPopMatrix();
///////////////////////////////////////////////////////
// Draw the Green Y axis 3rd, with arrowed head
glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
glPushMatrix();
glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
gluCylinder(pObj, fAxisRadius, fAxisRadius, fAxisHeight, 10, 1);
glPushMatrix();
glTranslatef(0.0f, 0.0f, 1.0f);
gluCylinder(pObj, fArrowRadius, 0.0f, fArrowHeight, 10, 1);
glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
gluDisk(pObj, fAxisRadius, fArrowRadius, 10, 1);
glPopMatrix();
glPopMatrix();
////////////////////////////////////////////////////////
// White Sphere at origin
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
gluSphere(pObj, 0.05f, 15, 15);
// Delete the quadric
gluDeleteQuadric(pObj);
}