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)
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
procedure
(gl-make-current! window ctx) → void?
window : window? ctx : gl-context?
This must be called before issuing OpenGL commands.
procedure
(gl-swap-window! window) → void?
window : 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?
;; 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)
procedure
(gl-get-attribute attr) → exact-integer?
attr : exact-nonnegative-integer?
25.2.1 Attribute Constants
25.2.1.1 Buffer Sizes
25.2.1.2 Accumulation Buffer
25.2.1.3 Multisampling
25.2.1.4 Context Settings
25.2.1.5 Context Version and Profile
25.2.1.6 Context Profiles
25.2.1.7 Context Flags
25.2.1.8 Other
25.3 Swap Interval (VSync)
procedure
(gl-set-swap-interval! interval) → void?
interval : exact-integer?
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)
procedure