gtkglarea r99 - trunk/gtkgl
- From: samh svn gnome org
- To: svn-commits-list gnome org
- Subject: gtkglarea r99 - trunk/gtkgl
- Date: Fri, 7 Mar 2008 12:45:30 +0000 (GMT)
Author: samh
Date: Fri Mar 7 12:45:30 2008
New Revision: 99
URL: http://svn.gnome.org/viewvc/gtkglarea?rev=99&view=rev
Log:
* Starting the gtkgl.c reorganisation.
Modified:
trunk/gtkgl/gdkgl.c
Modified: trunk/gtkgl/gdkgl.c
==============================================================================
--- trunk/gtkgl/gdkgl.c (original)
+++ trunk/gtkgl/gdkgl.c Fri Mar 7 12:45:30 2008
@@ -31,118 +31,71 @@
#include "gdkgl.h"
+/*
+ * The GdkGLContext class
+ */
+struct _GdkGLContext {
+ GObject parent;
#ifdef USE_WIN32
-static void fill_pfd(PIXELFORMATDESCRIPTOR *pfd, int *attriblist)
-{
- /*
- * Ripped from glut's win32_x11.c
- */
-
- int *p = attriblist;
-
- memset(pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
- pfd->nSize = (sizeof(PIXELFORMATDESCRIPTOR));
- pfd->nVersion = 1;
+ gboolean initialised;
+ HGLRC hglrc;
+ HDC hdc;
+ HWND hwnd;
+ GdkGLContext *share;
+ PIXELFORMATDESCRIPTOR pfd;
+#else
+ Display *xdisplay;
+ GLXContext glxcontext;
+#endif
+};
- /* Defaults. */
- pfd->dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
- pfd->iPixelType = PFD_TYPE_COLORINDEX;
- pfd->cColorBits = 32;
- pfd->cDepthBits = 0;
- pfd->cAccumBits = 0;
+struct _GdkGLContextClass {
+ GObjectClass parent_class;
+};
+typedef struct _GdkGLContextClass GdkGLContextClass;
- while (*p) {
- switch (*p) {
- case GDK_GL_USE_GL:
- pfd->dwFlags |= PFD_SUPPORT_OPENGL;
- break;
- case GDK_GL_BUFFER_SIZE:
- pfd->cColorBits = *(++p);
- break;
- case GDK_GL_LEVEL:
- /* the bReserved flag of the pfd contains the
- overlay/underlay info. */
- pfd->bReserved = *(++p);
- break;
- case GDK_GL_RGBA:
- pfd->iPixelType = PFD_TYPE_RGBA;
- break;
- case GDK_GL_DOUBLEBUFFER:
- pfd->dwFlags |= PFD_DOUBLEBUFFER;
- break;
- case GDK_GL_STEREO:
- pfd->dwFlags |= PFD_STEREO;
- break;
- case GDK_GL_AUX_BUFFERS:
- pfd->cAuxBuffers = *(++p);
- break;
- case GDK_GL_RED_SIZE:
- pfd->cRedBits = 8; /* Try to get the maximum. */
- ++p;
- break;
- case GDK_GL_GREEN_SIZE:
- pfd->cGreenBits = 8;
- ++p;
- break;
- case GDK_GL_BLUE_SIZE:
- pfd->cBlueBits = 8;
- ++p;
- break;
- case GDK_GL_ALPHA_SIZE:
- pfd->cAlphaBits = 8;
- ++p;
- break;
- case GDK_GL_DEPTH_SIZE:
- pfd->cDepthBits = 32;
- ++p;
- break;
- case GDK_GL_STENCIL_SIZE:
- pfd->cStencilBits = *(++p);
- break;
- case GDK_GL_ACCUM_RED_SIZE:
- case GDK_GL_ACCUM_GREEN_SIZE:
- case GDK_GL_ACCUM_BLUE_SIZE:
- case GDK_GL_ACCUM_ALPHA_SIZE:
- /* I believe that WGL only used the cAccumRedBits,
- cAccumBlueBits, cAccumGreenBits, and cAccumAlphaBits fields
- when returning info about the accumulation buffer precision.
- Only cAccumBits is used for requesting an accumulation
- buffer. */
- pfd->cAccumBits += *(++p);
- break;
- }
- ++p;
- }
-}
+static GObjectClass *glcontext_parent_class;
+static void gdk_gl_context_class_init (GdkGLContextClass *class);
+/*
+ * The GdkGLPixmap class
+ */
+struct _GdkGLPixmap {
+ GObject parent;
+#ifdef USE_WIN32
+ gboolean initialised;
+ HDC hdc;
+ HBITMAP hbitmap;
+ GdkPixmap *pixmap;
#else
-static XVisualInfo *get_xvisualinfo(GdkVisual *visual)
-{
- Display *dpy;
- XVisualInfo vinfo_template;
- XVisualInfo *vi;
- int nitems_return;
-
- dpy = GDK_DISPLAY();
+ Display *xdisplay;
+ GLXPixmap glxpixmap;
+ GdkPixmap *front_left;
+#endif
+};
- /* 'GLX uses VisualInfo records because they uniquely identify
- * a (VisualID,screen,depth) tuple.'
- */
- vinfo_template.visual = GDK_VISUAL_XVISUAL(visual);
- vinfo_template.visualid = XVisualIDFromVisual(vinfo_template.visual);
- vinfo_template.depth = visual->depth;
- vinfo_template.screen = DefaultScreen(dpy);
- vi = XGetVisualInfo(dpy, VisualIDMask|VisualDepthMask|VisualScreenMask,
- &vinfo_template, &nitems_return);
+struct _GdkGLPixmapClass {
+ GObjectClass parent_class;
+};
+typedef struct _GdkGLPixmapClass GdkGLPixmapClass;
- g_assert( vi!=0 && nitems_return==1 ); /* visualinfo needs to be unique */
+static GObjectClass *glpixmap_parent_class;
+static void gdk_gl_pixmap_class_init (GdkGLPixmapClass *class);
- /* remember to XFree returned XVisualInfo !!! */
- return vi;
-}
+/*
+ * Local helper functions
+ */
+#ifdef USE_WIN32
+static void fill_pfd(PIXELFORMATDESCRIPTOR *pfd, int *attriblist);
+#else
+static XVisualInfo *get_xvisualinfo(GdkVisual *visual);
#endif
+/*
+ * Generic GL support
+ */
+
gint gdk_gl_query(void)
{
#ifdef USE_WIN32
@@ -155,21 +108,20 @@
gchar *gdk_gl_get_info()
{
+ char const *vendor, *version, *extensions;
#ifdef USE_WIN32
+ vendor = glGetString (GL_VENDOR);
+ version = glGetString (GL_VERSION);
+ extensions = glGetString (GL_EXTENSIONS);
+#else
+ vendor = glXGetClientString(GDK_DISPLAY(), GLX_VENDOR);
+ version = glXGetClientString(GDK_DISPLAY(), GLX_VERSION);
+ extensions = glXGetClientString(GDK_DISPLAY(), GLX_EXTENSIONS);
+#endif
return g_strdup_printf("VENDOR : %s\n"
"VERSION : %s\n"
"EXTENSIONS : %s\n",
- glGetString ( GL_VENDOR ),
- glGetString ( GL_VERSION ),
- glGetString ( GL_EXTENSIONS ));
-#else
- return g_strdup_printf("VENDOR : %s\n"
- "VERSION : %s\n"
- "EXTENSIONS : %s\n",
- glXGetClientString(GDK_DISPLAY(), GLX_VENDOR),
- glXGetClientString(GDK_DISPLAY(), GLX_VERSION),
- glXGetClientString(GDK_DISPLAY(), GLX_EXTENSIONS));
-#endif
+ vendor, version, extensions);
}
@@ -180,14 +132,15 @@
#else
Display *dpy;
XVisualInfo *vi;
- GdkVisual *visual;
+ GdkVisual *visual;
g_return_val_if_fail(attrlist != NULL, NULL);
dpy = GDK_DISPLAY();
- if ((vi = glXChooseVisual(dpy,DefaultScreen(dpy), attrlist)) == NULL)
+ vi = glXChooseVisual(dpy, DefaultScreen(dpy), attrlist);
+ if (!vi)
return NULL;
-
+
visual = gdkx_visual_get(vi->visualid);
XFree(vi);
return visual;
@@ -198,7 +151,7 @@
int gdk_gl_get_config(GdkVisual *visual, int attrib)
{
#ifdef USE_WIN32
- g_warning ( "not implemented" );
+ g_warning ("not implemented");
return 0;
#else
Display *dpy;
@@ -221,28 +174,10 @@
#endif
}
-struct _GdkGLContext {
- GObject parent;
-#ifdef USE_WIN32
- gboolean initialised;
- HGLRC hglrc;
- HDC hdc;
- HWND hwnd;
- GdkGLContext *share;
- PIXELFORMATDESCRIPTOR pfd;
-#else
- Display *xdisplay;
- GLXContext glxcontext;
-#endif
-};
-struct _GdkGLContextClass {
- GObjectClass parent_class;
-};
-typedef struct _GdkGLContextClass GdkGLContextClass;
-static GObjectClass *glcontext_parent_class;
-
-static void gdk_gl_context_class_init (GdkGLContextClass *class);
+/*
+ * GL context support
+ */
GType
gdk_gl_context_get_type (void)
@@ -279,15 +214,15 @@
context = GDK_GL_CONTEXT(object);
#ifdef USE_WIN32
- if (context->hglrc == wglGetCurrentContext () )
- wglMakeCurrent ( NULL, NULL );
+ if (context->hglrc == wglGetCurrentContext ())
+ wglMakeCurrent (NULL, NULL);
- wglDeleteContext ( context->hglrc );
+ wglDeleteContext (context->hglrc);
- if ( context->hwnd )
- ReleaseDC ( context->hwnd, context->hdc );
+ if (context->hwnd)
+ ReleaseDC (context->hwnd, context->hdc);
else
- DeleteDC ( context->hdc );
+ DeleteDC (context->hdc);
#else
if (context->glxcontext) {
if (context->glxcontext == glXGetCurrentContext())
@@ -301,6 +236,7 @@
(* glcontext_parent_class->finalize)(object);
}
+
static void
gdk_gl_context_class_init(GdkGLContextClass *class)
{
@@ -312,6 +248,7 @@
gobject_class->finalize = gdk_gl_context_finalize;
}
+
GdkGLContext *
gdk_gl_context_new(GdkVisual *visual)
{
@@ -324,55 +261,41 @@
{
#ifdef USE_WIN32
GdkGLContext *context;
+#else
+ Display *dpy;
+ XVisualInfo *vi;
+ GLXContext glxcontext;
+ GdkGLContext *context;
+#endif
- g_return_val_if_fail ( visual != NULL, NULL );
+ g_return_val_if_fail (visual != NULL, NULL);
context = g_object_new(GDK_TYPE_GL_CONTEXT, NULL);
- if (!context) return NULL;
+ if (!context)
+ return NULL;
+#ifdef USE_WIN32
context->initialised = FALSE;
context->hglrc = NULL;
context->hdc = NULL;
context->hwnd = NULL;
context->share = sharelist ? g_object_ref(sharelist) : NULL;
- memset ( &(context->pfd), 0, sizeof(PIXELFORMATDESCRIPTOR) );
+ memset (&(context->pfd), 0, sizeof(PIXELFORMATDESCRIPTOR));
- /* if direct is TRUE, we create a context which renders to the screen, otherwise
- we create one to render to an offscreen bitmap */
- if ( direct )
- {
- context->pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
- context->pfd.nVersion = 1;
+ /* if direct is TRUE, we create a context which renders to the screen,
+ otherwise we create one to render to an offscreen bitmap */
+ context->pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
+ context->pfd.nVersion = 1;
+ if (direct)
context->pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
- context->pfd.iPixelType = PFD_TYPE_RGBA;
- context->pfd.cColorBits = 24;
- context->pfd.cDepthBits = 32;
- context->pfd.iLayerType = PFD_MAIN_PLANE;
- }
else
- {
- context->pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
- context->pfd.nVersion = 1;
context->pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI;
- context->pfd.iPixelType = PFD_TYPE_RGBA;
- context->pfd.cColorBits = 24;
- context->pfd.cDepthBits = 32;
- context->pfd.iLayerType = PFD_MAIN_PLANE;
- }
-
- return context;
+ context->pfd.iPixelType = PFD_TYPE_RGBA;
+ context->pfd.cColorBits = 24;
+ context->pfd.cDepthBits = 32;
+ context->pfd.iLayerType = PFD_MAIN_PLANE;
#else
- Display *dpy;
- XVisualInfo *vi;
- GLXContext glxcontext;
- GdkGLContext *context;
-
- g_return_val_if_fail(visual != NULL, NULL);
-
- context = g_object_new(GDK_TYPE_GL_CONTEXT, NULL);
- if (!context) return NULL;
-
dpy = GDK_DISPLAY();
vi = get_xvisualinfo(visual);
@@ -390,20 +313,25 @@
context->xdisplay = dpy;
context->glxcontext = glxcontext;
+#endif
return context;
-#endif
}
GdkGLContext *gdk_gl_context_attrlist_share_new(int *attrlist, GdkGLContext *sharelist, gint direct)
{
#ifdef USE_WIN32
GdkGLContext *context;
+#else
+ GdkVisual *visual;
+#endif
g_return_val_if_fail(attrlist != NULL, NULL);
+#ifdef USE_WIN32
context = g_object_new(GDK_TYPE_GL_CONTEXT, NULL);
- if (!context) return NULL;
+ if (!context)
+ return NULL;
context->initialised = FALSE;
context->hglrc = NULL;
@@ -414,55 +342,53 @@
return context;
#else
- GdkVisual *visual = gdk_gl_choose_visual(attrlist);
- if (visual)
- return gdk_gl_context_share_new(visual, sharelist, direct);
- return NULL;
+ visual = gdk_gl_choose_visual(attrlist);
+ if (!visual)
+ return NULL;
+
+ return gdk_gl_context_share_new(visual, sharelist, direct);
#endif
}
gint gdk_gl_make_current(GdkDrawable *drawable, GdkGLContext *context)
{
-#ifdef USE_WIN32
- g_return_val_if_fail (GDK_IS_DRAWABLE(drawable), FALSE );
- g_return_val_if_fail (GDK_IS_GL_CONTEXT(context), FALSE );
+ g_return_val_if_fail (GDK_IS_DRAWABLE(drawable), FALSE);
+ g_return_val_if_fail (GDK_IS_GL_CONTEXT(context), FALSE);
- if ( !context->initialised )
+#ifdef USE_WIN32
+ if (!context->initialised)
{
int pf;
- HWND hwnd = (HWND) gdk_win32_drawable_get_handle ( drawable );
+ HWND hwnd = (HWND) gdk_win32_drawable_get_handle (drawable);
- context->hdc = GetDC ( hwnd );
+ context->hdc = GetDC (hwnd);
- pf = ChoosePixelFormat ( context->hdc, &context->pfd );
+ pf = ChoosePixelFormat (context->hdc, &context->pfd);
- if ( pf != 0 )
+ if (pf != 0)
{
- SetPixelFormat ( context->hdc, pf, &context->pfd );
- context->hglrc = wglCreateContext ( context->hdc );
+ SetPixelFormat (context->hdc, pf, &context->pfd);
+ context->hglrc = wglCreateContext (context->hdc);
}
if (context->share)
{
- if ( context->share->hglrc )
- wglShareLists ( context->share->hglrc, context->hglrc );
- g_object_unref ( context->share );
+ if (context->share->hglrc)
+ wglShareLists (context->share->hglrc, context->hglrc);
+ g_object_unref (context->share);
}
context->initialised = TRUE;
}
- g_return_val_if_fail ( context->hdc != NULL, FALSE );
- g_return_val_if_fail ( context->hglrc != NULL, FALSE );
+ g_return_val_if_fail (context->hdc != NULL, FALSE);
+ g_return_val_if_fail (context->hglrc != NULL, FALSE);
- wglMakeCurrent ( context->hdc, context->hglrc );
+ wglMakeCurrent (context->hdc, context->hglrc);
return TRUE;
#else
- g_return_val_if_fail(drawable != NULL, FALSE);
- g_return_val_if_fail(context != NULL, FALSE);
-
return (glXMakeCurrent(context->xdisplay, GDK_WINDOW_XWINDOW(drawable),
context->glxcontext) == True) ? TRUE : FALSE;
@@ -485,21 +411,21 @@
#ifdef USE_WIN32
HDC hdc;
HWND hwnd;
+#endif
- g_return_if_fail ( GDK_IS_DRAWABLE(drawable) );
+ g_return_if_fail (GDK_IS_DRAWABLE(drawable));
- hwnd = (HWND) gdk_win32_drawable_get_handle ( drawable );
- hdc = GetDC ( hwnd );
- if ( hdc == NULL )
+#ifdef USE_WIN32
+ hwnd = (HWND) gdk_win32_drawable_get_handle (drawable);
+ hdc = GetDC (hwnd);
+ if (hdc == NULL)
{
- g_warning ( "gdk_gl_swap_buffers: GetDC failed" );
+ g_warning ("gdk_gl_swap_buffers: GetDC failed");
return;
}
- SwapBuffers ( hdc );
- ReleaseDC ( hwnd, hdc );
+ SwapBuffers (hdc);
+ ReleaseDC (hwnd, hdc);
#else
- g_return_if_fail(drawable != NULL);
-
glXSwapBuffers(GDK_WINDOW_XDISPLAY(drawable), GDK_WINDOW_XWINDOW(drawable));
#endif
}
@@ -507,7 +433,7 @@
void gdk_gl_wait_gdk(void)
{
#ifdef USE_WIN32
- GdiFlush ();
+ GdiFlush();
#else
glXWaitX();
#endif
@@ -516,38 +442,16 @@
void gdk_gl_wait_gl (void)
{
#ifdef USE_WIN32
- glFinish ();
+ glFinish();
#else
glXWaitGL();
#endif
}
-/* glpixmap stuff */
-
-struct _GdkGLPixmap {
-#ifdef USE_WIN32
- GObject object;
- gboolean initialised;
- HDC hdc;
- HBITMAP hbitmap;
- GdkPixmap *pixmap;
-#else
- GObject parent;
- Display *xdisplay;
- GLXPixmap glxpixmap;
- GdkPixmap *front_left;
-#endif
-};
-
-struct _GdkGLPixmapClass {
- GObjectClass parent_class;
-};
-typedef struct _GdkGLPixmapClass GdkGLPixmapClass;
-
-static GObjectClass *glpixmap_parent_class;
-
-static void gdk_gl_pixmap_class_init (GdkGLPixmapClass *class);
+/*
+ * Pixmap support
+ */
GType
gdk_gl_pixmap_get_type (void)
@@ -585,8 +489,8 @@
#ifdef USE_WIN32
glFinish ();
- SelectObject ( pixmap->hdc, pixmap->hbitmap );
- gdk_pixmap_unref ( pixmap->pixmap );
+ SelectObject (pixmap->hdc, pixmap->hbitmap);
+ gdk_pixmap_unref (pixmap->pixmap);
#else
if (pixmap->glxpixmap != None) {
glXDestroyGLXPixmap(pixmap->xdisplay, pixmap->glxpixmap);
@@ -617,36 +521,29 @@
GdkGLPixmap *
gdk_gl_pixmap_new(GdkVisual *visual, GdkPixmap *pixmap)
{
-#ifdef USE_WIN32
GdkGLPixmap *glpixmap;
-
- g_return_val_if_fail(GDK_IS_VISUAL(visual), NULL);
- g_return_val_if_fail(GDK_IS_PIXMAP(pixmap), NULL);
-
- glpixmap = g_object_new(GDK_TYPE_GL_PIXMAP, NULL);
- if (!glpixmap) return NULL;
-
- glpixmap->initialised = FALSE;
- glpixmap->hdc = NULL;
- glpixmap->hbitmap = NULL;
- glpixmap->pixmap = gdk_pixmap_ref ( pixmap );
-
- return glpixmap;
-#else
+#ifndef USE_WIN32
Display *dpy;
XVisualInfo *vi;
Pixmap xpixmap;
- GdkGLPixmap *glpixmap;
GLXPixmap glxpixmap;
Window root_return;
unsigned int x_ret, y_ret, w_ret, h_ret, bw_ret, depth_ret;
+#endif
g_return_val_if_fail(GDK_IS_VISUAL(visual), NULL);
g_return_val_if_fail(GDK_IS_PIXMAP(pixmap), NULL);
glpixmap = g_object_new(GDK_TYPE_GL_PIXMAP, NULL);
- if (!glpixmap) return NULL;
+ if (!glpixmap)
+ return NULL;
+#ifdef USE_WIN32
+ glpixmap->initialised = FALSE;
+ glpixmap->hdc = NULL;
+ glpixmap->hbitmap = NULL;
+ glpixmap->pixmap = gdk_pixmap_ref (pixmap);
+#else
dpy = GDK_DISPLAY();
xpixmap = (Pixmap)GDK_DRAWABLE_XID(pixmap);
@@ -666,58 +563,57 @@
glpixmap->xdisplay = dpy;
glpixmap->glxpixmap = glxpixmap;
glpixmap->front_left = gdk_pixmap_ref(pixmap);
+#endif
return glpixmap;
-#endif
}
gint gdk_gl_pixmap_make_current(GdkGLPixmap *glpixmap, GdkGLContext *context)
{
-#ifdef USE_WIN32
- g_return_val_if_fail (GDK_IS_GL_PIXMAP(glpixmap), FALSE );
- g_return_val_if_fail (GDK_IS_GL_CONTEXT(context), FALSE );
+#ifndef USE_WIN32
+ Display *dpy;
+ GLXPixmap glxpixmap;
+ GLXContext glxcontext;
+#endif
+
+ g_return_val_if_fail (GDK_IS_GL_PIXMAP(glpixmap), FALSE);
+ g_return_val_if_fail (GDK_IS_GL_CONTEXT(context), FALSE);
- if ( !context->initialised )
+#ifdef USE_WIN32
+ if (!context->initialised)
{
int pf;
- context->hdc = CreateCompatibleDC ( NULL );
+ context->hdc = CreateCompatibleDC (NULL);
glpixmap->hdc = context->hdc;
- glpixmap->hbitmap = SelectObject ( context->hdc, (HBITMAP) gdk_win32_drawable_get_handle ( glpixmap->pixmap ) );
+ glpixmap->hbitmap = SelectObject (context->hdc, (HBITMAP) gdk_win32_drawable_get_handle (glpixmap->pixmap));
- pf = ChoosePixelFormat ( context->hdc, &context->pfd );
+ pf = ChoosePixelFormat (context->hdc, &context->pfd);
- if ( pf != 0 )
+ if (pf != 0)
{
- SetPixelFormat ( context->hdc, pf, &context->pfd );
- context->hglrc = wglCreateContext ( context->hdc );
+ SetPixelFormat (context->hdc, pf, &context->pfd);
+ context->hglrc = wglCreateContext (context->hdc);
}
if (context->share)
{
- if ( context->share->hglrc )
- wglShareLists ( context->share->hglrc, context->hglrc );
- gdk_gl_context_unref ( (GdkGLContext*)context->share );
+ if (context->share->hglrc)
+ wglShareLists (context->share->hglrc, context->hglrc);
+ gdk_gl_context_unref ((GdkGLContext*)context->share);
}
context->initialised = TRUE;
}
- g_return_val_if_fail ( context->hdc != NULL, FALSE );
- g_return_val_if_fail ( context->hglrc != NULL, FALSE );
+ g_return_val_if_fail (context->hdc != NULL, FALSE);
+ g_return_val_if_fail (context->hglrc != NULL, FALSE);
- wglMakeCurrent ( context->hdc, context->hglrc );
+ wglMakeCurrent (context->hdc, context->hglrc);
return TRUE;
#else
- Display *dpy;
- GLXPixmap glxpixmap;
- GLXContext glxcontext;
-
- g_return_val_if_fail(GDK_IS_GL_PIXMAP(glpixmap), FALSE);
- g_return_val_if_fail(GDK_IS_GL_CONTEXT(context), FALSE);
-
dpy = context->xdisplay;
glxpixmap = glpixmap->glxpixmap;
glxcontext = context->glxcontext;
@@ -726,20 +622,140 @@
#endif
}
-/* fonts */
+/*
+ * Font support
+ */
+
void gdk_gl_use_gdk_font(GdkFont *font, int first, int count, int list_base)
{
#ifdef USE_WIN32
- HDC dc = CreateCompatibleDC ( NULL );
- HFONT old_font = SelectObject ( dc, (void *)gdk_font_id ( font ) );
+ HDC dc = CreateCompatibleDC (NULL);
+ HFONT old_font = SelectObject (dc, (void *)gdk_font_id (font));
- wglUseFontBitmaps ( dc, first, count, list_base );
+ wglUseFontBitmaps (dc, first, count, list_base);
- SelectObject ( dc, old_font );
- DeleteDC ( dc );
+ SelectObject (dc, old_font);
+ DeleteDC (dc);
#else
g_return_if_fail(font != NULL);
glXUseXFont(gdk_font_id(font), first, count, list_base);
#endif
}
+
+/*
+ * Helper functions
+ */
+
+#ifdef USE_WIN32
+static void fill_pfd(PIXELFORMATDESCRIPTOR *pfd, int *attriblist)
+{
+ /*
+ * Ripped from glut's win32_x11.c
+ */
+
+ int *p = attriblist;
+
+ memset(pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
+ pfd->nSize = (sizeof(PIXELFORMATDESCRIPTOR));
+ pfd->nVersion = 1;
+
+ /* Defaults. */
+ pfd->dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
+ pfd->iPixelType = PFD_TYPE_COLORINDEX;
+ pfd->cColorBits = 32;
+ pfd->cDepthBits = 0;
+ pfd->cAccumBits = 0;
+
+ while (*p) {
+ switch (*p) {
+ case GDK_GL_USE_GL:
+ pfd->dwFlags |= PFD_SUPPORT_OPENGL;
+ break;
+ case GDK_GL_BUFFER_SIZE:
+ pfd->cColorBits = *(++p);
+ break;
+ case GDK_GL_LEVEL:
+ /* the bReserved flag of the pfd contains the
+ overlay/underlay info. */
+ pfd->bReserved = *(++p);
+ break;
+ case GDK_GL_RGBA:
+ pfd->iPixelType = PFD_TYPE_RGBA;
+ break;
+ case GDK_GL_DOUBLEBUFFER:
+ pfd->dwFlags |= PFD_DOUBLEBUFFER;
+ break;
+ case GDK_GL_STEREO:
+ pfd->dwFlags |= PFD_STEREO;
+ break;
+ case GDK_GL_AUX_BUFFERS:
+ pfd->cAuxBuffers = *(++p);
+ break;
+ case GDK_GL_RED_SIZE:
+ pfd->cRedBits = 8; /* Try to get the maximum. */
+ ++p;
+ break;
+ case GDK_GL_GREEN_SIZE:
+ pfd->cGreenBits = 8;
+ ++p;
+ break;
+ case GDK_GL_BLUE_SIZE:
+ pfd->cBlueBits = 8;
+ ++p;
+ break;
+ case GDK_GL_ALPHA_SIZE:
+ pfd->cAlphaBits = 8;
+ ++p;
+ break;
+ case GDK_GL_DEPTH_SIZE:
+ pfd->cDepthBits = 32;
+ ++p;
+ break;
+ case GDK_GL_STENCIL_SIZE:
+ pfd->cStencilBits = *(++p);
+ break;
+ case GDK_GL_ACCUM_RED_SIZE:
+ case GDK_GL_ACCUM_GREEN_SIZE:
+ case GDK_GL_ACCUM_BLUE_SIZE:
+ case GDK_GL_ACCUM_ALPHA_SIZE:
+ /* I believe that WGL only used the cAccumRedBits,
+ cAccumBlueBits, cAccumGreenBits, and cAccumAlphaBits fields
+ when returning info about the accumulation buffer precision.
+ Only cAccumBits is used for requesting an accumulation
+ buffer. */
+ pfd->cAccumBits += *(++p);
+ break;
+ }
+ ++p;
+ }
+}
+
+
+#else
+static XVisualInfo *get_xvisualinfo(GdkVisual *visual)
+{
+ Display *dpy;
+ XVisualInfo vinfo_template;
+ XVisualInfo *vi;
+ int nitems_return;
+
+ dpy = GDK_DISPLAY();
+
+ /* 'GLX uses VisualInfo records because they uniquely identify
+ * a (VisualID,screen,depth) tuple.'
+ */
+ vinfo_template.visual = GDK_VISUAL_XVISUAL(visual);
+ vinfo_template.visualid = XVisualIDFromVisual(vinfo_template.visual);
+ vinfo_template.depth = visual->depth;
+ vinfo_template.screen = DefaultScreen(dpy);
+ vi = XGetVisualInfo(dpy, VisualIDMask|VisualDepthMask|VisualScreenMask,
+ &vinfo_template, &nitems_return);
+
+ g_assert(vi!=0 && nitems_return==1); /* visualinfo needs to be unique */
+
+ /* remember to XFree returned XVisualInfo !!! */
+ return vi;
+}
+#endif
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]