Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
grapa_alisa
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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Alisa Jung
grapa_alisa
Commits
f7a1ac58
Commit
f7a1ac58
authored
Nov 02, 2015
by
Alisa Jung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
phong shading alles bis auf korrekte farben
parent
d093f154
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
101 additions
and
5 deletions
+101
-5
helloqube.pro
helloqube/helloqube.pro
+4
-0
helloqube.pro.user
helloqube/helloqube.pro.user
+1
-1
helloqube.qrc
helloqube/helloqube.qrc
+2
-0
myglwidget.cpp
helloqube/myglwidget.cpp
+35
-4
myglwidget.h
helloqube/myglwidget.h
+5
-0
phong.frag
helloqube/phong.frag
+40
-0
phong.vert
helloqube/phong.vert
+14
-0
No files found.
helloqube/helloqube.pro
View file @
f7a1ac58
...
@@ -21,3 +21,7 @@ HEADERS += mainwindow.h \
...
@@ -21,3 +21,7 @@ HEADERS += mainwindow.h \
RESOURCES
+=
\
RESOURCES
+=
\
helloqube
.
qrc
helloqube
.
qrc
DISTFILES
+=
\
phong
.
vert
\
phong
.
frag
helloqube/helloqube.pro.user
View file @
f7a1ac58
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.5.1, 2015-11-0
1T21:26:19
. -->
<!-- Written by QtCreator 3.5.1, 2015-11-0
2T15:23:12
. -->
<qtcreator>
<qtcreator>
<data>
<data>
<variable>
EnvironmentId
</variable>
<variable>
EnvironmentId
</variable>
...
...
helloqube/helloqube.qrc
View file @
f7a1ac58
...
@@ -5,5 +5,7 @@
...
@@ -5,5 +5,7 @@
<file>img/gouraud.png</file>
<file>img/gouraud.png</file>
<file>img/phong.png</file>
<file>img/phong.png</file>
<file>img/wireframe.png</file>
<file>img/wireframe.png</file>
<file>phong.frag</file>
<file>phong.vert</file>
</qresource>
</qresource>
</RCC>
</RCC>
helloqube/myglwidget.cpp
View file @
f7a1ac58
...
@@ -46,7 +46,33 @@ void MyGLWidget::initializeGL()
...
@@ -46,7 +46,33 @@ void MyGLWidget::initializeGL()
glClearColor
(
0.0
,
0.0
,
0.0
,
0.0
);
//TODO brauch ich das?
glClearColor
(
0.0
,
0.0
,
0.0
,
0.0
);
//TODO brauch ich das?
glEnable
(
GL_DEPTH_TEST
);
//TODO warum genau?
glEnable
(
GL_DEPTH_TEST
);
//TODO warum genau?
//Phong Shader:
QGLShader
*
vert
=
new
QGLShader
(
QGLShader
::
Vertex
);
qDebug
()
<<
"new vert shader"
;
QGLShader
*
frag
=
new
QGLShader
(
QGLShader
::
Fragment
);
qDebug
()
<<
"new frag shader"
;
bool
e
=
QFile
::
exists
(
":/phong.vert"
);
qDebug
()
<<
"vert exists"
<<
e
;
bool
successVertex
=
vert
->
compileSourceFile
(
":/phong.vert"
);
if
(
!
successVertex
)
qDebug
()
<<
"Vertex compilation failed."
;
else
qDebug
()
<<
"Vertex compiled."
;
bool
successFragment
=
frag
->
compileSourceFile
(
":/phong.frag"
);
if
(
!
successFragment
)
qDebug
()
<<
"Frag failed"
;
else
qDebug
()
<<
"frag success"
;
phongShader
=
new
QGLShaderProgram
(
this
);
phongShader
->
addShader
(
vert
);
phongShader
->
addShader
(
frag
);
phongShader
->
link
();
shadeFlatSlot
();
//set up flat shading
shadeFlatSlot
();
//set up flat shading
qDebug
()
<<
"flat done"
;
// glEnable(GL_CULL_FACE);//backface culling.
// glEnable(GL_CULL_FACE);//backface culling.
// glCullFace(GL_BACK);//backface culling
// glCullFace(GL_BACK);//backface culling
...
@@ -90,15 +116,14 @@ void MyGLWidget::paintGL(){
...
@@ -90,15 +116,14 @@ void MyGLWidget::paintGL(){
double
dist
=
qubeWidth
/
(
double
)
tesselation
;
double
dist
=
qubeWidth
/
(
double
)
tesselation
;
//for cube rotation
QMatrix4x4
translateRot1
=
QMatrix4x4
(
1
,
0
,
0
,
tx
,
0
,
1
,
0
,
ty
,
0
,
0
,
1
,
0
,
0
,
0
,
0
,
1
);
QMatrix4x4
translateRot1
=
QMatrix4x4
(
1
,
0
,
0
,
tx
,
0
,
1
,
0
,
ty
,
0
,
0
,
1
,
0
,
0
,
0
,
0
,
1
);
QMatrix4x4
translateRot2
=
QMatrix4x4
(
1
,
0
,
0
,
-
tx
,
0
,
1
,
0
,
-
ty
,
0
,
0
,
1
,
0
,
0
,
0
,
0
,
1
);
QMatrix4x4
translateRot2
=
QMatrix4x4
(
1
,
0
,
0
,
-
tx
,
0
,
1
,
0
,
-
ty
,
0
,
0
,
1
,
0
,
0
,
0
,
0
,
1
);
//for cube rotation
QMatrix4x4
m
=
QMatrix4x4
();
QMatrix4x4
m
=
QMatrix4x4
();
m
.
rotate
(
qubeRotationQuaternion
);
m
.
rotate
(
qubeRotationQuaternion
);
glMultMatrixf
(
translateRot1
.
data
());
//Punkte
ins zentrum ver
schieben damit rotation um qube zentrum ist
glMultMatrixf
(
translateRot1
.
data
());
//Punkte
zurück
schieben damit rotation um qube zentrum ist
glMultMatrixf
(
m
.
data
());
glMultMatrixf
(
m
.
data
());
glMultMatrixf
(
translateRot2
.
data
());
//Punkte
zurück ver
schieben
glMultMatrixf
(
translateRot2
.
data
());
//Punkte
ins Zentrum
schieben
//4.1.1 Unit Qube + Tesselation + Diffuse Material
//4.1.1 Unit Qube + Tesselation + Diffuse Material
{
{
...
@@ -317,12 +342,15 @@ void MyGLWidget::wheelEvent(QWheelEvent *event){
...
@@ -317,12 +342,15 @@ void MyGLWidget::wheelEvent(QWheelEvent *event){
void
MyGLWidget
::
shadeWireframeSlot
(){
void
MyGLWidget
::
shadeWireframeSlot
(){
qDebug
()
<<
"Wireframe selected"
;
qDebug
()
<<
"Wireframe selected"
;
phongShader
->
release
();
glPolygonMode
(
GL_FRONT_AND_BACK
,
GL_LINE
);
//Wireframe looks way cooler with both faces on
glPolygonMode
(
GL_FRONT_AND_BACK
,
GL_LINE
);
//Wireframe looks way cooler with both faces on
updateGL
();
updateGL
();
}
}
void
MyGLWidget
::
shadeFlatSlot
(){
void
MyGLWidget
::
shadeFlatSlot
(){
qDebug
()
<<
"Flat selected"
;
qDebug
()
<<
"Flat selected"
;
phongShader
->
release
();
glShadeModel
(
GL_FLAT
);
glShadeModel
(
GL_FLAT
);
glPolygonMode
(
GL_FRONT
,
GL_FILL
);
glPolygonMode
(
GL_FRONT
,
GL_FILL
);
updateGL
();
updateGL
();
...
@@ -330,6 +358,7 @@ void MyGLWidget::shadeFlatSlot(){
...
@@ -330,6 +358,7 @@ void MyGLWidget::shadeFlatSlot(){
void
MyGLWidget
::
shadeGouraudSlot
(){
void
MyGLWidget
::
shadeGouraudSlot
(){
qDebug
()
<<
"Gouraud selected"
;
qDebug
()
<<
"Gouraud selected"
;
phongShader
->
release
();
glShadeModel
(
GL_SMOOTH
);
glShadeModel
(
GL_SMOOTH
);
glPolygonMode
(
GL_FRONT
,
GL_FILL
);
glPolygonMode
(
GL_FRONT
,
GL_FILL
);
updateGL
();
updateGL
();
...
@@ -337,6 +366,8 @@ void MyGLWidget::shadeGouraudSlot(){
...
@@ -337,6 +366,8 @@ void MyGLWidget::shadeGouraudSlot(){
void
MyGLWidget
::
shadePhongSlot
(){
void
MyGLWidget
::
shadePhongSlot
(){
qDebug
()
<<
"Phong selected"
;
qDebug
()
<<
"Phong selected"
;
glPolygonMode
(
GL_FRONT
,
GL_FILL
);
phongShader
->
bind
();
updateGL
();
updateGL
();
}
}
...
...
helloqube/myglwidget.h
View file @
f7a1ac58
...
@@ -9,6 +9,8 @@
...
@@ -9,6 +9,8 @@
#include <QMatrix4x4>
#include <QMatrix4x4>
#include <math.h>
#include <math.h>
#include <QVector3D>
#include <QVector3D>
#include <QGLShaderProgram>
#include <QGLShader>
class
MyGLWidget
:
public
QGLWidget
class
MyGLWidget
:
public
QGLWidget
{
{
...
@@ -49,6 +51,9 @@ private:
...
@@ -49,6 +51,9 @@ private:
QQuaternion
qubeRotationQuaternion
;
QQuaternion
qubeRotationQuaternion
;
QPoint
screenCenter
;
//Center of screen in pixel coordinates
QPoint
screenCenter
;
//Center of screen in pixel coordinates
//Phong Shader
QGLShaderProgram
*
phongShader
;
public
slots
:
public
slots
:
//4.1.1 slots for shading modes
//4.1.1 slots for shading modes
...
...
helloqube/phong.frag
0 → 100644
View file @
f7a1ac58
varying
vec3
Normal
;
varying
vec4
Vertex
;
varying
vec4
VertexColor
;
uniform
gl_MaterialParameters
gl_FrontMaterial
;
void
main
(
void
)
{
/*
// vec4 white = vec4(1.0f,1.0f,1.0f,1.0f);
// gl_FragColor = white;
*/
vec3
V
=
-
normalize
(
Vertex
.
xyz
);
vec3
N
=
normalize
(
Normal
);
vec3
L
=
normalize
(
gl_LightSource
[
0
].
position
.
xyz
-
Vertex
.
xyz
);
vec3
R
=
normalize
(
reflect
(
-
L
,
N
));
//- oder +?
float
shininess
=
gl_FrontMaterial
.
shininess
;
float
kd
=
max
(
0
.
0
,
dot
(
L
.
xyz
,
N
));
float
rdotv
=
max
(
dot
(
R
,
V
.
xyz
),
0
);
float
ks
=
pow
(
rdotv
,
shininess
);
vec4
color
=
vec4
(
rdotv
);
// gl_FragColor = color;
gl_FragColor
=
vec4
(
ks
+
0
.
5
f
*
kd
);
// gl_FragColor = vec4(gl_FrontMaterial.diffuse*kd);//es fehlt: licht und color
// gl_FragColor = vec4(gl_Color);//Nein.
// gl_FragColor = VertexColor;//Pink.
}
helloqube/phong.vert
0 → 100644
View file @
f7a1ac58
varying
vec3
Normal
;
varying
vec4
Vertex
;
varying
vec4
VertexColor
;
void
main
(
void
)
{
Vertex
=
gl_ModelViewMatrix
*
gl_Vertex
;
Normal
=
normalize
(
gl_NormalMatrix
*
gl_Normal
);
gl_Position
=
gl_ModelViewProjectionMatrix
*
gl_Vertex
;
VertexColor
=
gl_FrontMaterial
.
diffuse
;
}
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