Problem drawing a 2D grid

Started by
1 comment, last by cossie 16 years, 6 months ago
Hi, I'm trying to draw a 2D grid using GL_QUADS - sort of like a chessboard I guess. I have a 2D array storing each tiles information, e.g. 1 for a red tile, 2 for a blue one etc. The problem I'm having is that when I draw the grid it appears on screen like a mirror image :-/ The tiles located at the "bottom" of my grid array are drawn at the top of the screen. I compared what I'm doing against this example: http://www.gamedev.net/reference/articles/article1256.asp but I still can't sort out the problem. This is how I process the array:


int size = 10;
...

...

for (int y = 0; y < NUM_TILES; y++)
{
    for (int x = 0; x < NUM_TILES; x++)
    {
       if (grid[y][x] == 1)
          glColor3f(1.0f, 0.0f, 0.0f);
       else
         glColor3f(0.0f, 0.0f, 0.0f);

       	glPushMatrix();
	glBegin(GL_QUADS);
  
          glVertex2i(x * size, y * size);
          glVertex2i((x * size) + size, y * size);
	  glVertex2i((x * size) + size, (y * size)+size);
          glVertex2i(x * size, (y * size) +size);
        
        glEnd();
	glPopMatrix();
  
    }
}

Thanks Cos PS for some reason the 'plus' symbol won't show up when I preview the post :-/
Advertisement
It sounds like you want to invert your tiles' positions in the Y direction. You could do this with an inverted projection matrix, however that would flip the actual tile, not just move it up or down to the proper location.

Instead of using y in your loop, try (NUM_TILES - y - 1):

int tmp_y = (NUM_TILES - y - 1);
glVertex2i(x * size, tmp_y * size);
glVertex2i((x * size) + size, tmp_y * size);
glVertex2i((x * size) + size, (tmp_y * size)+size);
glVertex2i(x * size, (tmp_y * size) +size);
Thanks Zipster :)

This topic is closed to new replies.

Advertisement