Public Group

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.

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 on other sites
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 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.

1. 1
2. 2
3. 3
Rutin
19
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• Forum Statistics

• Total Topics
633657
• Total Posts
3013197
×