Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
GraPa
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kai Westerkamp
GraPa
Commits
62105739
Commit
62105739
authored
Oct 22, 2015
by
Kai Westerkamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added Slots
parent
3b08f256
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
45 deletions
+91
-45
cubewidget.cpp
A1/hellocube/cubewidget.cpp
+74
-42
cubewidget.h
A1/hellocube/cubewidget.h
+8
-0
mainwindow.cpp
A1/hellocube/mainwindow.cpp
+9
-3
No files found.
A1/hellocube/cubewidget.cpp
View file @
62105739
#include "cubewidget.h"
#include "cubewidget.h"
#include <QOpenGLFunctions>
CubeWidget
::
CubeWidget
(
QWidget
*
parent
)
CubeWidget
::
CubeWidget
(
QWidget
*
parent
)
:
QGLWidget
(
QGLFormat
(
QGL
::
SampleBuffers
),
parent
)
:
QGLWidget
(
QGLFormat
(
QGL
::
SampleBuffers
),
parent
)
{
{
...
@@ -22,13 +20,13 @@ void CubeWidget::initializeGL ()
...
@@ -22,13 +20,13 @@ 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
);
glEnable
(
GL_CULL_FACE
);
// enable default shading
// enable default shading
glShadeModel
(
GL_FLAT
);
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
);
...
@@ -41,45 +39,45 @@ void CubeWidget::paintGL ( )
...
@@ -41,45 +39,45 @@ void CubeWidget::paintGL ( )
glLoadIdentity
();
glLoadIdentity
();
glTranslatef
(
0.0
f
,
0.0
f
,
-
3.0
f
);
glTranslatef
(
0.0
f
,
0.0
f
,
-
3.0
f
);
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
glBegin
(
GL_QUADS
);
// Draw A Quad
glColor3f
(
0.0
f
,
1.0
f
,
0.0
f
);
glColor3f
(
0.0
f
,
1.0
f
,
0.0
f
);
glVertex3f
(
0.5
f
,
0.5
f
,
-
0.5
f
);
glVertex3f
(
0.5
f
,
0.5
f
,
-
0.5
f
);
glVertex3f
(
-
0.5
f
,
0.5
f
,
-
0.5
f
);
glVertex3f
(
-
0.5
f
,
0.5
f
,
-
0.5
f
);
glVertex3f
(
-
0.5
f
,
0.5
f
,
0.5
f
);
glVertex3f
(
-
0.5
f
,
0.5
f
,
0.5
f
);
glVertex3f
(
0.5
f
,
0.5
f
,
0.5
f
);
glVertex3f
(
0.5
f
,
0.5
f
,
0.5
f
);
glColor3f
(
0.0
f
,
1.0
f
,
1.0
f
);
glColor3f
(
0.0
f
,
1.0
f
,
1.0
f
);
glVertex3f
(
0.5
f
,
-
0.5
f
,
0.5
f
);
glVertex3f
(
0.5
f
,
-
0.5
f
,
0.5
f
);
glVertex3f
(
-
0.5
f
,
-
0.5
f
,
0.5
f
);
glVertex3f
(
-
0.5
f
,
-
0.5
f
,
0.5
f
);
glVertex3f
(
-
0.5
f
,
-
0.5
f
,
-
0.5
f
);
glVertex3f
(
-
0.5
f
,
-
0.5
f
,
-
0.5
f
);
glVertex3f
(
0.5
f
,
-
0.5
f
,
-
0.5
f
);
glVertex3f
(
0.5
f
,
-
0.5
f
,
-
0.5
f
);
glColor3f
(
1.0
f
,
0.0
f
,
0.0
f
);
glColor3f
(
1.0
f
,
0.0
f
,
0.0
f
);
glVertex3f
(
0.5
f
,
0.5
f
,
0.5
f
);
glVertex3f
(
0.5
f
,
0.5
f
,
0.5
f
);
glVertex3f
(
-
0.5
f
,
0.5
f
,
0.5
f
);
glVertex3f
(
-
0.5
f
,
0.5
f
,
0.5
f
);
glVertex3f
(
-
0.5
f
,
-
0.5
f
,
0.5
f
);
glVertex3f
(
-
0.5
f
,
-
0.5
f
,
0.5
f
);
glVertex3f
(
0.5
f
,
-
0.5
f
,
0.5
f
);
glVertex3f
(
0.5
f
,
-
0.5
f
,
0.5
f
);
glColor3f
(
1.0
f
,
0.0
f
,
1.0
f
);
glColor3f
(
1.0
f
,
0.0
f
,
1.0
f
);
glVertex3f
(
0.5
f
,
-
0.5
f
,
-
0.5
f
);
glVertex3f
(
0.5
f
,
-
0.5
f
,
-
0.5
f
);
glVertex3f
(
-
0.5
f
,
-
0.5
f
,
-
0.5
f
);
glVertex3f
(
-
0.5
f
,
-
0.5
f
,
-
0.5
f
);
glVertex3f
(
-
0.5
f
,
0.5
f
,
-
0.5
f
);
glVertex3f
(
-
0.5
f
,
0.5
f
,
-
0.5
f
);
glVertex3f
(
0.5
f
,
0.5
f
,
-
0.5
f
);
glVertex3f
(
0.5
f
,
0.5
f
,
-
0.5
f
);
glColor3f
(
0.0
f
,
0.0
f
,
1.0
f
);
glColor3f
(
0.0
f
,
0.0
f
,
1.0
f
);
glVertex3f
(
-
0.5
f
,
0.5
f
,
0.5
f
);
glVertex3f
(
-
0.5
f
,
0.5
f
,
0.5
f
);
glVertex3f
(
-
0.5
f
,
0.5
f
,
-
0.5
f
);
glVertex3f
(
-
0.5
f
,
0.5
f
,
-
0.5
f
);
glVertex3f
(
-
0.5
f
,
-
0.5
f
,
-
0.5
f
);
glVertex3f
(
-
0.5
f
,
-
0.5
f
,
-
0.5
f
);
glVertex3f
(
-
0.5
f
,
-
0.5
f
,
0.5
f
);
glVertex3f
(
-
0.5
f
,
-
0.5
f
,
0.5
f
);
glColor3f
(
1.0
f
,
1.0
f
,
0.0
f
);
glColor3f
(
1.0
f
,
1.0
f
,
0.0
f
);
glVertex3f
(
0.5
f
,
0.5
f
,
-
0.5
f
);
glVertex3f
(
0.5
f
,
0.5
f
,
-
0.5
f
);
glVertex3f
(
0.5
f
,
0.5
f
,
0.5
f
);
glVertex3f
(
0.5
f
,
0.5
f
,
0.5
f
);
glVertex3f
(
0.5
f
,
-
0.5
f
,
0.5
f
);
glVertex3f
(
0.5
f
,
-
0.5
f
,
0.5
f
);
glVertex3f
(
0.5
f
,
-
0.5
f
,
-
0.5
f
);
glVertex3f
(
0.5
f
,
-
0.5
f
,
-
0.5
f
);
glEnd
();
glEnd
();
}
}
void
CubeWidget
::
resizeGL
(
int
width
,
int
height
)
void
CubeWidget
::
resizeGL
(
int
width
,
int
height
)
...
@@ -106,6 +104,40 @@ void CubeWidget::perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLd
...
@@ -106,6 +104,40 @@ void CubeWidget::perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLd
glFrustum
(
xmin
,
xmax
,
ymin
,
ymax
,
zNear
,
zFar
);
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
::
mousePressEvent
(
QMouseEvent
*
event
)
{}
void
CubeWidget
::
mouseMoveEvent
(
QMouseEvent
*
event
)
{}
void
CubeWidget
::
mouseMoveEvent
(
QMouseEvent
*
event
)
{}
void
CubeWidget
::
wheelEvent
(
QWheelEvent
*
event
)
{}
void
CubeWidget
::
wheelEvent
(
QWheelEvent
*
event
)
{}
A1/hellocube/cubewidget.h
View file @
62105739
...
@@ -3,12 +3,14 @@
...
@@ -3,12 +3,14 @@
#include <QtGui>
#include <QtGui>
#include <QtOpenGL>
#include <QtOpenGL>
#include <QGLFunctions>
#include <QOpenGLFunctions>
#include <QOpenGLFunctions>
class
CubeWidget
:
public
QGLWidget
class
CubeWidget
:
public
QGLWidget
{
{
Q_OBJECT
protected
:
protected
:
void
initializeGL
(
)
;
void
initializeGL
(
)
;
void
paintGL
(
)
;
void
paintGL
(
)
;
...
@@ -23,6 +25,12 @@ public:
...
@@ -23,6 +25,12 @@ public:
QSize
minimumSizeHint
()
const
;
QSize
minimumSizeHint
()
const
;
QSize
sizeHint
()
const
;
QSize
sizeHint
()
const
;
public
slots
:
void
showWireframe
();
void
showFlat
();
void
showGouraut
();
void
showPhong
();
private
:
private
:
void
perspective
(
GLdouble
fovy
,
GLdouble
aspect
,
GLdouble
zNear
,
GLdouble
zFar
);
void
perspective
(
GLdouble
fovy
,
GLdouble
aspect
,
GLdouble
zNear
,
GLdouble
zFar
);
};
};
...
...
A1/hellocube/mainwindow.cpp
View file @
62105739
...
@@ -12,6 +12,10 @@ MainWindow::MainWindow(QWidget *parent)
...
@@ -12,6 +12,10 @@ MainWindow::MainWindow(QWidget *parent)
toolBar
=
new
QToolBar
(
"Shading"
,
this
);
toolBar
=
new
QToolBar
(
"Shading"
,
this
);
statusBar
=
new
QStatusBar
(
this
);
statusBar
=
new
QStatusBar
(
this
);
//Main Widget
mainWidget
=
new
CubeWidget
(
this
);
setCentralWidget
(
mainWidget
);
//File Menu Actions
//File Menu Actions
fileMenu
=
new
QMenu
(
"&File"
);
fileMenu
=
new
QMenu
(
"&File"
);
shadingMenu
=
new
QMenu
(
"Shading"
);
shadingMenu
=
new
QMenu
(
"Shading"
);
...
@@ -26,6 +30,7 @@ MainWindow::MainWindow(QWidget *parent)
...
@@ -26,6 +30,7 @@ MainWindow::MainWindow(QWidget *parent)
noneAction
->
setShortcut
(
QKeySequence
(
"Ctrl+1"
));
noneAction
->
setShortcut
(
QKeySequence
(
"Ctrl+1"
));
noneAction
->
setCheckable
(
true
);
noneAction
->
setCheckable
(
true
);
noneAction
->
setIcon
(
QIcon
(
":/img/wireframe.png"
));
noneAction
->
setIcon
(
QIcon
(
":/img/wireframe.png"
));
connect
(
noneAction
,
SIGNAL
(
triggered
()),
mainWidget
,
SLOT
(
showWireframe
()));
shadingGroup
->
addAction
(
noneAction
);
shadingGroup
->
addAction
(
noneAction
);
flatAction
=
new
QAction
(
"Flat"
,
shadingMenu
);
flatAction
=
new
QAction
(
"Flat"
,
shadingMenu
);
...
@@ -33,18 +38,21 @@ MainWindow::MainWindow(QWidget *parent)
...
@@ -33,18 +38,21 @@ MainWindow::MainWindow(QWidget *parent)
flatAction
->
setCheckable
(
true
);
flatAction
->
setCheckable
(
true
);
flatAction
->
setChecked
(
true
);
flatAction
->
setChecked
(
true
);
flatAction
->
setIcon
(
QIcon
(
":/img/flat.png"
));
flatAction
->
setIcon
(
QIcon
(
":/img/flat.png"
));
connect
(
flatAction
,
SIGNAL
(
triggered
()),
mainWidget
,
SLOT
(
showFlat
()));
shadingGroup
->
addAction
(
flatAction
);
shadingGroup
->
addAction
(
flatAction
);
gouraudAction
=
new
QAction
(
"Gouraud"
,
shadingMenu
);
gouraudAction
=
new
QAction
(
"Gouraud"
,
shadingMenu
);
gouraudAction
->
setShortcut
(
QKeySequence
(
"Ctrl+3"
));
gouraudAction
->
setShortcut
(
QKeySequence
(
"Ctrl+3"
));
gouraudAction
->
setCheckable
(
true
);
gouraudAction
->
setCheckable
(
true
);
gouraudAction
->
setIcon
(
QIcon
(
":/img/gouraud.png"
));
gouraudAction
->
setIcon
(
QIcon
(
":/img/gouraud.png"
));
connect
(
gouraudAction
,
SIGNAL
(
triggered
()),
mainWidget
,
SLOT
(
showGouraut
()));
shadingGroup
->
addAction
(
gouraudAction
);
shadingGroup
->
addAction
(
gouraudAction
);
phongAction
=
new
QAction
(
"Phong"
,
shadingMenu
);
phongAction
=
new
QAction
(
"Phong"
,
shadingMenu
);
phongAction
->
setShortcut
(
QKeySequence
(
"Ctrl+4"
));
phongAction
->
setShortcut
(
QKeySequence
(
"Ctrl+4"
));
phongAction
->
setCheckable
(
true
);
phongAction
->
setCheckable
(
true
);
phongAction
->
setIcon
(
QIcon
(
":/img/phong.png"
));
phongAction
->
setIcon
(
QIcon
(
":/img/phong.png"
));
connect
(
phongAction
,
SIGNAL
(
triggered
()),
mainWidget
,
SLOT
(
showPhong
()));
shadingGroup
->
addAction
(
phongAction
);
shadingGroup
->
addAction
(
phongAction
);
//Other Actions
//Other Actions
...
@@ -78,9 +86,7 @@ MainWindow::MainWindow(QWidget *parent)
...
@@ -78,9 +86,7 @@ MainWindow::MainWindow(QWidget *parent)
statusBar
->
showMessage
(
"Hello"
);
statusBar
->
showMessage
(
"Hello"
);
setStatusBar
(
statusBar
);
setStatusBar
(
statusBar
);
//Main Widget
mainWidget
=
new
CubeWidget
(
this
);
setCentralWidget
(
mainWidget
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment