Sign in to follow this  
cossie

Problem drawing a 2D grid

Recommended Posts

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

Share this post


Link to post
Share on other sites
Zipster    2359
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);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this