I will display my code here,
unsigned char image[512][512][4];
int wind_x,wind_y;
ifstream fin;
void ReadImageFromFile(void)
{
//loading 512*512 pixel values from file current offset
}
void SetupImage(void)
{
glClearColor(0.25,0.25,0.25,0.0);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_FLAT);
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glGenTextures(1,&texture_name);
glBindTexture(GL_TEXTURE_2D,texture_name);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,512,512,0,GL_RGBA,GL_UNSIGNED_BYTE,image);
}
void Display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
glBindTexture(GL_TEXTURE_2D,texture_name);
glBegin(GL_QUADS);
glTexCoord2f(0.0,0.0);glVertex3f(0,0,0);
glTexCoord2f(1.0,0.0);glVertex3f(wind_x,0,0);
glTexCoord2f(1.0,1.0);glVertex3f(wind_x,wind_y,0);
glTexCoord2f(0.0,1.0);glVertex3f(0,wind_y,0);
glEnd();
glFlush();
glutSwapBuffers();
glDisable(GL_TEXTURE_2D);
}
void Reshape(int x,int y)
{
wind_x=x;
wind_y=y;
glViewport(0,0,x,y);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,x,y,0,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void Move(void)
{
ReadImageFromFile();
SetupImage();
Display();
}
void Keyboard(unsigned char key,int x,int y)
{
switch(key){
case RIGHT:
//…Set the file offset to right
……………………
………………………
glutIdleFunc(NULL);
glutIdleFunc(Move);
break;
case LEFT:
//Set the file offset to Left ………………
………………………
glutIdleFunc(NULL);
glutIdleFunc(Move);
break;
case TOP:
//Set the file offset to Top ……………………
………………………
glutIdleFunc(NULL);
glutIdleFunc(Move);
break;
case BOTTOM:
//Set the file offset to Bottom
……………………
………………………
glutIdleFunc(NULL);
glutIdleFunc(Move);
break;
}
}
void main(int argc,char *argv[])
{
ReadImageFromFile();
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
wind_x=500; wind_y=500;
glutInitWindowSize(wind_x,wind_y);
glutInitWindowPosition(200,100);
glutCreateWindow(“Image Display”);
SetupImage();
glutDisplayFunc(Display);
glutReshapeFunc(Reshape);
glutKeyboardFunc(Keyboard);
glutMainLoop();
}
to brief, at each time I load buffer of 512 by 512 with
pixel values read from the file. The values are read from the offset(at file) which is set correspondingly on arrow key is pressed. This makes image to be moved on screen. The problem is that the motion is jerking/vibrating.
What should I have to do to have smooth movement of images on screen??