Commit 3b08f256 by Kai Westerkamp

Added a Cube

parent c3e1e5e8
/A1/build-hellocube-Desktop_Qt_5_4_2_MSVC2013_OpenGL_64bit-Debug
/A1/hellocube/*.user
......@@ -20,22 +20,92 @@ QSize CubeWidget::sizeHint() const
void CubeWidget::initializeGL ()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST);
/* glEnable(GL_CULL_FACE);
glShadeModel(GL_SMOOTH);
glEnable(GL_MULTISAMPLE);
glEnable(GL_LIGHTING);
glEnable(GL_CULL_FACE);
// enable default shading
glShadeModel(GL_FLAT);
// glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
static GLfloat lightPosition[4] = { 0.5, 0.0, 2.0, 1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
*/
}
void CubeWidget::paintGL ( )
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-3.0f);
glRotated(45,1,0,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();
}
void CubeWidget::resizeGL(int width , int height )
{
glMatrixMode(GL_PROJECTION);
glViewport(0, 0, width, height);
glLoadIdentity();
perspective(45.0,1.0*width/height,0.01,5.0);
glMatrixMode(GL_MODELVIEW);
}
void CubeWidget::perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
{
GLdouble xmin, xmax, ymin, ymax;
ymax = zNear * tan( fovy * M_PI / 360.0 );
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
glFrustum( xmin, xmax, ymin, ymax, zNear, zFar );
}
void CubeWidget::paintGL ( ) {}
void CubeWidget::resizeGL(int width , int height ) {}
void CubeWidget::mousePressEvent(QMouseEvent *event ) {}
void CubeWidget::mouseMoveEvent(QMouseEvent *event ) {}
void CubeWidget::wheelEvent(QWheelEvent *event ) {}
......@@ -22,6 +22,9 @@ public:
QSize minimumSizeHint() const;
QSize sizeHint() const;
private:
void perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar);
};
#endif // CUBEWIDGET_H
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