Friday, 25 May 2007

Now we're talking!

Computergraphics project is near the end!
There are some minor features to program (asteroids belt, pluto, music in background), but most is gone!!

A huge thank goes to Alessandro Re for the help and infinite knowledge in OpenGL programming. For instance, he explained me how to texture map spheres correctly: matter of three steps.

1) Quit using glut*Sphere(), 'cause "this function does not correctly set up the texture parameters needed for mapping". There's a GLU function that does it, and it's gluSphere().

gluSphere() draws a sphere of the given radius centered around the origin. The sphere is subdivided around the z axis into slices and along the z axis into stacks (similar to lines of longitude and latitude).
If texturing is turned on (with gluQuadricTexture), then texture coordinates are generated.

2) As documentation says, we have to specity a gluQuadricTexture before calling gluSphere();
gluQuadricTexture() accepts two parameters: a reference to some quadratic object and a boolean value.

3) We have to create the quadric object then! We do it with gluNewQuadric() function; it returns a pointer to a GLUquadric object that can be passed to gluQuadricTexture.

So here it comes the snippet:

GLUquadric *sfera;
sfera = gluNewQuadric();
gluQuadricTexture (sfera, GL_TRUE);
glBindTexture(GL_TEXTURE_2D, texture);
gluSphere (sfera, radius, slices, stacks);

This code will create a perfectly textured sphere, with specified radius, made by that number of slices and stacks!

Another important issue solved speaking with Alessandro and doc. Paolo Scala is the handling of lights. They can't be set up at beginning, or randomly in models/camera definition: despite the coordinates we give, they will mess up. Discovered that is FUNDAMENTAL to place them soon after the gluLookAt() call, to be sure they will be where we expect them!


AkiRoss' said...

What is it still left? (oh well, thanks for the compliments :$)

Aresio said...

you deserve it!

Only three things are still missing now:

1) asteroids belt - gonna implement it after Monaco qualifying! :D

2) OpenAL hangs up - they require too much processor! Will use standard APIs instead for music commentary.

3) the eccentric orbit of Pluto. not very simple to program..

What about your project then? Do you really wanna jump this session? :)

I think you can program anything in a couple of hours!!

eda said...