/usr/share/doc/libgtkglextmm-x11-1.2-doc/simple-darea_8cc-example.html is in libgtkglextmm-x11-1.2-doc 1.2.0-8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>gtkglextmm: simple-darea.cc</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.4 -->
<div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="globals.html">File Members</a> | <a class="qindex" href="examples.html">Examples</a></div>
<h1>simple-darea.cc</h1>Simple <a class="el" href="classGtk_1_1GL_1_1DrawingArea.html">Gtk::GL::DrawingArea</a> example.<p>
<div class="fragment"><pre class="fragment"><span class="comment">// -*- C++ -*-</span>
<span class="comment">/*</span>
<span class="comment"> * simple.cc:</span>
<span class="comment"> * Simple Gtk::GL::DrawingArea example.</span>
<span class="comment"> *</span>
<span class="comment"> * written by Naofumi Yasufuku <naofumi@users.sourceforge.net></span>
<span class="comment"> */</span>
<span class="preprocessor">#include <iostream></span>
<span class="preprocessor">#include <cstdlib></span>
<span class="preprocessor">#include <gtkmm.h></span>
<span class="preprocessor">#include <<a class="code" href="gtkglmm_8h.html">gtkglmm.h</a>></span>
<span class="preprocessor">#ifdef G_OS_WIN32</span>
<span class="preprocessor"></span><span class="preprocessor">#define WIN32_LEAN_AND_MEAN 1</span>
<span class="preprocessor"></span><span class="preprocessor">#include <windows.h></span>
<span class="preprocessor">#endif</span>
<span class="preprocessor"></span>
<span class="preprocessor">#include <GL/gl.h></span>
<span class="preprocessor">#include <GL/glu.h></span>
<span class="comment">//</span>
<span class="comment">// OpenGL frame buffer configuration utilities.</span>
<span class="comment">//</span>
<span class="comment"></span>
<span class="keyword">struct </span>GLConfigUtil
{
<span class="keyword">static</span> <span class="keywordtype">void</span> print_gl_attrib(<span class="keyword">const</span> Glib::RefPtr<const Gdk::GL::Config>& glconfig,
<span class="keyword">const</span> <span class="keywordtype">char</span>* attrib_str,
<span class="keywordtype">int</span> attrib,
<span class="keywordtype">bool</span> is_boolean);
<span class="keyword">static</span> <span class="keywordtype">void</span> examine_gl_attrib(<span class="keyword">const</span> Glib::RefPtr<const Gdk::GL::Config>& glconfig);
};
<span class="comment">//</span>
<span class="comment">// Print a configuration attribute.</span>
<span class="comment">//</span>
<span class="keywordtype">void</span> GLConfigUtil::print_gl_attrib(<span class="keyword">const</span> Glib::RefPtr<const Gdk::GL::Config>& glconfig,
<span class="keyword">const</span> <span class="keywordtype">char</span>* attrib_str,
<span class="keywordtype">int</span> attrib,
<span class="keywordtype">bool</span> is_boolean)
{
<span class="keywordtype">int</span> value;
<span class="keywordflow">if</span> (glconfig->get_attrib(attrib, value))
{
std::cout << attrib_str << <span class="stringliteral">" = "</span>;
<span class="keywordflow">if</span> (is_boolean)
std::cout << (value == <span class="keyword">true</span> ? <span class="stringliteral">"true"</span> : <span class="stringliteral">"false"</span>) << std::endl;
<span class="keywordflow">else</span>
std::cout << value << std::endl;
}
<span class="keywordflow">else</span>
{
std::cout << <span class="stringliteral">"*** Cannot get "</span>
<< attrib_str
<< <span class="stringliteral">" attribute value\n"</span>;
}
}
<span class="comment">//</span>
<span class="comment">// Print configuration attributes.</span>
<span class="comment">//</span>
<span class="keywordtype">void</span> GLConfigUtil::examine_gl_attrib(<span class="keyword">const</span> Glib::RefPtr<const Gdk::GL::Config>& glconfig)
{
std::cout << <span class="stringliteral">"\nOpenGL visual configurations :\n\n"</span>;
std::cout << <span class="stringliteral">"glconfig->is_rgba() = "</span>
<< (glconfig->is_rgba() ? <span class="stringliteral">"true"</span> : <span class="stringliteral">"false"</span>)
<< std::endl;
std::cout << <span class="stringliteral">"glconfig->is_double_buffered() = "</span>
<< (glconfig->is_double_buffered() ? <span class="stringliteral">"true"</span> : <span class="stringliteral">"false"</span>)
<< std::endl;
std::cout << <span class="stringliteral">"glconfig->is_stereo() = "</span>
<< (glconfig->is_stereo() ? <span class="stringliteral">"true"</span> : <span class="stringliteral">"false"</span>)
<< std::endl;
std::cout << <span class="stringliteral">"glconfig->has_alpha() = "</span>
<< (glconfig->has_alpha() ? <span class="stringliteral">"true"</span> : <span class="stringliteral">"false"</span>)
<< std::endl;
std::cout << <span class="stringliteral">"glconfig->has_depth_buffer() = "</span>
<< (glconfig->has_depth_buffer() ? <span class="stringliteral">"true"</span> : <span class="stringliteral">"false"</span>)
<< std::endl;
std::cout << <span class="stringliteral">"glconfig->has_stencil_buffer() = "</span>
<< (glconfig->has_stencil_buffer() ? <span class="stringliteral">"true"</span> : <span class="stringliteral">"false"</span>)
<< std::endl;
std::cout << <span class="stringliteral">"glconfig->has_accum_buffer() = "</span>
<< (glconfig->has_accum_buffer() ? <span class="stringliteral">"true"</span> : <span class="stringliteral">"false"</span>)
<< std::endl;
std::cout << std::endl;
print_gl_attrib(glconfig, <span class="stringliteral">"Gdk::GL::USE_GL"</span>, <a name="a147"></a><a class="code" href="group__gdkmm__glEnums.html#gga36a15">Gdk::GL::USE_GL</a>, <span class="keyword">true</span>);
print_gl_attrib(glconfig, <span class="stringliteral">"Gdk::GL::BUFFER_SIZE"</span>, <a name="a148"></a><a class="code" href="group__gdkmm__glEnums.html#gga36a16">Gdk::GL::BUFFER_SIZE</a>, <span class="keyword">false</span>);
print_gl_attrib(glconfig, <span class="stringliteral">"Gdk::GL::LEVEL"</span>, <a name="a149"></a><a class="code" href="group__gdkmm__glEnums.html#gga36a17">Gdk::GL::LEVEL</a>, <span class="keyword">false</span>);
print_gl_attrib(glconfig, <span class="stringliteral">"Gdk::GL::RGBA"</span>, <a name="a150"></a><a class="code" href="group__gdkmm__glEnums.html#gga36a18">Gdk::GL::RGBA</a>, <span class="keyword">true</span>);
print_gl_attrib(glconfig, <span class="stringliteral">"Gdk::GL::DOUBLEBUFFER"</span>, <a name="a151"></a><a class="code" href="group__gdkmm__glEnums.html#gga36a19">Gdk::GL::DOUBLEBUFFER</a>, <span class="keyword">true</span>);
print_gl_attrib(glconfig, <span class="stringliteral">"Gdk::GL::STEREO"</span>, <a name="a152"></a><a class="code" href="group__gdkmm__glEnums.html#gga36a20">Gdk::GL::STEREO</a>, <span class="keyword">true</span>);
print_gl_attrib(glconfig, <span class="stringliteral">"Gdk::GL::AUX_BUFFERS"</span>, <a name="a153"></a><a class="code" href="group__gdkmm__glEnums.html#gga36a21">Gdk::GL::AUX_BUFFERS</a>, <span class="keyword">false</span>);
print_gl_attrib(glconfig, <span class="stringliteral">"Gdk::GL::RED_SIZE"</span>, <a name="a154"></a><a class="code" href="group__gdkmm__glEnums.html#gga36a22">Gdk::GL::RED_SIZE</a>, <span class="keyword">false</span>);
print_gl_attrib(glconfig, <span class="stringliteral">"Gdk::GL::GREEN_SIZE"</span>, <a name="a155"></a><a class="code" href="group__gdkmm__glEnums.html#gga36a23">Gdk::GL::GREEN_SIZE</a>, <span class="keyword">false</span>);
print_gl_attrib(glconfig, <span class="stringliteral">"Gdk::GL::BLUE_SIZE"</span>, <a name="a156"></a><a class="code" href="group__gdkmm__glEnums.html#gga36a24">Gdk::GL::BLUE_SIZE</a>, <span class="keyword">false</span>);
print_gl_attrib(glconfig, <span class="stringliteral">"Gdk::GL::ALPHA_SIZE"</span>, <a name="a157"></a><a class="code" href="group__gdkmm__glEnums.html#gga36a25">Gdk::GL::ALPHA_SIZE</a>, <span class="keyword">false</span>);
print_gl_attrib(glconfig, <span class="stringliteral">"Gdk::GL::DEPTH_SIZE"</span>, <a name="a158"></a><a class="code" href="group__gdkmm__glEnums.html#gga36a26">Gdk::GL::DEPTH_SIZE</a>, <span class="keyword">false</span>);
print_gl_attrib(glconfig, <span class="stringliteral">"Gdk::GL::STENCIL_SIZE"</span>, <a name="a159"></a><a class="code" href="group__gdkmm__glEnums.html#gga36a27">Gdk::GL::STENCIL_SIZE</a>, <span class="keyword">false</span>);
print_gl_attrib(glconfig, <span class="stringliteral">"Gdk::GL::ACCUM_RED_SIZE"</span>, <a name="a160"></a><a class="code" href="group__gdkmm__glEnums.html#gga36a28">Gdk::GL::ACCUM_RED_SIZE</a>, <span class="keyword">false</span>);
print_gl_attrib(glconfig, <span class="stringliteral">"Gdk::GL::ACCUM_GREEN_SIZE"</span>, <a name="a161"></a><a class="code" href="group__gdkmm__glEnums.html#gga36a29">Gdk::GL::ACCUM_GREEN_SIZE</a>, <span class="keyword">false</span>);
print_gl_attrib(glconfig, <span class="stringliteral">"Gdk::GL::ACCUM_BLUE_SIZE"</span>, <a name="a162"></a><a class="code" href="group__gdkmm__glEnums.html#gga36a30">Gdk::GL::ACCUM_BLUE_SIZE</a>, <span class="keyword">false</span>);
print_gl_attrib(glconfig, <span class="stringliteral">"Gdk::GL::ACCUM_ALPHA_SIZE"</span>, <a name="a163"></a><a class="code" href="group__gdkmm__glEnums.html#gga36a31">Gdk::GL::ACCUM_ALPHA_SIZE</a>, <span class="keyword">false</span>);
std::cout << std::endl;
}
<span class="comment">//</span>
<span class="comment">// Simple OpenGL scene.</span>
<span class="comment">//</span>
<span class="comment"></span>
<span class="keyword">class </span>SimpleGLScene : <span class="keyword">public</span> Gtk::GL::DrawingArea
{
<span class="keyword">public</span>:
SimpleGLScene(<span class="keyword">const</span> Glib::RefPtr<const Gdk::GL::Config>& config);
<span class="keyword">virtual</span> ~SimpleGLScene();
<span class="keyword">protected</span>:
<span class="keyword">virtual</span> <span class="keywordtype">void</span> on_realize();
<span class="keyword">virtual</span> <span class="keywordtype">bool</span> on_configure_event(GdkEventConfigure* event);
<span class="keyword">virtual</span> <span class="keywordtype">bool</span> on_expose_event(GdkEventExpose* event);
};
SimpleGLScene::SimpleGLScene(<span class="keyword">const</span> Glib::RefPtr<const Gdk::GL::Config>& config)
: Gtk::GL::DrawingArea(config)
{
}
SimpleGLScene::~SimpleGLScene()
{
}
<span class="keywordtype">void</span> SimpleGLScene::on_realize()
{
<span class="comment">// We need to call the base on_realize()</span>
Gtk::GL::DrawingArea::on_realize();
<span class="comment">//</span>
<span class="comment">// Get GL::Window.</span>
<span class="comment">//</span>
Glib::RefPtr<Gdk::GL::Window> glwindow = get_gl_window();
<span class="comment">//</span>
<span class="comment">// GL calls.</span>
<span class="comment">//</span>
<span class="comment">// *** OpenGL BEGIN ***</span>
<span class="keywordflow">if</span> (!glwindow->gl_begin(get_gl_context()))
<span class="keywordflow">return</span>;
GLUquadricObj* qobj = gluNewQuadric();
gluQuadricDrawStyle(qobj, GLU_FILL);
glNewList(1, GL_COMPILE);
gluSphere(qobj, 1.0, 20, 20);
glEndList();
<span class="keyword">static</span> GLfloat light_diffuse[] = {1.0, 0.0, 0.0, 1.0};
<span class="keyword">static</span> GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0};
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glClearColor(1.0, 1.0, 1.0, 1.0);
glClearDepth(1.0);
glViewport(0, 0, get_width(), get_height());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40.0, 1.0, 1.0, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 3.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);
glTranslatef(0.0, 0.0, -3.0);
glwindow->gl_end();
<span class="comment">// *** OpenGL END ***</span>
}
<span class="keywordtype">bool</span> SimpleGLScene::on_configure_event(GdkEventConfigure* event)
{
<span class="comment">//</span>
<span class="comment">// Get GL::Window.</span>
<span class="comment">//</span>
Glib::RefPtr<Gdk::GL::Window> glwindow = get_gl_window();
<span class="comment">//</span>
<span class="comment">// GL calls.</span>
<span class="comment">//</span>
<span class="comment">// *** OpenGL BEGIN ***</span>
<span class="keywordflow">if</span> (!glwindow->gl_begin(get_gl_context()))
<span class="keywordflow">return</span> <span class="keyword">false</span>;
glViewport(0, 0, get_width(), get_height());
glwindow->gl_end();
<span class="comment">// *** OpenGL END ***</span>
<span class="keywordflow">return</span> <span class="keyword">true</span>;
}
<span class="keywordtype">bool</span> SimpleGLScene::on_expose_event(GdkEventExpose* event)
{
<span class="comment">//</span>
<span class="comment">// Get GL::Window.</span>
<span class="comment">//</span>
Glib::RefPtr<Gdk::GL::Window> glwindow = get_gl_window();
<span class="comment">//</span>
<span class="comment">// GL calls.</span>
<span class="comment">//</span>
<span class="comment">// *** OpenGL BEGIN ***</span>
<span class="keywordflow">if</span> (!glwindow->gl_begin(get_gl_context()))
<span class="keywordflow">return</span> <span class="keyword">false</span>;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glCallList(1);
<span class="comment">// Swap buffers.</span>
<span class="keywordflow">if</span> (glwindow->is_double_buffered())
glwindow->swap_buffers();
<span class="keywordflow">else</span>
glFlush();
glwindow->gl_end();
<span class="comment">// *** OpenGL END ***</span>
<span class="keywordflow">return</span> <span class="keyword">true</span>;
}
<span class="comment">//</span>
<span class="comment">// The application class.</span>
<span class="comment">//</span>
<span class="comment"></span>
<span class="keyword">class </span>Simple : <span class="keyword">public</span> Gtk::Window
{
<span class="keyword">public</span>:
Simple(<span class="keyword">const</span> Glib::RefPtr<const Gdk::GL::Config>& config);
<span class="keyword">virtual</span> ~Simple();
<span class="keyword">protected</span>:
<span class="comment">// signal handlers:</span>
<span class="keywordtype">void</span> on_button_quit_clicked();
<span class="keyword">protected</span>:
<span class="comment">// member widgets:</span>
Gtk::VBox m_VBox;
SimpleGLScene m_SimpleGLScene;
Gtk::Button m_ButtonQuit;
};
Simple::Simple(<span class="keyword">const</span> Glib::RefPtr<const Gdk::GL::Config>& config)
: m_VBox(false, 0), m_SimpleGLScene(config), m_ButtonQuit(<span class="stringliteral">"Quit"</span>)
{
<span class="comment">//</span>
<span class="comment">// Top-level window.</span>
<span class="comment">//</span>
set_title(<span class="stringliteral">"Gtk::GL::DrawingArea"</span>);
<span class="comment">// Get automatically redrawn if any of their children changed allocation.</span>
set_reallocate_redraws(<span class="keyword">true</span>);
add(m_VBox);
<span class="comment">//</span>
<span class="comment">// Simple OpenGL scene.</span>
<span class="comment">//</span>
m_SimpleGLScene.set_size_request(200, 200);
m_VBox.pack_start(m_SimpleGLScene);
<span class="comment">//</span>
<span class="comment">// Simple quit button.</span>
<span class="comment">//</span>
m_ButtonQuit.signal_clicked().connect(
sigc::mem_fun(*<span class="keyword">this</span>, &Simple::on_button_quit_clicked));
m_VBox.pack_start(m_ButtonQuit, Gtk::PACK_SHRINK, 0);
<span class="comment">//</span>
<span class="comment">// Show window.</span>
<span class="comment">//</span>
show_all();
}
Simple::~Simple()
{}
<span class="keywordtype">void</span> Simple::on_button_quit_clicked()
{
Gtk::Main::quit();
}
<span class="comment">//</span>
<span class="comment">// Main.</span>
<span class="comment">//</span>
<span class="comment"></span>
<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv)
{
Gtk::Main kit(argc, argv);
<span class="comment">//</span>
<span class="comment">// Init gtkglextmm.</span>
<span class="comment">//</span>
<a name="a164"></a><a class="code" href="namespaceGtk_1_1GL.html#a2">Gtk::GL::init</a>(argc, argv);
<span class="comment">//</span>
<span class="comment">// Query OpenGL extension version.</span>
<span class="comment">//</span>
<span class="keywordtype">int</span> major, minor;
<a name="a165"></a><a class="code" href="namespaceGdk_1_1GL.html#a116">Gdk::GL::query_version</a>(major, minor);
std::cout << <span class="stringliteral">"OpenGL extension version - "</span>
<< major << <span class="stringliteral">"."</span> << minor << std::endl;
<span class="comment">//</span>
<span class="comment">// Configure OpenGL-capable visual.</span>
<span class="comment">//</span>
Glib::RefPtr<Gdk::GL::Config> glconfig;
<span class="comment">// Try double-buffered visual</span>
glconfig = <a name="a166"></a><a class="code" href="classGdk_1_1GL_1_1Config.html#e0">Gdk::GL::Config::create</a>(<a name="a167"></a><a class="code" href="group__gdkmm__glEnums.html#gga35a0">Gdk::GL::MODE_RGB</a> |
<a name="a168"></a><a class="code" href="group__gdkmm__glEnums.html#gga35a7">Gdk::GL::MODE_DEPTH</a> |
<a name="a169"></a><a class="code" href="group__gdkmm__glEnums.html#gga35a4">Gdk::GL::MODE_DOUBLE</a>);
<span class="keywordflow">if</span> (!glconfig)
{
std::cerr << <span class="stringliteral">"*** Cannot find the double-buffered visual.\n"</span>
<< <span class="stringliteral">"*** Trying single-buffered visual.\n"</span>;
<span class="comment">// Try single-buffered visual</span>
glconfig = <a class="code" href="classGdk_1_1GL_1_1Config.html#e0">Gdk::GL::Config::create</a>(<a class="code" href="group__gdkmm__glEnums.html#gga35a0">Gdk::GL::MODE_RGB</a> |
<a class="code" href="group__gdkmm__glEnums.html#gga35a7">Gdk::GL::MODE_DEPTH</a>);
<span class="keywordflow">if</span> (!glconfig)
{
std::cerr << <span class="stringliteral">"*** Cannot find any OpenGL-capable visual.\n"</span>;
std::exit(1);
}
}
<span class="comment">// print frame buffer attributes.</span>
GLConfigUtil::examine_gl_attrib(glconfig);
<span class="comment">//</span>
<span class="comment">// Instantiate and run the application.</span>
<span class="comment">//</span>
Simple simple(glconfig);
kit.run(simple);
<span class="keywordflow">return</span> 0;
}
</pre></div> <hr size="1"><address style="align: right;"><small>Generated on Mon Feb 27 18:46:53 2006 for gtkglextmm by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.4 </small></address>
</body>
</html>
|