Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ OpenGL
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);
print background
forloop
{ print maze's one box at a time n also apply texture}
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 Frown | :(
 
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 1-Oct-11 10:46am
Edited 1-Oct-11 20:40pm
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Sweety Khan at 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 at 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)

  Print Answers RSS
0 OriginalGriff 245
1 Jochen Arndt 155
2 PIEBALDconsult 150
3 Afzaal Ahmad Zeeshan 120
4 DamithSL 115
0 OriginalGriff 5,695
1 DamithSL 4,591
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 2 Oct 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100