GTKGLContext.cpp
Go to the documentation of this file.
1 // ****************************************************************************
2 // Filename: GTKGLContext.cpp
3 // Author: Florian Hecht
4 // Date: 2009
5 // ****************************************************************************
6 
7 
8 #include "GTKGLContext.h"
9 
10 #include <gtk/gtk.h>
11 #include <gdk/gdk.h>
12 #include <gdk/gdkx.h>
13 
15 : initialized(false), xdisplay(NULL)
16 {
17  if (glXQueryExtension(GDK_DISPLAY(), NULL, NULL) == FALSE)
18  {
19  printf("CGTKGLContext: no OpenGL support.\n");
20  return;
21  }
22 
23  xdisplay = GDK_DISPLAY();
24 
25  int attrlist[] = {GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 16, None};
26 
27  XVisualInfo *vi = glXChooseVisual(xdisplay, DefaultScreen(xdisplay), attrlist);
28  if (!vi)
29  {
30  printf("CGTKGLContext: couldn't find suitable VisualInfo for the GL context. (%d)\n", (size_t) xdisplay);
31  return;
32  }
33 
34  if (shared_context)
35  glxcontext = glXCreateContext(xdisplay, vi, shared_context->glxcontext, True);
36  else
37  glxcontext = glXCreateContext(xdisplay, vi, 0, True);
38 
39  if (glxcontext == NULL)
40  {
41  printf("CGTKGLContext: creation of GL context failed.\n");
42  XFree(vi);
43  return;
44  }
45 
46  visual = gdkx_visual_get(vi->visualid);
47  XFree(vi);
48 
49  initialized = true;
50 }
51 
53 {
54  if (!initialized)
55  return;
56 
57  if (glxcontext == glXGetCurrentContext())
58  glXMakeCurrent(xdisplay, None, NULL);
59 
60  glXDestroyContext(xdisplay, glxcontext);
61 }
62 
64 {
65  return initialized;
66 }
67 
69 {
70  if (!initialized)
71  return;
72 
73  if (drawable)
74  {
75  if (glXMakeCurrent(xdisplay, GDK_WINDOW_XWINDOW(drawable), glxcontext) == False)
76  {
77  printf("GTKGLContext: make current failed\n");
78  }
79  }
80 }
81 
83 {
84  if (!initialized)
85  return;
86 
87  glXSwapBuffers(GDK_WINDOW_XDISPLAY(drawable), GDK_WINDOW_XWINDOW(drawable));
88 }
89 
91 {
92  if (!initialized)
93  return;
94 
95  glXMakeCurrent(xdisplay, None, NULL);
96 }
97 
GdkVisual * visual
Definition: GTKGLContext.h:58
void SwapBuffers(GdkDrawable *drawable)
CGTKGLContext(CGTKGLContext *shared_context=NULL)
GLXContext glxcontext
Definition: GTKGLContext.h:57
void DoneCurrent()
_GdkDrawable GdkDrawable
Definition: GTKGLContext.h:24
bool IsInitialized()
Display * xdisplay
Definition: GTKGLContext.h:56
void MakeCurrent(GdkDrawable *drawable)


asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Mon Dec 2 2019 03:47:28