2

I want to create a kind of a simulation. It should display the certain position of a fish/shark/orca (not real ones, they are set up randomly). My Simulation can display the starting situation:

glOrtho(0, breite, 0, hoehe, 0, 1);
glClearColor(0, 0, 1, 0);
glClear(GL_COLOR_BUFFER_BIT);

//Besetzen der Felder
srand(time(0));
NSMutableArray* Wator = [NSMutableArray new];
for(int y = 0; y < hoehe; y++){
    for(int x = 0; x < breite; x++){
        NSInteger r = rand() % 100;
        if (r < fishPer) {
            [Wator addObject:[[[Fish alloc]init]autorelease]];
            drawAFish(x,y);

        }else {
            if (r < sharkPer + fishPer) {
                [Wator addObject:[[[Shark alloc]init]autorelease]];
                drawAShark(x, y);
            }else {
                if (r < orcaPer + sharkPer + fishPer) {
                    [Wator addObject:[[[Orca alloc]init]autorelease]];
                    drawAOrca(x, y);
                }
            }
        }
    }
}
glFlush();

It works fine. drawAFish/drawAShark ... draw a simple Quad:

static void drawAOrca (int x, int y)
{
    glColor3f(1.0f, 1.0f, 0.0f);
    glBegin(GL_QUADS);
    {
        glVertex3i( x, y, 0);
        glVertex3i( x+1, y, 0);
        glVertex3i( x+1, y+1, 0);
        glVertex3i( x, y+1, 0);
    }
    glEnd();
}

So my question is: How can I redraw the scene?

There are not many helpful information at google or in the documentation.

thanks for your help

Marcel

Marcel
  • 53
  • 6

1 Answers1

2

Just clear the screen and draw everything again. It's the standard method.

Dr. Snoopy
  • 55,122
  • 7
  • 121
  • 140
  • I tried this, but when the application wait until the end of the script. But I want to display the steps in between. I also tried it with glFinish instead of glflush, but the same problem occurred. – Marcel Aug 17 '10 at 14:08
  • @Marcel What same problem ocurred? – Dr. Snoopy Aug 17 '10 at 14:21
  • that the is displayed at the end, but there should be a redrawing in between. I get just one output. I tested it with a sleep function to control if it runs to fast. – Marcel Aug 17 '10 at 14:36
  • You should be clearing the screen (color buffer, depth etc.) every frame. – mk12 Aug 18 '10 at 17:47
  • I tried all glClear() i found, but nothing changed. It is still so that only the last one is shown. May you can tell me how to clear the screen correctly. – Marcel Aug 21 '10 at 14:14
  • glClear is the way to clear the screen correctly, your issue might be WHEN you are clearing the screen. – Dr. Snoopy Aug 21 '10 at 16:36