On 1/8/10 14:30 , Frédéric wrote:
Le vendredi 8 janvier 2010 12:55, Frédéric a écrit :

I'm still trying to made crossfade between 2 images, using opengl
textures, but it does not work fine. Here is my code :
Ok, I found my mistake: the first texture is at z index 0, so I changed:

    glOrtho(0., 1., 1., 0., 0., 10.)


    glOrtho(0., 1., 1., 0., -10., 10.)

and it now works.

Is there a way to optimize this code? On my old computer (P4 / GeForce FX 
5200), it takes 100% of the CPU with only a 640x480 windows. If I resize it 
to 320x200, it does not take more than 5%...

My next step will be to update the textures as the pictures change; what is 
the best way to do this?

Hello Frédéric,

I haven't done any QT programming, so I could be wrong, but your code shouldn't even require a couple of %'s of your CPU. The work that your script does is hardly CPU-intensive and if your timer really updates your frame every 1/50th of a second, then the CPU hardly does anything. If on the other hand somehow OpenGL does updates without any sleeptime inbetween, then it would explain the CPU usage. So I would check the timer function or at least check how often your draw function is called.

Some optimizations might be to move the glBlendFunc out of the drawing function to the init function. If you don't change the blending function somewhere else, then setting it once is enough since it is a global setting (not something that you need to set everytime you call glEnable(GL_BLEND)). You can also move glLoadIdentity to the init function if you don't call glRotate/glTranslate/glScale commands in other parts of your code. Also, though I'm not completely sure on this, you should be able to clear your screen without having to disable/enable dither and blending every time. Put the enable calls in the init section and see what happens.

There are many ways to change a texture though I'm not sure your video card would support all of them. Shaders, PBOs, and FBOs are the usual way to do this but check and see if your FX5200 supports those. Otherwise you'd need to use the standard OpenGL calls like glCopyTexImage2D.

Regards, Gijs