Commit 79fb5c86 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Graphics assignment 10 - Texture mapping

Finished the complete assignment
parent 2c97965d
......@@ -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 / 360.0;
t->y = latitude / 90.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.
......
......@@ -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 20.0
2 10.0 20.0
3 10.0 0.0
......@@ -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
......@@ -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,16 +422,26 @@ DrawGLScene(void)
glScalef(1, 1 + (rand_float()-0.5)*0.6, 1);
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);
glPopMatrix();
}
glPopMatrix();
}
// Draw the skydome with lighting turned off
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
......
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment