如何重绘视图? (OpenGl)

发布于 2024-09-14 08:22:49 字数 1314 浏览 4 评论 0原文

我想创建一种模拟。它应该显示鱼/鲨鱼/逆戟鲸的特定位置(不是真实的,它们是随机设置的)。我的模拟可以显示起始情况:

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

工作正常。 drawAFish/drawAShark ...绘制一个简单的四边形:

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

所以我的问题是:如何重绘场景?

谷歌或文档中没有太多有用的信息。

谢谢你的帮助,

马塞尔

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

年少掌心 2024-09-21 08:22:51

只需清除屏幕并重新绘制所有内容即可。这是标准方法。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文