PDA

View Full Version : GLWidget



dragon
1st June 2007, 15:35
Hello anyone,

I have Qt-4.2.3 on WindowsXP
I have made a cube that is rotating on y-axis with a logo on the sides.
I put the cube into QMessageBox but i see only a part of the height of the glWidget.
I have also done this on Linux there i see the compleet cube.
Is this a misbehavior on WindowsXP or i missing something.

my glWidget.cpp


#include <QtGui>
#include <QtOpenGL>
#include <QGLWidget>

#include <math.h>

#include "glwidget.h"


GLWidget::GLWidget(QWidget *parent)
: QGLWidget(parent)
{
clearColor = Qt::red;
yRot = 0;
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(animate()));
timer->start(5);
}

GLWidget::~GLWidget()
{
makeCurrent();
glDeleteLists(object, 1);
}

QSize GLWidget::minimumSizeHint() const
{
return QSize(50, 50);
}

QSize GLWidget::sizeHint() const
{
return QSize(200, 200);
}



void GLWidget::setClearColor(const QColor &color)
{
clearColor = color;
updateGL();
}

void GLWidget::initializeGL()
{

object = makeObject();
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
}

void GLWidget::paintGL()
{
qglClearColor(clearColor);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslated(0.0, 0.0, -12.0);
glRotated(yRot, 0.0, 1.0, 0.0);
glCallList(object);
}

void GLWidget::resizeGL(int width, int height)
{
glViewport(0, 0, width, height);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}



GLuint GLWidget::makeObject()
{
static const int coords[4][4][3] = {
{ { +1, -1, -1 }, { -1, -1, -1 }, { -1, +1, -1 }, { +1, +1, -1 } },
{ { +1, -1, +1 }, { +1, -1, -1 }, { +1, +1, -1 }, { +1, +1, +1 } },
{ { -1, -1, -1 }, { -1, -1, +1 }, { -1, +1, +1 }, { -1, +1, -1 } },
{ { -1, -1, +1 }, { +1, -1, +1 }, { +1, +1, +1 }, { -1, +1, +1 } }
};


GLuint textures[4];
for (int j=0; j < 4; ++j)
textures[j] = bindTexture(QPixmap(QString(":/images/triple%1.png").arg(j + 1)),
GL_TEXTURE_2D);

GLuint list = glGenLists(1);
glNewList(list, GL_COMPILE);
for (int i = 0; i < 4; ++i) {
glBindTexture(GL_TEXTURE_2D, textures[i]);
glBegin(GL_QUADS);
for (int j = 0; j < 4; ++j) {
glTexCoord2d(j == 0 || j == 3, j == 0 || j == 1);
glVertex3d(0.2 * coords[i][j][0], 0.2 * coords[i][j][1],
0.2 * coords[i][j][2]);
}
glEnd();
}

glEndList();
return list;
}

void GLWidget::animate()
{

yRot += 1.0f;
updateGL();
}



Part of my MainWindow.cpp


void MainWindow::info()
{
QMessageBox *mb = new QMessageBox(this);
mb->setWindowTitle("Triple/S");
mb->setPalette(QPalette(qRgb(255, 255, 255)));
mb->setAutoFillBackground(true);
mb->setWindowIcon(QIcon(":/images/triple20.png"));
glWidget = new GLWidget(mb);
mb->setText( " some text....");
mb->exec();
}



I also try glWidget->show(); the same result.
thanks in advance.