如何重绘视图? (OpenGl)
我想创建一种模拟。它应该显示鱼/鲨鱼/逆戟鲸的特定位置(不是真实的,它们是随机设置的)。我的模拟可以显示起始情况:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需清除屏幕并重新绘制所有内容即可。这是标准方法。
Just clear the screen and draw everything again. It's the standard method.