--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: glcanvas.cpp
+// Purpose: wxGLCanvas, for using OpenGL/Mesa with wxWindows and GTK
+// Author: Robert Roebling
+// Modified by:
+// Created: 17/08/98
+// RCS-ID: $Id$
+// Copyright: (c) Robert Roebling
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "glcanvas.h"
+#endif
+
+#include "wx/wxprec.h"
+
+#include "wx/frame.h"
+#include "wx/colour.h"
+#include "glcanvas.h"
+#include <gdk/gdkx.h>
+
+//---------------------------------------------------------------------------
+// wxGLContext
+//---------------------------------------------------------------------------
+
+IMPLEMENT_CLASS(wxGLContext,wxObject)
+
+wxGLContext::wxGLContext( bool WXUNUSED(isRGB), wxWindow *win, const wxPalette& WXUNUSED(palette) )
+{
+ m_window = win;
+ m_widget = win->m_wxwindow;
+
+ int data[] = {GLX_RGBA,GLX_RED_SIZE,1,GLX_GREEN_SIZE,1,
+ GLX_BLUE_SIZE,1,GLX_DOUBLEBUFFER,None};
+
+ Display *display = GDK_WINDOW_XDISPLAY( m_widget->window );
+ XVisualInfo *visual_info = glXChooseVisual( display, DefaultScreen(display), data );
+
+ wxCHECK_RET( visual_info != NULL, "Couldn't choose visual for OpenGl" );
+
+ m_glContext = glXCreateContext( display, visual_info, None, GL_TRUE );
+
+ wxCHECK_RET( m_glContext != NULL, "Couldn't create OpenGl context" );
+
+ glXMakeCurrent( display, GDK_WINDOW_XWINDOW(m_widget->window), m_glContext );
+}
+
+wxGLContext::~wxGLContext()
+{
+ if (m_glContext)
+ {
+ Display *display = GDK_WINDOW_XDISPLAY( m_widget->window );
+ glXMakeCurrent( display, GDK_WINDOW_XWINDOW(m_widget->window), m_glContext );
+
+ glXDestroyContext( display, m_glContext );
+ }
+}
+
+void wxGLContext::SwapBuffers()
+{
+ if (m_glContext)
+ {
+ Display *display = GDK_WINDOW_XDISPLAY( m_widget->window );
+ glXSwapBuffers( display, GDK_WINDOW_XWINDOW( m_widget->window ) );
+ }
+}
+
+void wxGLContext::SetCurrent()
+{
+ if (m_glContext)
+ {
+ Display *display = GDK_WINDOW_XDISPLAY( m_widget->window );
+ glXMakeCurrent( display, GDK_WINDOW_XWINDOW(m_widget->window), m_glContext );
+ }
+}
+
+void wxGLContext::SetColour(const char *colour)
+{
+ float r = 0.0;
+ float g = 0.0;
+ float b = 0.0;
+ wxColour *col = wxTheColourDatabase->FindColour(colour);
+ if (col)
+ {
+ r = (float)(col->Red()/256.0);
+ g = (float)(col->Green()/256.0);
+ b = (float)(col->Blue()/256.0);
+ glColor3f( r, g, b);
+ }
+}
+
+void wxGLContext::SetupPixelFormat()
+{
+}
+
+void wxGLContext::SetupPalette( const wxPalette& WXUNUSED(palette) )
+{
+}
+
+wxPalette wxGLContext::CreateDefaultPalette()
+{
+ return wxNullPalette;
+}
+
+//---------------------------------------------------------------------------
+// wxGlCanvas
+//---------------------------------------------------------------------------
+
+IMPLEMENT_CLASS(wxGLCanvas, wxScrolledWindow)
+
+BEGIN_EVENT_TABLE(wxGLCanvas, wxScrolledWindow)
+ EVT_SIZE(wxGLCanvas::OnSize)
+END_EVENT_TABLE()
+
+wxGLCanvas::wxGLCanvas(wxWindow *parent, wxWindowID id,
+ const wxPoint& pos, const wxSize& size, long style, const wxString& name,
+ int *WXUNUSED(attribList), const wxPalette& palette):
+ wxScrolledWindow(parent, id, pos, size, style, name)
+{
+ m_glContext = new wxGLContext( TRUE, this, palette );
+}
+
+wxGLCanvas::~wxGLCanvas()
+{
+ if (m_glContext) delete m_glContext;
+}
+
+void wxGLCanvas::SwapBuffers()
+{
+ if (m_glContext) m_glContext->SwapBuffers();
+}
+
+void wxGLCanvas::OnSize(wxSizeEvent& WXUNUSED(event))
+{
+ int width, height;
+ GetClientSize(& width, & height);
+
+ if (m_glContext)
+ {
+ m_glContext->SetCurrent();
+
+ glViewport(0, 0, (GLint)width, (GLint)height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 15.0 );
+ glMatrixMode(GL_MODELVIEW);
+ }
+}
+
+void wxGLCanvas::SetCurrent()
+{
+ if (m_glContext) m_glContext->SetCurrent();
+}
+
+void wxGLCanvas::SetColour( const char *colour )
+{
+ if (m_glContext) m_glContext->SetColour( colour );
+}
+
+
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: glcanvas.h
+// Purpose: wxGLCanvas, for using OpenGL/Mesa with wxWindows and GTK
+// Author: Robert Roebling
+// Modified by:
+// Created: 17/8/98
+// RCS-ID: $Id$
+// Copyright: (c) Robert Roebling
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma interface "glcanvas.h"
+#endif
+
+#ifndef _WX_GLCANVAS_H_
+#define _WX_GLCANVAS_H_
+
+#include "wx/defs.h"
+#include "wx/scrolwin.h"
+
+#include "GL/gl.h"
+#include "GL/glx.h"
+#include "GL/glu.h"
+
+//---------------------------------------------------------------------------
+// classes
+//---------------------------------------------------------------------------
+
+class wxGLContext;
+class wxGLCanvas;
+
+//---------------------------------------------------------------------------
+// wxGLContext
+//---------------------------------------------------------------------------
+
+
+class wxGLContext: public wxObject
+{
+ DECLARE_CLASS(wxGLContext)
+
+ public:
+
+ wxGLContext( bool isRGB, wxWindow *win, const wxPalette& palette = wxNullPalette );
+ ~wxGLContext();
+
+ void SetCurrent();
+ void SetColour(const char *colour);
+ void SwapBuffers();
+
+ void SetupPixelFormat();
+ void SetupPalette(const wxPalette& palette);
+ wxPalette CreateDefaultPalette();
+
+ inline wxPalette* GetPalette() const { return (wxPalette*) & m_palette; }
+ inline wxWindow* GetWindow() const { return m_window; }
+ inline GtkWidget* GetWidget() const { return m_widget; }
+ inline GLXContext GetContext() const { return m_glContext; }
+
+ public:
+
+ GLXContext m_glContext;
+
+ GtkWidget *m_widget;
+ wxPalette m_palette;
+ wxWindow* m_window;
+};
+
+//---------------------------------------------------------------------------
+// wxGLContext
+//---------------------------------------------------------------------------
+
+class wxGLCanvas: public wxScrolledWindow
+{
+ DECLARE_CLASS(wxGLCanvas)
+
+ public:
+ wxGLCanvas(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,
+ const wxSize& size = wxDefaultSize, long style = 0,
+ const wxString& name = "GLCanvas", int *attribList = 0, const wxPalette& palette = wxNullPalette);
+ ~wxGLCanvas();
+
+ void SetCurrent();
+ void SetColour(const char *colour);
+ void SwapBuffers();
+
+ void OnSize(wxSizeEvent& event);
+
+ inline wxGLContext* GetContext() const { return m_glContext; }
+
+ protected:
+
+ wxGLContext* m_glContext; // this is typedef-ed ptr, in fact
+
+ DECLARE_EVENT_TABLE()
+};
+
+#endif