From WxWiki
Jump to navigation Jump to search

I removed the wxGLCanvas sample provided because it seemed incorrect to me. GL Canvases must create DCs AFAIK, also the author was editing headers instead of passing flags to configure. also it didn't use sizers and didn't run on mac. Hopefully the one i put instead is better, feel free to enhance it.

  • There had been some discussion of this page (and the sample in question) on IRC just a couple days ago before your edits. The old sample encouraged some bad design with GL operations being handled inside wxApp::OnInit(), which is just a bad idea in general. You're sample could be better shown with paint events handled inside a (derived) panel inside the frame, but at least it shows proper use of OnInit(). --Tierra 09:09, 6 July 2007 (PDT)
  • I used wxGLCanvas extensively in a project and learned a lot about it. I realised the sample I had posted encouraged some very bad practices like using wxPaintDC outside paint events. I fixed it.

Constructor version?

In the wxGLCanvas entry in the online manual here:


it says "For the newer (wx 2.7.x+) method, create a wxGLCanvas window using the constructor that does not create an implicit rendering context"

which is this one:

void wxGLCanvas(wxWindow* parent, wxWindowID id = wxID_ANY, int* attribList = 0, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style=0, const wxString& name="GLCanvas", const wxPalette& palette = wxNullPalette)

As far as I can see none of the examples given on this page do this. Am I missing something?

--Nortino 12:55, 6 November 2008 (UTC)

The sample is not working for me (Opensuse 11.1, wxGTK 2.8, using the wx-config flags) first in compilation the following error is thrown: /usr/include/wx-2.8/wx/app.h: In constructor ‘wxGLCanvasSubClass::wxGLCanvasSubClass(wxFrame*)’: /usr/include/wx-2.8/wx/app.h:293: error: object missing in reference to ‘wxAppConsole::argv’ which refers to this line:

   char* argv[1] = { wxString(wxApp::argv[0]).char_str() };

so replacing that with

   char* argv[1] = {"test"};

which shouldn't affect the program (I'm not passing in glut-specific args) It compiles fine, but when I run it, the window is blank. In a debugger, it appears the Paintit method is not being called. Anybody know what's going on?

--scriptjunkie 30 March 2009

I've tried correcting the argv initialisation. See the new initialisation code and tell me whether it works.

--net147 31 March 2009

Works great! Thanks.

--scriptjunkie 3 April 2009

I need to find a way for users to select stuff in the GL canvas. Does anyone know how I can go about this?


--m0rf 2 Sept 2009

Added code to an example

I added the followinf code to an example, to prevent the application from flashing in Windows when resizing the window:

// To avoid flashing on MSW

It works in Windows, and I hope it doesn't cause any problem in Linux or on Mac, although I haven't tested the code on those systems. --Kri 13:56, 27 February 2011 (MST)


My theory is that when resized using Refresh, the graphics card shows whatever happened to be in the vram at that spot without updating the size. This also occurs in plain normal OpenGL.