• 12
• 11
• 9
• 10
• 13

# Problem drawing a 2D grid

This topic is 3813 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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();

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 :-/

##### Share on other sites
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);