Commit 60a1e7e0 by Kai Westerkamp

Material

Tesselation Slot
parent a110ad01
...@@ -20,18 +20,23 @@ void CubeWidget::initializeGL () ...@@ -20,18 +20,23 @@ 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);
glEnable(GL_CULL_FACE);
// enable default shading // enable default shading
showFlat(); showFlat();
// glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0); glEnable(GL_LIGHT0);
static GLfloat lightPosition[4] = { 0.5, 0.0, 2.0, 1.0 }; static GLfloat lightPosition[4] = { 0.5, 0.0, 2.0, 1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
} }
void CubeWidget::setMaterial(GLfloat *color )
{
glMaterialfv(GL_FRONT,GL_DIFFUSE,color);
glMaterialfv(GL_FRONT,GL_SPECULAR,color);
glMaterialfv(GL_FRONT,GL_SHININESS,color);
}
void CubeWidget::paintGL ( ) void CubeWidget::paintGL ( )
{ {
...@@ -41,38 +46,46 @@ void CubeWidget::paintGL ( ) ...@@ -41,38 +46,46 @@ void CubeWidget::paintGL ( )
glRotated(45,1,0,0); glRotated(45,1,0,0);
glRotated(45,0,1,0); glRotated(45,0,1,0);
glBegin(GL_QUADS); // Draw A Quad
glColor3f(0.0f,1.0f,0.0f); GLfloat red[] = {1.0,0.0,0.0};
GLfloat green[] = {0.0,1.0,0.0};
GLfloat blue[] = {0.0,0.0,1.0};
GLfloat cyan[] = {0.0,1.0,1.0};
GLfloat magenta[] = {1.0,0.0,1.0};
GLfloat yellow[] = {1.0,1.0,0.0};
glBegin(GL_QUADS);
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);
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);
glColor3f(0.0f,1.0f,1.0f); 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);
glColor3f(1.0f,0.0f,0.0f); 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);
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);
glColor3f(1.0f,0.0f,1.0f); 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);
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);
glColor3f(0.0f,0.0f,1.0f); 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);
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);
glColor3f(1.0f,1.0f,0.0f); 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);
glVertex3f( 0.5f,-0.5f, 0.5f); glVertex3f( 0.5f,-0.5f, 0.5f);
...@@ -107,23 +120,31 @@ void CubeWidget::perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLd ...@@ -107,23 +120,31 @@ void CubeWidget::perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLd
void CubeWidget::showWireframe() void CubeWidget::showWireframe()
{ {
qDebug("show Wireframe"); qDebug("show Wireframe");
glShadeModel(GL_FLAT); glShadeModel(GL_FLAT);
glPolygoneMode(GL_FRONT, GL_LINE); glDisable(GL_CULL_FACE);
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
repaint();
} }
void CubeWidget::showFlat() void CubeWidget::showFlat()
{ {
qDebug("show Flat"); qDebug("show Flat");
glShadeModel(GL_FLAT); glShadeModel(GL_FLAT);
glPolygoneMode(GL_FRONT, GL_FILL); glEnable(GL_CULL_FACE);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
repaint();
} }
void CubeWidget::showGouraut() void CubeWidget::showGouraut()
{ {
qDebug("show Gouraut"); qDebug("show Gouraut");
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
glPolygoneMode(GL_FRONT, GL_FILL); glEnable(GL_CULL_FACE);
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
repaint();
} }
void CubeWidget::showPhong() void CubeWidget::showPhong()
...@@ -135,7 +156,7 @@ void CubeWidget::showPhong() ...@@ -135,7 +156,7 @@ void CubeWidget::showPhong()
void CubeWidget::setTessellation(int t) void CubeWidget::setTessellation(int t)
{ {
qDebug()<<"Tesselation" << t;
} }
void CubeWidget::mousePressEvent(QMouseEvent *event ) {} void CubeWidget::mousePressEvent(QMouseEvent *event ) {}
......
...@@ -35,6 +35,7 @@ public slots: ...@@ -35,6 +35,7 @@ public slots:
private: private:
void perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar); void perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar);
void setMaterial(GLfloat *color );
}; };
#endif // CUBEWIDGET_H #endif // CUBEWIDGET_H
...@@ -61,6 +61,13 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -61,6 +61,13 @@ MainWindow::MainWindow(QWidget *parent)
camHome = new QAction(QIcon(":/img/cam_home.png"),"Cam Home", toolBar); camHome = new QAction(QIcon(":/img/cam_home.png"),"Cam Home", toolBar);
slider = new QSlider(Qt::Horizontal,toolBar);
slider->setMinimum( 0 );
slider->setMaximum( 4 );
slider->setValue( 0 );
connect(slider,SIGNAL(valueChanged(int)),mainWidget,SLOT(setTessellation(int)));
// slider->setSizePolicy();
// Assemble Menus // Assemble Menus
fileMenu->addAction(exitAction); fileMenu->addAction(exitAction);
menuBar->addMenu(fileMenu); menuBar->addMenu(fileMenu);
...@@ -80,6 +87,7 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -80,6 +87,7 @@ MainWindow::MainWindow(QWidget *parent)
toolBar->addAction(flatAction); toolBar->addAction(flatAction);
toolBar->addAction(gouraudAction); toolBar->addAction(gouraudAction);
toolBar->addAction(phongAction); toolBar->addAction(phongAction);
toolBar->addWidget(slider);
toolBar->addAction(camHome); toolBar->addAction(camHome);
addToolBar( toolBar); addToolBar( toolBar);
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QToolBar> #include <QToolBar>
#include <QStatusBar> #include <QStatusBar>
#include <QSlider>
#include <cubewidget.h> #include <cubewidget.h>
...@@ -37,6 +38,7 @@ private: ...@@ -37,6 +38,7 @@ private:
QToolBar *toolBar; QToolBar *toolBar;
QStatusBar *statusBar; QStatusBar *statusBar;
QSlider *slider;
CubeWidget *mainWidget; CubeWidget *mainWidget;
......
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