Jump to content
  • Advertisement
Sign in to follow this  
thyrgle

Infinite graph made out of squares.

This topic is 3073 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,

So I was wondering how you make an infinitely sized graph and each unit is a square (made with GL_QUADS). I have made a grid in OpenGL (using C++) and have came up with the following:

//Declare varaibles.
//This is for rows.
int row = 0;
//Goes through array NOT for the drawing.
int i;
//This is for drawing. Because it can be reset with affecting the length of the loop.
static int g;
for (i = 0; i < 100; i++)
{
g++;
if (cellActivation == false)
{
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
glVertex3f(g, row, -10);
glVertex3f(g+1, row, -10);
glVertex3f(g+1, row-1, -10);
glVertex3f(g, row-1, -10);
glEnd();
}
else if (cellActivation == true)
{
glColor3f(0.2f, 0.3f, 1.0f);
glBegin(GL_QUADS);
glVertex3f(g, row, -10);
glVertex3f(g+1, row, -10);
glVertex3f(g+1, row-1, -10);
glVertex3f(g, row-1, -10);
glEnd();
}
if(g == 10)
{
row--;
g = 0;
}
}





But, this is not infinite. Is there a way to make it infinite (and I mean make it so it can expand at runtime)?

Share this post


Link to post
Share on other sites
Advertisement
As a dirty hack...I've not considered it too much. But could you double the size of the your array in each dimension when you reach a certain distance away from it, so it just keeps growing and growing?

Share this post


Link to post
Share on other sites
I think the size of arrays are finite. Plus this needs to be efficient. I'm not even sure my current method for making a finite grid is that efficient.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!