Can you do it? wxGLCanvas

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
mattropolis
In need of some credit
In need of some credit
Posts: 4
Joined: Mon Sep 17, 2007 11:30 pm

Can you do it? wxGLCanvas

Post by mattropolis » Wed Oct 17, 2007 5:21 pm

I would *really* like to use wxWidgets for this, but things don't look good based on what I've read through the wiki + forums. Perhaps I missed something?

I'm working on a simple visualization app that needs to have an OpenGL window draw a simple GL scene. However, I need the OpenGL window/wxGLCanvas be updating constantly - even when no events are happening. Basically, I need the machine to be drawing as often as possible (high fps), but also be able to handle gui/keyboard events too.

In win32, you'd do this in the WinMain:
winmain()
{
TranslateMessage();
DispatchMessage();
MyDrawingRoutine();
}

But from what I see in the forums - you can't get access to the main message pump like this.

So, can I make my wxApp to do the UI stuff, and then start a thread that will do the wxGLCanvas drawing loop? Can GL window live in the same physical window as the wxApp if the GLCanvas is in another thread? Has anyone got this working in another way?

Here's what I have tried and doesn't work:
1. draw on wxTimer events - all animation stops when another event such as click/drag or keyboard events happen
2. OnPaint() invalidate - the last line of the OnPaint function invalidates the OpenGL rect so another draw command is issued. Unfortunately, keyboard input/mouse input gets lost or greatly delayed - very sluggish. App often can't exit as side effect.

Help? Thanks!

Scorcher24
Earned some good credits
Earned some good credits
Posts: 128
Joined: Sat Sep 25, 2004 9:11 pm
Location: Nuremberg, Germany
Contact:

Post by Scorcher24 » Sun Oct 21, 2007 12:27 am

I have done it this way:

Code: Select all

m_timer = new wxTimer(this, ID_RENDERTIMER);
if (m_timer != NULL){
  m_timer->Start(40, false);
}

void CCanvas::OnMyTimer(wxTimerEvent &event)
{
    if (m_plugin == NULL)
    {
        return;
    }
    m_plugin->OnTimer();
    this->Refresh(false);
}
It works just fine. I don't know how much load GLCanvas can handle, but I am just drawing primitives for designing OpenGL-Shader. But GLSL and Textures work :P.
Hope this helps.
rya.
OS: Windows 7 Ultimate 64bit
IDE: VC++ 2008 Professional
WX: 2.9.2
My Projects

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Sun Oct 21, 2007 3:05 pm

wx is indeed not the best for intensive game-like stuff, it was more designed for applications than games. Note that it is possible to do it, but your framerate will probably be a bit lower and rendering may stop while other events are processed (e.g. if you are browsing a menu)

Post Reply