frame->m_canvas = new TestGLCanvas(frame, -1, wxPoint(0, 0), wxSize(200, 200));
-// InitGL();
-
// Show the frame
frame->Show(TRUE);
return TRUE;
}
-void MyApp::InitGL(void)
-{
- /* set viewing projection */
- glMatrixMode(GL_PROJECTION);
- glFrustum(-0.5F, 0.5F, -0.5F, 0.5F, 1.0F, 3.0F);
-
- /* position viewer */
- glMatrixMode(GL_MODELVIEW);
- glTranslatef(0.0F, 0.0F, -2.0F);
-
- /* position object */
- glRotatef(30.0F, 1.0F, 0.0F, 0.0F);
- glRotatef(30.0F, 0.0F, 1.0F, 0.0F);
-
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
-}
-
IMPLEMENT_APP(MyApp)
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
const wxPoint& pos, const wxSize& size, long style, const wxString& name):
wxGLCanvas(parent, id, pos, size, style, name)
{
+ m_init = FALSE;
}
TestGLCanvas::~TestGLCanvas(void)
// OnPaint handlers must always create a wxPaintDC.
wxPaintDC dc(this);
- if ( !GetContext() )
- return;
+ if (!GetContext()) return;
SetCurrent();
+ /* init OpenGL once, but after SetCurrent */
+ if (!m_init)
+ {
+ InitGL();
+ m_init = TRUE;
+ }
+
/* clear color and depth buffers */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Do nothing, to avoid flashing.
}
+void TestGLCanvas::InitGL(void)
+{
+ /* set viewing projection */
+ glMatrixMode(GL_PROJECTION);
+ glFrustum(-0.5F, 0.5F, -0.5F, 0.5F, 1.0F, 3.0F);
+
+ /* position viewer */
+ glMatrixMode(GL_MODELVIEW);
+ glTranslatef(0.0F, 0.0F, -2.0F);
+
+ /* position object */
+ glRotatef(30.0F, 1.0F, 0.0F, 0.0F);
+ glRotatef(30.0F, 0.0F, 1.0F, 0.0F);
+
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_LIGHTING);
+ glEnable(GL_LIGHT0);
+}
+