Problems about repainting wxGLCanvas when resizing

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
yoohan
In need of some credit
In need of some credit
Posts: 1
Joined: Thu Jan 03, 2019 8:16 am

Problems about repainting wxGLCanvas when resizing

Post by yoohan »

I'm using wxGLCanvas to "plot" something. When I resize the window, the size of canvas changes normally(with sizers), but the "graph" inside the canvas won't fit this change. So what should I do to repaint glcanvas "normally"?

Code: Select all

//here is the code
//opSubplot is inherited from wxPlane, and "canvas" is a member of type wxGLCanvas*

void opSubplot::OnSize(wxSizeEvent & event)
{
	if (context->IsOK()) {
		context->SetCurrent(*canvas);
		glViewport(0, 0, canvas->GetSize().GetWidth(), canvas->GetSize().GetHeight());
		//glFlush(); //makes no difference?
	}
}
Last edited by catalin on Thu Jan 03, 2019 9:12 am, edited 1 time in total.
Reason: code tags
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Problems about repainting wxGLCanvas when resizing

Post by doublemax »

Did you confirm that the OnSize handler gets called?

Try using event.GetSize().x/y for the size. With canvas->GetSize() you're getting the old size.

Try calling event.Skip() in the OnSize handler.
Use the source, Luke!
Manolo
Can't get richer than this
Can't get richer than this
Posts: 828
Joined: Mon Apr 30, 2012 11:07 pm

Re: Problems about repainting wxGLCanvas when resizing

Post by Manolo »

The OpenGL API does not contain any command to automagically resize anything. It's your task, which is normally achieved by setting proper parameters to the projection matrix you use. Scaling or translating or moving the camera may also work (the model and view matrices).

BTW, glFlush() just tells the GPU to issue any pending commands. glFinish() will make the CPU to wait until all gl-commands have been proccessed. None of them will re-draw anything.

Is short: Redraw your scene after the call to glViewport.
Post Reply