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
859a3df7
Commit
859a3df7
authored
Oct 29, 2015
by
Kai Westerkamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Normals added ^^
specular color fixed
parent
26c7c733
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
15 deletions
+29
-15
cubewidget.cpp
A1/hellocube/cubewidget.cpp
+13
-7
phong.frag
A1/hellocube/phong.frag
+16
-8
No files found.
A1/hellocube/cubewidget.cpp
View file @
859a3df7
...
...
@@ -32,11 +32,9 @@ void CubeWidget::initializeGL ()
static
GLfloat
lightPosition
[
4
]
=
{
0.5
,
0.0
,
2.0
,
1.0
};
glLightfv
(
GL_LIGHT0
,
GL_POSITION
,
lightPosition
);
GLfloat
white
[]
=
{
1.0
,
1.0
,
1.0
};
glLightfv
(
GL_LIGHT0
,
GL_DIFFUSE
,
white
);
glLightfv
(
GL_LIGHT0
,
GL_SPECULAR
,
white
);
//glLightfv(GL_LIGHT0, GL_DIFFUSE, white);
//glLightfv(GL_LIGHT0, GL_SPECULAR, white);
//glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 2.0f);
}
...
...
@@ -60,10 +58,12 @@ void CubeWidget::prepareShader()
void
CubeWidget
::
setMaterial
(
GLfloat
*
color
)
{
glMaterialfv
(
GL_FRONT
,
GL_AMBIENT
,
color
);
GLfloat
white
[]
=
{
1.0
,
1.0
,
1.0
};
glMaterialfv
(
GL_FRONT
,
GL_DIFFUSE
,
color
);
glMaterialfv
(
GL_FRONT
,
GL_SPECULAR
,
color
);
glMaterialfv
(
GL_FRONT
,
GL_SPECULAR
,
white
);
glMaterialfv
(
GL_FRONT
,
GL_SHININESS
,
new
GLfloat
(
50.0
));
GLfloat
mShininess
[]
=
{
128
};
glMaterialfv
(
GL_FRONT
,
GL_SHININESS
,
mShininess
);
}
...
...
@@ -88,6 +88,7 @@ void CubeWidget::paintGL ( )
glBegin
(
GL_QUADS
);
setMaterial
(
red
);
glNormal3f
(
0
,
1
,
0
);
for
(
float
x
=
-
0.5
;
x
<
0.5
;
x
+=
increment
)
{
for
(
float
y
=
-
0.5
;
y
<
0.5
;
y
+=
increment
)
{
glVertex3f
(
x
+
increment
,
0.5
f
,
y
);
...
...
@@ -100,6 +101,7 @@ void CubeWidget::paintGL ( )
glBegin
(
GL_QUADS
);
setMaterial
(
magenta
);
glNormal3f
(
0
,
-
1
,
0
);
for
(
float
x
=
-
0.5
;
x
<
0.5
;
x
+=
increment
)
{
for
(
float
y
=
-
0.5
;
y
<
0.5
;
y
+=
increment
)
{
glVertex3f
(
x
+
increment
,
-
0.5
f
,
y
+
increment
);
...
...
@@ -112,6 +114,7 @@ void CubeWidget::paintGL ( )
glBegin
(
GL_QUADS
);
setMaterial
(
green
);
glNormal3f
(
0
,
0
,
1
);
for
(
float
x
=
-
0.5
;
x
<
0.5
;
x
+=
increment
)
{
for
(
float
y
=
-
0.5
;
y
<
0.5
;
y
+=
increment
)
{
glVertex3f
(
x
+
increment
,
y
+
increment
,
0.5
f
);
...
...
@@ -124,6 +127,7 @@ void CubeWidget::paintGL ( )
glBegin
(
GL_QUADS
);
setMaterial
(
yellow
);
glNormal3f
(
0
,
0
,
-
1
);
for
(
float
x
=
-
0.5
;
x
<
0.5
;
x
+=
increment
)
{
for
(
float
y
=
-
0.5
;
y
<
0.5
;
y
+=
increment
)
{
glVertex3f
(
x
+
increment
,
y
,
-
0.5
f
);
...
...
@@ -136,6 +140,7 @@ void CubeWidget::paintGL ( )
glBegin
(
GL_QUADS
);
setMaterial
(
blue
);
glNormal3f
(
-
1
,
0
,
0
);
for
(
float
x
=
-
0.5
;
x
<
0.5
;
x
+=
increment
)
{
for
(
float
y
=
-
0.5
;
y
<
0.5
;
y
+=
increment
)
{
glVertex3f
(
-
0.5
f
,
x
+
increment
,
y
+
increment
);
...
...
@@ -147,6 +152,7 @@ void CubeWidget::paintGL ( )
glEnd
();
glBegin
(
GL_QUADS
);
setMaterial
(
cyan
);
glNormal3f
(
1
,
0
,
0
);
for
(
float
x
=
-
0.5
;
x
<
0.5
;
x
+=
increment
)
{
for
(
float
y
=
-
0.5
;
y
<
0.5
;
y
+=
increment
)
{
glVertex3f
(
0.5
f
,
x
+
increment
,
y
);
...
...
A1/hellocube/phong.frag
View file @
859a3df7
...
...
@@ -8,21 +8,29 @@ varying vec3 normal;
void
main
(
void
)
{
vec3
N
=
normalize
(
normal
);
vec3
L
=
normalize
(
vec3
(
gl_LightSource
[
0
].
position
)
-
position
);
vec3
V
=
normalize
(
-
position
.
xyz
);
vec3
R
=
reflect
(
-
L
,
N
);
vec3
L
=
normalize
(
gl_LightSource
[
0
].
position
-
position
);
vec4
diffuse
=
vec4
(
max
(
dot
(
L
,
N
),
0
.
0
));
vec4
specular
=
vec4
(
pow
(
max
(
dot
(
R
,
V
),
0
.
0
),
gl_FrontMaterial
.
shininess
));
vec4
Iamb
=
gl_FrontLightProduct
[
0
].
ambient
;
vec4
Idiff
=
gl_FrontLightProduct
[
0
].
diffuse
*
diffuse
;
Idiff
=
clamp
(
Idiff
,
0
.
0
,
1
.
0
);
vec4
Ispec
=
gl_FrontLightProduct
[
0
].
specular
*
specular
;
Ispec
=
clamp
(
Idiff
,
0
.
0
,
1
.
0
);
vec3
V
=
normalize
(
-
position
);
vec4
color
=
/*gl_FrontLightModelProduct.sceneColor +*/
Iamb
+
Idiff
+
Ispec
;
gl_FragColor
=
vec4
(
color
);
vec3
R
=
normalize
(
reflect
(
-
L
,
N
));
float
specular
=
pow
(
max
(
dot
(
R
,
V
),
0
.
0
),
gl_FrontMaterial
.
shininess
);
//);
vec4
Ispec
=
gl_FrontLightProduct
[
0
].
specular
*
specular
;
Ispec
=
clamp
(
Ispec
,
0
.
0
,
1
.
0
);
vec4
color
=
(
Iamb
+
Idiff
+
Ispec
);
gl_FragColor
=
vec4
(
specular
);
gl_FragColor
=
color
;
}
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