+/*
+ * GLContext implementation
+ */
+
+IMPLEMENT_CLASS(wxGLContext,wxObject)
+
+wxGLContext::wxGLContext( bool WXUNUSED(isRGB), wxWindow *win,
+ const wxPalette& WXUNUSED(palette) )
+{
+ m_window = win;
+ // m_widget = win->m_wxwindow;
+
+ wxGLCanvas *gc = (wxGLCanvas*) win;
+ XVisualInfo *vi = (XVisualInfo *) gc->m_vi;
+
+ wxCHECK_RET( vi, "invalid visual for OpenGl" );
+
+ m_glContext = glXCreateContext( (Display *)m_window->GetXDisplay(), vi,
+ None, GL_TRUE);
+
+ wxCHECK_RET( m_glContext, "Couldn't create OpenGl context" );
+}
+
+wxGLContext::wxGLContext(
+ bool WXUNUSED(isRGB), wxWindow *win,
+ const wxPalette& WXUNUSED(palette),
+ const wxGLContext *other /* for sharing display lists */
+)
+{
+ m_window = win;
+ // m_widget = win->m_wxwindow;
+
+ wxGLCanvas *gc = (wxGLCanvas*) win;
+ XVisualInfo *vi = (XVisualInfo *) gc->m_vi;
+
+ wxCHECK_RET( vi, "invalid visual for OpenGl" );
+
+ if( other != 0 )
+ m_glContext = glXCreateContext( (Display *)m_window->GetXDisplay(), vi,
+ other->m_glContext, GL_TRUE );
+ else
+ m_glContext = glXCreateContext( (Display *)m_window->GetXDisplay(), vi,
+ None, GL_TRUE );
+
+ wxCHECK_RET( m_glContext, "Couldn't create OpenGl context" );
+}
+
+wxGLContext::~wxGLContext()
+{
+ if (!m_glContext) return;
+
+ if (m_glContext == glXGetCurrentContext())
+ {
+ glXMakeCurrent( (Display*) m_window->GetXDisplay(), None, NULL);
+ }
+
+ glXDestroyContext( (Display*) m_window->GetXDisplay(), m_glContext );
+}
+
+void wxGLContext::SwapBuffers()
+{
+ if (m_glContext)
+ {
+ Display* display = (Display*) m_window->GetXDisplay();
+ glXSwapBuffers(display, (Window) m_window->GetXWindow());
+ }
+}
+
+void wxGLContext::SetCurrent()
+{
+ if (m_glContext)
+ {
+ Display* display = (Display*) m_window->GetXDisplay();
+ glXMakeCurrent(display, (Window) m_window->GetXWindow(),
+ m_glContext );;
+ }
+}
+
+void wxGLContext::SetColour(const char *colour)
+{
+ wxColour *the_colour = wxTheColourDatabase->FindColour(colour);
+ if(the_colour) {
+ GLboolean b;
+ glGetBooleanv(GL_RGBA_MODE, &b);
+ if(b) {
+ glColor3ub(the_colour->Red(),
+ the_colour->Green(),
+ the_colour->Blue());
+ } else {
+ GLint pix = (GLint)the_colour->m_pixel;
+ if(pix == -1) {
+ XColor exact_def;
+ exact_def.red = (unsigned short)the_colour->Red() << 8;
+ exact_def.green = (unsigned short)the_colour->Green() << 8;
+ exact_def.blue = (unsigned short)the_colour->Blue() << 8;
+ exact_def.flags = DoRed | DoGreen | DoBlue;
+ if(!XAllocColor((Display*) m_window->GetXDisplay(),
+ (Colormap) wxTheApp->GetMainColormap(m_window->GetXDisplay()),
+ &exact_def)) {
+ wxLogError("wxGLCanvas: cannot allocate color\n");
+ return;
+ }
+ pix = the_colour->m_pixel = exact_def.pixel;
+ }
+ glIndexi(pix);
+ }
+ }
+}
+
+void wxGLContext::SetupPixelFormat()
+{
+}
+
+void wxGLContext::SetupPalette( const wxPalette& WXUNUSED(palette) )
+{
+}
+
+wxPalette wxGLContext::CreateDefaultPalette()
+{
+ return wxNullPalette;
+}
+
+
+
+