-
Notifications
You must be signed in to change notification settings - Fork 1
/
GLWindow.cpp
94 lines (82 loc) · 2.56 KB
/
GLWindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "GLStdafx.h"
#include "GLWindow.h"
#include "GLDrawingArea.h"
namespace Gtk
{
namespace GL
{
/*******************************************/
CGLWindow::CGLWindow(CGLDrawingArea& drawArea) :
_drawArea(drawArea),
_isDoubleBuffered(false)
/*******************************************/
{
CreateOpenGLCapability();
InitializeDrawingArea();
AttachDrawingAreaToWindow();
}
/*******************************************/
CGLWindow::~CGLWindow()
/*******************************************/
{
}
/*******************************************/
void CGLWindow::AttachDrawingAreaToWindow()
/*******************************************/
{
set_reallocate_redraws(true); // Get automatically redrawn if any of their children changed allocation.
set_border_width(0/*10*/); // Set border width.
add(DrawArea());
show_all();
}
/***************************************/
GdkGLConfig* CGLWindow::CreateGDKGLConfig()
/***************************************/
{
/* Try double-buffered visual */
GdkGLConfig* glconfig = gdk_gl_config_new_by_mode (static_cast<GdkGLConfigMode>(GDK_GL_MODE_RGB |
GDK_GL_MODE_DEPTH |
GDK_GL_MODE_DOUBLE));
if (glconfig == NULL)
{
IsDoubleBuffered(false);
g_print ("*** Cannot find the double-buffered visual.\n");
g_print ("*** Trying single-buffered visual.\n");
/* Try single-buffered visual */
glconfig = gdk_gl_config_new_by_mode (static_cast<GdkGLConfigMode>(GDK_GL_MODE_RGB |
GDK_GL_MODE_DEPTH));
if (glconfig == NULL)
{
g_print ("*** No appropriate OpenGL-capable visual found.\n");
exit (1);
}
}
else
{
IsDoubleBuffered(true);
}
return(glconfig);
}
/***************************************/
void CGLWindow::CreateOpenGLCapability()
/***************************************/
{
// Configure OpenGL-capable visual.
GLConfig(CreateGDKGLConfig());
// Set OpenGL-capability to the widget.
gtk_widget_set_gl_capability (reinterpret_cast<GtkWidget*>(gobj()),
GLConfig(),
NULL,
TRUE,
GDK_GL_RGBA_TYPE);
}
/***************************************/
void CGLWindow::InitializeDrawingArea()
/***************************************/
{
DrawArea().Holder(this);
DrawArea().MakeDrawingAreaAnOpenGLContext();
DrawArea().RegisterSignalHandlers();
}
};
};