Jump to content
  • Advertisement
Sign in to follow this  

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.

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;
std::cout << subCounter << "\n";
prev = x;

//And in my draw function:
for (int i = 0; i < 100; i++)
glVertex2i(0, 0);
glVertex2i(20, 0);
glVertex2i(20, 20);
glVertex2i(0, 20);

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 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++) {

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

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!