Jump to content
  • Advertisement
Sign in to follow this  
thyrgle

Need help understanding why this grid will not start up.

This topic is 2661 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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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++;
}

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!