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
Hide 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,
p
->
z
=
oz
+
cos
(
longitude
*
dToR
)
*
cos
(
latitude
*
dToR
)
*
s
;
// Set texture coordinate
t
->
x
=
0
.
0
;
t
->
y
=
0
.
0
;
t
->
x
=
longitude
/
36
0
.
0
;
t
->
y
=
latitude
/
9
0
.
0
;
// calculate normal
n
->
x
=
p
->
x
-
ox
;
...
...
@@ -165,6 +165,7 @@ createCylinder(polys * list, double radius, double height,
double
len
;
poly
p
;
int
i
;
GLfloat
tex_height
=
(
GLfloat
)(
height
/
(
2
*
M_PI
*
radius
));
// prepare poly datastructure, as these values are the same for all generated polys
p
.
points
=
4
;
...
...
@@ -197,8 +198,9 @@ createCylinder(polys * list, double radius, double height,
p
.
normal
[
i
].
x
/=
len
;
p
.
normal
[
i
].
z
/=
len
;
// Set texture coordinate
p
.
tcoord
[
i
].
x
=
p
.
tcoord
[
i
].
y
=
0
.
0
;
// Set texture coordinate/
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
);
...
...
@@ -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.
...
...
graphics/ass10/ground.obj
View file @
79fb5c86
...
...
@@ -7,6 +7,6 @@ v -100 0 50
p 4 0
0.5 1.0 0.5
0 0.0 0.0
1 0.0 0.0
2
0.0
0.0
3 0.0 0.0
1 0.0
2
0.0
2
10.0 2
0.0
3
1
0.0 0.0
graphics/ass10/house.obj
View file @
79fb5c86
...
...
@@ -27,53 +27,53 @@ v -2.8 1.4 -1.2
p 4 2
0.7 0.7 0.7
0 0.0 0.0
1
0
.0 0.0
5
0.0 0.0
4 0.0 0.
0
1
1
.0 0.0
5
1.0 0.8
4 0.0 0.
8
p 3 2
0.7 0.7 0.7
5
0
.0 0.0
8 0.
0 0.0
5
1
.0 0.0
8 0.
5 0.5
4 0.0 0.0
p 4 2
0.7 0.7 0.7
2
0.0
0.0
3 0.
0
0.0
7 0.
0 0.0
6
0.0 0.0
2
-0.5
0.0
3 0.
5
0.0
7 0.
5 0.8
6
-0.5 0.8
p 3 2
0.7 0.7 0.7
7 0.
0
0.0
9 0.0 0.
0
6
0.0
0.0
7 0.
5
0.0
9 0.0 0.
5
6
-0.5
0.0
p 4 2
0.7 0.7 0.7
3 0.
0
0.0
0
0
.0 0.0
4
0.0 0.0
7 0.
0 0.0
3 0.
5
0.0
0
3
.0 0.0
4
3.0 0.8
7 0.
5 0.8
p 4 2
0.7 0.7 0.7
2
0.0
0.0
6
0.0 0.0
5 0.0 0.
0
2
2.5
0.0
6
2.5 0.8
5 0.0 0.
8
1 0.0 0.0
# roof polygons (1=roof texture)
p 4 1
0.7 0.7 0.7
10 0.0
0
.0
11
0.0 0
.0
12
0
.0 0.0
10 0.0
1
.0
11
3.0 1
.0
12
3
.0 0.0
13 0.0 0.0
p 4 1
0.7 0.7 0.7
11 0.0
0
.0
10
0.0 0
.0
14
0
.0 0.0
11 0.0
1
.0
10
3.0 1
.0
14
3
.0 0.0
15 0.0 0.0
graphics/ass10/main.c
View file @
79fb5c86
...
...
@@ -132,10 +132,9 @@ InitializePolygonlists(void)
object_positions
[
0
].
x
,
object_positions
[
0
].
y
,
object_positions
[
0
].
z
);
// A single tree object
polylistTreeLeafs
=
CreatePolylist
(
10
);
createSphere
(
polylistTreeLeafs
,
0
.
7
,
0
.
7
,
0
.
7
,
0
,
1
.
7
,
0
,
0
,
1
,
0
);
for
(
i
=
0
;
i
<
polylistTreeLeafs
->
length
;
i
++
)
polylistTreeLeafs
->
items
[
i
].
texture_id
=
texture_names
[
0
];
polylistTreeLeafs
=
CreatePolylist
(
4
);
loadPolygonalObject
(
polylistTreeLeafs
,
"banana_leaf.obj"
,
texture_names
,
1
.
0
,
0
,
1
.
8
,
0
);
polylistTreeStem
=
CreatePolylist
(
10
);
createCylinder
(
polylistTreeStem
,
0
.
075
,
1
.
8
,
0
,
0
,
0
,
0
.
5
,
0
.
3
,
0
);
...
...
@@ -145,10 +144,10 @@ InitializePolygonlists(void)
// Done!
printf
(
"%d polygons
\n
"
,
polylistHouse
->
length
+
polylistTreeLeafs
->
length
+
polylistTreeStem
->
length
+
polylistGround1
->
length
+
polylistGround2
->
length
);
polylistTreeStem
->
length
+
polylistGround1
->
length
+
polylistGround2
->
length
);
}
void
InitGL
(
void
)
{
...
...
@@ -257,14 +256,16 @@ InitGL(void)
glBindTexture
(
GL_TEXTURE_2D
,
texture_names
[
i
]);
glCheckError
(
"glBindTexture"
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_WRAP_S
,
GL_
CLAMP
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_WRAP_T
,
GL_
CLAMP
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_WRAP_S
,
GL_
REPEAT
);
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_MIN_FILTER
,
GL_LINEAR
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MIN_FILTER
,
GL_LINEAR
_MIPMAP_LINEAR
);
glCheckError
(
"glTexParameteri"
);
glTexImage2D
(
GL_TEXTURE_2D
,
0
,
texture_internal_format
,
width
,
height
,
0
,
texture_format
,
texture_type
,
image_data
);
gluBuild2DMipmaps
(
GL_TEXTURE_2D
,
texture_internal_format
,
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"
);
// Free the image data, as OpenGL will have made its internal copy by now
...
...
@@ -312,6 +313,7 @@ DrawPolylist(polys * list)
glBegin
(
GL_POLYGON
);
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
);
glVertex3f
(
p
.
pts
[
j
].
x
,
p
.
pts
[
j
].
y
,
p
.
pts
[
j
].
z
);
}
...
...
@@ -420,7 +422,17 @@ DrawGLScene(void)
glScalef
(
1
,
1
+
(
rand_float
()
-
0
.
5
)
*
0
.
6
,
1
);
DrawPolylist
(
polylistTreeStem
);
DrawPolylist
(
polylistTreeLeafs
);
// 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
);
glPopMatrix
();
}
glPopMatrix
();
}
...
...
@@ -429,7 +441,7 @@ DrawGLScene(void)
glPushAttrib
(
GL_LIGHTING_BIT
);
glDisable
(
GL_LIGHTING
);
//
DrawPolylist(polylistSkydome);
DrawPolylist
(
polylistSkydome
);
glPopAttrib
();
glutSwapBuffers
();
...
...
@@ -511,7 +523,6 @@ mouseFunc(int button, int state, int x, int y)
// pressed button released
mouse_mode
=
0
;
}
}
static
void
...
...
graphics/ass10/road.obj
View file @
79fb5c86
...
...
@@ -7,6 +7,6 @@ v -100 0 5
p 4 5
0.85 0.85 0.85
0 0.0 0.0
1 0.0 0.0
2 0.0 0.0
3 0.0 0.0
\ No newline at end of file
1 0.0 1.0
2 20.0 1.0
3 20.0 0.0
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