Draw at 3D

glNewList(1, GL_COMPILE); //Board matrix (Horizontal Lines)
glBegin(GL_LINES);
glColor3f(1, 1, 1);
for (i=0; i<numRows+1; i++)
{
glVertex3f(0, (float)(i10), 0);
glVertex3f(numRows
10, (float)(i10), 0);
}
glEnd();
glEndList();
glNewList(2, GL_COMPILE); //Board matrix (Vertical Lines)
glBegin(GL_LINES);
glColor3f(1, 1, 1);
for (i=0; i<numCols+1; i++)
{
glVertex3f((float)(i
10), 0, 0);
glVertex3f((float)(i10), numCols10, 0);
}
glEnd();
glEndList();

glNewList(3, GL_COMPILE); //Board
glBegin(GL_QUADS);
glVertex3f(0, 0, 10);
glVertex3f(numRows10, 0, 0);
glVertex3f(numRows
10, numCols10, 0);
glVertex3f(0, numCols
10, 0);
glEnd();
glEndList();

How can I draw this in 3D???

Thanks

Hi !

It already is in 3D ?, not sure what you are after here, but if you do a glRotate you will have a nice 3D view of the board…

Mikael

The problem is that when I rotate (I use glRotatef) in axis x or y or z my table disappear.

Why?
If you want I can send my code.

Thanks

How are you setting up your projection matrix?

I have this:

void myReshape(int w, int h)
{

glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-200, 200, -150, 150);
glMatrixMode(GL_MODELVIEW);
glPolygonMode(GL_FRONT, GL_FILL);
WinW = w;
WinH = h;
}

gluOrtho2D(-200, 200, -150, 150);

this is probably the problem, since gluOrtho setup clipping planes at z near = -1 and z far = 1 , i guess the your object get clipped.

use glOrtho to set up your own z-far and z-near, or switch over to perspective projection.

I want that the table have the aspect, like for example, a box. When I rotate I want to see some thickness.
How can I do that.

Hi !

OpenGL can’t do that for you, you have to do it yourself, you already have the vertices, take the same vertices but add some Z to them and you have the vertices for the other “side” of the grid/box, then you have put some quads at the sides to create the “walls”.

Small example:
We have a quad like:
glBegin( GL_QUADS);
glVertex3d(0,0,0);
glVertex3d(1,0,0);
glVertex3d(1,1,0);
glVertex3d(0,1,0);
glEnd();

To turn this into a box you have to add:
glBegin( GL_QUADS);
; The other side of the box (top or bottom)
glVertex3d(0,0,1);
glVertex3d(1,0,1);
glVertex3d(1,1,1);
glVertex3d(0,1,1);
; Left side side of the box
glVertex3d(0,1,1);
glVertex3d(0,0,1);
glVertex3d(0,0,0);
glVertex3d(0,1,0);
; Right side of the box
glVertex3d(1,1,1);
glVertex3d(1,0,1);
glVertex3d(1,0,0);
glVertex3d(1,1,0);

… And so on…

NOTE: Please notice that I did not get the winding order correct so some of the triangles are facing the wrong way, you have to fix that, but I hope you get the idea, I may also have had some meltdown on the way so don’t trust my values to 100%.

glEnd();

Mikael

It sounds like you want a perspective view rather than an ortho view. Instead of gluOrtho2d (which probably IS what is causing the clipping), use gluPerspective.