Thread: [PyOpenGL-Users] Textures usage
Brought to you by:
mcfletch
From: Frédéric <fre...@gb...> - 2010-01-08 13:01:28
|
Hi, I'm still trying to made crossfade between 2 images, using opengl textures, but it does not work fine. Here is my code : http://www.pycasso.org/browser/trunk/proto/crossFadeOpenGL.py I only see the second texture. Where is my mistake? Thanks, -- Frédéric http://www.gbiloba.org |
From: Frédéric <fre...@gb...> - 2010-01-08 14:06:39
|
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.) to: 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? -- Frédéric http://www.gbiloba.org |
From: Gijs <in...@bs...> - 2010-01-08 14:29:54
|
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.) > > to: > > 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// |
From: Frédéric <fre...@gb...> - 2010-01-08 15:04:52
|
Le vendredi 8 janvier 2010 14:29, Gijs a écrit : > 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. It appears that the CPU is not used by my process. I'm not sure, but it seems to be a kernel-space usage (orange in the Gkrellm default theme)... > 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. Thanks for the tips. > 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. Ok, I will first try glCopyTexImage2D. From where should I call it? Should it be in a GL-specific context? What if the image ratio change? How do I handle this? Can I resize the texture? -- Frédéric http://www.gbiloba.org |
From: Frédéric <fre...@gb...> - 2010-01-08 15:12:58
|
Le vendredi 8 janvier 2010 15:04, Frédéric a écrit : > It appears that the CPU is not used by my process. I'm not sure, but it > seems to be a kernel-space usage (orange in the Gkrellm default theme)... It is 80% system usage, 20% process usage... Resizing the windows shows a strange thing: height=351 -> 5% CPU height=357 -> 100% CPU Why such a big step? -- Frédéric http://www.gbiloba.org |
From: Gijs <in...@bs...> - 2010-01-08 15:51:07
|
On 1/8/10 16:12 , Frédéric wrote: > Le vendredi 8 janvier 2010 15:04, Frédéric a écrit : > > >> It appears that the CPU is not used by my process. I'm not sure, but it >> seems to be a kernel-space usage (orange in the Gkrellm default theme)... >> > It is 80% system usage, 20% process usage... > > Resizing the windows shows a strange thing: > > height=351 -> 5% CPU > height=357 -> 100% CPU > > Why such a big step? > > No idea :) I'd call that a bug but without having extra information about what's happening, I don't know for sure. Maybe Google has an answer. |
From: Frédéric <fre...@gb...> - 2010-01-11 14:24:39
|
Le vendredi 8 janvier 2010 15:12, Frédéric a écrit : > > It appears that the CPU is not used by my process. I'm not sure, but it > > seems to be a kernel-space usage (orange in the Gkrellm default > > theme)... > > It is 80% system usage, 20% process usage... Someone on another ml suggested me to use strace to see where the system spend all its time. But the results don't show anything usefull. During a 10s run, I get: % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 91.73 0.267082 1 385350 sched_yield 2.73 0.007951 9 882 2 ioctl 1.42 0.004130 0 13364 futex 1.18 0.003442 2 2046 1744 open 1.07 0.003113 10 307 mmap2 0.72 0.002089 7 311 close 0.58 0.001693 13 129 munmap 0.42 0.001216 2 723 539 stat64 0.08 0.000227 0 1404 189 read 0.04 0.000109 4 25 brk 0.02 0.000061 6 10 getdents64 0.01 0.000028 0 298 write 0.01 0.000023 0 337 fstat64 0.00 0.000000 0 1 execve 0.00 0.000000 0 9 chdir 0.00 0.000000 0 3 time 0.00 0.000000 0 1 lseek 0.00 0.000000 0 75 49 access 0.00 0.000000 0 2 pipe 0.00 0.000000 0 964 gettimeofday 0.00 0.000000 0 5 2 readlink 0.00 0.000000 0 1 fstatfs 0.00 0.000000 0 17 uname 0.00 0.000000 0 9 mprotect 0.00 0.000000 0 11 _llseek 0.00 0.000000 0 5 readv 0.00 0.000000 0 15 writev 0.00 0.000000 0 363 poll 0.00 0.000000 0 69 rt_sigaction 0.00 0.000000 0 1 rt_sigprocmask 0.00 0.000000 0 11 getcwd 0.00 0.000000 0 1 getrlimit 0.00 0.000000 0 54 3 lstat64 0.00 0.000000 0 7 geteuid32 0.00 0.000000 0 31 fcntl64 0.00 0.000000 0 1 set_thread_area 0.00 0.000000 0 1 set_tid_address 0.00 0.000000 0 5 socket 0.00 0.000000 0 5 2 connect 0.00 0.000000 0 2 shutdown 0.00 0.000000 0 3 shmat ------ ----------- ----------- --------- --------- ---------------- 100.00 0.291164 406858 2530 total As you can see, systems calls used less than 3% of the CPU! So, what are these system calls I can see in Gkrellm? The same person also suggested me to have a look at OpenGL lib support. Here is what I get with glxinfo: name of display: :0.0 display: :0 screen: 0 direct rendering: Yes server glx vendor string: NVIDIA Corporation server glx version string: 1.4 client glx vendor string: NVIDIA Corporation client glx version string: 1.4 GLX version: 1.3 OpenGL vendor string: NVIDIA Corporation OpenGL renderer string: GeForce FX 5200/PCI/SSE2 OpenGL version string: 2.0.2 NVIDIA 87.76 I think all is fine (as other applications, like GoogleEarth or Phun works smoothly). Could it be a hardware limitation? I can imagine this on the above one (P4, GeForce FX 5200), but I have similar results on my Q6600 + GeForce 8400 GS... Could someone make a test and tell me if he has the same behaviour? Thanks, -- Frédéric http://www.gbiloba.org |
From: Gijs <in...@bs...> - 2010-01-08 15:49:07
|
On 1/8/10 16:04 , Frédéric wrote: > Le vendredi 8 janvier 2010 14:29, Gijs a écrit : > >> 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. > > It appears that the CPU is not used by my process. I'm not sure, but it > seems to be a kernel-space usage (orange in the Gkrellm default theme)... > >> 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. > > Thanks for the tips. > >> 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. > > Ok, I will first try glCopyTexImage2D. From where should I call it? Should > it be in a GL-specific context? What if the image ratio change? How do I > handle this? Can I resize the texture? > Well, depends on your implementation where you'd want to put the glCopyTex command, but probably somewhere after or before the drawing function. If you want to draw a texture that has dimensions of 512x512 on a 640x480 screen, OpenGL just resizes the texture accordingly. The final image might look a bit crushed or stretched, depending on the resolution that you draw at and the original resolution of your texture, so you might need something like mipmapping to fix this. But try it without mipmapping first. |
From: Frédéric <fre...@gb...> - 2010-01-08 16:10:46
|
On vendredi 08 janvier 2010, Gijs wrote: > > Ok, I will first try glCopyTexImage2D. From where should I call it? > > Should it be in a GL-specific context? What if the image ratio change? > > How do I handle this? Can I resize the texture? > > Well, depends on your implementation where you'd want to put the > glCopyTex command, but probably somewhere after or before the drawing > function. My goal is to make a slideshow program. So, new images are loaded according to the timeline... But I presume that I can't use opengl functions outside initializeGL(), resizeGL() or paintGL() methods, in my callback binded to that timeline? > If you want to draw a texture that has dimensions of 512x512 > on a 640x480 screen, OpenGL just resizes the texture accordingly. The > final image might look a bit crushed or stretched, depending on the > resolution that you draw at and the original resolution of your > texture, so you might need something like mipmapping to fix this. But > try it without mipmapping first. My question was more about the ratio; as you can see in the code, I compute the mapping of the texture from the image size. But then, if I want to load a new image with a different ratio, how do I expand/shrink the previous one? -- Frédéric http://www.gbiloba.org |
From: Frédéric <fre...@gb...> - 2010-01-12 08:08:13
|
Le vendredi 8 janvier 2010 16:10, Frédéric a écrit : > My question was more about the ratio; as you can see in the code, I > compute the mapping of the texture from the image size. But then, if I > want to load a new image with a different ratio, how do I expand/shrink > the previous one? In fact, I have a problem with my textures. I think I mis-understood the mapping between the textures coordinates and the space coordinates... Is there a simple tutorial explaining it? Thanks, -- Frédéric http://www.gbiloba.org |
From: Frédéric <fre...@gb...> - 2010-01-12 08:36:16
|
Le mardi 12 janvier 2010 08:08, Frédéric a écrit : > In fact, I have a problem with my textures. I think I mis-understood the > mapping between the textures coordinates and the space coordinates... My problem is: how do I fill the window with my texture, when neither the window nor the texture is a square? -- Frédéric http://www.gbiloba.org |
From: Ian M. <geo...@gm...> - 2010-01-12 20:35:04
|
Best plan is to use a 2D view and then draw a quad going from (0,0) to (screen_x, screen_y). I have some code somewhere. |
From: Ian M. <geo...@gm...> - 2010-01-13 05:00:59
|
Hi, Set 2D View: #if your screen is 800x600, rect = [0,0,800,600] glViewport(*rect) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluOrtho2D(rect[0],rect[0]+rect[2],rect[1],rect[1]+rect[3]) glMatrixMode(GL_MODELVIEW) glLoadIdentity() Draw textured fullscreen quad. Make sure you bind to your texture too! param = glGetFloatv(GL_VIEWPORT) glBegin(GL_QUADS) glTexCoord2f(0,0);glVertex2f(param[0], param[1] ) glTexCoord2f(1,0);glVertex2f(param[0]+param[2],param[1] ) glTexCoord2f(1,1);glVertex2f(param[0]+param[2],param[1]+param[3]) glTexCoord2f(0,1);glVertex2f(param[0], param[1]+param[3]) glEnd() Ian |