On this page:
25.1 Creating Contexts
create-gl-context
gl-context?
gl-make-current!
gl-swap-window!
25.2 Open  GL Attributes
gl-set-attribute!
gl-get-attribute
25.2.1 Attribute Constants
25.2.1.1 Buffer Sizes
SDL_  GL_  RED_  SIZE
SDL_  GL_  GREEN_  SIZE
SDL_  GL_  BLUE_  SIZE
SDL_  GL_  ALPHA_  SIZE
SDL_  GL_  BUFFER_  SIZE
SDL_  GL_  DEPTH_  SIZE
SDL_  GL_  STENCIL_  SIZE
25.2.1.2 Accumulation Buffer
SDL_  GL_  ACCUM_  RED_  SIZE
SDL_  GL_  ACCUM_  GREEN_  SIZE
SDL_  GL_  ACCUM_  BLUE_  SIZE
SDL_  GL_  ACCUM_  ALPHA_  SIZE
25.2.1.3 Multisampling
SDL_  GL_  MULTISAMPLEBUFFERS
SDL_  GL_  MULTISAMPLESAMPLES
25.2.1.4 Context Settings
SDL_  GL_  DOUBLEBUFFER
SDL_  GL_  STEREO
SDL_  GL_  ACCELERATED_  VISUAL
SDL_  GL_  RETAINED_  BACKING
SDL_  GL_  FRAMEBUFFER_  SRGB_  CAPABLE
SDL_  GL_  FLOATBUFFERS
25.2.1.5 Context Version and Profile
SDL_  GL_  CONTEXT_  MAJOR_  VERSION
SDL_  GL_  CONTEXT_  MINOR_  VERSION
SDL_  GL_  CONTEXT_  PROFILE_  MASK
SDL_  GL_  CONTEXT_  FLAGS
25.2.1.6 Context Profiles
SDL_  GL_  CONTEXT_  PROFILE_  CORE
SDL_  GL_  CONTEXT_  PROFILE_  COMPATIBILITY
SDL_  GL_  CONTEXT_  PROFILE_  ES
25.2.1.7 Context Flags
SDL_  GL_  CONTEXT_  DEBUG_  FLAG
SDL_  GL_  CONTEXT_  FORWARD_  COMPATIBLE_  FLAG
SDL_  GL_  CONTEXT_  ROBUST_  ACCESS_  FLAG
SDL_  GL_  CONTEXT_  RESET_  ISOLATION_  FLAG
25.2.1.8 Other
SDL_  GL_  SHARE_  WITH_  CURRENT_  CONTEXT
SDL_  GL_  CONTEXT_  RELEASE_  BEHAVIOR
SDL_  GL_  CONTEXT_  RESET_  NOTIFICATION
SDL_  GL_  CONTEXT_  NO_  ERROR
SDL_  GL_  EGL_  PLATFORM
25.3 Swap Interval (VSync)
gl-set-swap-interval!
gl-get-swap-interval
9.0.0.11

25 OpenGL🔗ℹ

This section covers OpenGL context management for use with external OpenGL libraries.

Note: This module provides context management only. For actual OpenGL rendering, use a separate OpenGL binding library.

25.1 Creating Contexts🔗ℹ

procedure

(create-gl-context window [#:custodian cust])  gl-context?

  window : window?
  cust : custodian? = (current-custodian)
Creates an OpenGL context for a window.

The window should be created with OpenGL support enabled.

;; Set up OpenGL attributes before creating window
(gl-set-attribute! SDL_GL_CONTEXT_MAJOR_VERSION 3)
(gl-set-attribute! SDL_GL_CONTEXT_MINOR_VERSION 3)
(gl-set-attribute! SDL_GL_CONTEXT_PROFILE_MASK SDL_GL_CONTEXT_PROFILE_CORE)
 
;; Create window with OpenGL flag
(define win (make-window "OpenGL" 800 600 #:flags '(opengl)))
 
;; Create context
(define ctx (create-gl-context win))
(gl-make-current! win ctx)

procedure

(gl-context? v)  boolean?

  v : any/c
Returns #t if v is an OpenGL context.

procedure

(gl-make-current! window ctx)  void?

  window : window?
  ctx : gl-context?
Makes an OpenGL context current for a window.

This must be called before issuing OpenGL commands.

procedure

(gl-swap-window! window)  void?

  window : window?
Swaps the OpenGL buffers for a window.

Call this after rendering to display the frame.

25.2 OpenGL Attributes🔗ℹ

OpenGL attributes control context creation. Set them before creating a context.

procedure

(gl-set-attribute! attr value)  void?

  attr : exact-nonnegative-integer?
  value : exact-integer?
Sets an OpenGL attribute.

;; Request OpenGL 4.1 core profile
(gl-set-attribute! SDL_GL_CONTEXT_MAJOR_VERSION 4)
(gl-set-attribute! SDL_GL_CONTEXT_MINOR_VERSION 1)
(gl-set-attribute! SDL_GL_CONTEXT_PROFILE_MASK SDL_GL_CONTEXT_PROFILE_CORE)
 
;; Request double buffering with 24-bit depth
(gl-set-attribute! SDL_GL_DOUBLEBUFFER 1)
(gl-set-attribute! SDL_GL_DEPTH_SIZE 24)

Gets an OpenGL attribute value.

25.2.1 Attribute Constants🔗ℹ

25.2.1.1 Buffer Sizes🔗ℹ

Red channel bits.
Green channel bits.
Blue channel bits.
Alpha channel bits.
Total color buffer bits.
Depth buffer bits.
Stencil buffer bits.

25.2.1.2 Accumulation Buffer🔗ℹ

Accumulation red bits.
Accumulation green bits.
Accumulation blue bits.
Accumulation alpha bits.

25.2.1.3 Multisampling🔗ℹ

Number of multisample buffers.
Number of samples per pixel.

25.2.1.4 Context Settings🔗ℹ

Enable double buffering.
Enable stereo rendering.
Require hardware acceleration.
Retain buffer contents.
sRGB framebuffer support.
Floating-point buffers.

25.2.1.5 Context Version and Profile🔗ℹ

OpenGL major version.
OpenGL minor version.
Context profile.
Context flags.

25.2.1.6 Context Profiles🔗ℹ

Core profile (no deprecated features).
Compatibility profile.
OpenGL ES profile.

25.2.1.7 Context Flags🔗ℹ

Debug context.
Forward compatible.
Robust access.
Reset isolation.

25.2.1.8 Other🔗ℹ

Share with current context.
Release behavior.
Reset notification.
No error context.
EGL platform selection.

25.3 Swap Interval (VSync)🔗ℹ

procedure

(gl-set-swap-interval! interval)  void?

  interval : exact-integer?
Sets the swap interval for the current context.

  • 0 Immediate (no vsync)

  • 1 VSync (wait for vertical retrace)

  • -1 Adaptive vsync (vsync if possible, else immediate)

;; Enable vsync
(gl-set-swap-interval! 1)
 
;; Disable vsync for maximum framerate
(gl-set-swap-interval! 0)

Gets the current swap interval.