/////////////////////////////////////////////////////////////////////////////
// Name: glcanvas.cpp
-// Purpose: wxGLCanvas, for using OpenGL with wxWindows 2.0 for Motif.
+// Purpose: wxGLCanvas, for using OpenGL with wxWindows
// Uses the GLX extension.
// Author: Julian Smart and Wolfram Gloger
// Modified by:
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "glcanvas.h"
#endif
#if wxUSE_GLCANVAS
-#error Sorry, wxGLCanvas does not work yet with wxX11
-
#include "wx/glcanvas.h"
#include "wx/utils.h"
#include "wx/app.h"
#ifdef __VMS
# pragma message disable nosimpint
#endif
-#include <Xm/Xm.h>
+#include <X11/Xlib.h>
#ifdef __VMS
# pragma message enable nosimpint
#endif
-#include "wx/motif/private.h"
+#include "wx/x11/private.h"
+
+// DLL options compatibility check:
+#include "wx/build.h"
+WX_CHECK_BUILD_OPTIONS("wxGL")
+
+static inline WXWindow wxGetClientAreaWindow(wxWindow* win)
+{
+#ifdef __WXMOTIF__
+ return win->GetClientXWindow();
+#else
+ return win->GetClientAreaWindow();
+#endif
+}
#ifdef OLD_MESA
// workaround for bug in Mesa's glx.c
wxGLCanvas *gc = (wxGLCanvas*) win;
XVisualInfo *vi = (XVisualInfo *) gc->m_vi;
- wxCHECK_RET( vi, "invalid visual for OpenGl" );
+ wxCHECK_RET( vi, wxT("invalid visual for OpenGL") );
m_glContext = glXCreateContext( (Display *)wxGetDisplay(), vi,
None, GL_TRUE);
- wxCHECK_RET( m_glContext, "Couldn't create OpenGl context" );
+ wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGL context") );
}
wxGLContext::wxGLContext(
wxGLCanvas *gc = (wxGLCanvas*) win;
XVisualInfo *vi = (XVisualInfo *) gc->m_vi;
- wxCHECK_RET( vi, "invalid visual for OpenGl" );
+ wxCHECK_RET( vi, wxT("invalid visual for OpenGL") );
if( other != 0 )
m_glContext = glXCreateContext( (Display *)wxGetDisplay(), vi,
m_glContext = glXCreateContext( (Display *)wxGetDisplay(), vi,
None, GL_TRUE );
- wxCHECK_RET( m_glContext, "Couldn't create OpenGl context" );
+ wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGL context") );
}
wxGLContext::~wxGLContext()
if (m_glContext)
{
Display* display = (Display*) wxGetDisplay();
- glXSwapBuffers(display, (Window) m_window->GetClientAreaWindow());
+ glXSwapBuffers(display, (Window) wxGetClientAreaWindow(m_window));
}
}
if (m_glContext)
{
Display* display = (Display*) wxGetDisplay();
- glXMakeCurrent(display, (Window) m_window->GetClientAreaWindow(),
+ glXMakeCurrent(display, (Window) wxGetClientAreaWindow(m_window),
m_glContext );;
}
}
-void wxGLContext::SetColour(const char *colour)
+void wxGLContext::SetColour(const wxChar *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 {
- the_colour->CalcPixel(wxTheApp->GetMainColormap(wxGetDisplay()));
- GLint pix = (GLint)the_colour->GetPixel();
- if(pix == -1)
+ wxColour the_colour = wxTheColourDatabase->Find(colour);
+ if(the_colour.Ok())
+ {
+ GLboolean b;
+ glGetBooleanv(GL_RGBA_MODE, &b);
+ if(b)
+ {
+ glColor3ub(the_colour.Red(),
+ the_colour.Green(),
+ the_colour.Blue());
+ }
+ else
+ {
+#ifdef __WXMOTIF__
+ the_colour.AllocColour(m_window->GetXDisplay());
+#else
+ the_colour.CalcPixel(wxTheApp->GetMainColormap(wxGetDisplay()));
+#endif
+ GLint pix = (GLint)the_colour.GetPixel();
+ if(pix == -1)
{
- wxLogError("wxGLCanvas: cannot allocate color\n");
- return;
+ wxLogError(wxT("wxGLCanvas: cannot allocate color\n"));
+ return;
}
- glIndexi(pix);
- }
+ glIndexi(pix);
+ }
}
}
// Check for the presence of the GLX extension
if(!glXQueryExtension(display, NULL, NULL)) {
- wxLogDebug("wxGLCanvas: GLX extension is missing\n");
+ wxLogDebug(wxT("wxGLCanvas: GLX extension is missing\n"));
return FALSE;
}
} else {
// By default, we use the visual of xwindow
// NI: is this really senseful ? opengl in e.g. color index mode ?
- XGetWindowAttributes(display, (Window) GetClientAreaWindow(), &xwa);
+ XGetWindowAttributes(display, (Window)wxGetClientAreaWindow(this), &xwa);
vi_templ.visualid = XVisualIDFromVisual(xwa.visual);
vi = XGetVisualInfo(display, VisualIDMask, &vi_templ, &n);
if(!vi) return FALSE;
m_vi = vi; // safe for later use
- wxCHECK_MSG( m_vi, FALSE, "required visual couldn't be found" );
+ wxCHECK_MSG( m_vi, FALSE, wxT("required visual couldn't be found") );
// Create the GLX context and make it current
// if(glx_cx) glXMakeCurrent(display, (Window) GetClientAreaWindow(), glx_cx);
}
-void wxGLCanvas::SetColour(const char *col)
+void wxGLCanvas::SetColour(const wxChar *col)
{
if( m_glContext ) m_glContext->SetColour(col);
}