From 5cf036d017b19e9447e52e271c4afac2109ffcd3 Mon Sep 17 00:00:00 2001 From: Dimitri Schoolwerth Date: Sat, 15 Nov 2003 04:21:10 +0000 Subject: [PATCH] Fixed Open Watcom compilation of OpenGL samples; Code cleanup. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24560 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/opengl/cube/cube.cpp | 347 ++++++++++++----------- samples/opengl/cube/cube.h | 107 +++---- samples/opengl/isosurf/isosurf.cpp | 438 ++++++++++++++++------------- samples/opengl/isosurf/isosurf.h | 52 ++-- samples/opengl/penguin/lw.cpp | 14 +- samples/opengl/penguin/penguin.cpp | 151 +++++----- samples/opengl/penguin/penguin.h | 40 +-- 7 files changed, 616 insertions(+), 533 deletions(-) diff --git a/samples/opengl/cube/cube.cpp b/samples/opengl/cube/cube.cpp index 5dc5faffc7..41ef971a99 100644 --- a/samples/opengl/cube/cube.cpp +++ b/samples/opengl/cube/cube.cpp @@ -25,8 +25,6 @@ #include "wx/wx.h" #endif -#include "wx/log.h" - #include "cube.h" #ifndef __WXMSW__ // for wxStopWatch, see remark below @@ -51,32 +49,37 @@ class ScanCodeCtrl : public wxTextCtrl { public: - ScanCodeCtrl( wxWindow* parent, wxWindowID id, int code, - const wxPoint& pos, const wxSize& size ); - void OnChar( wxKeyEvent& event ) { } /* do nothing */ - void OnKeyDown(wxKeyEvent& event); + ScanCodeCtrl( wxWindow* parent, wxWindowID id, int code, + const wxPoint& pos, const wxSize& size ); + + void OnChar( wxKeyEvent& WXUNUSED(event) ) + { + // Do nothing + } + + void OnKeyDown(wxKeyEvent& event); + private: -// any class wishing to process wxWindows events must use this macro - DECLARE_EVENT_TABLE() + + // Any class wishing to process wxWindows events must use this macro + DECLARE_EVENT_TABLE() }; + BEGIN_EVENT_TABLE( ScanCodeCtrl, wxTextCtrl ) - EVT_CHAR( ScanCodeCtrl::OnChar ) - EVT_KEY_DOWN( ScanCodeCtrl::OnKeyDown ) + EVT_CHAR( ScanCodeCtrl::OnChar ) + EVT_KEY_DOWN( ScanCodeCtrl::OnKeyDown ) END_EVENT_TABLE() ScanCodeCtrl::ScanCodeCtrl( wxWindow* parent, wxWindowID id, int code, - const wxPoint& pos, const wxSize& size ) - : wxTextCtrl( parent, id, wxEmptyString, pos, size ) -{ wxString buf; - buf.Printf( _T("0x%04x"), code ); - SetValue( buf ); + const wxPoint& pos, const wxSize& size ) + : wxTextCtrl( parent, id, wxEmptyString, pos, size ) +{ + SetValue( wxString::Format(wxT("0x%04x"), code) ); } void ScanCodeCtrl::OnKeyDown( wxKeyEvent& event ) { - wxString buf; - buf.Printf( _T("0x%04x"), event.GetKeyCode() ); - SetValue( buf ); + SetValue( wxString::Format(wxT("0x%04x"), event.GetKeyCode()) ); } /*------------------------------------------------------------------ @@ -86,39 +89,41 @@ void ScanCodeCtrl::OnKeyDown( wxKeyEvent& event ) class ScanCodeDialog : public wxDialog { public: - ScanCodeDialog( wxWindow* parent, wxWindowID id, const int code, - const wxString &descr, const wxString& title ); - int GetValue(); + ScanCodeDialog( wxWindow* parent, wxWindowID id, const int code, + const wxString &descr, const wxString& title ); + int GetValue(); + private: - ScanCodeCtrl *m_ScanCode; - wxTextCtrl *m_Description; + + ScanCodeCtrl *m_ScanCode; + wxTextCtrl *m_Description; }; ScanCodeDialog::ScanCodeDialog( wxWindow* parent, wxWindowID id, - const int code, const wxString &descr, const wxString& title ) - : wxDialog( parent, id, title, wxPoint(-1, -1), wxSize(96*2,76*2) ) + const int code, const wxString &descr, const wxString& title ) + : wxDialog( parent, id, title, wxDefaultPosition, wxSize(96*2,76*2) ) { - new wxStaticText( this, -1, _T("Scancode"), wxPoint(4*2,3*2), - wxSize(31*2,12*2) ); - m_ScanCode = new ScanCodeCtrl( this, -1, code, wxPoint(37*2,6*2), - wxSize(53*2,14*2) ); - - new wxStaticText( this, -1, _T("Description"), wxPoint(4*2,24*2), - wxSize(32*2,12*2) ); - m_Description = new wxTextCtrl( this, -1, descr, wxPoint(37*2,27*2), - wxSize(53*2,14*2) ); - - new wxButton( this, wxID_OK, _T("Ok"), wxPoint(20*2,50*2), wxSize(20*2,13*2) ); - new wxButton( this, wxID_CANCEL, _T("Cancel"), wxPoint(44*2,50*2), - wxSize(25*2,13*2) ); + new wxStaticText( this, wxID_ANY, _T("Scancode"), wxPoint(4*2,3*2), + wxSize(31*2,12*2) ); + m_ScanCode = new ScanCodeCtrl( this, wxID_ANY, code, wxPoint(37*2,6*2), + wxSize(53*2,14*2) ); + + new wxStaticText( this, wxID_ANY, _T("Description"), wxPoint(4*2,24*2), + wxSize(32*2,12*2) ); + m_Description = new wxTextCtrl( this, wxID_ANY, descr, wxPoint(37*2,27*2), + wxSize(53*2,14*2) ); + + new wxButton( this, wxID_OK, _T("Ok"), wxPoint(20*2,50*2), wxSize(20*2,13*2) ); + new wxButton( this, wxID_CANCEL, _T("Cancel"), wxPoint(44*2,50*2), + wxSize(25*2,13*2) ); } int ScanCodeDialog::GetValue() { - int code; - wxString buf = m_ScanCode->GetValue(); - wxSscanf( buf.c_str(), _T("%i"), &code ); - return( code ); + int code; + wxString buf = m_ScanCode->GetValue(); + wxSscanf( buf.c_str(), _T("%i"), &code ); + return code; } /*---------------------------------------------------------------------- @@ -160,12 +165,12 @@ unsigned long wxStopWatch( unsigned long *sec_base ) #if wxUSE_GLCANVAS BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas) - EVT_SIZE(TestGLCanvas::OnSize) - EVT_PAINT(TestGLCanvas::OnPaint) - EVT_ERASE_BACKGROUND(TestGLCanvas::OnEraseBackground) - EVT_KEY_DOWN( TestGLCanvas::OnKeyDown ) - EVT_KEY_UP( TestGLCanvas::OnKeyUp ) - EVT_ENTER_WINDOW( TestGLCanvas::OnEnterWindow ) + EVT_SIZE(TestGLCanvas::OnSize) + EVT_PAINT(TestGLCanvas::OnPaint) + EVT_ERASE_BACKGROUND(TestGLCanvas::OnEraseBackground) + EVT_KEY_DOWN( TestGLCanvas::OnKeyDown ) + EVT_KEY_UP( TestGLCanvas::OnKeyUp ) + EVT_ENTER_WINDOW( TestGLCanvas::OnEnterWindow ) END_EVENT_TABLE() unsigned long TestGLCanvas::m_secbase = 0; @@ -174,10 +179,10 @@ unsigned long TestGLCanvas::m_xsynct; unsigned long TestGLCanvas::m_gsynct; TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id, - const wxPoint& pos, const wxSize& size, long style, const wxString& name): - wxGLCanvas(parent, (wxGLCanvas*) NULL, id, pos, size, style, name ) + const wxPoint& pos, const wxSize& size, long style, const wxString& name) + : wxGLCanvas(parent, (wxGLCanvas*) NULL, id, pos, size, style, name ) { - m_init = FALSE; + m_init = false; m_gllist = 0; m_rleft = WXK_LEFT; m_rright = WXK_RIGHT; @@ -185,11 +190,11 @@ TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id, TestGLCanvas::TestGLCanvas(wxWindow *parent, const TestGLCanvas &other, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, - const wxString& name ) : - wxGLCanvas(parent, other.GetContext(), id, pos, size, style, name ) + const wxString& name ) + : wxGLCanvas(parent, other.GetContext(), id, pos, size, style, name) { - m_init = FALSE; - m_gllist = other.m_gllist; /* share display list */ + m_init = false; + m_gllist = other.m_gllist; // share display list m_rleft = WXK_LEFT; m_rright = WXK_RIGHT; } @@ -207,59 +212,61 @@ void TestGLCanvas::Render() #endif SetCurrent(); - /* init OpenGL once, but after SetCurrent */ + // Init OpenGL once, but after SetCurrent if (!m_init) { InitGL(); - m_init = TRUE; + m_init = true; } glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glFrustum(-0.5F, 0.5F, -0.5F, 0.5F, 1.0F, 3.0F); + glFrustum(-0.5f, 0.5f, -0.5f, 0.5f, 1.0f, 3.0f); glMatrixMode(GL_MODELVIEW); /* clear color and depth buffers */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - if( m_gllist == 0 ) - { - m_gllist = glGenLists( 1 ); - glNewList( m_gllist, GL_COMPILE_AND_EXECUTE ); - /* draw six faces of a cube */ - glBegin(GL_QUADS); - glNormal3f( 0.0F, 0.0F, 1.0F); - glVertex3f( 0.5F, 0.5F, 0.5F); glVertex3f(-0.5F, 0.5F, 0.5F); - glVertex3f(-0.5F,-0.5F, 0.5F); glVertex3f( 0.5F,-0.5F, 0.5F); - - glNormal3f( 0.0F, 0.0F,-1.0F); - glVertex3f(-0.5F,-0.5F,-0.5F); glVertex3f(-0.5F, 0.5F,-0.5F); - glVertex3f( 0.5F, 0.5F,-0.5F); glVertex3f( 0.5F,-0.5F,-0.5F); - - glNormal3f( 0.0F, 1.0F, 0.0F); - glVertex3f( 0.5F, 0.5F, 0.5F); glVertex3f( 0.5F, 0.5F,-0.5F); - glVertex3f(-0.5F, 0.5F,-0.5F); glVertex3f(-0.5F, 0.5F, 0.5F); - - glNormal3f( 0.0F,-1.0F, 0.0F); - glVertex3f(-0.5F,-0.5F,-0.5F); glVertex3f( 0.5F,-0.5F,-0.5F); - glVertex3f( 0.5F,-0.5F, 0.5F); glVertex3f(-0.5F,-0.5F, 0.5F); - - glNormal3f( 1.0F, 0.0F, 0.0F); - glVertex3f( 0.5F, 0.5F, 0.5F); glVertex3f( 0.5F,-0.5F, 0.5F); - glVertex3f( 0.5F,-0.5F,-0.5F); glVertex3f( 0.5F, 0.5F,-0.5F); - - glNormal3f(-1.0F, 0.0F, 0.0F); - glVertex3f(-0.5F,-0.5F,-0.5F); glVertex3f(-0.5F,-0.5F, 0.5F); - glVertex3f(-0.5F, 0.5F, 0.5F); glVertex3f(-0.5F, 0.5F,-0.5F); - glEnd(); - - glEndList(); - } - else - glCallList( m_gllist ); + if( m_gllist == 0 ) + { + m_gllist = glGenLists( 1 ); + glNewList( m_gllist, GL_COMPILE_AND_EXECUTE ); + /* draw six faces of a cube */ + glBegin(GL_QUADS); + glNormal3f( 0.0f, 0.0f, 1.0f); + glVertex3f( 0.5f, 0.5f, 0.5f); glVertex3f(-0.5f, 0.5f, 0.5f); + glVertex3f(-0.5f,-0.5f, 0.5f); glVertex3f( 0.5f,-0.5f, 0.5f); + + glNormal3f( 0.0f, 0.0f,-1.0f); + glVertex3f(-0.5f,-0.5f,-0.5f); glVertex3f(-0.5f, 0.5f,-0.5f); + glVertex3f( 0.5f, 0.5f,-0.5f); glVertex3f( 0.5f,-0.5f,-0.5f); + + glNormal3f( 0.0f, 1.0f, 0.0f); + glVertex3f( 0.5f, 0.5f, 0.5f); glVertex3f( 0.5f, 0.5f,-0.5f); + glVertex3f(-0.5f, 0.5f,-0.5f); glVertex3f(-0.5f, 0.5f, 0.5f); + + glNormal3f( 0.0f,-1.0f, 0.0f); + glVertex3f(-0.5f,-0.5f,-0.5f); glVertex3f( 0.5f,-0.5f,-0.5f); + glVertex3f( 0.5f,-0.5f, 0.5f); glVertex3f(-0.5f,-0.5f, 0.5f); + + glNormal3f( 1.0f, 0.0f, 0.0f); + glVertex3f( 0.5f, 0.5f, 0.5f); glVertex3f( 0.5f,-0.5f, 0.5f); + glVertex3f( 0.5f,-0.5f,-0.5f); glVertex3f( 0.5f, 0.5f,-0.5f); + + glNormal3f(-1.0f, 0.0f, 0.0f); + glVertex3f(-0.5f,-0.5f,-0.5f); glVertex3f(-0.5f,-0.5f, 0.5f); + glVertex3f(-0.5f, 0.5f, 0.5f); glVertex3f(-0.5f, 0.5f,-0.5f); + glEnd(); + + glEndList(); + } + else + { + glCallList(m_gllist); + } - glFlush(); - SwapBuffers(); + glFlush(); + SwapBuffers(); } void TestGLCanvas::OnEnterWindow( wxMouseEvent& WXUNUSED(event) ) @@ -300,15 +307,15 @@ void TestGLCanvas::InitGL() /* set viewing projection */ glMatrixMode(GL_PROJECTION); - glFrustum(-0.5F, 0.5F, -0.5F, 0.5F, 1.0F, 3.0F); + 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); + 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); + 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); @@ -409,8 +416,8 @@ void TestGLCanvas::Rotate( GLfloat deg ) SetCurrent(); glMatrixMode(GL_MODELVIEW); - glRotatef((GLfloat)deg, 0.0F, 0.0F, 1.0F); - Refresh(FALSE); + glRotatef((GLfloat)deg, 0.0f, 0.0f, 1.0f); + Refresh(false); } @@ -428,71 +435,95 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) END_EVENT_TABLE() // My frame constructor -MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, - const wxSize& size, long style) - : wxFrame(frame, -1, title, pos, size, style) +MyFrame::MyFrame(wxWindow *parent, const wxString& title, const wxPoint& pos, + const wxSize& size, long style) + : wxFrame(parent, wxID_ANY, title, pos, size, style) { m_canvas = NULL; } // Intercept menu commands -void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event)) +void MyFrame::OnExit( wxCommandEvent& WXUNUSED(event) ) { - Destroy(); + // true is to force the frame to close + Close(true); } -void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event)) +/*static*/ MyFrame *MyFrame::Create(MyFrame *parentFrame, bool isCloneWindow) { - MyFrame *frame = new MyFrame(NULL, _T("Cube OpenGL Demo Clone"), - wxPoint(50, 50), wxSize(400, 300)); - // Give it an icon + wxString str = wxT("wxWindows OpenGL Cube Sample"); + if (isCloneWindow) str += wxT(" - Clone"); + + MyFrame *frame = new MyFrame(NULL, str, wxDefaultPosition, + wxSize(400, 300)); + + // Give it an icon #ifdef __WXMSW__ - frame->SetIcon(wxIcon(_T("mondrian"))); + frame->SetIcon(wxIcon(_T("mondrian"))); #endif - // Make a menubar - wxMenu *winMenu = new wxMenu; + // Make a menubar + wxMenu *winMenu = new wxMenu; - winMenu->Append(wxID_EXIT, _T("&Close")); - winMenu->Append(ID_NEW_WINDOW, _T("&New") ); - wxMenuBar *menuBar = new wxMenuBar; - menuBar->Append(winMenu, _T("&Window")); + winMenu->Append(wxID_EXIT, _T("&Close")); + winMenu->Append(ID_NEW_WINDOW, _T("&New") ); + wxMenuBar *menuBar = new wxMenuBar; + menuBar->Append(winMenu, _T("&Window")); - winMenu = new wxMenu; - winMenu->Append(ID_DEF_ROTATE_LEFT_KEY, _T("Rotate &left")); - winMenu->Append(ID_DEF_ROTATE_RIGHT_KEY, _T("Rotate &right")); - menuBar->Append(winMenu, _T("&Key")); + winMenu = new wxMenu; + winMenu->Append(ID_DEF_ROTATE_LEFT_KEY, _T("Rotate &left")); + winMenu->Append(ID_DEF_ROTATE_RIGHT_KEY, _T("Rotate &right")); + menuBar->Append(winMenu, _T("&Key")); - frame->SetMenuBar(menuBar); + frame->SetMenuBar(menuBar); #if wxUSE_GLCANVAS - frame->m_canvas = new TestGLCanvas( frame, *m_canvas, -1, - wxDefaultPosition, wxDefaultSize ); + if (parentFrame) + { + frame->m_canvas = new TestGLCanvas( frame, parentFrame->m_canvas, + wxID_ANY, wxDefaultPosition, wxDefaultSize ); + } + else + { + frame->m_canvas = new TestGLCanvas(frame, wxID_ANY, + wxDefaultPosition, wxDefaultSize); + } #endif - // Show the frame - frame->Show(TRUE); + // Show the frame + frame->Show(true); + + return frame; } -void MyFrame::OnDefRotateLeftKey(wxCommandEvent& WXUNUSED(event)) +void MyFrame::OnNewWindow( wxCommandEvent& WXUNUSED(event) ) +{ + (void) Create(this, true); +} + +void MyFrame::OnDefRotateLeftKey( wxCommandEvent& WXUNUSED(event) ) { #if wxUSE_GLCANVAS - ScanCodeDialog dial( this, -1, m_canvas->m_rleft, - wxString(_T("Left")), _T("Define key") ); - int result = dial.ShowModal(); - if( result == wxID_OK ) - m_canvas->m_rleft = dial.GetValue(); + ScanCodeDialog dial( this, wxID_ANY, m_canvas->m_rleft, + wxString(_T("Left")), _T("Define key") ); + + int result = dial.ShowModal(); + + if( result == wxID_OK ) + m_canvas->m_rleft = dial.GetValue(); #endif } -void MyFrame::OnDefRotateRightKey(wxCommandEvent& WXUNUSED(event)) +void MyFrame::OnDefRotateRightKey( wxCommandEvent& WXUNUSED(event) ) { #if wxUSE_GLCANVAS - ScanCodeDialog dial( this, -1, m_canvas->m_rright, - wxString(_T("Right")), _T("Define key") ); - int result = dial.ShowModal(); - if( result == wxID_OK ) - m_canvas->m_rright = dial.GetValue(); + ScanCodeDialog dial( this, wxID_ANY, m_canvas->m_rright, + wxString(_T("Right")), _T("Define key") ); + + int result = dial.ShowModal(); + + if( result == wxID_OK ) + m_canvas->m_rright = dial.GetValue(); #endif } @@ -502,47 +533,25 @@ void MyFrame::OnDefRotateRightKey(wxCommandEvent& WXUNUSED(event)) IMPLEMENT_APP(MyApp) -bool MyApp::OnInit(void) +bool MyApp::OnInit() { - wxLog::SetTraceMask(wxTraceMessages); - - // Create the main frame window - MyFrame *frame = new MyFrame(NULL, _T("Cube OpenGL Demo"), wxPoint(50, 50), - wxSize(400, 300)); - // Give it an icon -#ifdef wx_msw - frame->SetIcon(wxIcon("mondrian")); +#if wxUSE_LOG + wxLog::SetTraceMask(wxTraceMessages); #endif - // Make a menubar - wxMenu *winMenu = new wxMenu; - - winMenu->Append(wxID_EXIT, _T("&Close")); - winMenu->Append(ID_NEW_WINDOW, _T("&New") ); - wxMenuBar *menuBar = new wxMenuBar; - menuBar->Append(winMenu, _T("&Window")); - - winMenu = new wxMenu; - winMenu->Append(ID_DEF_ROTATE_LEFT_KEY, _T("Rotate &left")); - winMenu->Append(ID_DEF_ROTATE_RIGHT_KEY, _T("Rotate &right")); - menuBar->Append(winMenu, _T("&Key")); - - frame->SetMenuBar(menuBar); + // Create the main frame window + (void) MyFrame::Create(NULL); #if wxUSE_GLCANVAS - frame->m_canvas = new TestGLCanvas(frame, -1, wxDefaultPosition, wxDefaultSize); - - // Show the frame - frame->Show(TRUE); - - return TRUE; + return true; #else - wxMessageBox( _T("This sample has to be compiled with wxUSE_GLCANVAS"), _T("Building error"), wxOK); + wxMessageBox( _T("This sample has to be compiled with wxUSE_GLCANVAS"), + _T("Building error"), wxOK); - return FALSE; + return false; #endif diff --git a/samples/opengl/cube/cube.h b/samples/opengl/cube/cube.h index f7d4de6fbd..077d4f16d9 100644 --- a/samples/opengl/cube/cube.h +++ b/samples/opengl/cube/cube.h @@ -18,80 +18,87 @@ class MyApp: public wxApp { public: - bool OnInit(void); + bool OnInit(); }; // Define a new frame type class TestGLCanvas; + class MyFrame: public wxFrame { public: - MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, - const wxSize& size, long style = wxDEFAULT_FRAME_STYLE); + static MyFrame *Create(MyFrame *parentFrame, bool isCloneWindow = false); void OnExit(wxCommandEvent& event); void OnNewWindow(wxCommandEvent& event); void OnDefRotateLeftKey(wxCommandEvent& event); void OnDefRotateRightKey(wxCommandEvent& event); - -public: - TestGLCanvas* m_canvas; -DECLARE_EVENT_TABLE() +private: + + MyFrame(wxWindow *parent, const wxString& title, const wxPoint& pos, + const wxSize& size, long style = wxDEFAULT_FRAME_STYLE); + + + TestGLCanvas *m_canvas; + + DECLARE_EVENT_TABLE() }; #if wxUSE_GLCANVAS class TestGLCanvas: public wxGLCanvas { - friend class MyFrame; + friend class MyFrame; public: - TestGLCanvas(wxWindow *parent, const wxWindowID id = -1, - const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = 0, const wxString& name = _T("TestGLCanvas")); - TestGLCanvas(wxWindow *parent, const TestGLCanvas &other, - const wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = 0, - const wxString& name = _T("TestGLCanvas") ); - - ~TestGLCanvas(void); - - void OnPaint(wxPaintEvent& event); - void OnSize(wxSizeEvent& event); - void OnEraseBackground(wxEraseEvent& event); - void OnKeyDown(wxKeyEvent& event); - void OnKeyUp(wxKeyEvent& event); - void OnEnterWindow( wxMouseEvent& event ); - - void Render( void ); - void InitGL(void); - void Rotate( GLfloat deg ); - static GLfloat CalcRotateSpeed( unsigned long acceltime ); - static GLfloat CalcRotateAngle( unsigned long lasttime, - unsigned long acceltime ); - void Action( long code, unsigned long lasttime, - unsigned long acceltime ); - + TestGLCanvas( wxWindow *parent, wxWindowID id = wxID_ANY, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, const wxString& name = _T("TestGLCanvas") ); + + TestGLCanvas( wxWindow *parent, const TestGLCanvas &other, + wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, long style = 0, + const wxString& name = _T("TestGLCanvas") ); + + ~TestGLCanvas(); + + void OnPaint(wxPaintEvent& event); + void OnSize(wxSizeEvent& event); + void OnEraseBackground(wxEraseEvent& event); + void OnKeyDown(wxKeyEvent& event); + void OnKeyUp(wxKeyEvent& event); + void OnEnterWindow(wxMouseEvent& event); + + void Render(); + void InitGL(); + void Rotate(GLfloat deg); + static GLfloat CalcRotateSpeed(unsigned long acceltime); + static GLfloat CalcRotateAngle( unsigned long lasttime, + unsigned long acceltime ); + void Action( long code, unsigned long lasttime, + unsigned long acceltime ); + private: - bool m_init; - GLuint m_gllist; - long m_rleft; - long m_rright; - - static unsigned long m_secbase; - static int m_TimeInitialized; - static unsigned long m_xsynct; - static unsigned long m_gsynct; - - long m_Key; - unsigned long m_StartTime; - unsigned long m_LastTime; - unsigned long m_LastRedraw; + bool m_init; + GLuint m_gllist; + long m_rleft; + long m_rright; + + static unsigned long m_secbase; + static int m_TimeInitialized; + static unsigned long m_xsynct; + static unsigned long m_gsynct; + + long m_Key; + unsigned long m_StartTime; + unsigned long m_LastTime; + unsigned long m_LastRedraw; DECLARE_EVENT_TABLE() }; -#endif +#endif // #if wxUSE_GLCANVAS -#endif +#endif // #ifndef _WX_CUBE_H_ diff --git a/samples/opengl/isosurf/isosurf.cpp b/samples/opengl/isosurf/isosurf.cpp index db1f68034a..3eda7123bb 100644 --- a/samples/opengl/isosurf/isosurf.cpp +++ b/samples/opengl/isosurf/isosurf.cpp @@ -29,16 +29,16 @@ #include "wx/glcanvas.h" #ifdef __WXMAC__ -# ifdef __DARWIN__ -# include -# include -# else -# include -# include -# endif +# ifdef __DARWIN__ +# include +# include +# else +# include +# include +# endif #else -# include -# include +# include +# include #endif // disabled because this has apparently changed in OpenGL 1.2, so doesn't link @@ -72,60 +72,63 @@ static GLfloat xrot; static GLfloat yrot; -static void read_surface( wxChar *filename ) +static void read_surface( const wxChar *filename ) { - FILE *f; - - f = wxFopen(filename,_T("r")); - if (!f) { - wxString msg(_T("Couldn't read ")); - msg += filename; - wxMessageBox(msg); - return; - } - - numverts = 0; - while (!feof(f) && numvertsSetIcon(wxIcon(_T("mondrian"))); + // Give it an icon + frame->SetIcon(wxIcon(_T("mondrian"))); - // Make a menubar - wxMenu *fileMenu = new wxMenu; + // Make a menubar + wxMenu *fileMenu = new wxMenu; - fileMenu->Append(wxID_EXIT, _T("E&xit")); - wxMenuBar *menuBar = new wxMenuBar; - menuBar->Append(fileMenu, _T("&File")); - frame->SetMenuBar(menuBar); + fileMenu->Append(wxID_EXIT, _T("E&xit")); + wxMenuBar *menuBar = new wxMenuBar; + menuBar->Append(fileMenu, _T("&File")); + frame->SetMenuBar(menuBar); // Make a TestGLCanvas // JACS #ifdef __WXMSW__ - int *gl_attrib = NULL; + int *gl_attrib = NULL; #else - int gl_attrib[20] = { WX_GL_RGBA, WX_GL_MIN_RED, 1, WX_GL_MIN_GREEN, 1, - WX_GL_MIN_BLUE, 1, WX_GL_DEPTH_SIZE, 1, - WX_GL_DOUBLEBUFFER, + int gl_attrib[20] = { WX_GL_RGBA, WX_GL_MIN_RED, 1, WX_GL_MIN_GREEN, 1, + WX_GL_MIN_BLUE, 1, WX_GL_DEPTH_SIZE, 1, + WX_GL_DOUBLEBUFFER, # ifdef __WXMAC__ - GL_NONE }; + GL_NONE }; # else - None }; + None }; # endif #endif - if(!doubleBuffer) - { - printf("don't have double buffer, disabling\n"); + if(!doubleBuffer) + { + printf("don't have double buffer, disabling\n"); #ifdef __WXGTK__ - gl_attrib[9] = None; + gl_attrib[9] = None; #endif - doubleBuffer = GL_FALSE; - } - + doubleBuffer = GL_FALSE; + } + #if wxUSE_GLCANVAS - frame->m_canvas = new TestGLCanvas(frame, -1, wxDefaultPosition, wxDefaultSize, - 0, _T("TestGLCanvas"), gl_attrib ); + frame->m_canvas = new TestGLCanvas(frame, wxID_ANY, wxDefaultPosition, + wxDefaultSize, 0, _T("TestGLCanvas"), gl_attrib ); // Show the frame - frame->Show(TRUE); + frame->Show(true); - frame->m_canvas->SetCurrent(); - read_surface( _T("isosurf.dat") ); + frame->m_canvas->SetCurrent(); + read_surface( _T("isosurf.dat") ); - Init(); + Init(); - return TRUE; + return true; #else - wxMessageBox( _T("This sample has to be compiled with wxUSE_GLCANVAS"), _T("Building error"), wxOK); + wxMessageBox( _T("This sample has to be compiled with wxUSE_GLCANVAS"), _T("Building error"), wxOK); - return FALSE; + return false; #endif } @@ -306,18 +317,29 @@ END_EVENT_TABLE() // My frame constructor MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, - const wxSize& size, long style): - wxFrame(frame, -1, title, pos, size, style) + const wxSize& size, long style) + : wxFrame(frame, wxID_ANY, title, pos, size, style) { #if wxUSE_GLCANVAS m_canvas = NULL; #endif } +MyFrame::~MyFrame() +{ +#if wxUSE_GLCANVAS + if (m_canvas) + { + delete m_canvas; m_canvas = NULL; + } +#endif +} + // Intercept menu commands -void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event)) +void MyFrame::OnExit( wxCommandEvent& WXUNUSED(event) ) { - Destroy(); + // true is to force the frame to close + Close(true); } /* @@ -335,21 +357,23 @@ BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas) END_EVENT_TABLE() TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id, - const wxPoint& pos, const wxSize& size, long style, const wxString& name, int* gl_attrib): - wxGLCanvas(parent, id, pos, size, style, name, gl_attrib) + const wxPoint& pos, const wxSize& size, long style, + const wxString& name, int* gl_attrib) + : wxGLCanvas(parent, id, pos, size, style, name, gl_attrib) { - parent->Show(TRUE); - SetCurrent(); - - /* Make sure server supports the vertex array extension */ - char* extensions = (char *) glGetString( GL_EXTENSIONS ); - if (!extensions || !strstr( extensions, "GL_EXT_vertex_array" )) { - use_vertex_arrays = GL_FALSE; - } + parent->Show(true); + SetCurrent(); + + /* Make sure server supports the vertex array extension */ + char* extensions = (char *) glGetString( GL_EXTENSIONS ); + if (!extensions || !strstr( extensions, "GL_EXT_vertex_array" )) + { + use_vertex_arrays = GL_FALSE; + } } -TestGLCanvas::~TestGLCanvas(void) +TestGLCanvas::~TestGLCanvas() { } @@ -373,7 +397,7 @@ void TestGLCanvas::OnSize(wxSizeEvent& event) { // this is also necessary to update the context on some platforms wxGLCanvas::OnSize(event); - + // set GL viewport (not called by wxGLCanvas::OnSize on all platforms...) int w, h; GetClientSize(&w, &h); @@ -388,45 +412,58 @@ void TestGLCanvas::OnSize(wxSizeEvent& event) void TestGLCanvas::OnChar(wxKeyEvent& event) { - switch(event.GetKeyCode()) { + switch( event.GetKeyCode() ) + { case WXK_ESCAPE: - exit(0); + wxTheApp->ExitMainLoop(); + return; + case WXK_LEFT: - yrot -= 15.0; - break; + yrot -= 15.0; + break; + case WXK_RIGHT: - yrot += 15.0; - break; + yrot += 15.0; + break; + case WXK_UP: - xrot += 15.0; - break; + xrot += 15.0; + break; + case WXK_DOWN: - xrot -= 15.0; - break; + xrot -= 15.0; + break; + case 's': case 'S': - smooth = !smooth; - if (smooth) { - glShadeModel(GL_SMOOTH); - } else { - glShadeModel(GL_FLAT); - } - break; + smooth = !smooth; + if (smooth) + { + glShadeModel(GL_SMOOTH); + } + else + { + glShadeModel(GL_FLAT); + } + break; + case 'l': case 'L': - lighting = !lighting; - if (lighting) { - glEnable(GL_LIGHTING); - } else { - glDisable(GL_LIGHTING); - } - break; - default: - { + lighting = !lighting; + if (lighting) + { + glEnable(GL_LIGHTING); + } + else + { + glDisable(GL_LIGHTING); + } + break; + + default: event.Skip(); - return; - } + return; } - Refresh(FALSE); + Refresh(false); } void TestGLCanvas::OnMouseEvent(wxMouseEvent& event) @@ -435,23 +472,30 @@ void TestGLCanvas::OnMouseEvent(wxMouseEvent& event) static float last_x, last_y; //printf("%f %f %d\n", event.GetX(), event.GetY(), (int)event.LeftIsDown()); - if(event.LeftIsDown()) { - if(!dragging) { - dragging = 1; - } else { - yrot += (event.GetX() - last_x)*1.0; - xrot += (event.GetY() - last_y)*1.0; - Refresh(FALSE); + if(event.LeftIsDown()) + { + if(!dragging) + { + dragging = 1; + } + else + { + yrot += (event.GetX() - last_x)*1.0; + xrot += (event.GetY() - last_y)*1.0; + Refresh(false); + } + last_x = event.GetX(); + last_y = event.GetY(); } - last_x = event.GetX(); - last_y = event.GetY(); - } else - dragging = 0; + else + dragging = 0; + } -void TestGLCanvas::OnEraseBackground(wxEraseEvent& WXUNUSED(event)) +void TestGLCanvas::OnEraseBackground( wxEraseEvent& WXUNUSED(event) ) { // Do nothing, to avoid flashing. } -#endif \ No newline at end of file +#endif // #if wxUSE_GLCANVAS + diff --git a/samples/opengl/isosurf/isosurf.h b/samples/opengl/isosurf/isosurf.h index a3dba1907a..66c81485f0 100644 --- a/samples/opengl/isosurf/isosurf.h +++ b/samples/opengl/isosurf/isosurf.h @@ -14,43 +14,53 @@ // Define a new application type class MyApp: public wxApp -{ public: - bool OnInit(void); +{ +public: + bool OnInit(); }; #if wxUSE_GLCANVAS + class TestGLCanvas: public wxGLCanvas { - public: - TestGLCanvas(wxWindow *parent, const wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = _T("TestGLCanvas"), - int* gl_attrib = NULL); - ~TestGLCanvas(void); - - void OnPaint(wxPaintEvent& event); - void OnSize(wxSizeEvent& event); - void OnEraseBackground(wxEraseEvent& event); - void OnChar(wxKeyEvent& event); - void OnMouseEvent(wxMouseEvent& event); +public: + TestGLCanvas(wxWindow *parent, wxWindowID id = wxID_ANY, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, long style = 0, + const wxString& name = _T("TestGLCanvas"), int *gl_attrib = NULL); -DECLARE_EVENT_TABLE() + ~TestGLCanvas(); + + void OnPaint(wxPaintEvent& event); + void OnSize(wxSizeEvent& event); + void OnEraseBackground(wxEraseEvent& event); + void OnChar(wxKeyEvent& event); + void OnMouseEvent(wxMouseEvent& event); + + DECLARE_EVENT_TABLE() }; -#endif + +#endif // #if wxUSE_GLCANVAS + class MyFrame: public wxFrame { public: - MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size, - long style = wxDEFAULT_FRAME_STYLE); + MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, + const wxSize& size, long style = wxDEFAULT_FRAME_STYLE); + + virtual ~MyFrame(); - void OnExit(wxCommandEvent& event); -public: #if wxUSE_GLCANVAS - TestGLCanvas* m_canvas; + TestGLCanvas *m_canvas; #endif +private : + + void OnExit(wxCommandEvent& event); + DECLARE_EVENT_TABLE() }; -#endif +#endif // #ifndef _WX_ISOSURF_H_ diff --git a/samples/opengl/penguin/lw.cpp b/samples/opengl/penguin/lw.cpp index baa729a2c8..5d548e556f 100644 --- a/samples/opengl/penguin/lw.cpp +++ b/samples/opengl/penguin/lw.cpp @@ -253,14 +253,9 @@ int lw_is_lwobject(const char *lw_file) lwObject *lw_object_read(const char *lw_file) { - FILE *f = NULL; - lwObject *lw_object = NULL; - - wxInt32 form_bytes = 0; - wxInt32 read_bytes = 0; /* open file */ - f = fopen(lw_file, "rb"); + FILE *f = fopen(lw_file, "rb"); if (f == NULL) { return NULL; } @@ -270,7 +265,10 @@ lwObject *lw_object_read(const char *lw_file) fclose(f); return NULL; } - form_bytes = read_long(f); + + wxInt32 read_bytes = 0; + + wxInt32 form_bytes = read_long(f); read_bytes += 4; if (read_long(f) != ID_LWOB) { @@ -279,7 +277,7 @@ lwObject *lw_object_read(const char *lw_file) } /* create new lwObject */ - lw_object = (lwObject*) calloc(sizeof(lwObject),1); + lwObject *lw_object = (lwObject*) calloc(sizeof(lwObject),1); /* read chunks */ while (read_bytes < form_bytes) { diff --git a/samples/opengl/penguin/penguin.cpp b/samples/opengl/penguin/penguin.cpp index b1e573bd9b..21e8b28c25 100644 --- a/samples/opengl/penguin/penguin.cpp +++ b/samples/opengl/penguin/penguin.cpp @@ -38,36 +38,39 @@ #define VIEW_ASPECT 1.3 -/* `Main program' equivalent, creating windows and returning main app frame */ +// `Main program' equivalent, creating windows and returning main app frame bool MyApp::OnInit() { - /* Create the main frame window */ - MyFrame *frame = new MyFrame(NULL, wxT("wxWindows OpenGL Demo"), wxPoint(50, 50), wxSize(400, 300)); + // Create the main frame window + MyFrame *frame = new MyFrame(NULL, wxT("wxWindows OpenGL Penguin Sample"), + wxDefaultPosition, wxDefaultSize); - /* Make a menubar */ - wxMenu *fileMenu = new wxMenu; + /* Make a menubar */ + wxMenu *fileMenu = new wxMenu; - fileMenu->Append(wxID_EXIT, wxT("E&xit")); - wxMenuBar *menuBar = new wxMenuBar; - menuBar->Append(fileMenu, wxT("&File")); - frame->SetMenuBar(menuBar); + fileMenu->Append(wxID_EXIT, wxT("E&xit")); + wxMenuBar *menuBar = new wxMenuBar; + menuBar->Append(fileMenu, wxT("&File")); + frame->SetMenuBar(menuBar); #if wxUSE_GLCANVAS - frame->SetCanvas( new TestGLCanvas(frame, -1, wxPoint(0, 0), wxSize(200, 200), wxSUNKEN_BORDER) ); + frame->SetCanvas( new TestGLCanvas(frame, wxID_ANY, wxDefaultPosition, + wxSize(200, 200), wxSUNKEN_BORDER) ); - /* Load file wiht mesh data */ - frame->GetCanvas()->LoadLWO( wxT("penguin.lwo") ); + /* Load file wiht mesh data */ + frame->GetCanvas()->LoadLWO( wxT("penguin.lwo") ); - /* Show the frame */ - frame->Show(TRUE); - - return TRUE; + /* Show the frame */ + frame->Show(true); + + return true; #else - wxMessageBox( _T("This sample has to be compiled with wxUSE_GLCANVAS"), _T("Building error"), wxOK); + wxMessageBox( _T("This sample has to be compiled with wxUSE_GLCANVAS"), + _T("Building error"), wxOK); - return FALSE; + return false; #endif } @@ -80,8 +83,8 @@ END_EVENT_TABLE() /* My frame constructor */ MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, - const wxSize& size, long style): - wxFrame(frame, -1, title, pos, size, style) + const wxSize& size, long style) + : wxFrame(frame, wxID_ANY, title, pos, size, style) { #if wxUSE_GLCANVAS m_canvas = NULL; @@ -89,9 +92,10 @@ MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, } /* Intercept menu commands */ -void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event)) +void MyFrame::OnExit( wxCommandEvent& WXUNUSED(event) ) { - Destroy(); + // true is to force the frame to close + Close(true); } #if wxUSE_GLCANVAS @@ -104,13 +108,13 @@ BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas) END_EVENT_TABLE() TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id, - const wxPoint& pos, const wxSize& size, long style, const wxString& name): - wxGLCanvas(parent, id, pos, size, style, name) + const wxPoint& pos, const wxSize& size, long style, const wxString& name) + : wxGLCanvas(parent, id, pos, size, style, name) { - block = FALSE; + block = false; } -TestGLCanvas::~TestGLCanvas(void) +TestGLCanvas::~TestGLCanvas() { /* destroy mesh */ lw_object_free(info.lwobject); @@ -126,38 +130,38 @@ void TestGLCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) ) #endif SetCurrent(); - - /* initialize OpenGL */ - if (info.do_init == TRUE) + + // Initialize OpenGL + if (info.do_init) { InitGL(); - info.do_init = FALSE; + info.do_init = false; } - - /* view */ + + // View glMatrixMode( GL_PROJECTION ); glLoadIdentity(); - gluPerspective( info.zoom, VIEW_ASPECT, 1, 100 ); + gluPerspective( info.zoom, VIEW_ASPECT, 1.0, 100.0 ); glMatrixMode( GL_MODELVIEW ); - /* clear */ - glClearColor( .3, .4, .6, 1 ); + // Clear + glClearColor( 0.3f, 0.4f, 0.6f, 1.0f ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); - /* transformations */ + // Transformations GLfloat m[4][4]; glLoadIdentity(); - glTranslatef( 0, 0, -30 ); + glTranslatef( 0.0f, 0.0f, -30.0f ); build_rotmatrix( m,info.quat ); glMultMatrixf( &m[0][0] ); - /* draw object */ + // Draw object lw_object_show( info.lwobject ); - - /* flush */ + + // Flush glFlush(); - /* swap */ + // Swap SwapBuffers(); } @@ -165,12 +169,12 @@ void TestGLCanvas::OnSize(wxSizeEvent& event) { // this is also necessary to update the context on some platforms wxGLCanvas::OnSize(event); - + // set GL viewport (not called by wxGLCanvas::OnSize on all platforms...) int w, h; GetClientSize(&w, &h); #ifndef __WXMOTIF__ - if (GetContext()) + if ( GetContext() ) #endif { SetCurrent(); @@ -187,56 +191,63 @@ void TestGLCanvas::LoadLWO(const wxString &filename) { /* test if lightwave object */ if (!lw_is_lwobject(filename.mb_str())) return; - + /* read lightwave object */ lwObject *lwobject = lw_object_read(filename.mb_str()); - + /* scale */ lw_object_scale(lwobject, 10.0 / lw_object_radius(lwobject)); - + /* set up mesh info */ - info.do_init = TRUE; + info.do_init = true; info.lwobject = lwobject; - info.beginx = 0; - info.beginy = 0; - info.zoom = 45; - trackball( info.quat, 0.0, 0.0, 0.0, 0.0 ); + info.beginx = 0.0f; + info.beginy = 0.0f; + info.zoom = 45.0f; + trackball( info.quat, 0.0f, 0.0f, 0.0f, 0.0f ); } void TestGLCanvas::OnMouse( wxMouseEvent& event ) { - wxSize sz(GetClientSize()); - if (event.Dragging()) + + if ( event.Dragging() ) { + wxSize sz( GetClientSize() ); + /* drag in progress, simulate trackball */ float spin_quat[4]; trackball(spin_quat, - (2.0*info.beginx - sz.x) / sz.x, - ( sz.y - 2.0*info.beginy) / sz.y, - ( 2.0*event.GetX() - sz.x) / sz.x, - ( sz.y - 2.0*event.GetY()) / sz.y); - + (2.0*info.beginx - sz.x) / sz.x, + ( sz.y - 2.0*info.beginy) / sz.y, + ( 2.0*event.GetX() - sz.x) / sz.x, + ( sz.y - 2.0*event.GetY()) / sz.y); + add_quats( spin_quat, info.quat, info.quat ); /* orientation has changed, redraw mesh */ - Refresh(FALSE); + Refresh(false); } info.beginx = event.GetX(); info.beginy = event.GetY(); } -void TestGLCanvas::InitGL(void) +void TestGLCanvas::InitGL() { - GLfloat light0_pos[4] = { -50.0, 50.0, 0.0, 0.0 }; - GLfloat light0_color[4] = { .6, .6, .6, 1.0 }; /* white light */ - GLfloat light1_pos[4] = { 50.0, 50.0, 0.0, 0.0 }; - GLfloat light1_color[4] = { .4, .4, 1, 1.0 }; /* cold blue light */ + static const GLfloat light0_pos[4] = { -50.0f, 50.0f, 0.0f, 0.0f }; + + // white light + static const GLfloat light0_color[4] = { 0.6f, 0.6f, 0.6f, 1.0f }; + + static const GLfloat light1_pos[4] = { 50.0f, 50.0f, 0.0f, 0.0f }; + + // cold blue light + static const GLfloat light1_color[4] = { 0.4f, 0.4f, 1.0f, 1.0f }; /* remove back faces */ glDisable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); - + /* speedups */ glEnable(GL_DITHER); glShadeModel(GL_SMOOTH); @@ -245,16 +256,16 @@ void TestGLCanvas::InitGL(void) /* light */ glLightfv(GL_LIGHT0, GL_POSITION, light0_pos); - glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_color); + glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_color); glLightfv(GL_LIGHT1, GL_POSITION, light1_pos); glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_color); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_LIGHTING); - - glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE); - glEnable(GL_COLOR_MATERIAL); + + glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); + glEnable(GL_COLOR_MATERIAL); } -#endif +#endif // #if wxUSE_GLCANVAS diff --git a/samples/opengl/penguin/penguin.h b/samples/opengl/penguin/penguin.h index 0020b657af..dae7ca35e9 100644 --- a/samples/opengl/penguin/penguin.h +++ b/samples/opengl/penguin/penguin.h @@ -20,16 +20,17 @@ #include "wx/glcanvas.h" -extern "C" { +extern "C" +{ #include "lw.h" #include "trackball.h" } /* information needed to display lightwave mesh */ -typedef struct +typedef struct { // gint do_init; /* true if initgl not yet called */ - int do_init; + bool do_init; lwObject *lwobject; /* lightwave object mesh */ float beginx,beginy; /* position of mouse */ float quat[4]; /* orientation of object */ @@ -41,7 +42,7 @@ typedef struct class MyApp: public wxApp { public: - bool OnInit(void); + bool OnInit(); }; /* Define a new frame type */ @@ -50,17 +51,17 @@ class TestGLCanvas; class MyFrame: public wxFrame { public: - MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size, - long style = wxDEFAULT_FRAME_STYLE); + MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, + const wxSize& size, long style = wxDEFAULT_FRAME_STYLE); void OnExit(wxCommandEvent& event); - + #if wxUSE_GLCANVAS - void SetCanvas( TestGLCanvas *canvas ) { m_canvas = canvas; } - TestGLCanvas *GetCanvas() { return m_canvas; } - + void SetCanvas( TestGLCanvas *canvas ) { m_canvas = canvas; } + TestGLCanvas *GetCanvas() { return m_canvas; } + private: - TestGLCanvas* m_canvas; + TestGLCanvas *m_canvas; #endif DECLARE_EVENT_TABLE() @@ -71,17 +72,20 @@ private: class TestGLCanvas: public wxGLCanvas { public: - TestGLCanvas(wxWindow *parent, const wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxT("TestGLCanvas")); - ~TestGLCanvas(void); + TestGLCanvas(wxWindow *parent, wxWindowID id = wxID_ANY, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, long style = 0, + const wxString& name = wxT("TestGLCanvas")); + + ~TestGLCanvas(); void OnPaint(wxPaintEvent& event); void OnSize(wxSizeEvent& event); void OnEraseBackground(wxEraseEvent& event); void LoadLWO( const wxString &filename); void OnMouse( wxMouseEvent& event ); - void InitGL(void); - + void InitGL(); + mesh_info info; bool block; @@ -89,7 +93,7 @@ private: DECLARE_EVENT_TABLE() }; -#endif +#endif // #if wxUSE_GLCANVAS -#endif +#endif // #ifndef _WX_PENGUIN_H_ -- 2.45.2