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