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
This commit is contained in:
@@ -25,8 +25,6 @@
|
|||||||
#include "wx/wx.h"
|
#include "wx/wx.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/log.h"
|
|
||||||
|
|
||||||
#include "cube.h"
|
#include "cube.h"
|
||||||
|
|
||||||
#ifndef __WXMSW__ // for wxStopWatch, see remark below
|
#ifndef __WXMSW__ // for wxStopWatch, see remark below
|
||||||
@@ -51,32 +49,37 @@
|
|||||||
class ScanCodeCtrl : public wxTextCtrl
|
class ScanCodeCtrl : public wxTextCtrl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ScanCodeCtrl( wxWindow* parent, wxWindowID id, int code,
|
ScanCodeCtrl( wxWindow* parent, wxWindowID id, int code,
|
||||||
const wxPoint& pos, const wxSize& size );
|
const wxPoint& pos, const wxSize& size );
|
||||||
void OnChar( wxKeyEvent& event ) { } /* do nothing */
|
|
||||||
void OnKeyDown(wxKeyEvent& event);
|
void OnChar( wxKeyEvent& WXUNUSED(event) )
|
||||||
|
{
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnKeyDown(wxKeyEvent& event);
|
||||||
|
|
||||||
private:
|
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 )
|
BEGIN_EVENT_TABLE( ScanCodeCtrl, wxTextCtrl )
|
||||||
EVT_CHAR( ScanCodeCtrl::OnChar )
|
EVT_CHAR( ScanCodeCtrl::OnChar )
|
||||||
EVT_KEY_DOWN( ScanCodeCtrl::OnKeyDown )
|
EVT_KEY_DOWN( ScanCodeCtrl::OnKeyDown )
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
ScanCodeCtrl::ScanCodeCtrl( wxWindow* parent, wxWindowID id, int code,
|
ScanCodeCtrl::ScanCodeCtrl( wxWindow* parent, wxWindowID id, int code,
|
||||||
const wxPoint& pos, const wxSize& size )
|
const wxPoint& pos, const wxSize& size )
|
||||||
: wxTextCtrl( parent, id, wxEmptyString, pos, size )
|
: wxTextCtrl( parent, id, wxEmptyString, pos, size )
|
||||||
{ wxString buf;
|
{
|
||||||
buf.Printf( _T("0x%04x"), code );
|
SetValue( wxString::Format(wxT("0x%04x"), code) );
|
||||||
SetValue( buf );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScanCodeCtrl::OnKeyDown( wxKeyEvent& event )
|
void ScanCodeCtrl::OnKeyDown( wxKeyEvent& event )
|
||||||
{
|
{
|
||||||
wxString buf;
|
SetValue( wxString::Format(wxT("0x%04x"), event.GetKeyCode()) );
|
||||||
buf.Printf( _T("0x%04x"), event.GetKeyCode() );
|
|
||||||
SetValue( buf );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------
|
/*------------------------------------------------------------------
|
||||||
@@ -86,39 +89,41 @@ void ScanCodeCtrl::OnKeyDown( wxKeyEvent& event )
|
|||||||
class ScanCodeDialog : public wxDialog
|
class ScanCodeDialog : public wxDialog
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ScanCodeDialog( wxWindow* parent, wxWindowID id, const int code,
|
ScanCodeDialog( wxWindow* parent, wxWindowID id, const int code,
|
||||||
const wxString &descr, const wxString& title );
|
const wxString &descr, const wxString& title );
|
||||||
int GetValue();
|
int GetValue();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ScanCodeCtrl *m_ScanCode;
|
|
||||||
wxTextCtrl *m_Description;
|
ScanCodeCtrl *m_ScanCode;
|
||||||
|
wxTextCtrl *m_Description;
|
||||||
};
|
};
|
||||||
|
|
||||||
ScanCodeDialog::ScanCodeDialog( wxWindow* parent, wxWindowID id,
|
ScanCodeDialog::ScanCodeDialog( wxWindow* parent, wxWindowID id,
|
||||||
const int code, const wxString &descr, const wxString& title )
|
const int code, const wxString &descr, const wxString& title )
|
||||||
: wxDialog( parent, id, title, wxPoint(-1, -1), wxSize(96*2,76*2) )
|
: wxDialog( parent, id, title, wxDefaultPosition, wxSize(96*2,76*2) )
|
||||||
{
|
{
|
||||||
new wxStaticText( this, -1, _T("Scancode"), wxPoint(4*2,3*2),
|
new wxStaticText( this, wxID_ANY, _T("Scancode"), wxPoint(4*2,3*2),
|
||||||
wxSize(31*2,12*2) );
|
wxSize(31*2,12*2) );
|
||||||
m_ScanCode = new ScanCodeCtrl( this, -1, code, wxPoint(37*2,6*2),
|
m_ScanCode = new ScanCodeCtrl( this, wxID_ANY, code, wxPoint(37*2,6*2),
|
||||||
wxSize(53*2,14*2) );
|
wxSize(53*2,14*2) );
|
||||||
|
|
||||||
new wxStaticText( this, -1, _T("Description"), wxPoint(4*2,24*2),
|
new wxStaticText( this, wxID_ANY, _T("Description"), wxPoint(4*2,24*2),
|
||||||
wxSize(32*2,12*2) );
|
wxSize(32*2,12*2) );
|
||||||
m_Description = new wxTextCtrl( this, -1, descr, wxPoint(37*2,27*2),
|
m_Description = new wxTextCtrl( this, wxID_ANY, descr, wxPoint(37*2,27*2),
|
||||||
wxSize(53*2,14*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_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),
|
new wxButton( this, wxID_CANCEL, _T("Cancel"), wxPoint(44*2,50*2),
|
||||||
wxSize(25*2,13*2) );
|
wxSize(25*2,13*2) );
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScanCodeDialog::GetValue()
|
int ScanCodeDialog::GetValue()
|
||||||
{
|
{
|
||||||
int code;
|
int code;
|
||||||
wxString buf = m_ScanCode->GetValue();
|
wxString buf = m_ScanCode->GetValue();
|
||||||
wxSscanf( buf.c_str(), _T("%i"), &code );
|
wxSscanf( buf.c_str(), _T("%i"), &code );
|
||||||
return( code );
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------
|
/*----------------------------------------------------------------------
|
||||||
@@ -160,12 +165,12 @@ unsigned long wxStopWatch( unsigned long *sec_base )
|
|||||||
#if wxUSE_GLCANVAS
|
#if wxUSE_GLCANVAS
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas)
|
BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas)
|
||||||
EVT_SIZE(TestGLCanvas::OnSize)
|
EVT_SIZE(TestGLCanvas::OnSize)
|
||||||
EVT_PAINT(TestGLCanvas::OnPaint)
|
EVT_PAINT(TestGLCanvas::OnPaint)
|
||||||
EVT_ERASE_BACKGROUND(TestGLCanvas::OnEraseBackground)
|
EVT_ERASE_BACKGROUND(TestGLCanvas::OnEraseBackground)
|
||||||
EVT_KEY_DOWN( TestGLCanvas::OnKeyDown )
|
EVT_KEY_DOWN( TestGLCanvas::OnKeyDown )
|
||||||
EVT_KEY_UP( TestGLCanvas::OnKeyUp )
|
EVT_KEY_UP( TestGLCanvas::OnKeyUp )
|
||||||
EVT_ENTER_WINDOW( TestGLCanvas::OnEnterWindow )
|
EVT_ENTER_WINDOW( TestGLCanvas::OnEnterWindow )
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
unsigned long TestGLCanvas::m_secbase = 0;
|
unsigned long TestGLCanvas::m_secbase = 0;
|
||||||
@@ -174,10 +179,10 @@ unsigned long TestGLCanvas::m_xsynct;
|
|||||||
unsigned long TestGLCanvas::m_gsynct;
|
unsigned long TestGLCanvas::m_gsynct;
|
||||||
|
|
||||||
TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id,
|
TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id,
|
||||||
const wxPoint& pos, const wxSize& size, long style, const wxString& name):
|
const wxPoint& pos, const wxSize& size, long style, const wxString& name)
|
||||||
wxGLCanvas(parent, (wxGLCanvas*) NULL, id, pos, size, style, name )
|
: wxGLCanvas(parent, (wxGLCanvas*) NULL, id, pos, size, style, name )
|
||||||
{
|
{
|
||||||
m_init = FALSE;
|
m_init = false;
|
||||||
m_gllist = 0;
|
m_gllist = 0;
|
||||||
m_rleft = WXK_LEFT;
|
m_rleft = WXK_LEFT;
|
||||||
m_rright = WXK_RIGHT;
|
m_rright = WXK_RIGHT;
|
||||||
@@ -185,11 +190,11 @@ TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id,
|
|||||||
|
|
||||||
TestGLCanvas::TestGLCanvas(wxWindow *parent, const TestGLCanvas &other,
|
TestGLCanvas::TestGLCanvas(wxWindow *parent, const TestGLCanvas &other,
|
||||||
wxWindowID id, const wxPoint& pos, const wxSize& size, long style,
|
wxWindowID id, const wxPoint& pos, const wxSize& size, long style,
|
||||||
const wxString& name ) :
|
const wxString& name )
|
||||||
wxGLCanvas(parent, other.GetContext(), id, pos, size, style, name )
|
: wxGLCanvas(parent, other.GetContext(), id, pos, size, style, name)
|
||||||
{
|
{
|
||||||
m_init = FALSE;
|
m_init = false;
|
||||||
m_gllist = other.m_gllist; /* share display list */
|
m_gllist = other.m_gllist; // share display list
|
||||||
m_rleft = WXK_LEFT;
|
m_rleft = WXK_LEFT;
|
||||||
m_rright = WXK_RIGHT;
|
m_rright = WXK_RIGHT;
|
||||||
}
|
}
|
||||||
@@ -207,59 +212,61 @@ void TestGLCanvas::Render()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
SetCurrent();
|
SetCurrent();
|
||||||
/* init OpenGL once, but after SetCurrent */
|
// Init OpenGL once, but after SetCurrent
|
||||||
if (!m_init)
|
if (!m_init)
|
||||||
{
|
{
|
||||||
InitGL();
|
InitGL();
|
||||||
m_init = TRUE;
|
m_init = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
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);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
|
||||||
/* clear color and depth buffers */
|
/* clear color and depth buffers */
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
if( m_gllist == 0 )
|
if( m_gllist == 0 )
|
||||||
{
|
{
|
||||||
m_gllist = glGenLists( 1 );
|
m_gllist = glGenLists( 1 );
|
||||||
glNewList( m_gllist, GL_COMPILE_AND_EXECUTE );
|
glNewList( m_gllist, GL_COMPILE_AND_EXECUTE );
|
||||||
/* draw six faces of a cube */
|
/* draw six faces of a cube */
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glNormal3f( 0.0F, 0.0F, 1.0F);
|
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);
|
||||||
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);
|
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);
|
||||||
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);
|
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);
|
||||||
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);
|
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);
|
||||||
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);
|
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);
|
||||||
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);
|
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);
|
||||||
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();
|
glEnd();
|
||||||
|
|
||||||
glEndList();
|
glEndList();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
glCallList( m_gllist );
|
{
|
||||||
|
glCallList(m_gllist);
|
||||||
|
}
|
||||||
|
|
||||||
glFlush();
|
glFlush();
|
||||||
SwapBuffers();
|
SwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestGLCanvas::OnEnterWindow( wxMouseEvent& WXUNUSED(event) )
|
void TestGLCanvas::OnEnterWindow( wxMouseEvent& WXUNUSED(event) )
|
||||||
@@ -300,15 +307,15 @@ void TestGLCanvas::InitGL()
|
|||||||
|
|
||||||
/* set viewing projection */
|
/* set viewing projection */
|
||||||
glMatrixMode(GL_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 */
|
/* position viewer */
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glTranslatef(0.0F, 0.0F, -2.0F);
|
glTranslatef(0.0f, 0.0f, -2.0f);
|
||||||
|
|
||||||
/* position object */
|
/* position object */
|
||||||
glRotatef(30.0F, 1.0F, 0.0F, 0.0F);
|
glRotatef(30.0f, 1.0f, 0.0f, 0.0f);
|
||||||
glRotatef(30.0F, 0.0F, 1.0F, 0.0F);
|
glRotatef(30.0f, 0.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
@@ -409,8 +416,8 @@ void TestGLCanvas::Rotate( GLfloat deg )
|
|||||||
SetCurrent();
|
SetCurrent();
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glRotatef((GLfloat)deg, 0.0F, 0.0F, 1.0F);
|
glRotatef((GLfloat)deg, 0.0f, 0.0f, 1.0f);
|
||||||
Refresh(FALSE);
|
Refresh(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -428,71 +435,95 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
// My frame constructor
|
// My frame constructor
|
||||||
MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
|
MyFrame::MyFrame(wxWindow *parent, const wxString& title, const wxPoint& pos,
|
||||||
const wxSize& size, long style)
|
const wxSize& size, long style)
|
||||||
: wxFrame(frame, -1, title, pos, size, style)
|
: wxFrame(parent, wxID_ANY, title, pos, size, style)
|
||||||
{
|
{
|
||||||
m_canvas = NULL;
|
m_canvas = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Intercept menu commands
|
// 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"),
|
wxString str = wxT("wxWindows OpenGL Cube Sample");
|
||||||
wxPoint(50, 50), wxSize(400, 300));
|
if (isCloneWindow) str += wxT(" - Clone");
|
||||||
// Give it an icon
|
|
||||||
|
MyFrame *frame = new MyFrame(NULL, str, wxDefaultPosition,
|
||||||
|
wxSize(400, 300));
|
||||||
|
|
||||||
|
// Give it an icon
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
frame->SetIcon(wxIcon(_T("mondrian")));
|
frame->SetIcon(wxIcon(_T("mondrian")));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Make a menubar
|
// Make a menubar
|
||||||
wxMenu *winMenu = new wxMenu;
|
wxMenu *winMenu = new wxMenu;
|
||||||
|
|
||||||
winMenu->Append(wxID_EXIT, _T("&Close"));
|
winMenu->Append(wxID_EXIT, _T("&Close"));
|
||||||
winMenu->Append(ID_NEW_WINDOW, _T("&New") );
|
winMenu->Append(ID_NEW_WINDOW, _T("&New") );
|
||||||
wxMenuBar *menuBar = new wxMenuBar;
|
wxMenuBar *menuBar = new wxMenuBar;
|
||||||
menuBar->Append(winMenu, _T("&Window"));
|
menuBar->Append(winMenu, _T("&Window"));
|
||||||
|
|
||||||
winMenu = new wxMenu;
|
winMenu = new wxMenu;
|
||||||
winMenu->Append(ID_DEF_ROTATE_LEFT_KEY, _T("Rotate &left"));
|
winMenu->Append(ID_DEF_ROTATE_LEFT_KEY, _T("Rotate &left"));
|
||||||
winMenu->Append(ID_DEF_ROTATE_RIGHT_KEY, _T("Rotate &right"));
|
winMenu->Append(ID_DEF_ROTATE_RIGHT_KEY, _T("Rotate &right"));
|
||||||
menuBar->Append(winMenu, _T("&Key"));
|
menuBar->Append(winMenu, _T("&Key"));
|
||||||
|
|
||||||
frame->SetMenuBar(menuBar);
|
frame->SetMenuBar(menuBar);
|
||||||
|
|
||||||
#if wxUSE_GLCANVAS
|
#if wxUSE_GLCANVAS
|
||||||
frame->m_canvas = new TestGLCanvas( frame, *m_canvas, -1,
|
if (parentFrame)
|
||||||
wxDefaultPosition, wxDefaultSize );
|
{
|
||||||
|
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
|
#endif
|
||||||
|
|
||||||
// Show the frame
|
// Show the frame
|
||||||
frame->Show(TRUE);
|
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
|
#if wxUSE_GLCANVAS
|
||||||
ScanCodeDialog dial( this, -1, m_canvas->m_rleft,
|
ScanCodeDialog dial( this, wxID_ANY, m_canvas->m_rleft,
|
||||||
wxString(_T("Left")), _T("Define key") );
|
wxString(_T("Left")), _T("Define key") );
|
||||||
int result = dial.ShowModal();
|
|
||||||
if( result == wxID_OK )
|
int result = dial.ShowModal();
|
||||||
m_canvas->m_rleft = dial.GetValue();
|
|
||||||
|
if( result == wxID_OK )
|
||||||
|
m_canvas->m_rleft = dial.GetValue();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyFrame::OnDefRotateRightKey(wxCommandEvent& WXUNUSED(event))
|
void MyFrame::OnDefRotateRightKey( wxCommandEvent& WXUNUSED(event) )
|
||||||
{
|
{
|
||||||
#if wxUSE_GLCANVAS
|
#if wxUSE_GLCANVAS
|
||||||
ScanCodeDialog dial( this, -1, m_canvas->m_rright,
|
ScanCodeDialog dial( this, wxID_ANY, m_canvas->m_rright,
|
||||||
wxString(_T("Right")), _T("Define key") );
|
wxString(_T("Right")), _T("Define key") );
|
||||||
int result = dial.ShowModal();
|
|
||||||
if( result == wxID_OK )
|
int result = dial.ShowModal();
|
||||||
m_canvas->m_rright = dial.GetValue();
|
|
||||||
|
if( result == wxID_OK )
|
||||||
|
m_canvas->m_rright = dial.GetValue();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -502,47 +533,25 @@ void MyFrame::OnDefRotateRightKey(wxCommandEvent& WXUNUSED(event))
|
|||||||
|
|
||||||
IMPLEMENT_APP(MyApp)
|
IMPLEMENT_APP(MyApp)
|
||||||
|
|
||||||
bool MyApp::OnInit(void)
|
bool MyApp::OnInit()
|
||||||
{
|
{
|
||||||
wxLog::SetTraceMask(wxTraceMessages);
|
#if wxUSE_LOG
|
||||||
|
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"));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Make a menubar
|
// Create the main frame window
|
||||||
wxMenu *winMenu = new wxMenu;
|
(void) MyFrame::Create(NULL);
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
#if wxUSE_GLCANVAS
|
#if wxUSE_GLCANVAS
|
||||||
|
|
||||||
frame->m_canvas = new TestGLCanvas(frame, -1, wxDefaultPosition, wxDefaultSize);
|
return true;
|
||||||
|
|
||||||
// Show the frame
|
|
||||||
frame->Show(TRUE);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
#else
|
#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
|
#endif
|
||||||
|
|
||||||
|
@@ -18,80 +18,87 @@
|
|||||||
class MyApp: public wxApp
|
class MyApp: public wxApp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool OnInit(void);
|
bool OnInit();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Define a new frame type
|
// Define a new frame type
|
||||||
class TestGLCanvas;
|
class TestGLCanvas;
|
||||||
|
|
||||||
class MyFrame: public wxFrame
|
class MyFrame: public wxFrame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
|
static MyFrame *Create(MyFrame *parentFrame, bool isCloneWindow = false);
|
||||||
const wxSize& size, long style = wxDEFAULT_FRAME_STYLE);
|
|
||||||
|
|
||||||
void OnExit(wxCommandEvent& event);
|
void OnExit(wxCommandEvent& event);
|
||||||
void OnNewWindow(wxCommandEvent& event);
|
void OnNewWindow(wxCommandEvent& event);
|
||||||
void OnDefRotateLeftKey(wxCommandEvent& event);
|
void OnDefRotateLeftKey(wxCommandEvent& event);
|
||||||
void OnDefRotateRightKey(wxCommandEvent& event);
|
void OnDefRotateRightKey(wxCommandEvent& event);
|
||||||
|
|
||||||
public:
|
private:
|
||||||
TestGLCanvas* m_canvas;
|
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
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
|
#if wxUSE_GLCANVAS
|
||||||
|
|
||||||
class TestGLCanvas: public wxGLCanvas
|
class TestGLCanvas: public wxGLCanvas
|
||||||
{
|
{
|
||||||
friend class MyFrame;
|
friend class MyFrame;
|
||||||
public:
|
public:
|
||||||
TestGLCanvas(wxWindow *parent, const wxWindowID id = -1,
|
TestGLCanvas( wxWindow *parent, wxWindowID id = wxID_ANY,
|
||||||
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
long style = 0, const wxString& name = _T("TestGLCanvas"));
|
const wxSize& size = wxDefaultSize,
|
||||||
TestGLCanvas(wxWindow *parent, const TestGLCanvas &other,
|
long style = 0, const wxString& name = _T("TestGLCanvas") );
|
||||||
const wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,
|
|
||||||
const wxSize& size = wxDefaultSize, long style = 0,
|
|
||||||
const wxString& name = _T("TestGLCanvas") );
|
|
||||||
|
|
||||||
~TestGLCanvas(void);
|
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") );
|
||||||
|
|
||||||
void OnPaint(wxPaintEvent& event);
|
~TestGLCanvas();
|
||||||
void OnSize(wxSizeEvent& event);
|
|
||||||
void OnEraseBackground(wxEraseEvent& event);
|
|
||||||
void OnKeyDown(wxKeyEvent& event);
|
|
||||||
void OnKeyUp(wxKeyEvent& event);
|
|
||||||
void OnEnterWindow( wxMouseEvent& event );
|
|
||||||
|
|
||||||
void Render( void );
|
void OnPaint(wxPaintEvent& event);
|
||||||
void InitGL(void);
|
void OnSize(wxSizeEvent& event);
|
||||||
void Rotate( GLfloat deg );
|
void OnEraseBackground(wxEraseEvent& event);
|
||||||
static GLfloat CalcRotateSpeed( unsigned long acceltime );
|
void OnKeyDown(wxKeyEvent& event);
|
||||||
static GLfloat CalcRotateAngle( unsigned long lasttime,
|
void OnKeyUp(wxKeyEvent& event);
|
||||||
unsigned long acceltime );
|
void OnEnterWindow(wxMouseEvent& event);
|
||||||
void Action( long code, unsigned long lasttime,
|
|
||||||
unsigned long acceltime );
|
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:
|
private:
|
||||||
bool m_init;
|
bool m_init;
|
||||||
GLuint m_gllist;
|
GLuint m_gllist;
|
||||||
long m_rleft;
|
long m_rleft;
|
||||||
long m_rright;
|
long m_rright;
|
||||||
|
|
||||||
static unsigned long m_secbase;
|
static unsigned long m_secbase;
|
||||||
static int m_TimeInitialized;
|
static int m_TimeInitialized;
|
||||||
static unsigned long m_xsynct;
|
static unsigned long m_xsynct;
|
||||||
static unsigned long m_gsynct;
|
static unsigned long m_gsynct;
|
||||||
|
|
||||||
long m_Key;
|
long m_Key;
|
||||||
unsigned long m_StartTime;
|
unsigned long m_StartTime;
|
||||||
unsigned long m_LastTime;
|
unsigned long m_LastTime;
|
||||||
unsigned long m_LastRedraw;
|
unsigned long m_LastRedraw;
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // #if wxUSE_GLCANVAS
|
||||||
|
|
||||||
#endif
|
#endif // #ifndef _WX_CUBE_H_
|
||||||
|
|
||||||
|
@@ -29,16 +29,16 @@
|
|||||||
#include "wx/glcanvas.h"
|
#include "wx/glcanvas.h"
|
||||||
|
|
||||||
#ifdef __WXMAC__
|
#ifdef __WXMAC__
|
||||||
# ifdef __DARWIN__
|
# ifdef __DARWIN__
|
||||||
# include <OpenGL/gl.h>
|
# include <OpenGL/gl.h>
|
||||||
# include <OpenGL/glu.h>
|
# include <OpenGL/glu.h>
|
||||||
# else
|
# else
|
||||||
# include <gl.h>
|
# include <gl.h>
|
||||||
# include <glu.h>
|
# include <glu.h>
|
||||||
# endif
|
# endif
|
||||||
#else
|
#else
|
||||||
# include <GL/gl.h>
|
# include <GL/gl.h>
|
||||||
# include <GL/glu.h>
|
# include <GL/glu.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// disabled because this has apparently changed in OpenGL 1.2, so doesn't link
|
// 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 GLfloat yrot;
|
||||||
|
|
||||||
|
|
||||||
static void read_surface( wxChar *filename )
|
static void read_surface( const wxChar *filename )
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f = wxFopen(filename,_T("r"));
|
||||||
|
if (!f)
|
||||||
|
{
|
||||||
|
wxString msg = _T("Couldn't read ");
|
||||||
|
msg += filename;
|
||||||
|
wxMessageBox(msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
f = wxFopen(filename,_T("r"));
|
numverts = 0;
|
||||||
if (!f) {
|
while (!feof(f) && numverts<MAXVERTS)
|
||||||
wxString msg(_T("Couldn't read "));
|
{
|
||||||
msg += filename;
|
fscanf( f, "%f %f %f %f %f %f",
|
||||||
wxMessageBox(msg);
|
&verts[numverts][0], &verts[numverts][1], &verts[numverts][2],
|
||||||
return;
|
&norms[numverts][0], &norms[numverts][1], &norms[numverts][2] );
|
||||||
}
|
numverts++;
|
||||||
|
}
|
||||||
|
|
||||||
numverts = 0;
|
numverts--;
|
||||||
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);
|
wxPrintf(_T("%d vertices, %d triangles\n"), numverts, numverts-2);
|
||||||
fclose(f);
|
|
||||||
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void draw_surface( void )
|
static void draw_surface()
|
||||||
{
|
{
|
||||||
GLint i;
|
GLint i;
|
||||||
|
|
||||||
#ifdef GL_EXT_vertex_array
|
#ifdef GL_EXT_vertex_array
|
||||||
if (use_vertex_arrays) {
|
if (use_vertex_arrays)
|
||||||
glDrawArraysEXT( GL_TRIANGLE_STRIP, 0, numverts );
|
{
|
||||||
}
|
glDrawArraysEXT( GL_TRIANGLE_STRIP, 0, numverts );
|
||||||
else {
|
}
|
||||||
#endif
|
else
|
||||||
glBegin( GL_TRIANGLE_STRIP );
|
|
||||||
for (i=0;i<numverts;i++) {
|
|
||||||
glNormal3fv( norms[i] );
|
|
||||||
glVertex3fv( verts[i] );
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
#ifdef GL_EXT_vertex_array
|
|
||||||
}
|
|
||||||
#endif
|
#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 );
|
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glRotatef( yrot, 0.0, 1.0, 0.0 );
|
glRotatef( yrot, 0.0f, 1.0f, 0.0f );
|
||||||
glRotatef( xrot, 1.0, 0.0, 0.0 );
|
glRotatef( xrot, 1.0f, 0.0f, 0.0f );
|
||||||
|
|
||||||
draw_surface();
|
draw_surface();
|
||||||
|
|
||||||
@@ -135,22 +138,22 @@ static void draw1(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void InitMaterials(void)
|
static void InitMaterials()
|
||||||
{
|
{
|
||||||
static float ambient[] = {0.1, 0.1, 0.1, 1.0};
|
static const GLfloat ambient[4] = {0.1f, 0.1f, 0.1f, 1.0f};
|
||||||
static float diffuse[] = {0.5, 1.0, 1.0, 1.0};
|
static const GLfloat diffuse[4] = {0.5f, 1.0f, 1.0f, 1.0f};
|
||||||
static float position0[] = {0.0, 0.0, 20.0, 0.0};
|
static const GLfloat position0[4] = {0.0f, 0.0f, 20.0f, 0.0f};
|
||||||
static float position1[] = {0.0, 0.0, -20.0, 0.0};
|
static const GLfloat position1[4] = {0.0f, 0.0f, -20.0f, 0.0f};
|
||||||
static float front_mat_shininess[] = {60.0};
|
static const GLfloat front_mat_shininess[1] = {60.0f};
|
||||||
static float front_mat_specular[] = {0.2, 0.2, 0.2, 1.0};
|
static const GLfloat front_mat_specular[4] = {0.2f, 0.2f, 0.2f, 1.0f};
|
||||||
static float front_mat_diffuse[] = {0.5, 0.28, 0.38, 1.0};
|
static const GLfloat front_mat_diffuse[4] = {0.5f, 0.28f, 0.38f, 1.0f};
|
||||||
/*
|
/*
|
||||||
static float back_mat_shininess[] = {60.0};
|
static const GLfloat back_mat_shininess[1] = {60.0f};
|
||||||
static float back_mat_specular[] = {0.5, 0.5, 0.2, 1.0};
|
static const GLfloat back_mat_specular[4] = {0.5f, 0.5f, 0.2f, 1.0f};
|
||||||
static float back_mat_diffuse[] = {1.0, 1.0, 0.2, 1.0};
|
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 const GLfloat lmodel_ambient[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||||
static float lmodel_twoside[] = {GL_FALSE};
|
static const GLfloat lmodel_twoside[1] = {GL_FALSE};
|
||||||
|
|
||||||
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
|
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
|
||||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
|
||||||
@@ -174,58 +177,65 @@ static void InitMaterials(void)
|
|||||||
|
|
||||||
static void Init(void)
|
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);
|
glShadeModel(GL_SMOOTH);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
InitMaterials();
|
InitMaterials();
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glFrustum( -1.0, 1.0, -1.0, 1.0, 5, 25 );
|
glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glTranslatef( 0.0, 0.0, -6.0 );
|
glTranslatef( 0.0, 0.0, -6.0 );
|
||||||
|
|
||||||
#ifdef GL_EXT_vertex_array
|
#ifdef GL_EXT_vertex_array
|
||||||
if (use_vertex_arrays) {
|
if (use_vertex_arrays)
|
||||||
glVertexPointerEXT( 3, GL_FLOAT, 0, numverts, verts );
|
{
|
||||||
glNormalPointerEXT( GL_FLOAT, 0, numverts, norms );
|
glVertexPointerEXT( 3, GL_FLOAT, 0, numverts, verts );
|
||||||
glEnable( GL_VERTEX_ARRAY_EXT );
|
glNormalPointerEXT( GL_FLOAT, 0, numverts, norms );
|
||||||
glEnable( GL_NORMAL_ARRAY_EXT );
|
glEnable( GL_VERTEX_ARRAY_EXT );
|
||||||
}
|
glEnable( GL_NORMAL_ARRAY_EXT );
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static GLenum Args(int argc, wxChar **argv)
|
static GLenum Args(int argc, wxChar **argv)
|
||||||
{
|
{
|
||||||
GLint i;
|
GLint i;
|
||||||
|
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++)
|
||||||
if (wxStrcmp(argv[i], _T("-sb")) == 0) {
|
{
|
||||||
doubleBuffer = GL_FALSE;
|
if (wxStrcmp(argv[i], _T("-sb")) == 0)
|
||||||
}
|
{
|
||||||
else if (wxStrcmp(argv[i], _T("-db")) == 0) {
|
doubleBuffer = GL_FALSE;
|
||||||
doubleBuffer = GL_TRUE;
|
}
|
||||||
}
|
else if (wxStrcmp(argv[i], _T("-db")) == 0)
|
||||||
else if (wxStrcmp(argv[i], _T("-speed")) == 0) {
|
{
|
||||||
speed_test = GL_TRUE;
|
doubleBuffer = GL_TRUE;
|
||||||
doubleBuffer = GL_TRUE;
|
}
|
||||||
}
|
else if (wxStrcmp(argv[i], _T("-speed")) == 0)
|
||||||
else if (wxStrcmp(argv[i], _T("-va")) == 0) {
|
{
|
||||||
use_vertex_arrays = GL_TRUE;
|
speed_test = GL_TRUE;
|
||||||
}
|
doubleBuffer = GL_TRUE;
|
||||||
else {
|
}
|
||||||
wxString msg(_T("Bad option: "));
|
else if (wxStrcmp(argv[i], _T("-va")) == 0)
|
||||||
msg += argv[i];
|
{
|
||||||
wxMessageBox(msg);
|
use_vertex_arrays = GL_TRUE;
|
||||||
return GL_FALSE;
|
}
|
||||||
}
|
else
|
||||||
}
|
{
|
||||||
|
wxString msg = _T("Bad option: ");
|
||||||
|
msg += argv[i];
|
||||||
|
wxMessageBox(msg);
|
||||||
|
return GL_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The following part was written for wxWindows 1.66
|
// The following part was written for wxWindows 1.66
|
||||||
@@ -234,69 +244,70 @@ MyFrame *frame = NULL;
|
|||||||
IMPLEMENT_APP(MyApp)
|
IMPLEMENT_APP(MyApp)
|
||||||
|
|
||||||
// `Main program' equivalent, creating windows and returning main app frame
|
// `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
|
// Create the main frame window
|
||||||
frame = new MyFrame(NULL, _T("Isosurf GL Sample"), wxPoint(50, 50), wxSize(200, 200));
|
frame = new MyFrame(NULL, wxT("wxWindows OpenGL Isosurf Sample"),
|
||||||
|
wxDefaultPosition, wxDefaultSize);
|
||||||
|
|
||||||
// Give it an icon
|
// Give it an icon
|
||||||
frame->SetIcon(wxIcon(_T("mondrian")));
|
frame->SetIcon(wxIcon(_T("mondrian")));
|
||||||
|
|
||||||
// Make a menubar
|
// Make a menubar
|
||||||
wxMenu *fileMenu = new wxMenu;
|
wxMenu *fileMenu = new wxMenu;
|
||||||
|
|
||||||
fileMenu->Append(wxID_EXIT, _T("E&xit"));
|
fileMenu->Append(wxID_EXIT, _T("E&xit"));
|
||||||
wxMenuBar *menuBar = new wxMenuBar;
|
wxMenuBar *menuBar = new wxMenuBar;
|
||||||
menuBar->Append(fileMenu, _T("&File"));
|
menuBar->Append(fileMenu, _T("&File"));
|
||||||
frame->SetMenuBar(menuBar);
|
frame->SetMenuBar(menuBar);
|
||||||
|
|
||||||
// Make a TestGLCanvas
|
// Make a TestGLCanvas
|
||||||
|
|
||||||
// JACS
|
// JACS
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
int *gl_attrib = NULL;
|
int *gl_attrib = NULL;
|
||||||
#else
|
#else
|
||||||
int gl_attrib[20] = { WX_GL_RGBA, WX_GL_MIN_RED, 1, WX_GL_MIN_GREEN, 1,
|
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_MIN_BLUE, 1, WX_GL_DEPTH_SIZE, 1,
|
||||||
WX_GL_DOUBLEBUFFER,
|
WX_GL_DOUBLEBUFFER,
|
||||||
# ifdef __WXMAC__
|
# ifdef __WXMAC__
|
||||||
GL_NONE };
|
GL_NONE };
|
||||||
# else
|
# else
|
||||||
None };
|
None };
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(!doubleBuffer)
|
if(!doubleBuffer)
|
||||||
{
|
{
|
||||||
printf("don't have double buffer, disabling\n");
|
printf("don't have double buffer, disabling\n");
|
||||||
#ifdef __WXGTK__
|
#ifdef __WXGTK__
|
||||||
gl_attrib[9] = None;
|
gl_attrib[9] = None;
|
||||||
#endif
|
#endif
|
||||||
doubleBuffer = GL_FALSE;
|
doubleBuffer = GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if wxUSE_GLCANVAS
|
#if wxUSE_GLCANVAS
|
||||||
|
|
||||||
frame->m_canvas = new TestGLCanvas(frame, -1, wxDefaultPosition, wxDefaultSize,
|
frame->m_canvas = new TestGLCanvas(frame, wxID_ANY, wxDefaultPosition,
|
||||||
0, _T("TestGLCanvas"), gl_attrib );
|
wxDefaultSize, 0, _T("TestGLCanvas"), gl_attrib );
|
||||||
|
|
||||||
// Show the frame
|
// Show the frame
|
||||||
frame->Show(TRUE);
|
frame->Show(true);
|
||||||
|
|
||||||
frame->m_canvas->SetCurrent();
|
frame->m_canvas->SetCurrent();
|
||||||
read_surface( _T("isosurf.dat") );
|
read_surface( _T("isosurf.dat") );
|
||||||
|
|
||||||
Init();
|
Init();
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
|
|
||||||
#else
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,18 +317,29 @@ END_EVENT_TABLE()
|
|||||||
|
|
||||||
// My frame constructor
|
// My frame constructor
|
||||||
MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
|
MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
|
||||||
const wxSize& size, long style):
|
const wxSize& size, long style)
|
||||||
wxFrame(frame, -1, title, pos, size, style)
|
: wxFrame(frame, wxID_ANY, title, pos, size, style)
|
||||||
{
|
{
|
||||||
#if wxUSE_GLCANVAS
|
#if wxUSE_GLCANVAS
|
||||||
m_canvas = NULL;
|
m_canvas = NULL;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Intercept menu commands
|
MyFrame::~MyFrame()
|
||||||
void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event))
|
|
||||||
{
|
{
|
||||||
Destroy();
|
#if wxUSE_GLCANVAS
|
||||||
|
if (m_canvas)
|
||||||
|
{
|
||||||
|
delete m_canvas; m_canvas = NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept menu commands
|
||||||
|
void MyFrame::OnExit( wxCommandEvent& WXUNUSED(event) )
|
||||||
|
{
|
||||||
|
// true is to force the frame to close
|
||||||
|
Close(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -335,21 +357,23 @@ BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas)
|
|||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id,
|
TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id,
|
||||||
const wxPoint& pos, const wxSize& size, long style, const wxString& name, int* gl_attrib):
|
const wxPoint& pos, const wxSize& size, long style,
|
||||||
wxGLCanvas(parent, id, pos, size, style, name, gl_attrib)
|
const wxString& name, int* gl_attrib)
|
||||||
|
: wxGLCanvas(parent, id, pos, size, style, name, gl_attrib)
|
||||||
{
|
{
|
||||||
parent->Show(TRUE);
|
parent->Show(true);
|
||||||
SetCurrent();
|
SetCurrent();
|
||||||
|
|
||||||
/* Make sure server supports the vertex array extension */
|
/* Make sure server supports the vertex array extension */
|
||||||
char* extensions = (char *) glGetString( GL_EXTENSIONS );
|
char* extensions = (char *) glGetString( GL_EXTENSIONS );
|
||||||
if (!extensions || !strstr( extensions, "GL_EXT_vertex_array" )) {
|
if (!extensions || !strstr( extensions, "GL_EXT_vertex_array" ))
|
||||||
use_vertex_arrays = GL_FALSE;
|
{
|
||||||
}
|
use_vertex_arrays = GL_FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TestGLCanvas::~TestGLCanvas(void)
|
TestGLCanvas::~TestGLCanvas()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -388,45 +412,58 @@ void TestGLCanvas::OnSize(wxSizeEvent& event)
|
|||||||
|
|
||||||
void TestGLCanvas::OnChar(wxKeyEvent& event)
|
void TestGLCanvas::OnChar(wxKeyEvent& event)
|
||||||
{
|
{
|
||||||
switch(event.GetKeyCode()) {
|
switch( event.GetKeyCode() )
|
||||||
|
{
|
||||||
case WXK_ESCAPE:
|
case WXK_ESCAPE:
|
||||||
exit(0);
|
wxTheApp->ExitMainLoop();
|
||||||
|
return;
|
||||||
|
|
||||||
case WXK_LEFT:
|
case WXK_LEFT:
|
||||||
yrot -= 15.0;
|
yrot -= 15.0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WXK_RIGHT:
|
case WXK_RIGHT:
|
||||||
yrot += 15.0;
|
yrot += 15.0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WXK_UP:
|
case WXK_UP:
|
||||||
xrot += 15.0;
|
xrot += 15.0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WXK_DOWN:
|
case WXK_DOWN:
|
||||||
xrot -= 15.0;
|
xrot -= 15.0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's': case 'S':
|
case 's': case 'S':
|
||||||
smooth = !smooth;
|
smooth = !smooth;
|
||||||
if (smooth) {
|
if (smooth)
|
||||||
glShadeModel(GL_SMOOTH);
|
{
|
||||||
} else {
|
glShadeModel(GL_SMOOTH);
|
||||||
glShadeModel(GL_FLAT);
|
}
|
||||||
}
|
else
|
||||||
break;
|
{
|
||||||
|
glShadeModel(GL_FLAT);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 'l': case 'L':
|
case 'l': case 'L':
|
||||||
lighting = !lighting;
|
lighting = !lighting;
|
||||||
if (lighting) {
|
if (lighting)
|
||||||
glEnable(GL_LIGHTING);
|
{
|
||||||
} else {
|
glEnable(GL_LIGHTING);
|
||||||
glDisable(GL_LIGHTING);
|
}
|
||||||
}
|
else
|
||||||
break;
|
{
|
||||||
default:
|
glDisable(GL_LIGHTING);
|
||||||
{
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
event.Skip();
|
event.Skip();
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Refresh(FALSE);
|
Refresh(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestGLCanvas::OnMouseEvent(wxMouseEvent& event)
|
void TestGLCanvas::OnMouseEvent(wxMouseEvent& event)
|
||||||
@@ -435,23 +472,30 @@ void TestGLCanvas::OnMouseEvent(wxMouseEvent& event)
|
|||||||
static float last_x, last_y;
|
static float last_x, last_y;
|
||||||
|
|
||||||
//printf("%f %f %d\n", event.GetX(), event.GetY(), (int)event.LeftIsDown());
|
//printf("%f %f %d\n", event.GetX(), event.GetY(), (int)event.LeftIsDown());
|
||||||
if(event.LeftIsDown()) {
|
if(event.LeftIsDown())
|
||||||
if(!dragging) {
|
{
|
||||||
dragging = 1;
|
if(!dragging)
|
||||||
} else {
|
{
|
||||||
yrot += (event.GetX() - last_x)*1.0;
|
dragging = 1;
|
||||||
xrot += (event.GetY() - last_y)*1.0;
|
}
|
||||||
Refresh(FALSE);
|
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();
|
else
|
||||||
last_y = event.GetY();
|
dragging = 0;
|
||||||
} else
|
|
||||||
dragging = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestGLCanvas::OnEraseBackground(wxEraseEvent& WXUNUSED(event))
|
void TestGLCanvas::OnEraseBackground( wxEraseEvent& WXUNUSED(event) )
|
||||||
{
|
{
|
||||||
// Do nothing, to avoid flashing.
|
// Do nothing, to avoid flashing.
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif // #if wxUSE_GLCANVAS
|
||||||
|
|
||||||
|
@@ -14,43 +14,53 @@
|
|||||||
|
|
||||||
// Define a new application type
|
// Define a new application type
|
||||||
class MyApp: public wxApp
|
class MyApp: public wxApp
|
||||||
{ public:
|
{
|
||||||
bool OnInit(void);
|
public:
|
||||||
|
bool OnInit();
|
||||||
};
|
};
|
||||||
|
|
||||||
#if wxUSE_GLCANVAS
|
#if wxUSE_GLCANVAS
|
||||||
|
|
||||||
class TestGLCanvas: public wxGLCanvas
|
class TestGLCanvas: public wxGLCanvas
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TestGLCanvas(wxWindow *parent, const wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,
|
TestGLCanvas(wxWindow *parent, wxWindowID id = wxID_ANY,
|
||||||
const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = _T("TestGLCanvas"),
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
int* gl_attrib = NULL);
|
const wxSize& size = wxDefaultSize, long style = 0,
|
||||||
~TestGLCanvas(void);
|
const wxString& name = _T("TestGLCanvas"), int *gl_attrib = NULL);
|
||||||
|
|
||||||
void OnPaint(wxPaintEvent& event);
|
~TestGLCanvas();
|
||||||
void OnSize(wxSizeEvent& event);
|
|
||||||
void OnEraseBackground(wxEraseEvent& event);
|
|
||||||
void OnChar(wxKeyEvent& event);
|
|
||||||
void OnMouseEvent(wxMouseEvent& event);
|
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
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
|
class MyFrame: public wxFrame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size,
|
MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
|
||||||
long style = wxDEFAULT_FRAME_STYLE);
|
const wxSize& size, long style = wxDEFAULT_FRAME_STYLE);
|
||||||
|
|
||||||
|
virtual ~MyFrame();
|
||||||
|
|
||||||
|
#if wxUSE_GLCANVAS
|
||||||
|
TestGLCanvas *m_canvas;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private :
|
||||||
|
|
||||||
void OnExit(wxCommandEvent& event);
|
void OnExit(wxCommandEvent& event);
|
||||||
public:
|
|
||||||
#if wxUSE_GLCANVAS
|
|
||||||
TestGLCanvas* m_canvas;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // #ifndef _WX_ISOSURF_H_
|
||||||
|
|
||||||
|
@@ -253,14 +253,9 @@ int lw_is_lwobject(const char *lw_file)
|
|||||||
|
|
||||||
lwObject *lw_object_read(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 */
|
/* open file */
|
||||||
f = fopen(lw_file, "rb");
|
FILE *f = fopen(lw_file, "rb");
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -270,7 +265,10 @@ lwObject *lw_object_read(const char *lw_file)
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
form_bytes = read_long(f);
|
|
||||||
|
wxInt32 read_bytes = 0;
|
||||||
|
|
||||||
|
wxInt32 form_bytes = read_long(f);
|
||||||
read_bytes += 4;
|
read_bytes += 4;
|
||||||
|
|
||||||
if (read_long(f) != ID_LWOB) {
|
if (read_long(f) != ID_LWOB) {
|
||||||
@@ -279,7 +277,7 @@ lwObject *lw_object_read(const char *lw_file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* create new lwObject */
|
/* create new lwObject */
|
||||||
lw_object = (lwObject*) calloc(sizeof(lwObject),1);
|
lwObject *lw_object = (lwObject*) calloc(sizeof(lwObject),1);
|
||||||
|
|
||||||
/* read chunks */
|
/* read chunks */
|
||||||
while (read_bytes < form_bytes) {
|
while (read_bytes < form_bytes) {
|
||||||
|
@@ -38,36 +38,39 @@
|
|||||||
|
|
||||||
#define VIEW_ASPECT 1.3
|
#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()
|
bool MyApp::OnInit()
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Create the main frame window */
|
// Create the main frame window
|
||||||
MyFrame *frame = new MyFrame(NULL, wxT("wxWindows OpenGL Demo"), wxPoint(50, 50), wxSize(400, 300));
|
MyFrame *frame = new MyFrame(NULL, wxT("wxWindows OpenGL Penguin Sample"),
|
||||||
|
wxDefaultPosition, wxDefaultSize);
|
||||||
|
|
||||||
/* Make a menubar */
|
/* Make a menubar */
|
||||||
wxMenu *fileMenu = new wxMenu;
|
wxMenu *fileMenu = new wxMenu;
|
||||||
|
|
||||||
fileMenu->Append(wxID_EXIT, wxT("E&xit"));
|
fileMenu->Append(wxID_EXIT, wxT("E&xit"));
|
||||||
wxMenuBar *menuBar = new wxMenuBar;
|
wxMenuBar *menuBar = new wxMenuBar;
|
||||||
menuBar->Append(fileMenu, wxT("&File"));
|
menuBar->Append(fileMenu, wxT("&File"));
|
||||||
frame->SetMenuBar(menuBar);
|
frame->SetMenuBar(menuBar);
|
||||||
|
|
||||||
#if wxUSE_GLCANVAS
|
#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 */
|
/* Load file wiht mesh data */
|
||||||
frame->GetCanvas()->LoadLWO( wxT("penguin.lwo") );
|
frame->GetCanvas()->LoadLWO( wxT("penguin.lwo") );
|
||||||
|
|
||||||
/* Show the frame */
|
/* Show the frame */
|
||||||
frame->Show(TRUE);
|
frame->Show(true);
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
#else
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
@@ -80,8 +83,8 @@ END_EVENT_TABLE()
|
|||||||
|
|
||||||
/* My frame constructor */
|
/* My frame constructor */
|
||||||
MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
|
MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
|
||||||
const wxSize& size, long style):
|
const wxSize& size, long style)
|
||||||
wxFrame(frame, -1, title, pos, size, style)
|
: wxFrame(frame, wxID_ANY, title, pos, size, style)
|
||||||
{
|
{
|
||||||
#if wxUSE_GLCANVAS
|
#if wxUSE_GLCANVAS
|
||||||
m_canvas = NULL;
|
m_canvas = NULL;
|
||||||
@@ -89,9 +92,10 @@ MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Intercept menu commands */
|
/* 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
|
#if wxUSE_GLCANVAS
|
||||||
@@ -104,13 +108,13 @@ BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas)
|
|||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id,
|
TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id,
|
||||||
const wxPoint& pos, const wxSize& size, long style, const wxString& name):
|
const wxPoint& pos, const wxSize& size, long style, const wxString& name)
|
||||||
wxGLCanvas(parent, id, pos, size, style, name)
|
: wxGLCanvas(parent, id, pos, size, style, name)
|
||||||
{
|
{
|
||||||
block = FALSE;
|
block = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TestGLCanvas::~TestGLCanvas(void)
|
TestGLCanvas::~TestGLCanvas()
|
||||||
{
|
{
|
||||||
/* destroy mesh */
|
/* destroy mesh */
|
||||||
lw_object_free(info.lwobject);
|
lw_object_free(info.lwobject);
|
||||||
@@ -127,37 +131,37 @@ void TestGLCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) )
|
|||||||
|
|
||||||
SetCurrent();
|
SetCurrent();
|
||||||
|
|
||||||
/* initialize OpenGL */
|
// Initialize OpenGL
|
||||||
if (info.do_init == TRUE)
|
if (info.do_init)
|
||||||
{
|
{
|
||||||
InitGL();
|
InitGL();
|
||||||
info.do_init = FALSE;
|
info.do_init = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* view */
|
// View
|
||||||
glMatrixMode( GL_PROJECTION );
|
glMatrixMode( GL_PROJECTION );
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluPerspective( info.zoom, VIEW_ASPECT, 1, 100 );
|
gluPerspective( info.zoom, VIEW_ASPECT, 1.0, 100.0 );
|
||||||
glMatrixMode( GL_MODELVIEW );
|
glMatrixMode( GL_MODELVIEW );
|
||||||
|
|
||||||
/* clear */
|
// Clear
|
||||||
glClearColor( .3, .4, .6, 1 );
|
glClearColor( 0.3f, 0.4f, 0.6f, 1.0f );
|
||||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||||
|
|
||||||
/* transformations */
|
// Transformations
|
||||||
GLfloat m[4][4];
|
GLfloat m[4][4];
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glTranslatef( 0, 0, -30 );
|
glTranslatef( 0.0f, 0.0f, -30.0f );
|
||||||
build_rotmatrix( m,info.quat );
|
build_rotmatrix( m,info.quat );
|
||||||
glMultMatrixf( &m[0][0] );
|
glMultMatrixf( &m[0][0] );
|
||||||
|
|
||||||
/* draw object */
|
// Draw object
|
||||||
lw_object_show( info.lwobject );
|
lw_object_show( info.lwobject );
|
||||||
|
|
||||||
/* flush */
|
// Flush
|
||||||
glFlush();
|
glFlush();
|
||||||
|
|
||||||
/* swap */
|
// Swap
|
||||||
SwapBuffers();
|
SwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +174,7 @@ void TestGLCanvas::OnSize(wxSizeEvent& event)
|
|||||||
int w, h;
|
int w, h;
|
||||||
GetClientSize(&w, &h);
|
GetClientSize(&w, &h);
|
||||||
#ifndef __WXMOTIF__
|
#ifndef __WXMOTIF__
|
||||||
if (GetContext())
|
if ( GetContext() )
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
SetCurrent();
|
SetCurrent();
|
||||||
@@ -195,43 +199,50 @@ void TestGLCanvas::LoadLWO(const wxString &filename)
|
|||||||
lw_object_scale(lwobject, 10.0 / lw_object_radius(lwobject));
|
lw_object_scale(lwobject, 10.0 / lw_object_radius(lwobject));
|
||||||
|
|
||||||
/* set up mesh info */
|
/* set up mesh info */
|
||||||
info.do_init = TRUE;
|
info.do_init = true;
|
||||||
info.lwobject = lwobject;
|
info.lwobject = lwobject;
|
||||||
info.beginx = 0;
|
info.beginx = 0.0f;
|
||||||
info.beginy = 0;
|
info.beginy = 0.0f;
|
||||||
info.zoom = 45;
|
info.zoom = 45.0f;
|
||||||
trackball( info.quat, 0.0, 0.0, 0.0, 0.0 );
|
trackball( info.quat, 0.0f, 0.0f, 0.0f, 0.0f );
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestGLCanvas::OnMouse( wxMouseEvent& event )
|
void TestGLCanvas::OnMouse( wxMouseEvent& event )
|
||||||
{
|
{
|
||||||
wxSize sz(GetClientSize());
|
|
||||||
if (event.Dragging())
|
if ( event.Dragging() )
|
||||||
{
|
{
|
||||||
|
wxSize sz( GetClientSize() );
|
||||||
|
|
||||||
/* drag in progress, simulate trackball */
|
/* drag in progress, simulate trackball */
|
||||||
float spin_quat[4];
|
float spin_quat[4];
|
||||||
trackball(spin_quat,
|
trackball(spin_quat,
|
||||||
(2.0*info.beginx - sz.x) / sz.x,
|
(2.0*info.beginx - sz.x) / sz.x,
|
||||||
( sz.y - 2.0*info.beginy) / sz.y,
|
( sz.y - 2.0*info.beginy) / sz.y,
|
||||||
( 2.0*event.GetX() - sz.x) / sz.x,
|
( 2.0*event.GetX() - sz.x) / sz.x,
|
||||||
( sz.y - 2.0*event.GetY()) / sz.y);
|
( sz.y - 2.0*event.GetY()) / sz.y);
|
||||||
|
|
||||||
add_quats( spin_quat, info.quat, info.quat );
|
add_quats( spin_quat, info.quat, info.quat );
|
||||||
|
|
||||||
/* orientation has changed, redraw mesh */
|
/* orientation has changed, redraw mesh */
|
||||||
Refresh(FALSE);
|
Refresh(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
info.beginx = event.GetX();
|
info.beginx = event.GetX();
|
||||||
info.beginy = event.GetY();
|
info.beginy = event.GetY();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestGLCanvas::InitGL(void)
|
void TestGLCanvas::InitGL()
|
||||||
{
|
{
|
||||||
GLfloat light0_pos[4] = { -50.0, 50.0, 0.0, 0.0 };
|
static const GLfloat light0_pos[4] = { -50.0f, 50.0f, 0.0f, 0.0f };
|
||||||
GLfloat light0_color[4] = { .6, .6, .6, 1.0 }; /* white light */
|
|
||||||
GLfloat light1_pos[4] = { 50.0, 50.0, 0.0, 0.0 };
|
// white light
|
||||||
GLfloat light1_color[4] = { .4, .4, 1, 1.0 }; /* cold blue 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 */
|
/* remove back faces */
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
@@ -252,9 +263,9 @@ void TestGLCanvas::InitGL(void)
|
|||||||
glEnable(GL_LIGHT1);
|
glEnable(GL_LIGHT1);
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
|
|
||||||
glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
|
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
||||||
glEnable(GL_COLOR_MATERIAL);
|
glEnable(GL_COLOR_MATERIAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif // #if wxUSE_GLCANVAS
|
||||||
|
@@ -20,7 +20,8 @@
|
|||||||
|
|
||||||
#include "wx/glcanvas.h"
|
#include "wx/glcanvas.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#include "lw.h"
|
#include "lw.h"
|
||||||
#include "trackball.h"
|
#include "trackball.h"
|
||||||
}
|
}
|
||||||
@@ -29,7 +30,7 @@ extern "C" {
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
// gint do_init; /* true if initgl not yet called */
|
// gint do_init; /* true if initgl not yet called */
|
||||||
int do_init;
|
bool do_init;
|
||||||
lwObject *lwobject; /* lightwave object mesh */
|
lwObject *lwobject; /* lightwave object mesh */
|
||||||
float beginx,beginy; /* position of mouse */
|
float beginx,beginy; /* position of mouse */
|
||||||
float quat[4]; /* orientation of object */
|
float quat[4]; /* orientation of object */
|
||||||
@@ -41,7 +42,7 @@ typedef struct
|
|||||||
class MyApp: public wxApp
|
class MyApp: public wxApp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool OnInit(void);
|
bool OnInit();
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Define a new frame type */
|
/* Define a new frame type */
|
||||||
@@ -50,17 +51,17 @@ class TestGLCanvas;
|
|||||||
class MyFrame: public wxFrame
|
class MyFrame: public wxFrame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size,
|
MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
|
||||||
long style = wxDEFAULT_FRAME_STYLE);
|
const wxSize& size, long style = wxDEFAULT_FRAME_STYLE);
|
||||||
|
|
||||||
void OnExit(wxCommandEvent& event);
|
void OnExit(wxCommandEvent& event);
|
||||||
|
|
||||||
#if wxUSE_GLCANVAS
|
#if wxUSE_GLCANVAS
|
||||||
void SetCanvas( TestGLCanvas *canvas ) { m_canvas = canvas; }
|
void SetCanvas( TestGLCanvas *canvas ) { m_canvas = canvas; }
|
||||||
TestGLCanvas *GetCanvas() { return m_canvas; }
|
TestGLCanvas *GetCanvas() { return m_canvas; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TestGLCanvas* m_canvas;
|
TestGLCanvas *m_canvas;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
@@ -71,16 +72,19 @@ private:
|
|||||||
class TestGLCanvas: public wxGLCanvas
|
class TestGLCanvas: public wxGLCanvas
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TestGLCanvas(wxWindow *parent, const wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,
|
TestGLCanvas(wxWindow *parent, wxWindowID id = wxID_ANY,
|
||||||
const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxT("TestGLCanvas"));
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
~TestGLCanvas(void);
|
const wxSize& size = wxDefaultSize, long style = 0,
|
||||||
|
const wxString& name = wxT("TestGLCanvas"));
|
||||||
|
|
||||||
|
~TestGLCanvas();
|
||||||
|
|
||||||
void OnPaint(wxPaintEvent& event);
|
void OnPaint(wxPaintEvent& event);
|
||||||
void OnSize(wxSizeEvent& event);
|
void OnSize(wxSizeEvent& event);
|
||||||
void OnEraseBackground(wxEraseEvent& event);
|
void OnEraseBackground(wxEraseEvent& event);
|
||||||
void LoadLWO( const wxString &filename);
|
void LoadLWO( const wxString &filename);
|
||||||
void OnMouse( wxMouseEvent& event );
|
void OnMouse( wxMouseEvent& event );
|
||||||
void InitGL(void);
|
void InitGL();
|
||||||
|
|
||||||
mesh_info info;
|
mesh_info info;
|
||||||
bool block;
|
bool block;
|
||||||
@@ -89,7 +93,7 @@ private:
|
|||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // #if wxUSE_GLCANVAS
|
||||||
|
|
||||||
#endif
|
#endif // #ifndef _WX_PENGUIN_H_
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user