views:

51

answers:

1

Hi, 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

+1  A: 

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

Matias Valdenegro
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
@Marcel What same problem ocurred?
Matias Valdenegro
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
You should be clearing the screen (color buffer, depth etc.) every frame.
Mk12
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
glClear is the way to clear the screen correctly, your issue might be WHEN you are clearing the screen.
Matias Valdenegro
I clear it after glFlush()
Marcel