Adding wxWidgets to existing app

Vadim Zeitlin vadim at wxwidgets.org
Sun Jan 6 04:57:53 PST 2008


On Sun, 06 Jan 2008 02:19:31 +0000 GyroTech <gyrotech at freakinabox.com> wrote:

G> Thanks for the ideas. I managed to hack something together earlier, 
G> creating a wxApp that opens a frame during OnInit as normal, then 
G> overriding OnRun() to work my OpenGL SDL window, like this:-
G> 
G> while( !done )
G> {
G>    if( Pending() )
G>      Dispatch();
G> 
G>    if( SDL_PollEvent( &event ) )
G>    {
G>      // Do SDL stuff here
G>    }
G> 
G>    // Draw OpenGL scene here
G> }

 The question is when does SDL_PollEvent() return? If it does it
immediately (when there are no events), then this loop will consume 100% of
the CPU time which is not ideal.

G> This seems to work for the most part, but I was wondering how, upon 
G> checking Pending() I could check the event waiting, and if it's a custom 
G> one for my code to run (loading objects, changing lights etc) do 
G> something, otherwise just pass it on to Dispatch()

 Why do you want to do this? Dispatch() will call the event handler on its
own...

G> Is this a decent way of doing things or have I put together a terrible 
G> kludge?? ;-)

 It's a decent way of doing things but you need to ensure that you block
somewhere until the next event arrives instead of always cycling in a tight
loop.

 Regards,
VZ

-- 
TT-Solutions: wxWidgets consultancy and technical support
               http://www.tt-solutions.com/




More information about the wx-users mailing list