fltk.gl.window

FLTK OpenGL Window Class

This module provides the GlWindow class that wraps FLTK's Fl_Gl_Window. GlWindow provides OpenGL rendering capabilities with RAII resource management.

The GlWindow class provides:

  • RAII-based resource management
  • OpenGL context activation and management
  • Double buffering support
  • Scoped context activation for safe GL calls

    Authors

    Dejan Lekić

    License

    BSD-3-Clause
struct GlScope
class GlWindow

Types 2

OpenGL-capable window.

GlWindow provides a window with an OpenGL rendering context. Use makeCurrent() before making GL calls and swapBuffers() after rendering to display the result.

The window supports a customizable draw callback that is invoked when the window needs to redraw its OpenGL content. Set the onDraw property to provide your rendering code.

Example:

auto win = new GlWindow(640, 480, "OpenGL Demo");
win.mode = Mode.DOUBLE | Mode.DEPTH;
win.onDraw = () {
   // OpenGL rendering code here
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   // ... draw scene ...
};
win.show();
run();

Fields
FltkGlWindow _handleThe underlying GL window handle
string _titleStored title for reference
void delegate() nothrow @nogc _onDrawDraw callback delegate
Methods
void drawTrampoline(FltkGlWindow win, void * userdata) nothrow @nogcStatic trampoline function to bridge C callback to D delegate.
FltkGlWindow handle() @safe nothrow @nogcReturns the underlying GL window handle.
bool isValid() const @safe nothrow @nogcChecks if this GL window has a valid handle.
int width() const nothrow @nogcGets the window width.
int height() const nothrow @nogcGets the window height.
string title() const @safe nothrow @nogcGets the window title.
bool shown() const nothrow @nogcChecks if the window is currently shown on screen.
int mode() const nothrow @nogcGets the OpenGL mode flags.
void mode(int m) nothrow @nogcSets the OpenGL mode flags.
bool canDo(int m) nothrow @nogcChecks if a display mode is available on this system.
void delegate() nothrow @nogc onDraw()Gets the draw callback delegate.
void onDraw(void delegate() nothrow @nogc dg)Sets the draw callback delegate.
bool valid() const nothrow @nogcChecks if the OpenGL context is valid.
bool contextValid() const nothrow @nogcChecks if the OpenGL context is valid for rendering.
void makeCurrent() nothrow @nogcMakes this window's OpenGL context current.
void swapBuffers() nothrow @nogcSwaps the front and back buffers.
GlScope activate() nothrow @nogcReturns a scoped context activator.
void show() nothrow @nogcShows the window on screen.
void hide() nothrow @nogcHides the window.
void invalidate() nothrow @nogcMarks the window as needing a redraw.
void redraw() nothrow @nogcRequests a redraw of the window.
Constructors
this(int width, int height, string title = null)Creates a new OpenGL window with the specified size.
this(int x, int y, int width, int height, string title = null)Creates a new OpenGL window with position and size.
Destructors
~thisDestroys the GL window and releases resources.
structGlScope

Scoped OpenGL context activation.

This struct provides RAII-style context management. When created, it makes the associated window's GL context current. This ensures GL calls are made in the correct context.

Example:

{
   auto ctx = window.activate();
   // All GL calls here use window's context
   glClear(GL_COLOR_BUFFER_BIT);
   glBegin(GL_TRIANGLES);
   // ...
   glEnd();
   window.swapBuffers();
}

Fields
GlWindow _window
Methods
GlWindow window() nothrow @nogcReturns the associated window.
bool isValid() const nothrow @nogcChecks if the context is valid.
Constructors
this(GlWindow window)Creates a scoped context activator.