PDA

View Full Version : Jerking display



akila
05-14-2008, 01:33 AM
Hi

I have written an openGL program to
do quick auto browse over image of various sizes.
At a time I render only 1024*1024 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?

ZbuffeR
05-14-2008, 03:25 AM
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 ?

akila
05-14-2008, 05:46 AM
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_FILTE R,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,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_RE PLACE);
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??

tanzanite
05-14-2008, 08:02 AM
Hm ... no blood on the wall yet. This place is impressively civilized!

knackered
05-14-2008, 12:14 PM
Give them time to fully absorb what has been presented before them.

Jan
05-14-2008, 12:19 PM
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.

akila
05-14-2008, 11:48 PM
Is it not the way to display image???
Is ther any better method to display??

CatDog
05-15-2008, 06:31 AM
From the glut docs on glutIdleFunc():

The amount of computation and rendering done in an idle callback should be minimized to avoid affecting the program's interactive response.
Now have a look at what Jan posted.

CatDog

Zengar
05-15-2008, 06:52 AM
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...

:D

knackered
05-15-2008, 12:20 PM
:)
why do I never get private messages like that?

akila
05-16-2008, 12:19 AM
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...

Jan
05-16-2008, 01:48 AM
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.

V-man
05-16-2008, 05:08 AM
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?

Eosie
05-16-2008, 09:35 PM
Yes, obviously reading file from disk will slow things down a lot.
Yes it will unless the file is cached in RAM by the system.

knackered
05-17-2008, 09:30 AM
it will still take a long time in the context of a render frame.

vs987
05-17-2008, 04:45 PM
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?

Zengar
05-17-2008, 05:37 PM
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).

vs987
05-18-2008, 01:54 AM
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).

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

akila
05-21-2008, 07:04 AM
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??

ZbuffeR
05-21-2008, 10:34 AM
And tell me what video card is able to handle a 5GB texture ?

akila
05-21-2008, 08:40 PM
I am forming 1024*1024 texture only at a time.

yooyo
05-22-2008, 12:30 AM
Create several 1024x1024 textures and preload them. Use separate thread to load pages from disk in RAM. In main render thread refresh existing textures from RAM.

vs987
05-23-2008, 09:13 AM
sry i have no idea about a free library for that purpose.

but the problem you have with your "megatextures" is a common one in flight simulators or similar.

be aware an unpreprocessed uncompressed file format is not very efficient and u wont get it much faster if u go that way.

i dont either recommend tiling the large texture into smaller ones, because u have then to fight with tri-linear filtering problems between tiles, which means u need redundant borders (very problematic with mipmaps) or some heavier fragment shader work.

but the common approach to that is called "texture clipmapping"
(u should find something useful with googling it),
which allows u to display !any! window-size of almost-infinite (if u would use progressive procedural synthesis) textures inclusive correct mipmap-antialiasing.
i.e. there are some approaches that use wavelet compression
, so u can progressively decode from lower to higher detail mipmaps. (in fact in "clipmapping" there do not exist mipmaps anymore, only clipmaps that have the same size as the toplevel)

there is one critical flaw in your approach,
you should detach the texture loading process from the rendering loop,
one of the best examples of that, u can find in unreal tournament 3: the game begins, even before the textures are fully loaded, only lower mipmap levels are available at level start, and while playing the game progessively loads the higher detail mipmaps.

mapped to ur problem means that: if u cant load the 1024x1024 fast enough, at least display a 512x512 or 256x256 version

but well, i need more information how u want to display ur 1024x1024 window of ur 5gb file, maybe u dont need mipmapping at all (cause maybe u dont do any 3D-transformations/projections or 2d-scalings).

if this is so, i would go the way yooyo suggested, with some extensions:

if i had to display any portion of a 5gb file with the requirement of low-latency access. i would tile that large texture into smaller tiles (half or quarter your windowsize seams reasonable), compress each tile using a compression library, so u can squeeze that 5gb easily into 500mb memory.

btw, 5gb is not "that" large in today terms, using DXT1 u have a compression ratio of 1:8 (from RGBA8 to DXT1_RGB) means 0.625gb which fits completely in today top cards.