main page | gallery | rationale | contact

a cool OpenGL effect

Written:Spring 2001
Last Touched:Spring 2001


I wrote this neat effect in the midst of rewriting some of the OpenGL code from modtanks. I was just kind of playing around with heightmaps, GL_TRIANGLE_STRIPS, and sine curves, and this is the end result. There's a couple strange things thrown in with the drawing code: a pseudo object-oriented system using C structures (similar to Quake), and the beginnings of a generic DirectInput wrapper.

What Was Difficult?

Not much, I just recycled my old code and added some new drawing code. I recall having some trouble getting the triangle strips to draw properly due to vertex ordering.

Here's the function that actually draws the cool wavy thing, which I apparently called "DrawBoxes." Be sure to note that you can specify per-vertex coloring and translucency and OpenGL will blend and draw polygons correctly, which is how part of the effect was achieved.

main.c (excerpt)

void DrawBoxes(entity_t *e)
	short i,j;


		glColor4f(1,1,1, g_fBoxes[i][0]*0.05+0.5);

		glVertex3f(0.2*i, 0, 0.1*g_fBoxes[i][0]);

		glColor4f(1,1,1, g_fBoxes[i+1][0]*0.05+0.5);

		glVertex3f(0.2*(i+1), 0, 0.1*g_fBoxes[i+1][0]);

			glColor4f(1,1,1, g_fBoxes[i][j+1]*0.05+0.5);

			glVertex3f(0.2*i, 0.2*(j+1), 0.1*g_fBoxes[i][j+1]);

			glColor4f(1,1,1, g_fBoxes[i+1][j+1]*0.05+0.5);
			glVertex3f(0.2*(i+1), 0.2*(j+1), 0.1*g_fBoxes[i+1][j+1]);

			g_fBoxes[i][j] = 10+5*sin((g_c+i+j)*0.1);
		g_fBoxes[i][0] = 10+5*sin((g_c+i)*0.1);
		g_fBoxes[i][j] = 10+5*sin((g_c+i+j)*0.1);

		g_fBoxes[i][j] = 10+5*sin((g_c+i+j)*0.1);

What you need to compile & run this

Well, for Windows, I'd recommend Microsoft Visual C++ 6.0 or greater, since that's exactly the tool I used to develop this project. You'll also need the DirectX 7.0a or later SDK, currently available from:


Quit:Escape, Alt+F4 (26.8 K) (18.5 K)

Last updated: 2003.03.03 by