对象在我移动时未正确显示n也挂起了我的IDE [英] object is not showing properly when i move it n also hangs my IDE

查看:83
本文介绍了对象在我移动时未正确显示n也挂起了我的IDE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

im使用箭头键在屏幕上移动对象,但它不是立即移动,一段时间后它也移动了,这也挂了我的netbeans,请看里面有问题.

我没有在这里粘贴我的巨大代码,而是用文字或某些确切的代码编写,因此任何想回答的人都可以轻松理解问题.
display()
{
.....
case startGame:

im moving an object on screen using arrow keys but it is not moving instantly, it moves after some time n also hangs my netbeans, plz see whts problem in it.

i m not pasting my huge code here, i m writing in words or some exact code so tht whoever wants to answer can understand the question easily
display()
{
.....
case startGame:

glClearColor(1.0,1.0,1.0,0);
glClear(GL_COLOR_BUFFER_BIT);


打印背景
forloop
{一次打印一个迷宫n也要应用纹理}


print background
forloop
{ print maze''s one box at a time n also apply texture}

Object(objectx,objecty);
glutSwapBuffers();
break;


}
使用glutSpecialFunc(mySpecialKeyFn)更改对象x和y;

我认为每次按箭头键时,它都必须打印很多东西,为什么它会缓慢移动并挂起,对吗?

在收到答案后更新
我在实现displayLIsts时遇到问题.这是我的display()代码,为此我创建了一个显示列表,但问题是它将纹理应用于每个框:(


}
objects x and y is changing using glutSpecialFunc(mySpecialKeyFn);

i think each time i press an arrow key, it has to print lot of things thts why it moves slow n hang, am i right?

updated after recieving answer
i got a problem in the implementation of displayLIsts. this is my code of display() for which i made a displaylist but the problem is tht it apply texture to every box :(

void generateDisplayList()
{
    index = glGenLists(1);
    glNewList(index, GL_COMPILE);
    int x = startx, y= starty;
    for(int i =0;i<mazeHeight;i++)
    {
        for(int j=0;j<mazeWidth;j++)
        {
            if(mazeArray[i][j]==1 ||mazeArray[i][j]==2)
            {
                if(i==0&& j==startpty)
                {
                    glColor3f(1,0,0);
                    objectx=x+25;
                    objecty=y-25;
                }
                else if(i==mazeHeight-1&&j==endpty)
                    glColor3f(1,0,0);
                else
                    glColor3f(201/255.0,228/255.0,228/255.0);
                        glBegin(GL_QUADS);
                        glVertex2f(x,y);
                        glVertex2f(x+size,y);
                        glVertex2f(x+size,y-size);
                        glVertex2f(x,y-size);
                        glEnd();
              }
              else
              {
                        glColor3f(1,1,1);
                        img[4].setTexture(2);
                        glEnable(GL_TEXTURE_2D);
                        glBindTexture(GL_TEXTURE_2D,2);
                        glBegin(GL_QUADS);
                        glTexCoord2f(0.0,0.0);
                        glVertex2f(x,y);
                        glTexCoord2f(1.0,0);
                        glVertex2f(x+size,y);
                        glTexCoord2f(1.0,1.0);
                        glVertex2f(x+size,y-size);
                        glTexCoord2f(0,1.0);
                        glVertex2f(x,y-size);
                        glEnd();
                }
                x+= size;
         }
                y-=size;
                x=startx;
      }
      glEndList();

}


我在main和glCallList(index)中将此称为fn;在display()


i call this fn in main and glCallList(index); in display()

推荐答案

中,响应时间应为1/frameRate秒.也就是说,如果您每秒在屏幕上投掷500帧,则您应该能够每秒处理500次移动-0.002s响应时间.

如果您的响应时间太慢而引人注目,那么我很乐意打赌整个绘制循环同样慢(实际上是问题的根源)
根据目标的OpenGL版本,程序员可以使用不同的优化方法.作为一个非常简单和基本的优化,例如,您是使用DisplayLists还是更奇特的Vertex Buffer Objects?


我还要指出,我在本周早些时候读到,在Quake2的典型帧中,任何时候屏幕上通常只能看到600-700个多边形.该引擎非常复杂,可以对1000s/100,000s/1,000,000s个多边形进行排序,只发送对OpenGL管道可见的多边形.这样可以极大地节省因在Z平面中每个相近的对象反复绘制任何特定像素而浪费的精力.
The response time should be 1/frameRate seconds. I.e if you''re throwing 500 frames a second onto the screen, you should be able to handle 500 moves per second - 0.002s response time.

If your response time is so slow as to be noticeable, I''m more than willing to bet that the whole draw-loop is equally slow (and in fact, the source of the problem)
Different optimizations are available to the programmer, based on the version of OpenGL being targeted. As a very simple and basic optimization, are you for example, using DisplayLists or the somewhat more exotic Vertex Buffer Objects?


I also will point out that I read earlier this week that in a typical frame of Quake2, there are often only some 600 - 700 polygons visible on the screen at any one time. The engine is sophisticated enough that it sorts through the 1000s/100,000s/1,000,000s of polygons and only sends the ones which will be visible to the OpenGL pipeline. This saves tremendously on the effort wasted by painting any particular pixel over and over again with each successively closer object in the Z plane.


这篇关于对象在我移动时未正确显示n也挂起了我的IDE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆