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
wxGLCanvas problem
-
- In need of some credit
- Posts: 5
- Joined: Sat Dec 16, 2017 6:59 am
Re: wxGLCanvas problem
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.
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.
-
- In need of some credit
- Posts: 5
- Joined: Sat Dec 16, 2017 6:59 am
Re: wxGLCanvas problem
Thank you Manolo,
I will look into it.
Periscopewxyun
I will look into it.
Periscopewxyun