Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Should Allegro on OpenGL in Windows's cpu be fluctuating?

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Should Allegro on OpenGL in Windows's cpu be fluctuating?
Trent Gamblin
Member #261
April 2000
avatar

The latter behaviour (of M.A.R.S) makes sense. The Allegro behaviour doesn't. I have this fuzzy memory of someone talking about vsync using up mad CPU but I don't remember who it was or all the details. But it's not happening with M.A.R.S so that makes it a little strange... It's possible the Windows code does something strange with Vsync, I can have a look at it but I've never messed around with WGL.

EDIT: The WGL display driver has no mention of "vsync" or even "sync" anywhere. I'll look into it tonight if I can. But maybe someone else has a better idea already how vsync works on WGL?

jmasterx
Member #11,410
October 2009

This could be useful:

http://stackoverflow.com/questions/589064/how-to-enable-vertical-sync-in-opengl

Quote:

If you are working on Windows you have to use extensions to use wglSwapIntervalExt function. It is defined in wglext.h. You will also want to download glext.h file. In wglext file all entry points for Windows specific extensions are declared. All such functions start with prefix wgl. To get more info about all published extensions you can look into OpenGL Extension Registry.

wglSwapIntervalEXT is from WGL_EXT_swap_control extension. It lets you specify minimum number of frames before each buffer swap. Usually it is used for vertical synchronization (if you set swap interval to 1). More info about whole extension can be found here. Before using this function you need query whether you card has support for WGL_EXT_swap_control and then obtain pointer to the function using wglGetProcAddress function.

Trent Gamblin
Member #261
April 2000
avatar

Thanks. Should be very easy to enable/disable vsync with this function. Allegro's extension handling already loads wglSwapIntervalEXT if it's supported, so it's just a matter of calling it if it's available (Allegro can check if extensions are available very easily too) with 1 or 0 depending on if the user requests it to be off or on (I think on should be the default). Don't know if it would make a difference in your case but it's worth a try.

jmasterx
Member #11,410
October 2009

Nice!!!

Calling wglSwapIntervalEXT(0); after creating the display totally solves the problem, so I think Allegro is missing this and I'm sure committing this change will solve this issue!

Trent Gamblin
Member #261
April 2000
avatar

Well it's more complicated than that, but I just committed a patch to 5.1 that makes WGL honor the ALLEGRO_VSYNC display option. So it should work for you to force it off or on.

jmasterx
Member #11,410
October 2009

Great thanks!

I was also wondering if it was normal that I can render a lot more bitmaps with D3D. I made a test and rendering 20x20 bitmaps in OpenGL consumed around 60% while it was only about 12% in D3D.

Trent Gamblin
Member #261
April 2000
avatar

On some hardware that is normal. Can you give me another simple compilable example, or does ex_draw_bitmap do the same thing, and I can test that?

jmasterx
Member #11,410
October 2009

If you add a for loop of 400 it should do it.

D3D: 5%
GL: 30%

But once again, the big differences come when this example runs at 60 fps, I also added the swapinternal function.

 1   2 


Go to: