Commit 62105739 by Kai Westerkamp

added Slots

parent 3b08f256
#include "cubewidget.h"
#include <QOpenGLFunctions>
CubeWidget::CubeWidget(QWidget *parent)
: QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
{
......@@ -22,13 +20,13 @@ void CubeWidget::initializeGL ()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_CULL_FACE);
// enable default shading
glShadeModel(GL_FLAT);
showFlat();
// glEnable(GL_LIGHTING);
// glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
static GLfloat lightPosition[4] = { 0.5, 0.0, 2.0, 1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
......@@ -41,45 +39,45 @@ void CubeWidget::paintGL ( )
glLoadIdentity();
glTranslatef(0.0f,0.0f,-3.0f);
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);
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);
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);
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);
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);
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);
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);
glEnd();
glColor3f(0.0f,1.0f,0.0f);
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);
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);
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);
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);
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);
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);
glEnd();
}
void CubeWidget::resizeGL(int width , int height )
......@@ -106,6 +104,40 @@ void CubeWidget::perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLd
glFrustum( xmin, xmax, ymin, ymax, zNear, zFar );
}
void CubeWidget::showWireframe()
{
qDebug("show Wireframe");
glShadeModel(GL_FLAT);
glPolygoneMode(GL_FRONT, GL_LINE);
}
void CubeWidget::showFlat()
{
qDebug("show Flat");
glShadeModel(GL_FLAT);
glPolygoneMode(GL_FRONT, GL_FILL);
}
void CubeWidget::showGouraut()
{
qDebug("show Gouraut");
glShadeModel(GL_SMOOTH);
glPolygoneMode(GL_FRONT, GL_FILL);
}
void CubeWidget::showPhong()
{
qDebug("show Phong");
showFlat();
}
void CubeWidget::setTessellation(int t)
{
}
void CubeWidget::mousePressEvent(QMouseEvent *event ) {}
void CubeWidget::mouseMoveEvent(QMouseEvent *event ) {}
void CubeWidget::wheelEvent(QWheelEvent *event ) {}
......@@ -3,12 +3,14 @@
#include <QtGui>
#include <QtOpenGL>
#include <QGLFunctions>
#include <QOpenGLFunctions>
class CubeWidget : public QGLWidget
{
Q_OBJECT
protected :
void initializeGL ( ) ;
void paintGL ( ) ;
......@@ -23,6 +25,12 @@ public:
QSize minimumSizeHint() const;
QSize sizeHint() const;
public slots:
void showWireframe();
void showFlat();
void showGouraut();
void showPhong();
private:
void perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar);
};
......
......@@ -12,6 +12,10 @@ MainWindow::MainWindow(QWidget *parent)
toolBar = new QToolBar("Shading",this);
statusBar = new QStatusBar(this);
//Main Widget
mainWidget = new CubeWidget(this);
setCentralWidget(mainWidget);
//File Menu Actions
fileMenu = new QMenu("&File");
shadingMenu= new QMenu("Shading");
......@@ -26,6 +30,7 @@ MainWindow::MainWindow(QWidget *parent)
noneAction->setShortcut(QKeySequence("Ctrl+1"));
noneAction->setCheckable(true);
noneAction->setIcon(QIcon(":/img/wireframe.png"));
connect(noneAction, SIGNAL(triggered()), mainWidget, SLOT(showWireframe()));
shadingGroup->addAction(noneAction);
flatAction = new QAction("Flat",shadingMenu);
......@@ -33,18 +38,21 @@ MainWindow::MainWindow(QWidget *parent)
flatAction->setCheckable(true);
flatAction->setChecked(true);
flatAction->setIcon(QIcon(":/img/flat.png"));
connect(flatAction, SIGNAL(triggered()), mainWidget, SLOT(showFlat()));
shadingGroup->addAction(flatAction);
gouraudAction = new QAction("Gouraud",shadingMenu);
gouraudAction->setShortcut(QKeySequence("Ctrl+3"));
gouraudAction->setCheckable(true);
gouraudAction->setIcon(QIcon(":/img/gouraud.png"));
connect(gouraudAction, SIGNAL(triggered()), mainWidget, SLOT(showGouraut()));
shadingGroup->addAction(gouraudAction);
phongAction = new QAction("Phong",shadingMenu);
phongAction->setShortcut(QKeySequence("Ctrl+4" ));
phongAction->setCheckable(true);
phongAction->setIcon(QIcon(":/img/phong.png"));
connect(phongAction, SIGNAL(triggered()), mainWidget, SLOT(showPhong()));
shadingGroup->addAction(phongAction);
//Other Actions
......@@ -78,9 +86,7 @@ MainWindow::MainWindow(QWidget *parent)
statusBar->showMessage("Hello");
setStatusBar(statusBar);
//Main Widget
mainWidget = new CubeWidget(this);
setCentralWidget(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