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:
@@ -38,36 +38,39 @@
|
||||
|
||||
#define VIEW_ASPECT 1.3
|
||||
|
||||
/* `Main program' equivalent, creating windows and returning main app frame */
|
||||
// `Main program' equivalent, creating windows and returning main app frame
|
||||
bool MyApp::OnInit()
|
||||
{
|
||||
|
||||
/* Create the main frame window */
|
||||
MyFrame *frame = new MyFrame(NULL, wxT("wxWindows OpenGL Demo"), wxPoint(50, 50), wxSize(400, 300));
|
||||
// Create the main frame window
|
||||
MyFrame *frame = new MyFrame(NULL, wxT("wxWindows OpenGL Penguin Sample"),
|
||||
wxDefaultPosition, wxDefaultSize);
|
||||
|
||||
/* Make a menubar */
|
||||
wxMenu *fileMenu = new wxMenu;
|
||||
/* Make a menubar */
|
||||
wxMenu *fileMenu = new wxMenu;
|
||||
|
||||
fileMenu->Append(wxID_EXIT, wxT("E&xit"));
|
||||
wxMenuBar *menuBar = new wxMenuBar;
|
||||
menuBar->Append(fileMenu, wxT("&File"));
|
||||
frame->SetMenuBar(menuBar);
|
||||
fileMenu->Append(wxID_EXIT, wxT("E&xit"));
|
||||
wxMenuBar *menuBar = new wxMenuBar;
|
||||
menuBar->Append(fileMenu, wxT("&File"));
|
||||
frame->SetMenuBar(menuBar);
|
||||
|
||||
#if wxUSE_GLCANVAS
|
||||
frame->SetCanvas( new TestGLCanvas(frame, -1, wxPoint(0, 0), wxSize(200, 200), wxSUNKEN_BORDER) );
|
||||
frame->SetCanvas( new TestGLCanvas(frame, wxID_ANY, wxDefaultPosition,
|
||||
wxSize(200, 200), wxSUNKEN_BORDER) );
|
||||
|
||||
/* Load file wiht mesh data */
|
||||
frame->GetCanvas()->LoadLWO( wxT("penguin.lwo") );
|
||||
/* Load file wiht mesh data */
|
||||
frame->GetCanvas()->LoadLWO( wxT("penguin.lwo") );
|
||||
|
||||
/* Show the frame */
|
||||
frame->Show(TRUE);
|
||||
|
||||
return TRUE;
|
||||
/* Show the frame */
|
||||
frame->Show(true);
|
||||
|
||||
return true;
|
||||
#else
|
||||
|
||||
wxMessageBox( _T("This sample has to be compiled with wxUSE_GLCANVAS"), _T("Building error"), wxOK);
|
||||
wxMessageBox( _T("This sample has to be compiled with wxUSE_GLCANVAS"),
|
||||
_T("Building error"), wxOK);
|
||||
|
||||
return FALSE;
|
||||
return false;
|
||||
|
||||
#endif
|
||||
}
|
||||
@@ -80,8 +83,8 @@ END_EVENT_TABLE()
|
||||
|
||||
/* My frame constructor */
|
||||
MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
|
||||
const wxSize& size, long style):
|
||||
wxFrame(frame, -1, title, pos, size, style)
|
||||
const wxSize& size, long style)
|
||||
: wxFrame(frame, wxID_ANY, title, pos, size, style)
|
||||
{
|
||||
#if wxUSE_GLCANVAS
|
||||
m_canvas = NULL;
|
||||
@@ -89,9 +92,10 @@ MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
|
||||
}
|
||||
|
||||
/* Intercept menu commands */
|
||||
void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event))
|
||||
void MyFrame::OnExit( wxCommandEvent& WXUNUSED(event) )
|
||||
{
|
||||
Destroy();
|
||||
// true is to force the frame to close
|
||||
Close(true);
|
||||
}
|
||||
|
||||
#if wxUSE_GLCANVAS
|
||||
@@ -104,13 +108,13 @@ BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id,
|
||||
const wxPoint& pos, const wxSize& size, long style, const wxString& name):
|
||||
wxGLCanvas(parent, id, pos, size, style, name)
|
||||
const wxPoint& pos, const wxSize& size, long style, const wxString& name)
|
||||
: wxGLCanvas(parent, id, pos, size, style, name)
|
||||
{
|
||||
block = FALSE;
|
||||
block = false;
|
||||
}
|
||||
|
||||
TestGLCanvas::~TestGLCanvas(void)
|
||||
TestGLCanvas::~TestGLCanvas()
|
||||
{
|
||||
/* destroy mesh */
|
||||
lw_object_free(info.lwobject);
|
||||
@@ -126,38 +130,38 @@ void TestGLCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) )
|
||||
#endif
|
||||
|
||||
SetCurrent();
|
||||
|
||||
/* initialize OpenGL */
|
||||
if (info.do_init == TRUE)
|
||||
|
||||
// Initialize OpenGL
|
||||
if (info.do_init)
|
||||
{
|
||||
InitGL();
|
||||
info.do_init = FALSE;
|
||||
info.do_init = false;
|
||||
}
|
||||
|
||||
/* view */
|
||||
|
||||
// View
|
||||
glMatrixMode( GL_PROJECTION );
|
||||
glLoadIdentity();
|
||||
gluPerspective( info.zoom, VIEW_ASPECT, 1, 100 );
|
||||
gluPerspective( info.zoom, VIEW_ASPECT, 1.0, 100.0 );
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
|
||||
/* clear */
|
||||
glClearColor( .3, .4, .6, 1 );
|
||||
// Clear
|
||||
glClearColor( 0.3f, 0.4f, 0.6f, 1.0f );
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
|
||||
/* transformations */
|
||||
// Transformations
|
||||
GLfloat m[4][4];
|
||||
glLoadIdentity();
|
||||
glTranslatef( 0, 0, -30 );
|
||||
glTranslatef( 0.0f, 0.0f, -30.0f );
|
||||
build_rotmatrix( m,info.quat );
|
||||
glMultMatrixf( &m[0][0] );
|
||||
|
||||
/* draw object */
|
||||
// Draw object
|
||||
lw_object_show( info.lwobject );
|
||||
|
||||
/* flush */
|
||||
|
||||
// Flush
|
||||
glFlush();
|
||||
|
||||
/* swap */
|
||||
// Swap
|
||||
SwapBuffers();
|
||||
}
|
||||
|
||||
@@ -165,12 +169,12 @@ void TestGLCanvas::OnSize(wxSizeEvent& event)
|
||||
{
|
||||
// this is also necessary to update the context on some platforms
|
||||
wxGLCanvas::OnSize(event);
|
||||
|
||||
|
||||
// set GL viewport (not called by wxGLCanvas::OnSize on all platforms...)
|
||||
int w, h;
|
||||
GetClientSize(&w, &h);
|
||||
#ifndef __WXMOTIF__
|
||||
if (GetContext())
|
||||
if ( GetContext() )
|
||||
#endif
|
||||
{
|
||||
SetCurrent();
|
||||
@@ -187,56 +191,63 @@ void TestGLCanvas::LoadLWO(const wxString &filename)
|
||||
{
|
||||
/* test if lightwave object */
|
||||
if (!lw_is_lwobject(filename.mb_str())) return;
|
||||
|
||||
|
||||
/* read lightwave object */
|
||||
lwObject *lwobject = lw_object_read(filename.mb_str());
|
||||
|
||||
|
||||
/* scale */
|
||||
lw_object_scale(lwobject, 10.0 / lw_object_radius(lwobject));
|
||||
|
||||
|
||||
/* set up mesh info */
|
||||
info.do_init = TRUE;
|
||||
info.do_init = true;
|
||||
info.lwobject = lwobject;
|
||||
info.beginx = 0;
|
||||
info.beginy = 0;
|
||||
info.zoom = 45;
|
||||
trackball( info.quat, 0.0, 0.0, 0.0, 0.0 );
|
||||
info.beginx = 0.0f;
|
||||
info.beginy = 0.0f;
|
||||
info.zoom = 45.0f;
|
||||
trackball( info.quat, 0.0f, 0.0f, 0.0f, 0.0f );
|
||||
}
|
||||
|
||||
void TestGLCanvas::OnMouse( wxMouseEvent& event )
|
||||
{
|
||||
wxSize sz(GetClientSize());
|
||||
if (event.Dragging())
|
||||
|
||||
if ( event.Dragging() )
|
||||
{
|
||||
wxSize sz( GetClientSize() );
|
||||
|
||||
/* drag in progress, simulate trackball */
|
||||
float spin_quat[4];
|
||||
trackball(spin_quat,
|
||||
(2.0*info.beginx - sz.x) / sz.x,
|
||||
( sz.y - 2.0*info.beginy) / sz.y,
|
||||
( 2.0*event.GetX() - sz.x) / sz.x,
|
||||
( sz.y - 2.0*event.GetY()) / sz.y);
|
||||
|
||||
(2.0*info.beginx - sz.x) / sz.x,
|
||||
( sz.y - 2.0*info.beginy) / sz.y,
|
||||
( 2.0*event.GetX() - sz.x) / sz.x,
|
||||
( sz.y - 2.0*event.GetY()) / sz.y);
|
||||
|
||||
add_quats( spin_quat, info.quat, info.quat );
|
||||
|
||||
/* orientation has changed, redraw mesh */
|
||||
Refresh(FALSE);
|
||||
Refresh(false);
|
||||
}
|
||||
|
||||
info.beginx = event.GetX();
|
||||
info.beginy = event.GetY();
|
||||
}
|
||||
|
||||
void TestGLCanvas::InitGL(void)
|
||||
void TestGLCanvas::InitGL()
|
||||
{
|
||||
GLfloat light0_pos[4] = { -50.0, 50.0, 0.0, 0.0 };
|
||||
GLfloat light0_color[4] = { .6, .6, .6, 1.0 }; /* white light */
|
||||
GLfloat light1_pos[4] = { 50.0, 50.0, 0.0, 0.0 };
|
||||
GLfloat light1_color[4] = { .4, .4, 1, 1.0 }; /* cold blue light */
|
||||
static const GLfloat light0_pos[4] = { -50.0f, 50.0f, 0.0f, 0.0f };
|
||||
|
||||
// white light
|
||||
static const GLfloat light0_color[4] = { 0.6f, 0.6f, 0.6f, 1.0f };
|
||||
|
||||
static const GLfloat light1_pos[4] = { 50.0f, 50.0f, 0.0f, 0.0f };
|
||||
|
||||
// cold blue light
|
||||
static const GLfloat light1_color[4] = { 0.4f, 0.4f, 1.0f, 1.0f };
|
||||
|
||||
/* remove back faces */
|
||||
glDisable(GL_CULL_FACE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
|
||||
/* speedups */
|
||||
glEnable(GL_DITHER);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
@@ -245,16 +256,16 @@ void TestGLCanvas::InitGL(void)
|
||||
|
||||
/* light */
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light0_pos);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_color);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_color);
|
||||
glLightfv(GL_LIGHT1, GL_POSITION, light1_pos);
|
||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_color);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_LIGHT1);
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
|
||||
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
#endif // #if wxUSE_GLCANVAS
|
||||
|
Reference in New Issue
Block a user