Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
IVT
src
gui
GTK
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
14
CGTKGLContext::CGTKGLContext
(
CGTKGLContext
*shared_context)
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
52
CGTKGLContext::~CGTKGLContext
()
53
{
54
if
(!
initialized
)
55
return
;
56
57
if
(
glxcontext
== glXGetCurrentContext())
58
glXMakeCurrent(
xdisplay
, None, NULL);
59
60
glXDestroyContext(
xdisplay
,
glxcontext
);
61
}
62
63
bool
CGTKGLContext::IsInitialized
()
64
{
65
return
initialized
;
66
}
67
68
void
CGTKGLContext::MakeCurrent
(
GdkDrawable
*drawable)
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
82
void
CGTKGLContext::SwapBuffers
(
GdkDrawable
*drawable)
83
{
84
if
(!
initialized
)
85
return
;
86
87
glXSwapBuffers(GDK_WINDOW_XDISPLAY(drawable), GDK_WINDOW_XWINDOW(drawable));
88
}
89
90
void
CGTKGLContext::DoneCurrent
()
91
{
92
if
(!
initialized
)
93
return
;
94
95
glXMakeCurrent(
xdisplay
, None, NULL);
96
}
97
CGTKGLContext::visual
GdkVisual * visual
Definition:
GTKGLContext.h:58
CGTKGLContext::SwapBuffers
void SwapBuffers(GdkDrawable *drawable)
Definition:
GTKGLContext.cpp:82
CGTKGLContext::CGTKGLContext
CGTKGLContext(CGTKGLContext *shared_context=NULL)
Definition:
GTKGLContext.cpp:14
GTKGLContext.h
CGTKGLContext::glxcontext
GLXContext glxcontext
Definition:
GTKGLContext.h:57
CGTKGLContext::~CGTKGLContext
~CGTKGLContext()
Definition:
GTKGLContext.cpp:52
CGTKGLContext::DoneCurrent
void DoneCurrent()
Definition:
GTKGLContext.cpp:90
GdkDrawable
_GdkDrawable GdkDrawable
Definition:
GTKGLContext.h:24
CGTKGLContext::IsInitialized
bool IsInitialized()
Definition:
GTKGLContext.cpp:63
CGTKGLContext::initialized
bool initialized
Definition:
GTKGLContext.h:55
CGTKGLContext::xdisplay
Display * xdisplay
Definition:
GTKGLContext.h:56
CGTKGLContext
Definition:
GTKGLContext.h:40
CGTKGLContext::MakeCurrent
void MakeCurrent(GdkDrawable *drawable)
Definition:
GTKGLContext.cpp:68
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