#include "wx/wx.h"
#endif
-#include "wx/log.h"
-
#include "cube.h"
#ifndef __WXMSW__ // for wxStopWatch, see remark below
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()) );
}
/*------------------------------------------------------------------
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;
}
/*----------------------------------------------------------------------
#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;
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;
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;
}
#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) )
/* 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);
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);
}
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
}
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
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_
#include "wx/glcanvas.h"
#ifdef __WXMAC__
-# ifdef __DARWIN__
-# include <OpenGL/gl.h>
-# include <OpenGL/glu.h>
-# else
-# include <gl.h>
-# include <glu.h>
-# endif
+# ifdef __DARWIN__
+# include <OpenGL/gl.h>
+# include <OpenGL/glu.h>
+# else
+# include <gl.h>
+# include <glu.h>
+# endif
#else
-# include <GL/gl.h>
-# include <GL/glu.h>
+# include <GL/gl.h>
+# include <GL/glu.h>
#endif
// disabled because this has apparently changed in OpenGL 1.2, so doesn't link
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) && numverts<MAXVERTS) {
- fscanf( f, "%f %f %f %f %f %f",
- &verts[numverts][0], &verts[numverts][1], &verts[numverts][2],
- &norms[numverts][0], &norms[numverts][1], &norms[numverts][2] );
- numverts++;
- }
- numverts--;
-
- wxPrintf(_T("%d vertices, %d triangles\n"), numverts, numverts-2);
- fclose(f);
+ FILE *f = wxFopen(filename,_T("r"));
+ if (!f)
+ {
+ wxString msg = _T("Couldn't read ");
+ msg += filename;
+ wxMessageBox(msg);
+ return;
+ }
+
+ numverts = 0;
+ while (!feof(f) && numverts<MAXVERTS)
+ {
+ fscanf( f, "%f %f %f %f %f %f",
+ &verts[numverts][0], &verts[numverts][1], &verts[numverts][2],
+ &norms[numverts][0], &norms[numverts][1], &norms[numverts][2] );
+ numverts++;
+ }
+
+ numverts--;
+
+ wxPrintf(_T("%d vertices, %d triangles\n"), numverts, numverts-2);
+
+ fclose(f);
}
-static void draw_surface( void )
+static void draw_surface()
{
- GLint i;
+ GLint i;
#ifdef GL_EXT_vertex_array
- if (use_vertex_arrays) {
- glDrawArraysEXT( GL_TRIANGLE_STRIP, 0, numverts );
- }
- else {
-#endif
- glBegin( GL_TRIANGLE_STRIP );
- for (i=0;i<numverts;i++) {
- glNormal3fv( norms[i] );
- glVertex3fv( verts[i] );
- }
- glEnd();
-#ifdef GL_EXT_vertex_array
- }
+ if (use_vertex_arrays)
+ {
+ glDrawArraysEXT( GL_TRIANGLE_STRIP, 0, numverts );
+ }
+ else
#endif
+ {
+ glBegin( GL_TRIANGLE_STRIP );
+ for (i=0;i<numverts;i++)
+ {
+ glNormal3fv( norms[i] );
+ glVertex3fv( verts[i] );
+ }
+ glEnd();
+ }
}
-static void draw1(void)
+static void draw1()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
- glRotatef( yrot, 0.0, 1.0, 0.0 );
- glRotatef( xrot, 1.0, 0.0, 0.0 );
+ glRotatef( yrot, 0.0f, 1.0f, 0.0f );
+ glRotatef( xrot, 1.0f, 0.0f, 0.0f );
draw_surface();
}
-static void InitMaterials(void)
+static void InitMaterials()
{
- static float ambient[] = {0.1, 0.1, 0.1, 1.0};
- static float diffuse[] = {0.5, 1.0, 1.0, 1.0};
- static float position0[] = {0.0, 0.0, 20.0, 0.0};
- static float position1[] = {0.0, 0.0, -20.0, 0.0};
- static float front_mat_shininess[] = {60.0};
- static float front_mat_specular[] = {0.2, 0.2, 0.2, 1.0};
- static float front_mat_diffuse[] = {0.5, 0.28, 0.38, 1.0};
+ static const GLfloat ambient[4] = {0.1f, 0.1f, 0.1f, 1.0f};
+ static const GLfloat diffuse[4] = {0.5f, 1.0f, 1.0f, 1.0f};
+ static const GLfloat position0[4] = {0.0f, 0.0f, 20.0f, 0.0f};
+ static const GLfloat position1[4] = {0.0f, 0.0f, -20.0f, 0.0f};
+ static const GLfloat front_mat_shininess[1] = {60.0f};
+ static const GLfloat front_mat_specular[4] = {0.2f, 0.2f, 0.2f, 1.0f};
+ static const GLfloat front_mat_diffuse[4] = {0.5f, 0.28f, 0.38f, 1.0f};
/*
- static float back_mat_shininess[] = {60.0};
- static float back_mat_specular[] = {0.5, 0.5, 0.2, 1.0};
- static float back_mat_diffuse[] = {1.0, 1.0, 0.2, 1.0};
+ static const GLfloat back_mat_shininess[1] = {60.0f};
+ static const GLfloat back_mat_specular[4] = {0.5f, 0.5f, 0.2f, 1.0f};
+ static const GLfloat back_mat_diffuse[4] = {1.0f, 1.0f, 0.2f, 1.0f};
*/
- static float lmodel_ambient[] = {1.0, 1.0, 1.0, 1.0};
- static float lmodel_twoside[] = {GL_FALSE};
+ static const GLfloat lmodel_ambient[4] = {1.0f, 1.0f, 1.0f, 1.0f};
+ static const GLfloat lmodel_twoside[1] = {GL_FALSE};
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, position0);
glEnable(GL_LIGHT0);
-
+
glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT1, GL_POSITION, position1);
glEnable(GL_LIGHT1);
-
+
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
glEnable(GL_LIGHTING);
static void Init(void)
{
- glClearColor(0.0, 0.0, 0.0, 0.0);
+ glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
- glShadeModel(GL_SMOOTH);
- glEnable(GL_DEPTH_TEST);
+ glShadeModel(GL_SMOOTH);
+ glEnable(GL_DEPTH_TEST);
- InitMaterials();
+ InitMaterials();
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum( -1.0, 1.0, -1.0, 1.0, 5, 25 );
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef( 0.0, 0.0, -6.0 );
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef( 0.0, 0.0, -6.0 );
#ifdef GL_EXT_vertex_array
- if (use_vertex_arrays) {
- glVertexPointerEXT( 3, GL_FLOAT, 0, numverts, verts );
- glNormalPointerEXT( GL_FLOAT, 0, numverts, norms );
- glEnable( GL_VERTEX_ARRAY_EXT );
- glEnable( GL_NORMAL_ARRAY_EXT );
- }
+ if (use_vertex_arrays)
+ {
+ glVertexPointerEXT( 3, GL_FLOAT, 0, numverts, verts );
+ glNormalPointerEXT( GL_FLOAT, 0, numverts, norms );
+ glEnable( GL_VERTEX_ARRAY_EXT );
+ glEnable( GL_NORMAL_ARRAY_EXT );
+ }
#endif
}
static GLenum Args(int argc, wxChar **argv)
{
- GLint i;
-
- for (i = 1; i < argc; i++) {
- if (wxStrcmp(argv[i], _T("-sb")) == 0) {
- doubleBuffer = GL_FALSE;
- }
- else if (wxStrcmp(argv[i], _T("-db")) == 0) {
- doubleBuffer = GL_TRUE;
- }
- else if (wxStrcmp(argv[i], _T("-speed")) == 0) {
- speed_test = GL_TRUE;
- doubleBuffer = GL_TRUE;
- }
- else if (wxStrcmp(argv[i], _T("-va")) == 0) {
- use_vertex_arrays = GL_TRUE;
- }
- else {
- wxString msg(_T("Bad option: "));
- msg += argv[i];
- wxMessageBox(msg);
- return GL_FALSE;
- }
- }
-
- return GL_TRUE;
+ GLint i;
+
+ for (i = 1; i < argc; i++)
+ {
+ if (wxStrcmp(argv[i], _T("-sb")) == 0)
+ {
+ doubleBuffer = GL_FALSE;
+ }
+ else if (wxStrcmp(argv[i], _T("-db")) == 0)
+ {
+ doubleBuffer = GL_TRUE;
+ }
+ else if (wxStrcmp(argv[i], _T("-speed")) == 0)
+ {
+ speed_test = GL_TRUE;
+ doubleBuffer = GL_TRUE;
+ }
+ else if (wxStrcmp(argv[i], _T("-va")) == 0)
+ {
+ use_vertex_arrays = GL_TRUE;
+ }
+ else
+ {
+ wxString msg = _T("Bad option: ");
+ msg += argv[i];
+ wxMessageBox(msg);
+ return GL_FALSE;
+ }
+ }
+
+ return GL_TRUE;
}
// The following part was written for wxWindows 1.66
IMPLEMENT_APP(MyApp)
// `Main program' equivalent, creating windows and returning main app frame
-bool MyApp::OnInit(void)
+bool MyApp::OnInit()
{
- Args(argc, argv);
+ Args(argc, argv);
- // Create the main frame window
- frame = new MyFrame(NULL, _T("Isosurf GL Sample"), wxPoint(50, 50), wxSize(200, 200));
+ // Create the main frame window
+ frame = new MyFrame(NULL, wxT("wxWindows OpenGL Isosurf Sample"),
+ wxDefaultPosition, wxDefaultSize);
- // Give it an icon
- frame->SetIcon(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
}
// 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);
}
/*
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()
{
}
{
// 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);
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)
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
+
// 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_
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;
}
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) {
}
/* 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) {
#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
}
/* 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;
}
/* 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
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);
#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();
}
{
// 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();
{
/* 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);
/* 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
#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 */
class MyApp: public wxApp
{
public:
- bool OnInit(void);
+ bool OnInit();
};
/* Define a new frame type */
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()
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;
DECLARE_EVENT_TABLE()
};
-#endif
+#endif // #if wxUSE_GLCANVAS
-#endif
+#endif // #ifndef _WX_PENGUIN_H_