View Full Version : drawing a 3D board

04-14-2004, 07:38 AM
please help me to draw a checkers boards whcih
is 3D.I need the board so that i can put some pieces on to it later.
This is urgent .
Help me soon.

04-14-2004, 08:47 AM
Sounds like homework to me... ;) Well, I'm not going to do the work for you, but will certainly point you in the right direction.

You don't mention whether the board should be a three-dimensional model, or whether it should just exist in a three-dimensional space. I'll assume the latter for now, and address the former at the end.

The most attractive technique would be to generate the surface of the board using a texture - you would draw a single quad of whatever size you want, then texture the squares on top. If you're pressed for time and are starting from scratch, this isn't the best choice!

Instead, try drawing a grid of quads of alternating colour. A simple loop such as the following should suffice (pseudocode):

for x = 0 to 7:
for y = 0 to 7:
if (x+y) % 2 is 0:
colour is white
colour is black
draw quad from (x*ss, y*ss) to ((x+1)*ss, (y+1)*ss)

Where ss is the length of the side of one board square. The methods you'll need are glVertex2f, glColor3f and glBegin/glEnd. Note that with a 2-component glVertex call, the z-component is implicitely set to 0.

If you want to make it appear to be floating in 3D, change to a perspective projection using gluPerspective (preferred) or glFrustum (if you don't have access to the GLU) and rotate the scene a little through one axis (glRotatef).

If you want a three-dimensional model of a board, the easiest thing to do is to turn the above grid into a box with four quads on each side and one on the bottom. As you'll need to supply z-coordinates, use glVertex3f instead of 2f.