Sign in to follow this  
maxest

How to repaint every frame with wxWidgets?

Recommended Posts

I got a simple rendering function written in OGL. It's used in GLCanvas::OnPaint(wxPaintEvent &event) event, which is declared as: EVT_PAINT(GLCanvas::OnPaint). But this causes OGL rendering only when window needs to be repainted. How/where should I call my OnPaint to make it rendering all the time? (since I don't have access to program's main rendering loop because of wxWidgets)

Share this post


Link to post
Share on other sites
Honestly.. I don't understand. What event (EVT_) should I actually use?

I think I found a way around - I'll simply use timer :)

EDIT: NumberXaero: I got it :). I just misundestood you because of "OnInternalIdle" instead of "OnIdle" - thought there's a separate EVT_ for OnInternalIdle :). Works nice without timer. Thanks for help

Share this post


Link to post
Share on other sites
Yeah, probably should have been more descriptive, I posted quick just to point you in the right direction. You seemed to know what you were after.
OnInternalIdle() can be overridden from base wxWindow, OnEraseBackground() is called on events using the event table. Sorry about that.

Share this post


Link to post
Share on other sites

void GLCanvas::OnIdle(wxIdleEvent &event)
{
Render();
/* Force the redraw immediately, gets the gfx card to its max */
event.RequestMore();
}


Share this post


Link to post
Share on other sites
Now I've got problem with initilization. I want to call some init OGL functions that sets initial states, creates additional framebuffer objects and so on. I want to call that function in my wxGLCanvas-derived class constructor. However, before I can call my CRenderer::init I need to have context set. But I can't set it since I don't have window's DC. And this can be created only in OnPaint event! Here's the code:

MapRender::MapRender(wxWindow *parent, wxWindowID id, int *attribList, const wxPoint &position, const wxSize &size):
wxGLCanvas(parent, id, attribList, position, size)
{
wxGLContext context(this); // problem here
SetCurrent(context);
CRenderer::init();
}

void MapRender::OnPaint(wxPaintEvent &event)
{
wxPaintDC dc(this);
wxGLContext context(this);
SetCurrent(context);
Render();
SwapBuffers();
}

In line with "problem here" I need DC to make the context. How can I get this DC in constructor?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this