PDA

View Full Version : little squares



03-27-2003, 02:05 PM
Just starting out in the 3d video (game) world, I have been playing with openGL and WOW - where has it been all my life?

Anyway, I wish to make flat (eg Y-axis fixed) square. However, I wish to make it out of other smaller squares. So I end up with a checkerboard effect.

However, when I compile and view the scene my little squares do not look square. Well, they look a mess of rand triangles.

Ang ideas on how to fix or achieve my goal?

some of my code:

void initGL()
{
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glLineWidth(3.0);

return;
}

void illustrateGLScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity();
glTranslatef(0.0f, 0.0f, -3.0f);

glRotatef(yAngle, 0.0f, 1.0f, 0.0f);
glRotatef(xAngle, 1.0f, 0.0f, 0.0f);
glBegin(GL_QUADS);

for (int i = 0; i < 10; ++i)
{
glColor3f(0.0f, i * 0.1f, 0.0f);

for (int j = 0; j < 10; ++j)
{
glVertex3f(-1.0f * i, -0.2f, 1.0f * j);
glVertex3f(1.0f * i, -0.2f, 1.0f * j);
glVertex3f(1.0f * i, -0.2f, -1.0f * j);
glVertex3f(-1.0f * i, -0.2f, -1.0f * j);
}
}

glEnd();
...
}

iNsaNEiVaN
03-27-2003, 04:54 PM
Im not quite sure why you call glRotate() when all you're doing is a checkerboard.

03-27-2003, 09:59 PM
I took out your for loop and printed out the vertices that you get. Here are the first several:

-0 -0.2 0
0 -0.2 0
0 -0.2 -0
-0 -0.2 -0
-------------
-0 -0.2 1
0 -0.2 1
0 -0.2 -1
-0 -0.2 -1
-------------
-0 -0.2 2
0 -0.2 2
0 -0.2 -2
-0 -0.2 -2
-------------
-0 -0.2 3
0 -0.2 3
0 -0.2 -3
-0 -0.2 -3
-------------
-0 -0.2 4
0 -0.2 4
0 -0.2 -4
-0 -0.2 -4
-------------
-0 -0.2 5
0 -0.2 5
0 -0.2 -5
-0 -0.2 -5
-------------
-0 -0.2 6
0 -0.2 6
0 -0.2 -6
-0 -0.2 -6
-------------
-0 -0.2 7
0 -0.2 7
0 -0.2 -7
-0 -0.2 -7
-------------
-0 -0.2 8
0 -0.2 8
0 -0.2 -8
-0 -0.2 -8
-------------
-0 -0.2 9
0 -0.2 9
0 -0.2 -9
-0 -0.2 -9
-------------

-1 -0.2 0
1 -0.2 0
1 -0.2 -0
-1 -0.2 -0
-------------
-1 -0.2 1
1 -0.2 1
1 -0.2 -1
-1 -0.2 -1
-------------
-1 -0.2 2
1 -0.2 2
1 -0.2 -2
-1 -0.2 -2

if you look at your vertices you will notice that some of them have the same coordinates... -0 = 0. For example, your very firs "square" is all one coordinate. So, while you may think that you are getting four distinct verices, you are only getting three.. hence your triangle problem. Get rid of that, and you should be all set