Jump to content
  • Advertisement
Sign in to follow this  
cossie

Problem drawing a 2D grid

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

If you intended to correct an error in the post then please contact us.

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!