package glfw-ocaml

  1. Overview
  2. Docs

OCaml binding for GLFW 3.3

val version_major : int

GLFW-OCaml version numbers.

val version_minor : int
val version_revision : int
exception NotInitialized of string

Exceptions raised by the various functions of this module.

exception NoCurrentContext of string
exception InvalidEnum of string
exception InvalidValue of string
exception OutOfMemory of string
exception ApiUnavailable of string
exception VersionUnavailable of string
exception PlatformError of string
exception FormatUnavailable of string
exception NoWindowContext of string
type key_action =
  1. | Release
  2. | Press
  3. | Repeat
type key =
  1. | Unknown
  2. | Space
  3. | Apostrophe
  4. | Comma
  5. | Minus
  6. | Period
  7. | Slash
  8. | Num0
  9. | Num1
  10. | Num2
  11. | Num3
  12. | Num4
  13. | Num5
  14. | Num6
  15. | Num7
  16. | Num8
  17. | Num9
  18. | Semicolon
  19. | Equal
  20. | A
  21. | B
  22. | C
  23. | D
  24. | E
  25. | F
  26. | G
  27. | H
  28. | I
  29. | J
  30. | K
  31. | L
  32. | M
  33. | N
  34. | O
  35. | P
  36. | Q
  37. | R
  38. | S
  39. | T
  40. | U
  41. | V
  42. | W
  43. | X
  44. | Y
  45. | Z
  46. | LeftBracket
  47. | Backslash
  48. | RightBracket
  49. | GraveAccent
  50. | World1
  51. | World2
  52. | Escape
  53. | Enter
  54. | Tab
  55. | Backspace
  56. | Insert
  57. | Delete
  58. | Right
  59. | Left
  60. | Down
  61. | Up
  62. | PageUp
  63. | PageDown
  64. | Home
  65. | End
  66. | CapsLock
  67. | ScrollLock
  68. | NumLock
  69. | PrintScreen
  70. | Pause
  71. | F1
  72. | F2
  73. | F3
  74. | F4
  75. | F5
  76. | F6
  77. | F7
  78. | F8
  79. | F9
  80. | F10
  81. | F11
  82. | F12
  83. | F13
  84. | F14
  85. | F15
  86. | F16
  87. | F17
  88. | F18
  89. | F19
  90. | F20
  91. | F21
  92. | F22
  93. | F23
  94. | F24
  95. | F25
  96. | Kp0
  97. | Kp1
  98. | Kp2
  99. | Kp3
  100. | Kp4
  101. | Kp5
  102. | Kp6
  103. | Kp7
  104. | Kp8
  105. | Kp9
  106. | KpDecimal
  107. | KpDivide
  108. | KpMultiply
  109. | KpSubtract
  110. | KpAdd
  111. | KpEnter
  112. | KpEqual
  113. | LeftShift
  114. | LeftControl
  115. | LeftAlt
  116. | LeftSuper
  117. | RightShift
  118. | RightControl
  119. | RightAlt
  120. | RightSuper
  121. | Menu
type key_mod =
  1. | Shift
  2. | Control
  3. | Alt
  4. | Super

Keyboard key and mouse button modifiers.

val mouse_button_max_count : int

Maximum number of buttons handled for a mouse.

val mouse_button_left : int

Values of common mouse buttons.

val mouse_button_right : int
val mouse_button_middle : int
val joystick_max_count : int

Maximum number of joysticks connected.

type client_api =
  1. | NoApi
  2. | OpenGLApi
  3. | OpenGLESApi

Client OpenGL API hint

type context_robustness =
  1. | NoRobustness
  2. | NoResetNotification
  3. | LoseContextOnReset

Context robustness hint

type opengl_profile =
  1. | AnyProfile
  2. | CoreProfile
  3. | CompatProfile

OpenGL profile hint

type context_release_behavior =
  1. | AnyReleaseBehavior
  2. | ReleaseBehaviorFlush
  3. | ReleaseBehaviorNone

Context release behavior hint

type context_creation_api =
  1. | NativeContextApi
  2. | EGLContextApi
  3. | OSMesaContextApi

Context creation API hint

module A : sig ... end

Window hints and attributes. Use with windowHint, getWindowAttrib and setWindowAttrib like this:

include module type of A

Window hints and attributes. Use with windowHint, getWindowAttrib and setWindowAttrib like this:

windowHint ~hint:Resizable ~value:false windowHint ~hint:OpenGLProfile ~value:CoreProfile windowHint ~hint:RefreshRate ~value:(Some 60) windowHint ~hint:DepthBits ~value:None windowHint ~hint:X11ClassName ~value:"MyApplicationName"

getWindowAttrib ~attribute:Resizable : bool getWindowAttrib ~attribute:OpenGLProfile : opengl_profile getWindowAttrib ~attribute:Hovered : bool getWindowAttrib ~attribute:ContextRevision : int

setWindowAttrib ~attribute:Resizable ~value:true

This type is wrapped inside a module only for technical reasons related to backward-compatibility. That module is opened right after it is declared and it is intended that you use the constructor names unprefixed as shown in the previous examples. It will be removed together with the old modules in the future (probably on the next major version).

type ('a, _) window_attr =
  1. | Focused : (bool, [< `hint | `attr ]) window_attr
  2. | Iconified : (bool, [< `attr ]) window_attr
  3. | Resizable : (bool, [< `hint | `attr | `update ]) window_attr
  4. | Visible : (bool, [< `hint | `attr ]) window_attr
  5. | Decorated : (bool, [< `hint | `attr | `update ]) window_attr
  6. | AutoIconify : (bool, [< `hint | `attr | `update ]) window_attr
  7. | Floating : (bool, [< `hint | `attr | `update ]) window_attr
  8. | Maximized : (bool, [< `hint | `attr ]) window_attr
  9. | CenterCursor : (bool, [< `hint ]) window_attr
  10. | TransparentFramebuffer : (bool, [< `hint | `attr ]) window_attr
  11. | Hovered : (bool, [< `attr ]) window_attr
  12. | FocusOnShow : (bool, [< `hint | `attr | `update ]) window_attr
  13. | RedBits : (int option, [< `hint ]) window_attr
  14. | GreenBits : (int option, [< `hint ]) window_attr
  15. | BlueBits : (int option, [< `hint ]) window_attr
  16. | AlphaBits : (int option, [< `hint ]) window_attr
  17. | DepthBits : (int option, [< `hint ]) window_attr
  18. | StencilBits : (int option, [< `hint ]) window_attr
  19. | AccumRedBits : (int option, [< `hint ]) window_attr
  20. | AccumGreenBits : (int option, [< `hint ]) window_attr
  21. | AccumBlueBits : (int option, [< `hint ]) window_attr
  22. | AccumAlphaBits : (int option, [< `hint ]) window_attr
  23. | AuxBuffers : (int option, [< `hint ]) window_attr
  24. | Stereo : (bool, [< `hint ]) window_attr
  25. | Samples : (int option, [< `hint ]) window_attr
  26. | SrgbCapable : (bool, [< `hint ]) window_attr
  27. | RefreshRate : (int option, [< `hint ]) window_attr
  28. | DoubleBuffer : (bool, [< `hint ]) window_attr
  29. | ClientApi : (client_api, [< `hint | `attr ]) window_attr
  30. | ContextVersionMajor : (int, [< `hint | `attr ]) window_attr
  31. | ContextVersionMinor : (int, [< `hint | `attr ]) window_attr
  32. | ContextRevision : (int, [< `attr ]) window_attr
  33. | ContextRobustness : (context_robustness, [< `hint | `attr ]) window_attr
  34. | OpenGLForwardCompat : (bool, [< `hint | `attr ]) window_attr
  35. | OpenGLDebugContext : (bool, [< `hint | `attr ]) window_attr
  36. | OpenGLProfile : (opengl_profile, [< `hint | `attr ]) window_attr
  37. | ContextReleaseBehavior : (context_release_behavior, [< `hint ]) window_attr
  38. | ContextNoError : (bool, [< `hint ]) window_attr
  39. | ContextCreationApi : (context_creation_api, [< `hint | `attr ]) window_attr
  40. | ScaleToMonitor : (bool, [< `hint ]) window_attr
  41. | CocoaRetinaFramebuffer : (bool, [< `hint ]) window_attr
  42. | CocoaFrameName : (string, [< `hint ]) window_attr
  43. | CocoaGraphicsSwitching : (bool, [< `hint ]) window_attr
  44. | X11ClassName : (string, [< `hint ]) window_attr
  45. | X11InstanceName : (string, [< `hint ]) window_attr
module type S = sig ... end

Deprecated window hints and attributes modules.

module WindowHint : S with type 'a t = ('a, [ `hint ]) window_attr
module WindowAttribute : S with type 'a t = ('a, [ `attr ]) window_attr
module WindowUpdateableAttribute : S with type 'a t = ('a, [ `update ]) window_attr
type cursor_mode =
  1. | Normal
  2. | Hidden
  3. | Disabled

Mouse cursor input mode.

type _ input_mode =
  1. | Cursor : cursor_mode input_mode
  2. | StickyKeys : bool input_mode
  3. | StickyMouseButtons : bool input_mode
  4. | LockKeyMods : bool input_mode
  5. | RawMouseMotion : bool input_mode

Input modes. Use with setInputMode and getInputMode in a similar manner as with window hints.

type cursor_shape =
  1. | ArrowCursor
  2. | IBeamCursor
  3. | CrosshairCursor
  4. | HandCursor
  5. | HResizeCursor
  6. | VResizeCursor

Standard cursor shapes.

type connection_event =
  1. | Connected
  2. | Disconnected

Joystick connection event.

type _ init_hint =
  1. | JoystickHatButtons : bool init_hint
  2. | CocoaChdirResources : bool init_hint
  3. | CocoaMenubar : bool init_hint
type video_mode = {
  1. width : int;
  2. height : int;
  3. red_bits : int;
  4. green_bits : int;
  5. blue_bits : int;
  6. refresh_rate : int;
}

Video mode description as returned by getVideoMode(s).

type monitor
type window
type cursor
module GammaRamp : sig ... end

GammaRamp module. Describes the gamma ramp for a monitor.

module Image : sig ... end

Image data for creating custom cursors and window icons.

type hat_status =
  1. | HatUp
  2. | HatRight
  3. | HatDown
  4. | HatLeft
type gamepad_state = {
  1. buttons : bool array;
  2. axes : float array;
}

Gamepad state data as returned by getGamepadState.

Module functions. These are mostly identical to their original GLFW counterparts.

There are no bindings for the glfwSet,Get*UserPointer functions because you would have to use unsafe features to set the correct type for your data. If you need to make user data accessible inside a callback you can instead capture it in a closure and use that closure as your callback function.

There is no binding for the glfwWindowHintString function. Simply pass your string to the windowHint function as you would for any other value type.

The window parameter of the set,getClipboardString functions has been deprecated and is no longer used. You may pass the unit value (or anything) as the window argument.

There is no binding for the glfwGetProcAddress function because it would basicaly require to write an entire OpenGL wrapper to make the functions returned by GLFW usable from OCaml. There are numerous OpenGL bindings available for OCaml that you can use instead.

The Vulkan related functions are not supported as of now but we might look into it at some point.

val init : unit -> unit
val terminate : unit -> unit
val initHint : hint:'a init_hint -> value:'a -> unit
val getVersion : unit -> int * int * int
val getVersionString : unit -> string
val getMonitors : unit -> monitor list
val getPrimaryMonitor : unit -> monitor
val getMonitorPos : monitor:monitor -> int * int
val getMonitorWorkarea : monitor:monitor -> int * int * int * int
val getMonitorPhysicalSize : monitor:monitor -> int * int
val getMonitorContentScale : monitor:monitor -> float * float
val getMonitorName : monitor:monitor -> string
val setMonitorCallback : f:(monitor -> connection_event -> unit) option -> (monitor -> connection_event -> unit) option
val getVideoModes : monitor:monitor -> video_mode list
val getVideoMode : monitor:monitor -> video_mode
val setGamma : monitor:monitor -> gamma:float -> unit
val getGammaRamp : monitor:monitor -> GammaRamp.t
val setGammaRamp : monitor:monitor -> gamma_ramp:GammaRamp.t -> unit
val defaultWindowHints : unit -> unit
val windowHint : hint:('a, [ `hint ]) window_attr -> value:'a -> unit
val createWindow : width:int -> height:int -> title:string -> ?monitor:monitor -> ?share:window -> unit -> window
val destroyWindow : window:window -> unit
val windowShouldClose : window:window -> bool
val setWindowShouldClose : window:window -> b:bool -> unit
val setWindowTitle : window:window -> title:string -> unit
val setWindowIcon : window:window -> images:Image.t list -> unit
val getWindowPos : window:window -> int * int
val setWindowPos : window:window -> xpos:int -> ypos:int -> unit
val getWindowSize : window:window -> int * int
val setWindowSizeLimits : window:window -> minWidth:int option -> minHeight:int option -> maxWidth:int option -> maxHeight:int option -> unit
val setWindowAspectRatio : window:window -> numer:int -> denom:int -> unit
val setWindowSize : window:window -> width:int -> height:int -> unit
val getFramebufferSize : window:window -> int * int
val getWindowFrameSize : window:window -> int * int * int * int
val getWindowContentScale : window:window -> float * float
val getWindowOpacity : window:window -> float
val setWindowOpacity : window:window -> opacity:float -> unit
val iconifyWindow : window:window -> unit
val restoreWindow : window:window -> unit
val maximizeWindow : window:window -> unit
val showWindow : window:window -> unit
val hideWindow : window:window -> unit
val focusWindow : window:window -> unit
val requestWindowAttention : window:window -> unit
val getWindowMonitor : window:window -> monitor option
val setWindowMonitor : window:window -> monitor:monitor option -> xpos:int -> ypos:int -> width:int -> height:int -> refreshRate:int option -> unit
val getWindowAttrib : window:window -> attribute:('a, [ `attr ]) window_attr -> 'a
val setWindowAttrib : window:window -> attribute:('a, [ `update ]) window_attr -> value:'a -> unit
val setWindowPosCallback : window:window -> f:(window -> int -> int -> unit) option -> (window -> int -> int -> unit) option
val setWindowSizeCallback : window:window -> f:(window -> int -> int -> unit) option -> (window -> int -> int -> unit) option
val setWindowCloseCallback : window:window -> f:(window -> unit) option -> (window -> unit) option
val setWindowRefreshCallback : window:window -> f:(window -> unit) option -> (window -> unit) option
val setWindowFocusCallback : window:window -> f:(window -> bool -> unit) option -> (window -> bool -> unit) option
val setWindowIconifyCallback : window:window -> f:(window -> bool -> unit) option -> (window -> bool -> unit) option
val setWindowMaximizeCallback : window:window -> f:(window -> bool -> unit) option -> (window -> bool -> unit) option
val setFramebufferSizeCallback : window:window -> f:(window -> int -> int -> unit) option -> (window -> int -> int -> unit) option
val setWindowContentScaleCallback : window:window -> f:(window -> float -> float -> unit) option -> (window -> float -> float -> unit) option
val pollEvents : unit -> unit
val waitEvents : unit -> unit
val waitEventsTimeout : timeout:float -> unit
val postEmptyEvent : unit -> unit
val getInputMode : window:window -> mode:'a input_mode -> 'a
val setInputMode : window:window -> mode:'a input_mode -> value:'a -> unit
val rawMouseMotionSupported : unit -> bool
val getKeyName : key:key -> scancode:int -> string option
val getKeyScancode : key:key -> int
val getKey : window:window -> key:key -> bool
val getMouseButton : window:window -> button:int -> bool
val getCursorPos : window:window -> float * float
val setCursorPos : window:window -> xpos:float -> ypos:float -> unit
val createCursor : image:Image.t -> xhot:int -> yhot:int -> cursor
val createStandardCursor : shape:cursor_shape -> cursor
val destroyCursor : cursor:cursor -> unit
val setCursor : window:window -> cursor:cursor -> unit
val setKeyCallback : window:window -> f:(window -> key -> int -> key_action -> key_mod list -> unit) option -> (window -> key -> int -> key_action -> key_mod list -> unit) option
val setCharCallback : window:window -> f:(window -> int -> unit) option -> (window -> int -> unit) option
val setCharModsCallback : window:window -> f:(window -> int -> key_mod list -> unit) option -> (window -> int -> key_mod list -> unit) option
  • deprecated
val setMouseButtonCallback : window:window -> f:(window -> int -> bool -> key_mod list -> unit) option -> (window -> int -> bool -> key_mod list -> unit) option
val setCursorPosCallback : window:window -> f:(window -> float -> float -> unit) option -> (window -> float -> float -> unit) option
val setCursorEnterCallback : window:window -> f:(window -> bool -> unit) option -> (window -> bool -> unit) option
val setScrollCallback : window:window -> f:(window -> float -> float -> unit) option -> (window -> float -> float -> unit) option
val setDropCallback : window:window -> f:(window -> string list -> unit) option -> (window -> string list -> unit) option
val joystickPresent : joy:int -> bool
val getJoystickAxes : joy:int -> float array
val getJoystickButtons : joy:int -> bool array
val getJoystickHats : joy:int -> hat_status list array
val getJoystickName : joy:int -> string option
val getJoystickGUID : joy:int -> string option
val joystickIsGamepad : joy:int -> bool
val setJoystickCallback : f:(int -> connection_event -> unit) option -> (int -> connection_event -> unit) option
val updateGamepadMappings : string:string -> unit
val getGamepadName : joy:int -> string option
val getGamepadState : joy:int -> gamepad_state
val setClipboardString : window:_ -> string:string -> unit
val getClipboardString : window:_ -> string
val getTime : unit -> float
val setTime : time:float -> unit
val getTimerValue : unit -> int64
val getTimerFrequency : unit -> int64
val makeContextCurrent : window:window option -> unit
val getCurrentContext : unit -> window option
val swapBuffers : window:window -> unit
val swapInterval : interval:int -> unit
val extensionSupported : extension:string -> bool
OCaml

Innovation. Community. Security.