wxGLCanvas problem

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
periscopewxyun
In need of some credit
In need of some credit
Posts: 5
Joined: Sat Dec 16, 2017 6:59 am

wxGLCanvas problem

Post by periscopewxyun » Mon Feb 05, 2018 4:26 am

Hello all,

I am learning wxGLCanvas with Code::Blocks(16.01). I used a simple example but cannot make it work. I attached 3 figures to show what I have done. Basically, I want to place a glcanvas directly on a wxpanel. The glcanvas background color is set to be red and wxExpand is applied (Figure 1). The preview shows everything looks fine (Figure 2) but after build and run, the glcanvas seems not expand at all (Figure 3) and the red background color is not shown either. Can anyone see what is wrong here?

Many thanks,

periscopewxyun
Attachments
Figure 1.JPG
Figure 2.JPG
Figure 2.JPG (43.5 KiB) Viewed 448 times
Figure 3.JPG
Figure 3.JPG (35.67 KiB) Viewed 448 times

Manolo
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 698
Joined: Mon Apr 30, 2012 11:07 pm

Re: wxGLCanvas problem

Post by Manolo » Mon Feb 05, 2018 1:56 pm

A wxPanel is good if you want to put controls on it. wxGLCanvas is a window where you are going to draw with OpenGL, nothing to do with controls (buttons, textcontrols, etc).

If you use a wxWindow (wxPanel, wxGLCanvas, or a control) as the only child in a wxFrame, then it will be resized automatically to fill the whole client box (the part of the wxFrame without title, status bar, tool bar). Notice that in your case the wxPanel will be sized, but not the wxGLCanvas because the canvas has not a wxFrame as parent.

If you want to put several windows in the client part, then you need to use sizers (see http://docs.wxwidgets.org/trunk/overview_sizer.html).

By the way, setting a background color (via wxWindow::SetBackgroundColour) in a wxGLCanvas will do nothing because you surely send a glClear() command in your paint-event handler.

See the provided OpenGL samples in yourwxdir/samples/opengl. The pyramid sample shows how to use modern OpenGL (ver > 3.1); the others use old fixed-pipeline, no shaders, OpenGL.

periscopewxyun
In need of some credit
In need of some credit
Posts: 5
Joined: Sat Dec 16, 2017 6:59 am

Re: wxGLCanvas problem

Post by periscopewxyun » Thu Feb 08, 2018 8:44 pm

Thank you Manolo,

I will look into it.

Periscopewxyun

Post Reply