summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorleo2001-01-07 15:04:39 +0000
committerleo2001-01-07 15:04:39 +0000
commit33132667d786063f1c0ee9079e5015c463f5f5b0 (patch)
treea2d615535f909be34540f6109a6dd014b7a52a5d
parent5e30e9a7197c6b4d233374ca88765d02114d97c3 (diff)
Cross platform OpenGL window
git-svn-id: http://svn.leocad.org/trunk@213 c7d43263-9d01-0410-8a33-9dba5d9f93d6
-rw-r--r--common/glwindow.h37
-rw-r--r--linux/gdkgl.c298
-rw-r--r--linux/gdkgl.h109
-rw-r--r--linux/glwindow.cpp259
-rw-r--r--linux/gtkglarea.c178
-rw-r--r--linux/gtkglarea.h74
6 files changed, 296 insertions, 659 deletions
diff --git a/common/glwindow.h b/common/glwindow.h
new file mode 100644
index 0000000..837a9c2
--- /dev/null
+++ b/common/glwindow.h
@@ -0,0 +1,37 @@
+#ifndef _GLWINDOW_H_
+#define _GLWINDOW_H_
+
+class GLWindow
+{
+ public:
+ GLWindow (GLWindow *share);
+ virtual ~GLWindow ();
+
+ void Create (void* data);
+ void DestroyContext ();
+
+ bool MakeCurrent ();
+ void SwapBuffers ();
+ void Redraw ();
+
+ virtual void OnDraw () { };
+ virtual void OnSize (int cx, int cy)
+ { m_nWidth = cx; m_nHeight = cy; };
+ virtual void OnInitialUpdate ();
+ virtual void OnLeftButtonDown (int x, int y, bool bControl, bool bShift) { };
+ virtual void OnLeftButtonUp (int x, int y, bool bControl, bool bShift) { };
+ virtual void OnLeftButtonDoubleClick (int x, int y, bool bControl, bool bShift) { };
+ virtual void OnRightButtonDown (int x, int y, bool bControl, bool bShift) { };
+ virtual void OnRightButtonUp (int x, int y, bool bControl, bool bShift) { };
+ virtual void OnMouseMove (int x, int y, bool bControl, bool bShift) { };
+
+ protected:
+ int m_nWidth;
+ int m_nHeight;
+
+ private:
+ void *m_pData;
+ GLWindow *m_pShare;
+};
+
+#endif // _GLWINDOW_H_
diff --git a/linux/gdkgl.c b/linux/gdkgl.c
deleted file mode 100644
index 6d082fc..0000000
--- a/linux/gdkgl.c
+++ /dev/null
@@ -1,298 +0,0 @@
-/*
- * Copyright (C) 1998 Janne Lof <jlof@mail.student.oulu.fi>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-
-#include "gdkgl.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-#include <gdk/gdkx.h>
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#include <string.h>
-#include "opengl.h"
-
-static XVisualInfo *get_xvisualinfo(GdkVisual *visual)
-{
- Display *dpy;
- XVisualInfo vinfo_template;
- XVisualInfo *vi;
- int nitems_return;
-
- dpy = GDK_DISPLAY();
-
- /* TODO: is this right way to get VisualInfo from Visual ?? */
- /* AFAIK VisualID and depth should be enough to uniquely identify visual */
- vinfo_template.visual = GDK_VISUAL_XVISUAL(visual);
- vinfo_template.visualid = XVisualIDFromVisual(vinfo_template.visual);
- vinfo_template.depth = visual->depth;
- vi = XGetVisualInfo(dpy, VisualIDMask|VisualDepthMask, &vinfo_template, &nitems_return);
-
- g_assert( vi!=0 && nitems_return==1 ); /* visualinfo needs to be unique */
-
- /* remember to XFree returned XVisualInfo !!! */
- return vi;
-}
-
-
-struct _GdkGLContextPrivate {
- Display *xdisplay;
- GLXContext glxcontext;
- guint ref_count;
-};
-
-typedef struct _GdkGLContextPrivate GdkGLContextPrivate;
-
-gint gdk_gl_query(void)
-{
- return (pfnglXQueryExtension(GDK_DISPLAY(),NULL,NULL) == True) ? TRUE : FALSE;
-}
-
-GdkVisual *gdk_gl_choose_visual(int *attrList)
-{
- Display *dpy;
- XVisualInfo *vi;
- GdkVisual *visual;
-
- g_return_val_if_fail(attrList != NULL, NULL);
-
- dpy = GDK_DISPLAY();
- /* TODO: translate GDK_GL_ to GLX_ */
- if ((vi = pfnglXChooseVisual(dpy,DefaultScreen(dpy), attrList)) == NULL) {
- return NULL;
- }
- visual = gdkx_visual_get(vi->visualid);
- XFree(vi);
- return visual;
-}
-
-
-int gdk_gl_get_config(GdkVisual *visual, int attrib)
-{
- Display *dpy;
- XVisualInfo *vi;
- int value;
-
- g_return_val_if_fail(visual != NULL, -1);
-
- dpy = GDK_DISPLAY();
-
- vi = get_xvisualinfo(visual);
-
- /* TODO: translate GDK_GL_ to GLX_ */
- if (pfnglXGetConfig(dpy, vi, attrib, &value) == 0) {
- XFree(vi);
- return value;
- }
- XFree(vi);
- return -1;
-}
-
-
-GdkGLContext *gdk_gl_context_new(GdkVisual *visual)
-{
- return gdk_gl_context_share_new(visual, NULL, FALSE);
-}
-
-GdkGLContext *gdk_gl_context_share_new(GdkVisual *visual, GdkGLContext *sharelist, gint direct)
-{
- Display *dpy;
- XVisualInfo *vi;
- GLXContext glxcontext;
- GdkGLContextPrivate *contextprivate;
-
- g_return_val_if_fail(visual != NULL, NULL);
-
- dpy = GDK_DISPLAY();
-
- vi = get_xvisualinfo(visual);
-
- if (sharelist) {
- glxcontext = pfnglXCreateContext(dpy, vi, ((GdkGLContextPrivate*)sharelist)->glxcontext, direct ? True : False);
- } else {
- glxcontext = pfnglXCreateContext(dpy, vi, 0, direct ? True : False);
- }
- XFree(vi);
- if (glxcontext == NULL) {
- return NULL;
- }
-
- contextprivate = g_new(GdkGLContextPrivate, 1);
- contextprivate->xdisplay = dpy;
- contextprivate->glxcontext = glxcontext;
- contextprivate->ref_count = 1;
-
- return (GdkGLContext*)contextprivate;
-}
-
-GdkGLContext *gdk_gl_context_ref(GdkGLContext *context)
-{
- GdkGLContextPrivate *contextprivate = (GdkGLContextPrivate*)context;
-
- g_return_val_if_fail(context != NULL, NULL);
- contextprivate->ref_count += 1;
-
- return context;
-}
-
-void gdk_gl_context_unref(GdkGLContext *context)
-{
- GdkGLContextPrivate *contextprivate = (GdkGLContextPrivate*)context;
-
- g_return_if_fail(context != NULL);
-
- if (contextprivate->ref_count > 1) {
- contextprivate->ref_count -= 1;
- } else {
- if (contextprivate->glxcontext == pfnglXGetCurrentContext())
- pfnglXMakeCurrent(contextprivate->xdisplay, None, NULL);
- pfnglXDestroyContext(contextprivate->xdisplay, contextprivate->glxcontext);
- memset(context, 0, sizeof(GdkGLContextPrivate));
- g_free(context);
- }
-}
-
-gint gdk_gl_make_current(GdkDrawable *drawable, GdkGLContext *context)
-{
- GdkGLContextPrivate *contextprivate = (GdkGLContextPrivate*)context;
-
- g_return_val_if_fail(drawable != NULL, FALSE);
- g_return_val_if_fail(context != NULL, FALSE);
-
- return (pfnglXMakeCurrent(contextprivate->xdisplay, GDK_WINDOW_XWINDOW(drawable), contextprivate->glxcontext) == True) ? TRUE : FALSE;
-}
-
-void gdk_gl_swap_buffers(GdkDrawable *drawable)
-{
- g_return_if_fail(drawable != NULL);
-
- pfnglXSwapBuffers(GDK_WINDOW_XDISPLAY(drawable), GDK_WINDOW_XWINDOW(drawable));
-}
-
-void gdk_gl_wait_gdk(void)
-{
- pfnglXWaitX();
-}
-
-void gdk_gl_wait_gl (void)
-{
- pfnglXWaitGL();
-}
-
-
-/* glpixmap stuff */
-
-struct _GdkGLPixmapPrivate {
- Display *xdisplay;
- GLXPixmap glxpixmap;
- GdkPixmap *front_left;
- guint ref_count;
-};
-
-typedef struct _GdkGLPixmapPrivate GdkGLPixmapPrivate;
-
-
-GdkGLPixmap *gdk_gl_pixmap_new(GdkVisual *visual, GdkPixmap *pixmap)
-{
- Display *dpy;
- XVisualInfo *vi;
- Pixmap xpixmap;
- GdkGLPixmapPrivate *contextprivate;
- GLXPixmap glxpixmap;
- gint depth;
-
- g_return_val_if_fail(pixmap != NULL, NULL);
- g_return_val_if_fail(visual != NULL, NULL);
- g_return_val_if_fail(gdk_window_get_type(pixmap) == GDK_WINDOW_PIXMAP, NULL);
-
- gdk_window_get_geometry(pixmap, 0,0,0,0, &depth);
- g_return_val_if_fail(gdk_gl_get_config(visual, GDK_GL_BUFFER_SIZE) == depth, NULL);
-
- dpy = GDK_DISPLAY();
-
- vi = get_xvisualinfo(visual);
- xpixmap = ((GdkPixmapPrivate*)pixmap)->xwindow;
- glxpixmap = pfnglXCreateGLXPixmap(dpy, vi, xpixmap);
- XFree(vi);
-
- g_return_val_if_fail(glxpixmap != None, NULL);
-
- contextprivate = g_new(GdkGLPixmapPrivate, 1);
- contextprivate->xdisplay = dpy;
- contextprivate->glxpixmap = glxpixmap;
- contextprivate->front_left = gdk_pixmap_ref(pixmap);
- contextprivate->ref_count = 1;
-
- return (GdkGLPixmap*)contextprivate;
-}
-
-
-GdkGLPixmap *gdk_gl_pixmap_ref(GdkGLPixmap *glpixmap)
-{
- GdkGLPixmapPrivate *contextprivate = (GdkGLPixmapPrivate*)glpixmap;
-
- g_return_val_if_fail(glpixmap != NULL, NULL);
- contextprivate->ref_count += 1;
-
- return glpixmap;
-}
-
-void gdk_gl_pixmap_unref(GdkGLPixmap *glpixmap)
-{
- GdkGLPixmapPrivate *contextprivate = (GdkGLPixmapPrivate*)glpixmap;
-
- g_return_if_fail(glpixmap != NULL);
-
- if (contextprivate->ref_count > 1) {
- contextprivate->ref_count -= 1;
- } else {
- pfnglXDestroyGLXPixmap(contextprivate->xdisplay, contextprivate->glxpixmap);
- pfnglXWaitGL();
- gdk_pixmap_unref(contextprivate->front_left);
- pfnglXWaitX();
- memset(glpixmap, 0, sizeof(GdkGLPixmapPrivate));
- g_free(glpixmap);
- }
-}
-
-gint gdk_gl_pixmap_make_current(GdkGLPixmap *glpixmap, GdkGLContext *context)
-{
- Display *dpy;
- GLXPixmap glxpixmap;
- GLXContext glxcontext;
-
- g_return_val_if_fail(glpixmap != NULL, FALSE);
- g_return_val_if_fail(context != NULL, FALSE);
-
- dpy = ((GdkGLContextPrivate*)context)->xdisplay;
- glxpixmap = ((GdkGLPixmapPrivate*)glpixmap)->glxpixmap;
- glxcontext = ((GdkGLContextPrivate*)context)->glxcontext;
-
- return (pfnglXMakeCurrent(dpy, glxpixmap, glxcontext) == True) ? TRUE : FALSE;
-}
-
-/* fonts */
-void gdk_gl_use_gdk_font(GdkFont *font, int first, int count, int list_base)
-{
- g_return_if_fail(font != NULL);
- pfnglXUseXFont(gdk_font_id(font), first, count, list_base);
-}
-
diff --git a/linux/gdkgl.h b/linux/gdkgl.h
deleted file mode 100644
index f3876e1..0000000
--- a/linux/gdkgl.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (C) 1998 Janne Löf <jlof@mail.student.oulu.fi>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef __GDK_GL_H__
-#define __GDK_GL_H__
-
-#include <gdk/gdk.h>
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * These definitions are duplicated from GL/glx.h that comes with Mesa.
- * I don't want every program to include GL/glx.h, that might become
- * problem if GtkGLArea is ever ported to non X environments like
- * (horror!) Windows.
- */
-enum _GDK_GL_CONFIGS {
- GDK_GL_NONE = 0,
- GDK_GL_USE_GL = 1,
- GDK_GL_BUFFER_SIZE = 2,
- GDK_GL_LEVEL = 3,
- GDK_GL_RGBA = 4,
- GDK_GL_DOUBLEBUFFER = 5,
- GDK_GL_STEREO = 6,
- GDK_GL_AUX_BUFFERS = 7,
- GDK_GL_RED_SIZE = 8,
- GDK_GL_GREEN_SIZE = 9,
- GDK_GL_BLUE_SIZE = 10,
- GDK_GL_ALPHA_SIZE = 11,
- GDK_GL_DEPTH_SIZE = 12,
- GDK_GL_STENCIL_SIZE = 13,
- GDK_GL_ACCUM_RED_SIZE = 14,
- GDK_GL_ACCUM_GREEN_SIZE = 15,
- GDK_GL_ACCUM_BLUE_SIZE = 16,
- GDK_GL_ACCUM_ALPHA_SIZE = 17,
-
- /* GLX_EXT_visual_info extension */
- GDK_GL_X_VISUAL_TYPE_EXT = 0x22,
- GDK_GL_TRANSPARENT_TYPE_EXT = 0x23,
- GDK_GL_TRANSPARENT_INDEX_VALUE_EXT = 0x24,
- GDK_GL_TRANSPARENT_RED_VALUE_EXT = 0x25,
- GDK_GL_TRANSPARENT_GREEN_VALUE_EXT = 0x26,
- GDK_GL_TRANSPARENT_BLUE_VALUE_EXT = 0x27,
- GDK_GL_TRANSPARENT_ALPHA_VALUE_EXT = 0x28
-};
-
-
-typedef struct _GdkGLContext GdkGLContext;
-
-
-gint gdk_gl_query(void);
-
-GdkVisual *gdk_gl_choose_visual(int *attrList);
-int gdk_gl_get_config(GdkVisual *visual, int attrib);
-
-GdkGLContext *gdk_gl_context_new(GdkVisual *visual);
-GdkGLContext *gdk_gl_context_share_new(GdkVisual *visual, GdkGLContext *sharelist, gint direct);
-
-GdkGLContext *gdk_gl_context_ref(GdkGLContext *context);
-void gdk_gl_context_unref(GdkGLContext *context);
-
-gint gdk_gl_make_current(GdkDrawable *drawable, GdkGLContext *context);
-void gdk_gl_swap_buffers(GdkDrawable *drawable);
-
-
-void gdk_gl_wait_gdk(void);
-void gdk_gl_wait_gl(void);
-
-
-/* glpixmap stuff */
-
-typedef struct _GdkGLPixmap GdkGLPixmap;
-
-GdkGLPixmap *gdk_gl_pixmap_new(GdkVisual *visual, GdkPixmap *pixmap);
-GdkGLPixmap *gdk_gl_pixmap_ref(GdkGLPixmap *glpixmap);
-void gdk_gl_pixmap_unref(GdkGLPixmap *glpixmap);
-
-gint gdk_gl_pixmap_make_current(GdkGLPixmap *glpixmap, GdkGLContext *context);
-
-
-/* fonts */
-void gdk_gl_use_gdk_font(GdkFont *font, int first, int count, int list_base);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* __GDK_GL_H__ */
-
diff --git a/linux/glwindow.cpp b/linux/glwindow.cpp
new file mode 100644
index 0000000..29e0897
--- /dev/null
+++ b/linux/glwindow.cpp
@@ -0,0 +1,259 @@
+//
+// OpenGL window
+//
+
+#include <stdio.h>
+#include <gtk/gtk.h>
+#include <gdk/gdkx.h>
+#include "opengl.h"
+#include "glwindow.h"
+
+typedef struct
+{
+ GtkWidget *widget;
+ Display* xdisplay;
+ GLXContext context;
+} GLWindowPrivate;
+
+// =============================================================================
+// static functions
+
+static gint realize_event (GtkWidget *widget, gpointer data)
+{
+ GLWindow *wnd = (GLWindow*)data;
+
+ wnd->OnInitialUpdate ();
+
+ return TRUE;
+}
+
+static gint expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer data)
+{
+ GLWindow *wnd = (GLWindow*)data;
+
+ if (event->count > 0)
+ return TRUE;
+
+ wnd->OnDraw ();
+
+ return TRUE;
+}
+
+static gint button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer data)
+{
+ GLWindow *wnd = (GLWindow*)data;
+ int x, y;
+
+ x = (int)event->x;
+ y = widget->allocation.height - (int)event->y - 1;
+
+ if (event->type == GDK_BUTTON_PRESS)
+ {
+ if (event->button == 1)
+ wnd->OnLeftButtonDown (x, y, (event->state & GDK_CONTROL_MASK) != 0,
+ (event->state & GDK_SHIFT_MASK) != 0);
+ else if (event->button == 3)
+ wnd->OnRightButtonDown (x, y, (event->state & GDK_CONTROL_MASK) != 0,
+ (event->state & GDK_SHIFT_MASK) != 0);
+ }
+ else if (event->type == GDK_2BUTTON_PRESS)
+ {
+ wnd->OnLeftButtonDoubleClick (x, y, (event->state & GDK_CONTROL_MASK) != 0,
+ (event->state & GDK_SHIFT_MASK) != 0);
+ }
+
+ gtk_window_set_focus (GTK_WINDOW (gtk_widget_get_toplevel (widget)), widget);
+ gdk_pointer_grab (widget->window, FALSE,
+ (GdkEventMask)(GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK|GDK_POINTER_MOTION_MASK),
+ NULL, NULL, GDK_CURRENT_TIME);
+
+ return TRUE;
+}
+
+static gint button_release_event (GtkWidget *widget, GdkEventButton *event, gpointer data)
+{
+ GLWindow *wnd = (GLWindow*)data;
+ int x, y;
+
+ x = (int)event->x;
+ y = widget->allocation.height - (int)event->y - 1;
+
+ gdk_pointer_ungrab (GDK_CURRENT_TIME);
+
+ if (event->button == 1)
+ wnd->OnLeftButtonUp (x, y, (event->state & GDK_CONTROL_MASK) != 0,
+ (event->state & GDK_SHIFT_MASK) != 0);
+ else if (event->button == 3)
+ wnd->OnRightButtonUp (x, y, (event->state & GDK_CONTROL_MASK) != 0,
+ (event->state & GDK_SHIFT_MASK) != 0);
+
+ return TRUE;
+}
+
+static gint pointer_motion_event (GtkWidget *widget, GdkEventMotion *event, gpointer data)
+{
+ GLWindow *wnd = (GLWindow*)data;
+ GdkModifierType state;
+ int x, y;
+
+ if (event->is_hint)
+ gdk_window_get_pointer (event->window, &x, &y, &state);
+ else
+ {
+ x = (int)event->x;
+ y = (int)event->y;
+ state = (GdkModifierType)event->state;
+ }
+
+ y = widget->allocation.height - y - 1;
+
+ // if (state)
+ wnd->OnMouseMove (x, y, (event->state & GDK_CONTROL_MASK) != 0, (event->state & GDK_SHIFT_MASK) != 0);
+
+ return TRUE;
+}
+
+static gint size_allocate_event (GtkWidget *widget, GtkAllocation *allocation, gpointer data)
+{
+ GLWindow *wnd = (GLWindow*)data;
+
+ wnd->OnSize (allocation->width, allocation->height);
+
+ return TRUE;
+}
+/*
+static void destroy_event (GtkWidget *widget, gpointer data)
+{
+ GLWindow *wnd = (GLWindow*)data;
+
+ wnd->DestroyContext ();
+}
+*/
+// =============================================================================
+// GLWindow class
+
+GLWindow::GLWindow (GLWindow *share)
+{
+ m_pShare = share;
+ m_pData = g_malloc (sizeof (GLWindowPrivate));
+}
+
+GLWindow::~GLWindow ()
+{
+ DestroyContext ();
+ g_free (m_pData);
+}
+
+void GLWindow::Create (void *data)
+{
+ int attrlist[] = { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 16, 0 };
+ GLWindowPrivate *prv = (GLWindowPrivate*)m_pData;
+ Display *dpy = GDK_DISPLAY();
+ GdkVisual *visual;
+ XVisualInfo *vi;
+
+ // choose visual
+ visual = gdk_visual_get_system ();
+ if (visual->depth < 16)
+ printf ("OpenGL fatal error: GtkRadiant needs a display with at least 16 bit colors.\n");
+
+ if (dpy == NULL)
+ printf ("OpenGL fatal error: Cannot get display.\n");
+ prv->xdisplay = dpy;
+
+ vi = pfnglXChooseVisual (dpy, DefaultScreen (dpy), attrlist);
+ if (vi == NULL)
+ printf ("OpenGL fatal error: glXChooseVisual failed.\n");
+
+ visual = gdkx_visual_get (vi->visualid);
+ if (visual == NULL)
+ printf ("OpenGL fatal error: Cannot get visual.\n");
+
+ gtk_widget_push_colormap (gdk_colormap_new (visual, TRUE));
+ gtk_widget_push_visual (visual);
+
+ prv->widget = gtk_drawing_area_new ();
+
+ if (m_pShare == NULL)
+ prv->context = pfnglXCreateContext (dpy, vi, NULL, True);
+ else
+ {
+ GLWindowPrivate *share = (GLWindowPrivate*)m_pShare->m_pData;
+
+ prv->context = pfnglXCreateContext (dpy, vi, share->context, True);
+ }
+
+ gtk_widget_pop_visual ();
+ gtk_widget_pop_colormap ();
+
+ XFree (vi);
+
+ GTK_WIDGET_SET_FLAGS (prv->widget, GTK_CAN_FOCUS);
+
+ gtk_widget_set_events (GTK_WIDGET (prv->widget), GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK |
+ GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
+
+ // Connect signal handlers
+ gtk_signal_connect (GTK_OBJECT (prv->widget), "expose_event",
+ GTK_SIGNAL_FUNC (expose_event), this);
+ // gtk_signal_connect (GTK_OBJECT (prv->widget), "destroy",
+ // GTK_SIGNAL_FUNC (destroy_event), this);
+ gtk_signal_connect (GTK_OBJECT (prv->widget), "size_allocate",
+ GTK_SIGNAL_FUNC (size_allocate_event), this);
+ gtk_signal_connect (GTK_OBJECT (prv->widget), "motion_notify_event",
+ GTK_SIGNAL_FUNC (pointer_motion_event), this);
+ gtk_signal_connect (GTK_OBJECT (prv->widget), "button_press_event",
+ GTK_SIGNAL_FUNC (button_press_event), this);
+ gtk_signal_connect (GTK_OBJECT (prv->widget), "button_release_event",
+ GTK_SIGNAL_FUNC (button_release_event), this);
+ gtk_signal_connect (GTK_OBJECT (prv->widget), "realize",
+ GTK_SIGNAL_FUNC (realize_event), this);
+
+ *((GtkWidget**)data) = prv->widget;
+}
+
+void GLWindow::DestroyContext ()
+{
+ GLWindowPrivate *prv = (GLWindowPrivate*)m_pData;
+
+ if (prv->context == pfnglXGetCurrentContext ())
+ pfnglXMakeCurrent (prv->xdisplay, None, NULL);
+
+ if (prv->context)
+ pfnglXDestroyContext (prv->xdisplay, prv->context);
+
+ prv->context = NULL;
+}
+
+void GLWindow::OnInitialUpdate ()
+{
+ MakeCurrent ();
+ GL_InitializeExtensions ();
+}
+
+bool GLWindow::MakeCurrent ()
+{
+ GLWindowPrivate *prv = (GLWindowPrivate*)m_pData;
+ gboolean ret = false;
+
+ if (prv->context)
+ ret = pfnglXMakeCurrent (prv->xdisplay, GDK_WINDOW_XWINDOW (prv->widget->window), prv->context);
+
+ return ret;
+}
+
+void GLWindow::SwapBuffers ()
+{
+ GLWindowPrivate *prv = (GLWindowPrivate*)m_pData;
+
+ if (prv->context)
+ pfnglXSwapBuffers (GDK_WINDOW_XDISPLAY (prv->widget->window), GDK_WINDOW_XWINDOW (prv->widget->window));
+}
+
+void GLWindow::Redraw ()
+{
+ GLWindowPrivate *prv = (GLWindowPrivate*)m_pData;
+
+ gtk_widget_draw (prv->widget, (GdkRectangle*)NULL);
+}
+
diff --git a/linux/gtkglarea.c b/linux/gtkglarea.c
deleted file mode 100644
index 2a885af..0000000
--- a/linux/gtkglarea.c
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright (C) 1997-1998 Janne Lof <jlof@mail.student.oulu.fi>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include "gdkgl.h"
-#include "gtkglarea.h"
-#include <GL/gl.h>
-#include <stdarg.h>
-
-static void gtk_gl_area_class_init (GtkGLAreaClass *klass);
-static void gtk_gl_area_init (GtkGLArea *glarea);
-static void gtk_gl_area_destroy (GtkObject *object); /* change to finalize? */
-
-static GtkDrawingAreaClass *parent_class = (GtkDrawingAreaClass*)NULL;
-
-
-GtkType gtk_gl_area_get_type ()
-{
- static GtkType gl_area_type = 0;
-
- if (!gl_area_type)
- {
- GtkTypeInfo gl_area_info =
- {
- (gchar*)"GtkGLArea",
- sizeof (GtkGLArea),
- sizeof (GtkGLAreaClass),
- (GtkClassInitFunc) gtk_gl_area_class_init,
- (GtkObjectInitFunc) gtk_gl_area_init,
- /* reserved_1 */ NULL,
- /* reserved_2 */ NULL,
- (GtkClassInitFunc) NULL
- };
- gl_area_type = gtk_type_unique (gtk_drawing_area_get_type (), &gl_area_info);
- }
- return gl_area_type;
-}
-
-static void gtk_gl_area_class_init (GtkGLAreaClass *klass)
-{
- GtkObjectClass *object_class;
-
- parent_class = (GtkDrawingAreaClass*)gtk_type_class(gtk_drawing_area_get_type());
- object_class = (GtkObjectClass*) klass;
-
- object_class->destroy = gtk_gl_area_destroy;
-}
-
-
-static void gtk_gl_area_init (GtkGLArea *gl_area)
-{
- gl_area->glcontext = (GdkGLContext*)NULL;
-}
-
-
-
-GtkWidget* gtk_gl_area_new_vargs(GtkGLArea *share, ...)
-{
- GtkWidget *glarea;
- va_list ap;
- int i;
- gint *attrList;
-
- va_start(ap, share);
- i=1;
- while (va_arg(ap, int) != GDK_GL_NONE) /* get number of arguments */
- i++;
- va_end(ap);
-
- attrList = g_new(int,i);
-
- va_start(ap,share);
- i=0;
- while ( (attrList[i] = va_arg(ap, int)) != GDK_GL_NONE) /* copy args to list */
- i++;
- va_end(ap);
-
- glarea = gtk_gl_area_share_new(attrList, share);
-
- g_free(attrList);
-
- return glarea;
-}
-
-GtkWidget* gtk_gl_area_new (int *attrList)
-{
- return gtk_gl_area_share_new(attrList, (GtkGLArea*)NULL);
-}
-
-GtkWidget* gtk_gl_area_share_new (int *attrList, GtkGLArea *share)
-{
- GdkVisual *visual;
- GdkGLContext *glcontext;
- GtkGLArea *gl_area;
-
- g_return_val_if_fail(share == NULL || GTK_IS_GL_AREA(share), (GtkWidget*)NULL);
-
- visual = gdk_gl_choose_visual(attrList);
- if (visual == NULL)
- return (GtkWidget*)NULL;
-
- glcontext = gdk_gl_context_share_new(visual, share ? share->glcontext : (GdkGLContext*)NULL , TRUE);
- if (glcontext == NULL)
- return (GtkWidget*)NULL;
-
- /* use colormap and visual suitable for OpenGL rendering */
- gtk_widget_push_colormap(gdk_colormap_new(visual,TRUE));
- gtk_widget_push_visual(visual);
-
- gl_area = (GtkGLArea*)gtk_type_new (gtk_gl_area_get_type());
- gl_area->glcontext = glcontext;
-
- /* pop back defaults */
- gtk_widget_pop_visual();
- gtk_widget_pop_colormap();
-
- return GTK_WIDGET(gl_area);
-}
-
-static void
-gtk_gl_area_destroy(GtkObject *object)
-{
- GtkGLArea *gl_area;
-
- g_return_if_fail (object != NULL);
- g_return_if_fail (GTK_IS_GL_AREA(object));
-
- gl_area = GTK_GL_AREA(object);
- gdk_gl_context_unref(gl_area->glcontext);
-
- if (GTK_OBJECT_CLASS (parent_class)->destroy)
- (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
-}
-
-
-
-
-
-
-gint gtk_gl_area_make_current(GtkGLArea *gl_area)
-{
- g_return_val_if_fail(gl_area != NULL, FALSE);
- g_return_val_if_fail(GTK_IS_GL_AREA (gl_area), FALSE);
- g_return_val_if_fail(GTK_WIDGET_REALIZED(gl_area), FALSE);
-
- return gdk_gl_make_current(GTK_WIDGET(gl_area)->window, gl_area->glcontext);
-}
-
-void gtk_gl_area_swapbuffers(GtkGLArea *gl_area)
-{
- g_return_if_fail(gl_area != NULL);
- g_return_if_fail(GTK_IS_GL_AREA(gl_area));
- g_return_if_fail(GTK_WIDGET_REALIZED(gl_area));
-
- gdk_gl_swap_buffers(GTK_WIDGET(gl_area)->window);
-}
-
-void gtk_gl_area_size (GtkGLArea *glarea, gint width, gint height)
-{
- g_return_if_fail (glarea != NULL);
- g_return_if_fail (GTK_IS_GL_AREA (glarea));
-
- gtk_drawing_area_size(GTK_DRAWING_AREA(glarea), width, height);
-}
diff --git a/linux/gtkglarea.h b/linux/gtkglarea.h
deleted file mode 100644
index 47eee22..0000000
--- a/linux/gtkglarea.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 1997-1998 Janne Lof <jlof@mail.student.oulu.fi>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-
-#ifndef __GTK_GL_AREA_H__
-#define __GTK_GL_AREA_H__
-
-#include <gdk/gdk.h>
-#include <gdkgl.h>
-#include <gtk/gtkdrawingarea.h>
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-#define GTK_TYPE_GL_AREA (gtk_gl_area_get_type())
-#define GTK_GL_AREA(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_GL_AREA, GtkGLArea))
-#define GTK_GL_AREA_CLASS(klass) (GTK_CHECK_CLASS_CAST (klass, GTK_TYPE_GL_AREA, GtkGLAreaClass))
-#define GTK_IS_GL_AREA(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_GL_AREA))
-#define GTK_IS_GL_AREA_CLASS (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_GL_AREA))
-
-typedef struct _GtkGLArea GtkGLArea;
-typedef struct _GtkGLAreaClass GtkGLAreaClass;
-
-
-struct _GtkGLArea
-{
- GtkDrawingArea darea;
- GdkGLContext *glcontext;
-};
-
-struct _GtkGLAreaClass
-{
- GtkDrawingAreaClass parent_class;
-};
-
-GtkType gtk_gl_area_get_type (void);
-GtkWidget* gtk_gl_area_new (int *attrList);
-GtkWidget* gtk_gl_area_share_new (int *attrList,
- GtkGLArea *share);
-GtkWidget* gtk_gl_area_new_vargs (GtkGLArea *share,
- ...);
-
-
-gint gtk_gl_area_make_current(GtkGLArea *glarea);
-
-void gtk_gl_area_swapbuffers(GtkGLArea *glarea);
-
-void gtk_gl_area_size (GtkGLArea *glarea, /* deprecated, use gtk_drawing_area_size() */
- gint width,
- gint height);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-
-#endif /* __GTK_GL_AREA_H__ */