Commit 6f811dc5 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Graphics assignment 10: texture mapping

Added some finishing changes and comments.
parent 9fecafab
......@@ -99,7 +99,10 @@ setHemispherePoint(vec3 *p, vec3* n, vec3* t, int latitude, int longitude,
p->y = oy + sin(latitude * dToR) * s;
p->z = oz + cos(longitude * dToR) * cos(latitude * dToR) * s;
// Set texture coordinate
// Set texture coordinate, use the longitude to determine the vertical
// component and the latitude for vertical. Because the texture image
// is four times as wide as it is high, divide the latitude by 90 and
// the longitude by 360).
t->x = longitude / 360.0;
t->y = latitude / 90.0;
......
......@@ -128,7 +128,7 @@ InitializePolygonlists(void)
loadPolygonalObject(polylistHouse, "house.obj", texture_names, 1.0,
object_positions[0].x, object_positions[0].y, object_positions[0].z);
// A single tree object
// A single tree object, use the banana_leaf object for a single leaf
polylistTreeLeafs = CreatePolylist(4);
loadPolygonalObject(polylistTreeLeafs, "banana_leaf.obj", texture_names,
1.0, 0, 1.8, 0);
......@@ -256,14 +256,18 @@ InitGL(void)
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);
// Set mip-mapping type
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glCheckError("glTexParameteri");
// Enable mip-mapping
gluBuild2DMipmaps(GL_TEXTURE_2D, texture_internal_format,
width, height, texture_format, texture_type, image_data);
glCheckError("ggluBuild2DMipmaps");
//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(image_data);
......@@ -420,15 +424,16 @@ DrawGLScene(void)
DrawPolylist(polylistTreeStem);
// Draw 5 to 10 leafs
for( int l = 0, step = 360 / (5+rand()%6); l < 360; l += step )
// Draw 5 to 10 leafs, rotate them according to the number of leafs
int i = 0, n = 5 + rand() % 6;
float step = 360.0 / n;
while( i++ < n )
{
glPushMatrix();
if( i )
glRotatef(step, 0, 1, 0);
glRotatef((float)l, 0, 1, 0);
DrawPolylist(polylistTreeLeafs);
glPopMatrix();
}
glPopMatrix();
......
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