]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk1/glcanvas.cpp
more GTK2+ANSI fixes
[wxWidgets.git] / src / gtk1 / glcanvas.cpp
index ff037160c657ff184af1a24b96c902ac5a78b88f..1556694fe8bd5ca0eb41a328ad1248ee88c1fcab 100644 (file)
@@ -1,6 +1,6 @@
 /////////////////////////////////////////////////////////////////////////////
 // Name:        gtk/glcanvas.cpp
-// Purpose:     wxGLCanvas, for using OpenGL/Mesa with wxWindows and GTK
+// Purpose:     wxGLCanvas, for using OpenGL/Mesa with wxWidgets and GTK
 // Author:      Robert Roebling
 // Modified by:
 // Created:     17/08/98
@@ -9,10 +9,13 @@
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
 #pragma implementation "glcanvas.h"
 #endif
 
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
 #include "wx/setup.h"
 
 #if wxUSE_GLCANVAS
@@ -33,6 +36,10 @@ extern "C"
 
 #include "wx/gtk/win_gtk.h"
 
+// DLL options compatibility check:
+#include "wx/build.h"
+WX_CHECK_BUILD_OPTIONS("wxGL")
+
 //---------------------------------------------------------------------------
 // global data
 //---------------------------------------------------------------------------
@@ -123,15 +130,12 @@ void wxGLContext::SetCurrent()
 
 void wxGLContext::SetColour(const wxChar *colour)
 {
-    float r = 0.0;
-    float g = 0.0;
-    float b = 0.0;
-    wxColour *col = wxTheColourDatabase->FindColour(colour);
-    if (col)
+    wxColour col = wxTheColourDatabase->Find(colour);
+    if (col.Ok())
     {
-        r = (float)(col->Red()/256.0);
-        g = (float)(col->Green()/256.0);
-        b = (float)(col->Blue()/256.0);
+        float r = (float)(col.Red()/256.0);
+        float g = (float)(col.Green()/256.0);
+        float b = (float)(col.Blue()/256.0);
         glColor3f( r, g, b);
     }
 }
@@ -156,10 +160,16 @@ wxPalette wxGLContext::CreateDefaultPalette()
 static gint
 gtk_glwindow_realized_callback( GtkWidget * WXUNUSED(widget), wxGLCanvas *win )
 {
-    wxGLContext *share= win->m_sharedContext;
-    if (share==NULL && win->m_sharedContextOf) share=win->m_sharedContextOf->GetContext();
+    // VZ: apparently in some cases we're called twice -- no idea why,
+    //     but a check doesn't hurt
+    if ( !win->m_glContext )
+    {
+        wxGLContext *share = win->m_sharedContext;
+        if ( !share && win->m_sharedContextOf )
+            share = win->m_sharedContextOf->GetContext();
 
-    win->m_glContext = new wxGLContext( TRUE, win, wxNullPalette, share );
+        win->m_glContext = new wxGLContext( TRUE, win, wxNullPalette, share );
+    }
 
     return FALSE;
 }
@@ -206,6 +216,7 @@ gtk_glwindow_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExpose *gdk_e
 // "draw" of m_wxwindow
 //-----------------------------------------------------------------------------
 
+#ifndef __WXGTK20__
 static void
 gtk_glwindow_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle *rect, wxGLCanvas *win )
 {
@@ -217,6 +228,7 @@ gtk_glwindow_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle *rect, wxG
     win->GetUpdateRegion().Union( rect->x, rect->y,
                                   rect->width, rect->height );
 }
+#endif
 
 //-----------------------------------------------------------------------------
 // "size_allocate" of m_wxwindow
@@ -319,6 +331,10 @@ bool wxGLCanvas::Create( wxWindow *parent,
 
     m_glWidget = m_wxwindow;
 
+#ifdef __WXGTK20__
+    gtk_widget_set_double_buffered( m_glWidget, FALSE );
+#endif
+
     gtk_pizza_set_clear( GTK_PIZZA(m_wxwindow), FALSE );
 
     gtk_signal_connect( GTK_OBJECT(m_wxwindow), "realize",
@@ -330,8 +346,10 @@ bool wxGLCanvas::Create( wxWindow *parent,
     gtk_signal_connect( GTK_OBJECT(m_wxwindow), "expose_event",
         GTK_SIGNAL_FUNC(gtk_glwindow_expose_callback), (gpointer)this );
 
+#ifndef __WXGTK20__
     gtk_signal_connect( GTK_OBJECT(m_wxwindow), "draw",
         GTK_SIGNAL_FUNC(gtk_glwindow_draw_callback), (gpointer)this );
+#endif
 
     gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
         GTK_SIGNAL_FUNC(gtk_glcanvas_size_callback), (gpointer)this );
@@ -353,7 +371,7 @@ wxGLCanvas::~wxGLCanvas()
     XVisualInfo *vi = (XVisualInfo *) m_vi;
 
     if (vi && m_canFreeVi) XFree( vi );
-    if (m_glContext) delete m_glContext;
+    delete m_glContext;
 }
 
 void* wxGLCanvas::ChooseGLVisual(int *attribList)