fltk.core.gl

FLTK OpenGL Library Bindings

This package provides low-level D bindings for the FLTK OpenGL library (libfltk_gl), which adds OpenGL rendering support to FLTK windows.

Features:

  • OpenGL context creation and management
  • Double buffering support
  • GL context sharing between windows
  • Overlay support (where available)

Memory Management:

  • GL windows created with fltk_gl_window_new() must be destroyed with fltk_gl_window_delete()
  • GL contexts are managed automatically by FLTK

Thread Safety:

  • OpenGL contexts are thread-specific
  • Use make_current() before GL calls in each thread

Example:

import fltk.core.gl;
import fltk.core.enums : FltkMode;

void main() {
   if (!hasGlSupport()) {
      writeln("OpenGL not available");
      return;
   }

   // Create GL window with double buffering and depth buffer
   auto mode = FltkMode.DOUBLE | FltkMode.DEPTH;
   auto win = fltk_gl_window_new(640, 480, "OpenGL Demo");
   if (win !is null) {
      fltk_gl_window_show(win);
      // ... render loop ...
      fltk_gl_window_delete(win);
   }
}

Authors

Dejan Lekić

License

BSD-3-Clause

Types 5

Opaque handle for Fl_Gl_Window.

This is the primary type for OpenGL-capable windows in FLTK. It inherits from Fl_Window and provides OpenGL context management.

Fields
private void * ptr

Alias for GL window handle

Opaque handle for GL context.

Represents an OpenGL rendering context. Usually managed internally by Fl_Gl_Window, but exposed for advanced context sharing scenarios.

Fields
private void * ptr

Alias for GL context handle

aliasGlWindowDrawCallback = void function(FltkGlWindow win, void * userdata) nothrow @nogc

GL window draw callback function type.

Called when the GL window needs to redraw its OpenGL content. The GL context is made current before the callback is invoked.

Parameters

winThe GL window
userdataUser-provided data pointer

Functions 25

fnbool isValid(FltkGlWindow window) @safe nothrow @nogcChecks if a GL window handle is valid (non-null).
fnbool isValid(FltkGlContext context) @safe nothrow @nogcChecks if a GL context handle is valid (non-null).
fnbool isDisplayAvailable() @safe nothrowChecks if a display server is available.
fnbool hasGlSupport() @safe nothrowChecks if OpenGL support is available.
fnbool isHeadless() @safe nothrowChecks if running in a headless environment.
fnFltkGlWindow fltk_gl_window_new(int w, int h, const(char) * title)Creates a new OpenGL window with specified size.
fnFltkGlWindow fltk_gl_window_new_xy(int x, int y, int w, int h, const(char) * title)Creates a new OpenGL window with position and size.
fnvoid fltk_gl_window_delete(FltkGlWindow win)Deletes an OpenGL window.
fnvoid fltk_gl_window_show(FltkGlWindow win)Shows the OpenGL window.
fnvoid fltk_gl_window_hide(FltkGlWindow win)Hides the OpenGL window.
fnint fltk_gl_window_shown(FltkGlWindow win)Checks if the window is currently shown.
fnvoid fltk_gl_window_make_current(FltkGlWindow win)Makes the OpenGL context current for this window.
fnvoid fltk_gl_window_swap_buffers(FltkGlWindow win)Swaps the front and back buffers.
fnint fltk_gl_window_valid(FltkGlWindow win)Checks if the OpenGL context is valid.
fnint fltk_gl_window_context_valid(FltkGlWindow win)Checks if the OpenGL context is valid for rendering.
fnvoid fltk_gl_window_invalidate(FltkGlWindow win)Marks the window as needing a redraw.
fnvoid fltk_gl_window_redraw(FltkGlWindow win)Requests a redraw of the window.
fnint fltk_gl_window_mode(FltkGlWindow win)Gets the OpenGL mode flags.
fnvoid fltk_gl_window_set_mode(FltkGlWindow win, int mode)Sets the OpenGL mode flags.
fnint fltk_gl_window_can_do(int mode)Checks if a display mode is available.
fnint fltk_gl_window_w(FltkGlWindow win)Gets the window width.
fnint fltk_gl_window_h(FltkGlWindow win)Gets the window height.
fnWindowPtr fltk_gl_window_as_window(FltkGlWindow win)Casts a GL window to a base window handle.
fnWidgetPtr fltk_gl_window_as_widget(FltkGlWindow win)Casts a GL window to a widget handle.
fnvoid fltk_gl_window_set_draw_callback(FltkGlWindow win, GlWindowDrawCallback callback, void * userdata)Sets the draw callback for a GL window.