X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b1d4dd7add411ebff1ce4a8d1d992e0e43ee26b1..8829531cdbc850cb9d6221e517edef26df8ebcee:/samples/opengl/isosurf/isosurf.cpp diff --git a/samples/opengl/isosurf/isosurf.cpp b/samples/opengl/isosurf/isosurf.cpp index 9e474230f1..781d2a8a16 100644 --- a/samples/opengl/isosurf/isosurf.cpp +++ b/samples/opengl/isosurf/isosurf.cpp @@ -9,11 +9,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation -#pragma interface -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -26,23 +21,24 @@ #endif #if !wxUSE_GLCANVAS -#error Please set wxUSE_GLCANVAS to 1 in setup.h. + #error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library" #endif #include "wx/timer.h" #include "wx/glcanvas.h" - -#ifdef __WXMAC__ -# ifdef __DARWIN__ -# include -# include -# else -# include -# include -# endif +#include "wx/math.h" + +#if defined(__WXMAC__) || defined(__WXCOCOA__) +# ifdef __DARWIN__ +# include +# include +# else +# include +# include +# endif #else -# include -# include +# include +# include #endif // disabled because this has apparently changed in OpenGL 1.2, so doesn't link @@ -53,9 +49,9 @@ #include "isosurf.h" -// The following part is taken largely unchanged from the original C Version +#include "../../sample.xpm" -#include +// The following part is taken largely unchanged from the original C Version GLboolean speed_test = GL_FALSE; GLboolean use_vertex_arrays = GL_FALSE; @@ -76,60 +72,63 @@ static GLfloat xrot; static GLfloat yrot; -static void read_surface( char *filename ) +static void read_surface( const wxChar *filename ) { - FILE *f; - - f = fopen(filename,"r"); - if (!f) { - wxString msg("Couldn't read "); - msg += filename; - wxMessageBox(msg); - return; - } - - numverts = 0; - while (!feof(f) && numvertsSetIcon(wxIcon("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, "E&xit"); - wxMenuBar *menuBar = new wxMenuBar; - menuBar->Append(fileMenu, "&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, -# ifdef __WXMAC__ - GL_NONE }; + 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, +# if defined(__WXMAC__) || defined(__WXCOCOA__) + 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; - } - - frame->m_canvas = new TestGLCanvas(frame, -1, wxDefaultPosition, wxDefaultSize, - 0, "TestGLCanvas", gl_attrib ); + doubleBuffer = GL_FALSE; + } + + 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( "isosurf.dat" ); + frame->m_canvas->SetCurrent(); + read_surface( _T("isosurf.dat") ); - Init(); + Init(); - return TRUE; + return true; } BEGIN_EVENT_TABLE(MyFrame, wxFrame) @@ -301,16 +308,23 @@ 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) { m_canvas = NULL; + SetIcon(wxIcon(sample_xpm)); +} + +MyFrame::~MyFrame() +{ + delete m_canvas; } // Intercept menu commands -void MyFrame::OnExit(wxCommandEvent& event) +void MyFrame::OnExit( wxCommandEvent& WXUNUSED(event) ) { - Destroy(); + // true is to force the frame to close + Close(true); } /* @@ -326,25 +340,23 @@ BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas) END_EVENT_TABLE() TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id, - const wxPoint& pos, const wxSize& size, long style, const wxString& name, int* gl_attrib): - wxGLCanvas(parent, id, pos, size, style, name, gl_attrib) + const wxPoint& pos, const wxSize& size, long style, + const wxString& name, int* gl_attrib) + : wxGLCanvas(parent, id, pos, size, style|wxFULL_REPAINT_ON_RESIZE, 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(); -TestGLCanvas::~TestGLCanvas(void) -{ + /* 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; + } } -void TestGLCanvas::OnPaint( wxPaintEvent& event ) + +void TestGLCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) ) { // This is a dummy, to avoid an endless succession of paint messages. // OnPaint handlers must always create a wxPaintDC. @@ -364,7 +376,7 @@ void TestGLCanvas::OnSize(wxSizeEvent& event) { // this is also necessary to update the context on some platforms wxGLCanvas::OnSize(event); - + // set GL viewport (not called by wxGLCanvas::OnSize on all platforms...) int w, h; GetClientSize(&w, &h); @@ -379,45 +391,58 @@ void TestGLCanvas::OnSize(wxSizeEvent& event) void TestGLCanvas::OnChar(wxKeyEvent& event) { - switch(event.GetKeyCode()) { + switch( event.GetKeyCode() ) + { case WXK_ESCAPE: - exit(0); + wxTheApp->ExitMainLoop(); + return; + case WXK_LEFT: - yrot -= 15.0; - break; + yrot -= 15.0; + break; + case WXK_RIGHT: - yrot += 15.0; - break; + yrot += 15.0; + break; + case WXK_UP: - xrot += 15.0; - break; + xrot += 15.0; + break; + case WXK_DOWN: - xrot -= 15.0; - break; + xrot -= 15.0; + break; + case 's': case 'S': - smooth = !smooth; - if (smooth) { - glShadeModel(GL_SMOOTH); - } else { - glShadeModel(GL_FLAT); - } - break; + smooth = !smooth; + if (smooth) + { + glShadeModel(GL_SMOOTH); + } + else + { + glShadeModel(GL_FLAT); + } + break; + case 'l': case 'L': - lighting = !lighting; - if (lighting) { - glEnable(GL_LIGHTING); - } else { - glDisable(GL_LIGHTING); - } - break; - default: - { + lighting = !lighting; + if (lighting) + { + glEnable(GL_LIGHTING); + } + else + { + glDisable(GL_LIGHTING); + } + break; + + default: event.Skip(); - return; - } + return; } - Refresh(FALSE); + Refresh(false); } void TestGLCanvas::OnMouseEvent(wxMouseEvent& event) @@ -426,21 +451,27 @@ 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& event) +void TestGLCanvas::OnEraseBackground( wxEraseEvent& WXUNUSED(event) ) { // Do nothing, to avoid flashing. }