Commit 450e6140 by Kai Westerkamp

tesselation

naja
parent 60a1e7e0
...@@ -21,7 +21,7 @@ void CubeWidget::initializeGL () ...@@ -21,7 +21,7 @@ void CubeWidget::initializeGL ()
glClearColor(0.0, 0.0, 0.0, 0.0); glClearColor(0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
tesselation = 0;
// enable default shading // enable default shading
showFlat(); showFlat();
...@@ -55,41 +55,73 @@ void CubeWidget::paintGL ( ) ...@@ -55,41 +55,73 @@ void CubeWidget::paintGL ( )
GLfloat yellow[] = {1.0,1.0,0.0}; GLfloat yellow[] = {1.0,1.0,0.0};
glBegin(GL_QUADS); glBegin(GL_QUADS);
float increment = 1.0/(pow(2,tesselation));
setMaterial(red); setMaterial(red);
glVertex3f( 0.5f, 0.5f,-0.5f); for (float x = -0.5; x < 0.5 ; x+= increment) {
glVertex3f(-0.5f, 0.5f,-0.5f); for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f(-0.5f, 0.5f, 0.5f); glVertex3f( x+increment, 0.5f,y);
glVertex3f( 0.5f, 0.5f, 0.5f); glVertex3f(x, 0.5f,y);
glVertex3f(x, 0.5f, y+increment);
glVertex3f( x+increment, 0.5f, y+increment);
}
}
setMaterial(magenta); 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);
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); setMaterial(green);
glVertex3f( 0.5f, 0.5f, 0.5f); for (float x = -0.5; x < 0.5 ; x+= increment) {
glVertex3f(-0.5f, 0.5f, 0.5f); for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f(-0.5f,-0.5f, 0.5f); glVertex3f( x+increment,y+increment, 0.5f);
glVertex3f( 0.5f,-0.5f, 0.5f); glVertex3f(x, y+increment, 0.5f);
glVertex3f(x, y, 0.5f);
glVertex3f( x+increment, y, 0.5f);
}
}
setMaterial(yellow); setMaterial(yellow);
glVertex3f( 0.5f,-0.5f,-0.5f); for (float x = -0.5; x < 0.5 ; x+= increment) {
glVertex3f(-0.5f,-0.5f,-0.5f); for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f(-0.5f, 0.5f,-0.5f); glVertex3f( x+increment,y, -0.5f);
glVertex3f( 0.5f, 0.5f,-0.5f); glVertex3f(x, y,-0.5f);
glVertex3f(x, y+increment,-0.5f);
glVertex3f( x+increment,y+increment, -0.5f);
}
}
setMaterial(blue); setMaterial(blue);
glVertex3f(-0.5f, 0.5f, 0.5f); for (float x = -0.5; x < 0.5 ; x+= increment) {
glVertex3f(-0.5f, 0.5f,-0.5f); for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f(-0.5f,-0.5f,-0.5f); glVertex3f( -0.5f, x+increment,y+increment);
glVertex3f(-0.5f,-0.5f, 0.5f); glVertex3f( -0.5f,x+increment,y);
glVertex3f( -0.5f,x, y);
glVertex3f( -0.5f,x, y+increment);
}
}
setMaterial(cyan); setMaterial(cyan);
glVertex3f( 0.5f, 0.5f,-0.5f); for (float x = -0.5; x < 0.5 ; x+= increment) {
glVertex3f( 0.5f, 0.5f, 0.5f); for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( 0.5f,-0.5f, 0.5f); glVertex3f( 0.5f, x+increment,y);
glVertex3f( 0.5f,-0.5f,-0.5f); glVertex3f( 0.5f,x+increment,y+increment);
glVertex3f( 0.5f,x, y+increment);
glVertex3f( 0.5f,x, y);
}
}
glEnd(); glEnd();
} }
...@@ -126,7 +158,7 @@ void CubeWidget::showWireframe() ...@@ -126,7 +158,7 @@ void CubeWidget::showWireframe()
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
repaint(); updateGL();
} }
void CubeWidget::showFlat() void CubeWidget::showFlat()
...@@ -135,7 +167,7 @@ void CubeWidget::showFlat() ...@@ -135,7 +167,7 @@ void CubeWidget::showFlat()
glShadeModel(GL_FLAT); glShadeModel(GL_FLAT);
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
repaint(); updateGL();
} }
void CubeWidget::showGouraut() void CubeWidget::showGouraut()
...@@ -144,7 +176,7 @@ void CubeWidget::showGouraut() ...@@ -144,7 +176,7 @@ void CubeWidget::showGouraut()
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
repaint(); updateGL();
} }
void CubeWidget::showPhong() void CubeWidget::showPhong()
...@@ -156,6 +188,8 @@ void CubeWidget::showPhong() ...@@ -156,6 +188,8 @@ void CubeWidget::showPhong()
void CubeWidget::setTessellation(int t) void CubeWidget::setTessellation(int t)
{ {
tesselation = t;
updateGL();
qDebug()<<"Tesselation" << t; qDebug()<<"Tesselation" << t;
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <QtOpenGL> #include <QtOpenGL>
#include <QGLFunctions> #include <QGLFunctions>
#include <QOpenGLFunctions> #include <QOpenGLFunctions>
#include <math.h>
...@@ -34,6 +35,7 @@ public slots: ...@@ -34,6 +35,7 @@ public slots:
void setTessellation(int t ); void setTessellation(int t );
private: private:
int tesselation;
void perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar); void perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar);
void setMaterial(GLfloat *color ); 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