Tuesday, March 6, 2007

NeHe Lesson 11: Flag Effect (Waving Texture)

Got the next one ready at last. This one shows you how to do a flag effect. The only hard part should be the math for calculating the wave. Go read Bosco's explanation here.

I'll add the only new D bit in the code. I've used a nice way to initialize a dynamic multi-dimensional array.

First we have at the top of the module the declaration:

GLfloat[][][] points;

Then in initGL we initialize the array, like this:

points = new GLfloat[][][](45, 45, 3);

Then we just loop through the indices and assign values to them.

Here's the whole code, and here's the flag texture.