Thread: Combination C and OpenGL: Drawing multiple circles in a loop

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    1

    Combination C and OpenGL: Drawing multiple circles in a loop

    Hi, I'm making a simple 2D game where you use a cannon to shoot balls of the same color, I'd like to put my three rows of circles into three loops where 15 are drawn and translated over 28 units each time, but I've been running into some issues. Could I get ya'll to take a look at my code and explain what I'm doing wrong?

    Here's my code snippet I'm having issues with:

    Code:
    int Circle1 [20];
    
    
        for
        (Circle1=0; Circle1<15; Circle1++)
    {
       
        glPushMatrix();
        glTranslatef(d+28,455,1);
            random_generator(0,3);
            if (randomValue == 0)
    {
        glColor3f(0,.5,0);
    
    }
            else if (randomValue == 1)
    {
        glColor3f(.5,0,0);
    
    }
            else
    {
        glColor3f(0,0,.5);
    
    }
        glLineWidth(1.0);
        drawCircle(14,200);
        glPopMatrix();
    }

    When I compile it I get errors for the

    Code:
    (Circle1=0; Circle1<15; Circle1++)
    line of code saying:

    In function 'displayFunction':
    error: incompatible types when assigning to type 'int[20]' from type 'int'
    warning: comparison between point and integer
    error: lvalue required as increment operand
    Last edited by Chidori; 12-09-2009 at 01:36 AM.

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472

    .

    Code:
    int Circle1 [20];
    
    
        for
        (Circle1=0; Circle1<15; Circle1++)
    whats all this about?

    you declare a 20 element array called Circle1, then in your loop you use it like it was declared as an individual counting variable.

    did you mean to confusingly declare a same-named variable local to the for loop instead?

    if not then i would use a normal 'count' integer then reference your array contents with the count as index.

Popular pages Recent additions subscribe to a feed