# 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 on other sites
Try these

void OnInternalIdle() {
Refresh();
}

void OnEraseBackground(wxEraseEvent& e) {
// avoid flash, do nothing
}

##### 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 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 on other sites
void GLCanvas::OnIdle(wxIdleEvent &event){	Render();		/* Force the redraw immediately, gets the gfx card to its max */	event.RequestMore();}

##### 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?

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627653
• Total Posts
2978440

• 10
• 12
• 22
• 13
• 33