Commit 450e6140 by Kai Westerkamp

tesselation

naja
parent 60a1e7e0
......@@ -21,7 +21,7 @@ void CubeWidget::initializeGL ()
glClearColor(0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST);
tesselation = 0;
// enable default shading
showFlat();
......@@ -55,41 +55,73 @@ void CubeWidget::paintGL ( )
GLfloat yellow[] = {1.0,1.0,0.0};
glBegin(GL_QUADS);
float increment = 1.0/(pow(2,tesselation));
setMaterial(red);
glVertex3f( 0.5f, 0.5f,-0.5f);
glVertex3f(-0.5f, 0.5f,-0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f, 0.5f);
for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( x+increment, 0.5f,y);
glVertex3f(x, 0.5f,y);
glVertex3f(x, 0.5f, y+increment);
glVertex3f( x+increment, 0.5f, y+increment);
}
}
setMaterial(magenta);
glVertex3f( 0.5f,-0.5f, 0.5f);
glVertex3f(-0.5f,-0.5f, 0.5f);
glVertex3f(-0.5f,-0.5f,-0.5f);
glVertex3f( 0.5f,-0.5f,-0.5f);
for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( x+increment, -0.5f,y+increment);
glVertex3f(x, -0.5f,y+increment);
glVertex3f(x, -0.5f, y);
glVertex3f( x+increment, -0.5f, y);
}
}
setMaterial(green);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f,-0.5f, 0.5f);
glVertex3f( 0.5f,-0.5f, 0.5f);
for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( x+increment,y+increment, 0.5f);
glVertex3f(x, y+increment, 0.5f);
glVertex3f(x, y, 0.5f);
glVertex3f( x+increment, y, 0.5f);
}
}
setMaterial(yellow);
glVertex3f( 0.5f,-0.5f,-0.5f);
glVertex3f(-0.5f,-0.5f,-0.5f);
glVertex3f(-0.5f, 0.5f,-0.5f);
glVertex3f( 0.5f, 0.5f,-0.5f);
for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( x+increment,y, -0.5f);
glVertex3f(x, y,-0.5f);
glVertex3f(x, y+increment,-0.5f);
glVertex3f( x+increment,y+increment, -0.5f);
}
}
setMaterial(blue);
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f,-0.5f);
glVertex3f(-0.5f,-0.5f,-0.5f);
glVertex3f(-0.5f,-0.5f, 0.5f);
for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( -0.5f, x+increment,y+increment);
glVertex3f( -0.5f,x+increment,y);
glVertex3f( -0.5f,x, y);
glVertex3f( -0.5f,x, y+increment);
}
}
setMaterial(cyan);
glVertex3f( 0.5f, 0.5f,-0.5f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f,-0.5f, 0.5f);
glVertex3f( 0.5f,-0.5f,-0.5f);
for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( 0.5f, x+increment,y);
glVertex3f( 0.5f,x+increment,y+increment);
glVertex3f( 0.5f,x, y+increment);
glVertex3f( 0.5f,x, y);
}
}
glEnd();
}
......@@ -126,7 +158,7 @@ void CubeWidget::showWireframe()
glDisable(GL_CULL_FACE);
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
repaint();
updateGL();
}
void CubeWidget::showFlat()
......@@ -135,7 +167,7 @@ void CubeWidget::showFlat()
glShadeModel(GL_FLAT);
glEnable(GL_CULL_FACE);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
repaint();
updateGL();
}
void CubeWidget::showGouraut()
......@@ -144,7 +176,7 @@ void CubeWidget::showGouraut()
glShadeModel(GL_SMOOTH);
glEnable(GL_CULL_FACE);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
repaint();
updateGL();
}
void CubeWidget::showPhong()
......@@ -156,6 +188,8 @@ void CubeWidget::showPhong()
void CubeWidget::setTessellation(int t)
{
tesselation = t;
updateGL();
qDebug()<<"Tesselation" << t;
}
......
......@@ -5,6 +5,7 @@
#include <QtOpenGL>
#include <QGLFunctions>
#include <QOpenGLFunctions>
#include <math.h>
......@@ -34,6 +35,7 @@ public slots:
void setTessellation(int t );
private:
int tesselation;
void perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar);
void setMaterial(GLfloat *color );
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment