Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
glClearColor(1.0,1.0,1.0,0);
glClear(GL_COLOR_BUFFER_BIT);

print background
forloop
{ print maze's one box at a time n also apply texture}
C#
Object(objectx,objecty);
glutSwapBuffers();
break;

}
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 :(

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

}

i call this fn in main and glCallList(index); in display()
Posted
Updated 1-Oct-11 19:40pm
v3

1 solution

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.
 
Share this answer
 
Comments
Sweety Khan 2-Oct-11 1:26am    
woW i undrstand, hope it solves my problem. i got a problem in the implementation of wht u said. 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
Sweety Khan 2-Oct-11 1:27am    
my coding is not coming in the comment box wht can i do? :|

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900