Public Group

# Need help understanding why this grid will not start up.

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

## Recommended Posts

I am trying to make a grid of randomly colored squares (and just to let you know before hand: some of the squares are colored black).

Right now I am using the following code snippets to produce this effect:

 void getTransform(point x) { glTranslatef((float)x.x-prev.x+23-counter, (float)x.y+counter, 0.0); if (subCounter % 10 == 0) { counter = counter+10; } subCounter++; std::cout << subCounter << "\n"; prev = x; } //And in my draw function: for (int i = 0; i < 100; i++) { getColor(grid); getTransform(grid); glBegin(GL_QUADS); glVertex2i(0, 0); glVertex2i(20, 0); glVertex2i(20, 20); glVertex2i(0, 20); glEnd(); } 

Also, my grid is defined in the following way:
 typedef struct { int x; int y; int type; //For color don't worry about it... }point; point grid[100]; //I initialize the grid before initialize GLUT... void initGrid() { for (int i = 0.0; i<100.0; i++) { for (int g = 0.0; g < 100.0; g++) { grid.y=i; grid.x=g; } } } 

I have opted out the getColor function because it is working fine, but I am not able to get the grid to draw right. When I run the program my output looks something like the attached file. How can I change the code to make straight rows? Any help would be appreciated. If you need more code just ask. (Additional notes: I am using OpenGL and C++).

A result:

[attachment=1624:Screen shot 2011-03-12 at 11.41.44 AM.png]

##### Share on other sites
I don't know if it has anything to do with your problem, but your initGrid function looks suspicious. You're setting the x parameter for the same grid i subscript 100 times.

EDIT: I.e., your grid array is getting loaded with ( 0,99 ), ( 1,99 ), ..., ( 99,99 ).

##### Share on other sites
I figured it out.

In my getTransform function I changed it to:

void getTransform(point x) { glTranslatef(21, 0, 0.0); if (counter % 10 == 0 && counter >= 10) { glTranslatef(0, 21, 0); glTranslatef(-210, 0, 0); } counter++; }

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

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

• Total Topics
633662
• Total Posts
3013231
×