Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uva
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
uva
Commits
79fb5c86
Commit
79fb5c86
authored
Nov 25, 2010
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Graphics assignment 10 - Texture mapping
Finished the complete assignment
parent
2c97965d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
50 deletions
+62
-50
graphics/ass10/geometry.c
graphics/ass10/geometry.c
+6
-5
graphics/ass10/ground.obj
graphics/ass10/ground.obj
+3
-3
graphics/ass10/house.obj
graphics/ass10/house.obj
+25
-25
graphics/ass10/main.c
graphics/ass10/main.c
+25
-14
graphics/ass10/road.obj
graphics/ass10/road.obj
+3
-3
No files found.
graphics/ass10/geometry.c
View file @
79fb5c86
...
@@ -103,8 +103,8 @@ setHemispherePoint(vec3 *p, vec3* n, vec3* t, int latitude, int longitude,
...
@@ -103,8 +103,8 @@ setHemispherePoint(vec3 *p, vec3* n, vec3* t, int latitude, int longitude,
p
->
z
=
oz
+
cos
(
longitude
*
dToR
)
*
cos
(
latitude
*
dToR
)
*
s
;
p
->
z
=
oz
+
cos
(
longitude
*
dToR
)
*
cos
(
latitude
*
dToR
)
*
s
;
// Set texture coordinate
// Set texture coordinate
t
->
x
=
0
.
0
;
t
->
x
=
longitude
/
36
0
.
0
;
t
->
y
=
0
.
0
;
t
->
y
=
latitude
/
9
0
.
0
;
// calculate normal
// calculate normal
n
->
x
=
p
->
x
-
ox
;
n
->
x
=
p
->
x
-
ox
;
...
@@ -165,6 +165,7 @@ createCylinder(polys * list, double radius, double height,
...
@@ -165,6 +165,7 @@ createCylinder(polys * list, double radius, double height,
double
len
;
double
len
;
poly
p
;
poly
p
;
int
i
;
int
i
;
GLfloat
tex_height
=
(
GLfloat
)(
height
/
(
2
*
M_PI
*
radius
));
// prepare poly datastructure, as these values are the same for all generated polys
// prepare poly datastructure, as these values are the same for all generated polys
p
.
points
=
4
;
p
.
points
=
4
;
...
@@ -197,8 +198,9 @@ createCylinder(polys * list, double radius, double height,
...
@@ -197,8 +198,9 @@ createCylinder(polys * list, double radius, double height,
p
.
normal
[
i
].
x
/=
len
;
p
.
normal
[
i
].
x
/=
len
;
p
.
normal
[
i
].
z
/=
len
;
p
.
normal
[
i
].
z
/=
len
;
// Set texture coordinate
// Set texture coordinate/
p
.
tcoord
[
i
].
x
=
p
.
tcoord
[
i
].
y
=
0
.
0
;
p
.
tcoord
[
i
].
x
=
(
i
<
2
?
longitude
:
longitude
+
10
)
/
360
.
0
;
p
.
tcoord
[
i
].
y
=
(
i
==
1
||
i
==
2
)
?
tex_height
:
0
.
0
;
}
}
AddPolyToPolylist
(
list
,
p
);
AddPolyToPolylist
(
list
,
p
);
...
@@ -259,7 +261,6 @@ readPolyVertices(poly *p, FILE *f, const vec3 *vertex_list, int num_vertices_to_
...
@@ -259,7 +261,6 @@ readPolyVertices(poly *p, FILE *f, const vec3 *vertex_list, int num_vertices_to_
}
}
}
}
}
}
// Read a polygonal object from a .OBJ file.
// Read a polygonal object from a .OBJ file.
...
...
graphics/ass10/ground.obj
View file @
79fb5c86
...
@@ -7,6 +7,6 @@ v -100 0 50
...
@@ -7,6 +7,6 @@ v -100 0 50
p 4 0
p 4 0
0.5 1.0 0.5
0.5 1.0 0.5
0 0.0 0.0
0 0.0 0.0
1 0.0 0.0
1 0.0
2
0.0
2
0.0
0.0
2
10.0 2
0.0
3 0.0 0.0
3
1
0.0 0.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 0.0
15 0.0 0.0
15 0.0 0.0
graphics/ass10/main.c
View file @
79fb5c86
...
@@ -132,10 +132,9 @@ InitializePolygonlists(void)
...
@@ -132,10 +132,9 @@ InitializePolygonlists(void)
object_positions
[
0
].
x
,
object_positions
[
0
].
y
,
object_positions
[
0
].
z
);
object_positions
[
0
].
x
,
object_positions
[
0
].
y
,
object_positions
[
0
].
z
);
// A single tree object
// A single tree object
polylistTreeLeafs
=
CreatePolylist
(
10
);
polylistTreeLeafs
=
CreatePolylist
(
4
);
createSphere
(
polylistTreeLeafs
,
0
.
7
,
0
.
7
,
0
.
7
,
0
,
1
.
7
,
0
,
0
,
1
,
0
);
loadPolygonalObject
(
polylistTreeLeafs
,
"banana_leaf.obj"
,
texture_names
,
for
(
i
=
0
;
i
<
polylistTreeLeafs
->
length
;
i
++
)
1
.
0
,
0
,
1
.
8
,
0
);
polylistTreeLeafs
->
items
[
i
].
texture_id
=
texture_names
[
0
];
polylistTreeStem
=
CreatePolylist
(
10
);
polylistTreeStem
=
CreatePolylist
(
10
);
createCylinder
(
polylistTreeStem
,
0
.
075
,
1
.
8
,
0
,
0
,
0
,
0
.
5
,
0
.
3
,
0
);
createCylinder
(
polylistTreeStem
,
0
.
075
,
1
.
8
,
0
,
0
,
0
,
0
.
5
,
0
.
3
,
0
);
...
@@ -145,10 +144,10 @@ InitializePolygonlists(void)
...
@@ -145,10 +144,10 @@ InitializePolygonlists(void)
// Done!
// Done!
printf
(
"%d polygons
\n
"
,
printf
(
"%d polygons
\n
"
,
polylistHouse
->
length
+
polylistTreeLeafs
->
length
+
polylistHouse
->
length
+
polylistTreeLeafs
->
length
+
polylistTreeStem
->
length
+
polylistGround1
->
length
+
polylistGround2
->
length
);
polylistTreeStem
->
length
+
polylistGround1
->
length
+
polylistGround2
->
length
);
}
}
void
void
InitGL
(
void
)
InitGL
(
void
)
{
{
...
@@ -257,14 +256,16 @@ InitGL(void)
...
@@ -257,14 +256,16 @@ InitGL(void)
glBindTexture
(
GL_TEXTURE_2D
,
texture_names
[
i
]);
glBindTexture
(
GL_TEXTURE_2D
,
texture_names
[
i
]);
glCheckError
(
"glBindTexture"
);
glCheckError
(
"glBindTexture"
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_WRAP_S
,
GL_
CLAMP
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_WRAP_S
,
GL_
REPEAT
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_WRAP_T
,
GL_
CLAMP
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_WRAP_T
,
GL_
REPEAT
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MAG_FILTER
,
GL_LINEAR
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MAG_FILTER
,
GL_LINEAR
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MIN_FILTER
,
GL_LINEAR
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MIN_FILTER
,
GL_LINEAR
_MIPMAP_LINEAR
);
glCheckError
(
"glTexParameteri"
);
glCheckError
(
"glTexParameteri"
);
glTexImage2D
(
GL_TEXTURE_2D
,
0
,
texture_internal_format
,
gluBuild2DMipmaps
(
GL_TEXTURE_2D
,
texture_internal_format
,
width
,
height
,
0
,
texture_format
,
texture_type
,
image_data
);
width
,
height
,
texture_format
,
texture_type
,
image_data
);
//glTexImage2D(GL_TEXTURE_2D, 0, texture_internal_format,
// width, height, 0, texture_format, texture_type, image_data);
glCheckError
(
"glTexImage2D"
);
glCheckError
(
"glTexImage2D"
);
// Free the image data, as OpenGL will have made its internal copy by now
// Free the image data, as OpenGL will have made its internal copy by now
...
@@ -312,6 +313,7 @@ DrawPolylist(polys * list)
...
@@ -312,6 +313,7 @@ DrawPolylist(polys * list)
glBegin
(
GL_POLYGON
);
glBegin
(
GL_POLYGON
);
for
(
j
=
0
;
j
<
p
.
points
;
j
++
)
for
(
j
=
0
;
j
<
p
.
points
;
j
++
)
{
{
glTexCoord2f
(
p
.
tcoord
[
j
].
x
,
p
.
tcoord
[
j
].
y
);
glNormal3f
(
p
.
normal
[
j
].
x
,
p
.
normal
[
j
].
y
,
p
.
normal
[
j
].
z
);
glNormal3f
(
p
.
normal
[
j
].
x
,
p
.
normal
[
j
].
y
,
p
.
normal
[
j
].
z
);
glVertex3f
(
p
.
pts
[
j
].
x
,
p
.
pts
[
j
].
y
,
p
.
pts
[
j
].
z
);
glVertex3f
(
p
.
pts
[
j
].
x
,
p
.
pts
[
j
].
y
,
p
.
pts
[
j
].
z
);
}
}
...
@@ -420,16 +422,26 @@ DrawGLScene(void)
...
@@ -420,16 +422,26 @@ DrawGLScene(void)
glScalef
(
1
,
1
+
(
rand_float
()
-
0
.
5
)
*
0
.
6
,
1
);
glScalef
(
1
,
1
+
(
rand_float
()
-
0
.
5
)
*
0
.
6
,
1
);
DrawPolylist
(
polylistTreeStem
);
DrawPolylist
(
polylistTreeStem
);
// Draw 5 to 10 leafs
for
(
int
l
=
0
,
step
=
360
/
(
5
+
rand
()
%
6
);
l
<
360
;
l
+=
step
)
{
glPushMatrix
();
glRotatef
((
float
)
l
,
0
,
1
,
0
);
DrawPolylist
(
polylistTreeLeafs
);
DrawPolylist
(
polylistTreeLeafs
);
glPopMatrix
();
glPopMatrix
();
}
}
glPopMatrix
();
}
// Draw the skydome with lighting turned off
// Draw the skydome with lighting turned off
glPushAttrib
(
GL_LIGHTING_BIT
);
glPushAttrib
(
GL_LIGHTING_BIT
);
glDisable
(
GL_LIGHTING
);
glDisable
(
GL_LIGHTING
);
//
DrawPolylist(polylistSkydome);
DrawPolylist
(
polylistSkydome
);
glPopAttrib
();
glPopAttrib
();
glutSwapBuffers
();
glutSwapBuffers
();
...
@@ -511,7 +523,6 @@ mouseFunc(int button, int state, int x, int y)
...
@@ -511,7 +523,6 @@ mouseFunc(int button, int state, int x, int y)
// pressed button released
// pressed button released
mouse_mode
=
0
;
mouse_mode
=
0
;
}
}
}
}
static
void
static
void
...
...
graphics/ass10/road.obj
View file @
79fb5c86
...
@@ -7,6 +7,6 @@ v -100 0 5
...
@@ -7,6 +7,6 @@ v -100 0 5
p 4 5
p 4 5
0.85 0.85 0.85
0.85 0.85 0.85
0 0.0 0.0
0 0.0 0.0
1 0.0 0.0
1 0.0 1.0
2 0.0 0.0
2 20.0 1.0
3 0.0 0.0
3 20.0 0.0
\ No newline at end of file
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