2 # This file is part of duit.
4 # duit is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU Lesser General Public License as published by
6 # the Free Software Foundation; either version 2.1 of the License, or
7 # (at your option) any later version.
9 # duit is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with duit; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 # Definitions for wrapping gtk gl ext GL
31 public import glib.glibtypes;
32 public import glgdk.glgdktypes;
33 public import gtk.gtktypes;
59 # must start with wrap
64 ###########################################################
65 ### GL ####################################################
66 ###########################################################
68 file: /usr/share/doc/libgtkglext1-doc/html/gtkglext/gtkglext-gtkglinit.html
76 file: /usr/share/doc/libgtkglext1-doc/html/gtkglext/gtkglext-gtkglwidget.html
82 structWrap: GtkWidget* Widget
84 import: glgdk.GLDrawable
85 structWrap: GdkGLDrawable* Drawable
87 import: glgdk.GLConfig
88 structWrap: GdkGLConfig* GLConfig
90 import: glgdk.GLContext
91 structWrap: GdkGLContext* GLContext
93 import: glgdk.GLWindow
94 structWrap: GdkGLWindow* GLWindow
98 * Gets the GL Frawable for (from???) the widget
100 * @return a new GLDrawable
102 static GLDrawable getGLDrawable(Widget widget)
104 return new GLDrawable(cast(GdkGLDrawable*)gtk_widget_get_gl_window((widget is null) ? null : widget.getWidgetStruct()));
111 file: /usr/share/doc/libgtkglext1-doc/html/gtkglext/gtkglext-gtkglversion.html
113 #struct: GtkGLVersion
115 prefix: gtk_gl_version_
122 // SNEAKY MIXIN PROBLEM:
124 // These need to be public imports
125 // or GLCompatibility will not compile
126 // as a mixin in other modules!
128 // May as well be explicit about it:
131 public import std.stdio;
132 public import glgtk.GLWidget;
133 private import glgdk.GLDrawable;
134 public import gdk.Event;
135 public import lib.gl;
138 template GLCapability()
148 GLfloat getGLHeight()
155 * Sets the GL capabilities for the widget
157 bit setGLCapability(GLConfig glConfig = null, int renderType = GLRenderType.RGBA_TYPE)
159 if ( glConfig is null )
161 glConfig = new GLConfig(
162 GLConfigMode.MODE_RGB
163 | GLConfigMode.MODE_DEPTH
164 | GLConfigMode.MODE_DOUBLE,
165 GLConfigMode.MODE_RGB
166 | GLConfigMode.MODE_DEPTH
169 bit ok = setGLCapability(this, glConfig, null, true, renderType);
175 * Set the GL capabilities for the widget
177 bit setGLCapability(Widget widget, GLConfig glConfig, GLContext shareList, bit direct, int renderType)
179 GLWidget.setGLCapability(widget, glConfig, shareList, direct, renderType);
181 addOnRealize(&realizeFrame);
182 addOnUnrealize(&realizeFrame);
183 addOnExpose(&exposeFrame);
184 addOnConfigure(&configureFrame);
186 addOnUnmap(&unmapFrame);
187 addOnVisibilityNotify(&visibilityFrame);
192 * The widget should use this method to redraw it self at any time
194 public bit glDrawFrame()
196 return glDrawFrame(this);
200 * The application should use this method to redraw the scene at any time
202 bit glDrawFrame(Widget widget)
204 //printf("GLCapabilityT.realizeFrame \n" );
205 GLContext context = GLWidget.getGLContext(widget);
206 GLDrawable drawable = GLWidget.getGLDrawable(widget);
208 /*** OpenGL BEGIN ***/
209 if ( !drawable.glBegin(context) )
214 /*** do user actions ***/
215 bit consumeEvent = typeof(this).drawGL(null);
218 if ( drawable.isDoubleBuffered() )
220 drawable.swapBuffers();
233 bool alreadyRealized;
235 bool getAlreadyRealized()
237 return alreadyRealized;
240 void realizeFrame(Widget widget)
242 alreadyRealized = true;
244 //printf("GLCapabilityT.realizeFrame \n" );
245 GLContext context = GLWidget.getGLContext(widget);
246 GLDrawable drawable = GLWidget.getGLDrawable(widget);
248 /*** OpenGL BEGIN ***/
249 if ( !drawable.glBegin(context) )
254 /*** do user actions ***/
255 bit consumeEvent = typeof(this).initGL();
258 if ( drawable.isDoubleBuffered() )
260 drawable.swapBuffers();
270 //return consumeEvent;
273 int exposeFrame(GdkEventExpose* event, Widget widget)
275 //printf("GLCapabilityT.exposeFrame exposeFrame\n" );
276 GLContext context = GLWidget.getGLContext(widget);
277 GLDrawable drawable = GLWidget.getGLDrawable(widget);
279 /*** OpenGL BEGIN ***/
280 if ( !drawable.glBegin(context) )
285 /*** do user actions ***/
286 int consumeEvent = typeof(this).drawGL(event);
289 if ( drawable.isDoubleBuffered() )
291 drawable.swapBuffers();
304 private import std.gc;
306 int configureFrame(GdkEventConfigure* event, Widget widget)
311 height = event.height;
314 //writefln("configureFrame 1");
315 //printf("GLCapabilityT.configureFrame \n" );
316 GLContext context = GLWidget.getGLContext(widget);
317 GLDrawable drawable = GLWidget.getGLDrawable(widget);
319 /*** OpenGL BEGIN ***/
320 if ( !drawable.glBegin(context) )
325 //writefln("configureFrame 2");
326 /*** do user actions ***/
327 int consumeEvent = typeof(this).resizeGL(event);
329 //writefln("configureFrame 3");
332 if ( drawable.isDoubleBuffered() )
334 //writefln("configureFrame 4");
335 drawable.swapBuffers();
336 //writefln("configureFrame 5");
340 //writefln("configureFrame 6");
342 //writefln("configureFrame 7");
345 //writefln("configureFrame 8");
347 //writefln("configureFrame 9");
354 void mapFrame(Widget widget)
356 //printf("GLCapabilityT.mapFrame \n" );
357 GLContext context = GLWidget.getGLContext(widget);
358 GLDrawable drawable = GLWidget.getGLDrawable(widget);
360 /*** OpenGL BEGIN ***/
361 if ( !drawable.glBegin(context) )
366 /*** do user actions ***/
367 bit consumeEvent = typeof(this).onMap();
370 if ( drawable.isDoubleBuffered() )
372 drawable.swapBuffers();
382 //return consumeEvent;
385 void unmapFrame(Widget widget)
387 //printf("GLCapabilityT.unmapFrame \n" );
388 GLContext context = GLWidget.getGLContext(widget);
389 GLDrawable drawable = GLWidget.getGLDrawable(widget);
391 /*** OpenGL BEGIN ***/
392 if ( !drawable.glBegin(context) )
397 /*** do user actions ***/
398 bit consumeEvent = typeof(this).onUnmap();
401 if ( drawable.isDoubleBuffered() )
403 drawable.swapBuffers();
413 //return consumeEvent;
416 int visibilityFrame(GdkEventVisibility* event, Widget widget)
418 //printf("GLCapabilityT.visibilityFrame \n" );
419 GLContext context = GLWidget.getGLContext(widget);
420 GLDrawable drawable = GLWidget.getGLDrawable(widget);
422 /*** OpenGL BEGIN ***/
423 if ( !drawable.glBegin(context) )
428 /*** do user actions ***/
429 bool consumeEvent = typeof(this).onVisibility(event);
432 if ( drawable.isDoubleBuffered() )
434 drawable.swapBuffers();
449 //printf("GLCapabilityT.map \n" );
455 //printf("GLCapabilityT.unmap \n" );
459 bool onVisibility(GdkEventVisibility* event)
461 //printf("GLCapabilityT.visibility \n" );
467 outFile: GLCapability