00001 #include <iostream.h> 00002 #include "vuGLCanvas.h" 00003 #include <wx/dcclient.h> 00004 #include "vuSimpleTypes.h" 00005 00006 //---------------------------------------------------------------------------- 00007 //------------------------- GLCanvas Event Table ----------------------------- 00008 //---------------------------------------------------------------------------- 00009 00010 BEGIN_EVENT_TABLE(vuGLCanvas, wxGLCanvas) 00011 EVT_SIZE(vuGLCanvas::onSize) 00012 EVT_PAINT(vuGLCanvas::onPaint) 00013 EVT_ERASE_BACKGROUND(vuGLCanvas::onEraseBackground) 00014 END_EVENT_TABLE() 00015 00016 //---------------------------------------------------------------------------- 00017 //------------------------- public: vuGLCanvas() ----------------------------- 00018 //---------------------------------------------------------------------------- 00019 00020 vuGLCanvas::vuGLCanvas(wxWindow *parent, wxWindowID id, const wxPoint& pos, 00021 const wxSize& size, long style, const wxString& name, int* gl_attrib) 00022 : wxGLCanvas(parent, id, pos, size, style, name, gl_attrib) 00023 { 00024 m_init = false; 00025 m_useOGL = true; 00026 }; 00027 00028 //---------------------------------------------------------------------------- 00029 //------------------------- public: enableOpenGL() --------------------------- 00030 //---------------------------------------------------------------------------- 00031 00032 void vuGLCanvas::enableOpenGL() 00033 { 00034 m_useOGL = true; 00035 } 00036 00037 //---------------------------------------------------------------------------- 00038 //------------------------- public: enableOpenGL() --------------------------- 00039 //---------------------------------------------------------------------------- 00040 00041 void vuGLCanvas::disableOpenGL() 00042 { 00043 m_useOGL = false; 00044 } 00045 00046 //---------------------------------------------------------------------------- 00047 //------------------------- protected: redraw() ------------------------------ 00048 //---------------------------------------------------------------------------- 00049 00050 void vuGLCanvas::redraw() 00051 { 00052 Refresh(false); 00053 } 00054 00055 //---------------------------------------------------------------------------- 00056 //------------------------- protected: getWidth() ---------------------------- 00057 //---------------------------------------------------------------------------- 00058 00059 int vuGLCanvas::getWidth() const 00060 { 00061 return m_Width; 00062 } 00063 00064 //---------------------------------------------------------------------------- 00065 //------------------------- protected: getHeight() --------------------------- 00066 //---------------------------------------------------------------------------- 00067 00068 int vuGLCanvas::getHeight() const 00069 { 00070 return m_Height; 00071 } 00072 00073 //---------------------------------------------------------------------------- 00074 //------------------------- protected: OnPaint() ----------------------------- 00075 //---------------------------------------------------------------------------- 00076 00077 void vuGLCanvas::onPaint(wxPaintEvent& event) 00078 { 00079 //Define a painting device context, as required by wxWindows. 00080 wxPaintDC dc(this); 00081 00082 //In case the user called the redraw function before the gl context for 00083 //the canvas was initialized, exit the function. 00084 if (!GetContext()) return; 00085 00086 //Set opengl to the proper gl context. 00087 SetCurrent(); 00088 00089 //If this is the first onPaint event, initialize opengl for the canvas. 00090 //This has to be done here because under some operating systems, such as 00091 //gtk, the gl context is not assigned until the window has been created. 00092 00093 //changes by Steven Bergner 011002, perhaps the non-OpenGL refresh Problem can 00094 //be solved better... so far this little change: (render() outside m_Init cond.) 00095 if (!m_init) 00096 { 00097 m_init = glInit(); 00098 if(m_init) resize(); 00099 } 00100 if (m_init) render(); 00101 00102 SwapBuffers(); //Swap the buffers. 00103 //else vuDrawTools::quitDC(); //release draw context 00104 } 00105 00106 //---------------------------------------------------------------------------- 00107 //------------------------- protected: OnSize() ------------------------------ 00108 //---------------------------------------------------------------------------- 00109 00110 void vuGLCanvas::onSize(wxSizeEvent& event) 00111 { 00112 // this is also necessary to update the context on some platforms 00113 wxGLCanvas::OnSize(event); 00114 00115 //Find out the size of the screen. 00116 GetClientSize(&m_Width, &m_Height); 00117 #ifndef __WXMOTIF__ 00118 if (GetContext()) 00119 #endif 00120 { 00121 if(m_init) { 00122 SetCurrent(); 00123 //glViewport(0, 0, (GLint) m_Width, (GLint) m_Height); 00124 resize(); 00125 redraw(); 00126 } 00127 } 00128 } 00129 00130 //---------------------------------------------------------------------------- 00131 //------------------------- protected: OnEraseBackground() ------------------- 00132 //---------------------------------------------------------------------------- 00133 00134 void vuGLCanvas::onEraseBackground(wxEraseEvent& event) 00135 {}; 00136