#include "cubewidget.h"
cubeWidget::cubeWidget()
: rot(0.0)
{
}
void cubeWidget::initializeGL()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
/*
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
QString s = "C:/Dokumente und Einstellungen/me/Desktop/opengl_cmyk.png";
if(!texture.load(s))
{
std::cout << "Error loading texture!" << std::endl;
exit(1);
}
nr = bindTexture(texture, GL_TEXTURE_2D);
*/
connect(timer, SIGNAL(timeout()), this, SLOT(rotateOneStep()));
timer->start(10);
}
void cubeWidget::rotateOneStep()
{
rot += 0.5;
rot = rot < 360.0 ? rot : rot - 360.0;
updateGL();
}
void cubeWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/*
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(sin(rot /180.0*3.141) * 180, 1, 0, 0);
glRotatef(sin((rot+135)/180.0*3.141) * 180, 0, 1, 0);
glRotatef(sin((rot+270)/180.0*3.141) * 180, 0, 0, 1);
glBindTexture(GL_TEXTURE_2D, nr);
glBegin(GL_QUADS);
// vorne
glTexCoord2d(0.0, 0.0);
glVertex3i(-1, -1, +1);
glTexCoord2d(1.0, 0.0);
glVertex3i(+1, -1, +1);
glTexCoord2d(1.0, 1.0);
glVertex3i(+1, +1, +1);
glTexCoord2d(0.0, 1.0);
glVertex3i(-1, +1, +1);
// rechts
glTexCoord2d(0.0, 0.0);
glVertex3i(+1, -1, +1);
glTexCoord2d(1.0, 0.0);
glVertex3i(+1, -1, -1);
glTexCoord2d(1.0, 1.0);
glVertex3i(+1, +1, -1);
glTexCoord2d(0.0, 1.0);
glVertex3i(+1, +1, +1);
// hinten
glTexCoord2d(0.0, 0.0);
glVertex3i(+1, -1, -1);
glTexCoord2d(1.0, 0.0);
glVertex3i(-1, -1, -1);
glTexCoord2d(1.0, 1.0);
glVertex3i(-1, +1, -1);
glTexCoord2d(0.0, 1.0);
glVertex3i(+1, +1, -1);
// links
glTexCoord2d(0.0, 0.0);
glVertex3i(-1, -1, -1);
glTexCoord2d(1.0, 0.0);
glVertex3i(-1, -1, +1);
glTexCoord2d(1.0, 1.0);
glVertex3i(-1, +1, +1);
glTexCoord2d(0.0, 1.0);
glVertex3i(-1, +1, -1);
// oben
glTexCoord2d(0.0, 0.0);
glVertex3i(-1, +1, +1);
glTexCoord2d(1.0, 0.0);
glVertex3i(+1, +1, +1);
glTexCoord2d(1.0, 1.0);
glVertex3i(+1, +1, -1);
glTexCoord2d(0.0, 1.0);
glVertex3i(-1, +1, -1);
// unten
glTexCoord2d(0.0, 0.0);
glVertex3i(-1, -1, -1);
glTexCoord2d(1.0, 0.0);
glVertex3i(+1, -1, -1);
glTexCoord2d(1.0, 1.0);
glVertex3i(+1, -1, +1);
glTexCoord2d(0.0, 1.0);
glVertex3i(-1, -1, +1);
glEnd();*/
}
void cubeWidget::resizeGL(int width, int height)
{
glViewport(0, 0, (GLint)width, (GLint)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2.0, 2.0, -2.0, 2.0, 2.0, -2.0);
}
int main(int argc, char **argv)
{
cubeWidget cube;
cube.show();
return app.exec();
}
#include "cubewidget.h"
cubeWidget::cubeWidget()
: rot(0.0)
{
}
void cubeWidget::initializeGL()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
/*
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
QString s = "C:/Dokumente und Einstellungen/me/Desktop/opengl_cmyk.png";
if(!texture.load(s))
{
std::cout << "Error loading texture!" << std::endl;
exit(1);
}
nr = bindTexture(texture, GL_TEXTURE_2D);
*/
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(rotateOneStep()));
timer->start(10);
}
void cubeWidget::rotateOneStep()
{
rot += 0.5;
rot = rot < 360.0 ? rot : rot - 360.0;
updateGL();
}
void cubeWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/*
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(sin(rot /180.0*3.141) * 180, 1, 0, 0);
glRotatef(sin((rot+135)/180.0*3.141) * 180, 0, 1, 0);
glRotatef(sin((rot+270)/180.0*3.141) * 180, 0, 0, 1);
glBindTexture(GL_TEXTURE_2D, nr);
glBegin(GL_QUADS);
// vorne
glTexCoord2d(0.0, 0.0);
glVertex3i(-1, -1, +1);
glTexCoord2d(1.0, 0.0);
glVertex3i(+1, -1, +1);
glTexCoord2d(1.0, 1.0);
glVertex3i(+1, +1, +1);
glTexCoord2d(0.0, 1.0);
glVertex3i(-1, +1, +1);
// rechts
glTexCoord2d(0.0, 0.0);
glVertex3i(+1, -1, +1);
glTexCoord2d(1.0, 0.0);
glVertex3i(+1, -1, -1);
glTexCoord2d(1.0, 1.0);
glVertex3i(+1, +1, -1);
glTexCoord2d(0.0, 1.0);
glVertex3i(+1, +1, +1);
// hinten
glTexCoord2d(0.0, 0.0);
glVertex3i(+1, -1, -1);
glTexCoord2d(1.0, 0.0);
glVertex3i(-1, -1, -1);
glTexCoord2d(1.0, 1.0);
glVertex3i(-1, +1, -1);
glTexCoord2d(0.0, 1.0);
glVertex3i(+1, +1, -1);
// links
glTexCoord2d(0.0, 0.0);
glVertex3i(-1, -1, -1);
glTexCoord2d(1.0, 0.0);
glVertex3i(-1, -1, +1);
glTexCoord2d(1.0, 1.0);
glVertex3i(-1, +1, +1);
glTexCoord2d(0.0, 1.0);
glVertex3i(-1, +1, -1);
// oben
glTexCoord2d(0.0, 0.0);
glVertex3i(-1, +1, +1);
glTexCoord2d(1.0, 0.0);
glVertex3i(+1, +1, +1);
glTexCoord2d(1.0, 1.0);
glVertex3i(+1, +1, -1);
glTexCoord2d(0.0, 1.0);
glVertex3i(-1, +1, -1);
// unten
glTexCoord2d(0.0, 0.0);
glVertex3i(-1, -1, -1);
glTexCoord2d(1.0, 0.0);
glVertex3i(+1, -1, -1);
glTexCoord2d(1.0, 1.0);
glVertex3i(+1, -1, +1);
glTexCoord2d(0.0, 1.0);
glVertex3i(-1, -1, +1);
glEnd();*/
}
void cubeWidget::resizeGL(int width, int height)
{
glViewport(0, 0, (GLint)width, (GLint)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2.0, 2.0, -2.0, 2.0, 2.0, -2.0);
}
int main(int argc, char **argv)
{
QApplication app(argc, argv);
cubeWidget cube;
cube.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
I'm using QT 4.1.4 for windows with MingW compiler(3.4.2)
Bookmarks