Jerking display

Hi

I have written an openGL program to
do quick auto browse over image of various sizes.
At a time I render only 10241024 and keep updating the
frame buffer with different part of the image. It performs well.
But on display jerk appears. On small size rendering, say 128
128, it doesn’t happen. What i have to do to have smoother frame display?

Use vsync.

And do not use front buffer rendering, use only back buffer (the default) with double buffering.

keep updating the
frame buffer with different part of the image

Can you be more specific ? how do you update ?

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??

Hm … no blood on the wall yet. This place is impressively civilized!

Give them time to fully absorb what has been presented before them.

Just a hint:

void Move(void)
{
ReadImageFromFile();
[…]
}

Check out some basic tutorials at nehe.gamedev.net and get a bit more information about texturing etc.

Jan.

Is it not the way to display image???
Is ther any better method to display??

From the glut docs on glutIdleFunc():

Now have a look at what Jan posted.

CatDog

This, and a mysterious private message (from a guy who is having an eye disease and asking me if he should be a 3D programmer)… it is really too much…

:smiley:

:slight_smile:
why do I never get private messages like that?

Still auto sliding the subsequent chunks of a large image is making
jerk. I tried all the followings…

  1. Vsync is switched on
  2. MIP filters used
  3. instead of glutIdleFunc(), I made seperate thread to handle display…

But the problem remains…I m stuck up here…

  1. This isn’t in any way an advanced question.

  2. Posting the same problem twice (in the same forum) won’t speed up anything.

  3. Reading from file is SLOOOOOOOOOOW.

  4. You can actually load textures ONCE and render them as often as you wish.

  5. You can even slide the polygons / texture coordinates to only show a subset of your texture, so no re-reading from file necessary.

  6. Get a beginners book about OpenGL, i suggest the SuperBible.

  7. Read it.

  8. http://www.catb.org/~esr/faqs/smart-questions.html

  9. Be happy that i wasted my time ANSWERING your question, although it is so clear, that actually nobody WANTED to answer it.

Jan.

But on display jerk appears.

Perhaps you can explain what you mean by jerk.
If you are getting tearing, then vsync isn’t actually on. It might be forced disabled in your driver settings.

From the code you posted, you are recreating the texture non-stop. I can recommend that you create texture once, then update with glTexSubImage2D. Yes, obviously reading file from disk will slow things down a lot.
Can you tell us how much time it takes?

Yes it will unless the file is cached in RAM by the system.

it will still take a long time in the context of a render frame.

the file you are reading from, the filesize and what resolution it is?
and how large is the offset if u press an arrow button?

Why does it even matter? A stupid mistake is a stupid mistake; there is no excuse for reloading the same texture every frame unless you know what you are doing (the thread starter obviously does not).

Why does it even matter? A stupid mistake is a stupid mistake; there is no excuse for reloading the same texture every frame unless you know what you are doing (the thread starter obviously does not). [/QUOTE]

resolution matters, cause maybe he has a texture with a very high resolution (i.e. 1 million * 1 million) and he only wants to swap in a window (512*512) of it to display.

offset matters, because reloading the complete texture is NOT inefficient if he uses offsets>=512 (his windowsize)

filesize matters, because if his file suits in virtual adress space (on x64 systems it should), there is a little speedup
he can memory-map (readonly) the whole file, and directly feed texsubimage2d from it, eliminating one memorycopy

Thankx for the kind suggestion with great patience.
Sliding is now smooth…
All i did is dat single texture was created and file mapping was used to load the image.But when i go for loading huge image,say 5GB, mapping fails. Let me know is ther any open source library for loading raw images of any size with considerable speed??

And tell me what video card is able to handle a 5GB texture ?