Texture mapping the gluSphere

Here’s a quick tutorial on how to texture map the quadric sphere drawn by the gluSphere function. Learnt this while finishing my assignment for the Computer Graphics subject.

GLUquadricObj *qObj = gluNewQuadric();
gluQuadricNormals(qObj, GLU_SMOOTH);
gluQuadricTexture(qObj, GL_TRUE);

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texID);	// texID is the texture ID of a
										// previously generated texture

gluSphere(qObj, 1.0f, 24, 24);

In the above code we generate a quadric object, and specify the type of normals for the quadric object, which in this case is set to smooth shading with the GLU_SMOOTH flag. gluQuadricTexture tells OpenGL to generate texture coordinates for the quadric object automatically. Finally, we bind the desired texture and draw the quadric sphere using gluSphere.

Here’s what you would get:

Mapped quadric sphere

A mapped quadric sphere

Hope it helps. Good luck!

How I handled sounds

Since DirectSound is deprecated, I’d decided to go ahead and write a sound manager class for my Game Prog. II Assignent, using the Windows API’s PlaySound function instead of uisng DirectSound. This function is relatively easy to implement, and it plays a .wav file supplied as a parameter while using only one line of code. The downside however, is that it cannot handle multiple channels, ie playing multiple sounds simultaneously. This serves as only a quick and dirty hack to get things done, and highly unrecommended for use in larger projects.

Anyway, here’s how you would use it:

if (player.isHit()) {
	PlaySound("hitSound.wav", NULL, SND_ASYNC);
}

This tells Windows to play “hitSound.wav”, and the SND_ASYNC flag indicates that the program will continue to run while the sound is playing. If you would rather pause your program for the duration of the sound, you would call it with the SND_SYNC flag like this:

PlaySound("hitSound.wav", NULL, SND_SYNC);

For a list of available flags, you could refer to the MSDN docs. Commonly used flags are the SND_SYNC, SND_ASYNC and SND_LOOP.
Now go and finish your assignments!

Main Menu Completed

Now to post an update before I get too lazy…just completed the main menu for my game, which I (lamely) decided to name it “Lone Voyager”. Here’s a screenie:

Just two simple buttons

Good thing I implemented OOP into my game…made it so much easier to implement the menu and buttons. I also modified the distribution of the asteroids so that they appear more natural and evenly distributed.

More even distribution of asteroids

Well it should be enough to submit for the upcoming milestone…not gonna waste too much time on this one.