X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8b089c5e8c8a2140258d150ca1ce42afd3b79e1b..6d26dc89c5e7a421f4f8807728928eee91aa5f7e:/samples/opengl/isosurf/isosurf.cpp diff --git a/samples/opengl/isosurf/isosurf.cpp b/samples/opengl/isosurf/isosurf.cpp index 6ba560cff1..895c3d44e3 100644 --- a/samples/opengl/isosurf/isosurf.cpp +++ b/samples/opengl/isosurf/isosurf.cpp @@ -6,7 +6,7 @@ // Created: 04/01/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -25,11 +25,31 @@ #include "wx/wx.h" #endif +#if !wxUSE_GLCANVAS +#error Please set wxUSE_GLCANVAS to 1 in setup.h. +#endif + #include "wx/timer.h" #include "wx/glcanvas.h" -#include -#include +#ifdef __WXMAC__ +# ifdef __DARWIN__ +# include +# include +# else +# include +# include +# endif +#else +# include +# include +#endif + +// disabled because this has apparently changed in OpenGL 1.2, so doesn't link +// correctly if this is on... +#ifdef GL_EXT_vertex_array +#undef GL_EXT_vertex_array +#endif #include "isosurf.h" @@ -71,8 +91,8 @@ static void read_surface( char *filename ) numverts = 0; while (!feof(f) && numvertsm_canvas = new TestGLCanvas(frame, -1, wxPoint(0, 0), wxSize(200, 200), 0, "TestGLCanvas", - gl_attrib); + + frame->m_canvas = new TestGLCanvas(frame, -1, wxDefaultPosition, wxDefaultSize, + 0, "TestGLCanvas", gl_attrib ); // Show the frame frame->Show(TRUE); @@ -312,6 +331,7 @@ TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id, { 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" )) { @@ -330,55 +350,70 @@ void TestGLCanvas::OnPaint( wxPaintEvent& event ) // OnPaint handlers must always create a wxPaintDC. wxPaintDC dc(this); +#ifndef __WXMOTIF__ + if (!GetContext()) return; +#endif + + SetCurrent(); + draw1(); SwapBuffers(); } void TestGLCanvas::OnSize(wxSizeEvent& event) { - SetCurrent(); - int width, height; - GetClientSize(& width, & height); - Reshape(width, height); + // 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()) +#endif + { + SetCurrent(); + glViewport(0, 0, (GLint) w, (GLint) h); + } } void TestGLCanvas::OnChar(wxKeyEvent& event) { switch(event.KeyCode()) { case WXK_ESCAPE: - exit(0); + exit(0); 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; + lighting = !lighting; + if (lighting) { + glEnable(GL_LIGHTING); + } else { + glDisable(GL_LIGHTING); + } + break; default: { event.Skip(); - return; + return; } } @@ -392,17 +427,17 @@ void TestGLCanvas::OnMouseEvent(wxMouseEvent& event) //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); - } - last_x = event.GetX(); - last_y = event.GetY(); + 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(); } else - dragging = 0; + dragging = 0; } void TestGLCanvas::OnEraseBackground(wxEraseEvent& event)