/////////////////////////////////////////////////////////////////////////////
// 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
// 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
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);
}
}
// "realize" from m_wxwindow
//-----------------------------------------------------------------------------
+extern "C" {
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();
+ 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;
}
+}
//-----------------------------------------------------------------------------
// "map" from m_wxwindow
//-----------------------------------------------------------------------------
+extern "C" {
static gint
gtk_glwindow_map_callback( GtkWidget * WXUNUSED(widget), wxGLCanvas *win )
{
return FALSE;
}
+}
//-----------------------------------------------------------------------------
// "expose_event" of m_wxwindow
//-----------------------------------------------------------------------------
+extern "C" {
static void
gtk_glwindow_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExpose *gdk_event, wxGLCanvas *win )
{
gdk_event->area.width,
gdk_event->area.height );
}
+}
//-----------------------------------------------------------------------------
// "draw" of m_wxwindow
//-----------------------------------------------------------------------------
#ifndef __WXGTK20__
+extern "C" {
static void
gtk_glwindow_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle *rect, wxGLCanvas *win )
{
win->GetUpdateRegion().Union( rect->x, rect->y,
rect->width, rect->height );
}
+}
#endif
//-----------------------------------------------------------------------------
// "size_allocate" of m_wxwindow
//-----------------------------------------------------------------------------
+extern "C" {
static void
gtk_glcanvas_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxGLCanvas *win )
{
event.SetEventObject( win );
win->GetEventHandler()->ProcessEvent( event );
}
+}
//---------------------------------------------------------------------------
// wxGlCanvas
wxCHECK_MSG( m_vi, FALSE, _T("required visual couldn't be found") );
GdkVisual *visual = gdkx_visual_get( vi->visualid );
- GdkColormap *colormap = gdk_colormap_new( gdkx_visual_get(vi->visualid), TRUE );
+ GdkColormap *colormap = gdk_colormap_new( visual, TRUE );
gtk_widget_push_colormap( colormap );
gtk_widget_push_visual( visual );
gtk_widget_pop_visual();
gtk_widget_pop_colormap();
+ // if our parent window is already visible, we had been realized before we
+ // connected to the "realize" signal and hence our m_glContext hasn't been
+ // initialized yet and we have to do it now
if (GTK_WIDGET_REALIZED(m_wxwindow))
gtk_glwindow_realized_callback( m_wxwindow, this );
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)