├── .gitignore ├── FsGlfw3.sln ├── FsGlfw3 ├── FsGlfw3.fsproj ├── Glfw3.fs └── lib │ └── glfw3.dll ├── LICENSE ├── README.md └── Sample ├── App.config ├── Program.fs ├── Sample.fsproj └── packages.config /.gitignore: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # This .gitignore file was automatically created by Microsoft(R) Visual Studio. 3 | ################################################################################ 4 | 5 | /FsGlfw3/bin 6 | /FsGlfw3/obj 7 | /.vs/FsGlfw3/v14/.suo 8 | /packages/OpenTK.1.1.2349.61993 9 | /Sample/bin/Debug 10 | /Sample/obj/Debug 11 | /Sample/bin/Release 12 | /Sample/obj/Release 13 | /FsGlfw.3.2.0.nupkg 14 | /FsGlfw.3.2.nupkg 15 | -------------------------------------------------------------------------------- /FsGlfw3.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26124.0 5 | MinimumVisualStudioVersion = 15.0.26124.0 6 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FsGlfw3", "FsGlfw3\FsGlfw3.fsproj", "{73072D21-AB06-4B80-B21D-BF5E70418E6B}" 7 | EndProject 8 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Sample", "Sample\Sample.fsproj", "{5A245A54-A71B-4934-94A0-8074BDA46DFD}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|Any CPU = Release|Any CPU 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {73072D21-AB06-4B80-B21D-BF5E70418E6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 24 | {73072D21-AB06-4B80-B21D-BF5E70418E6B}.Debug|Any CPU.Build.0 = Debug|Any CPU 25 | {73072D21-AB06-4B80-B21D-BF5E70418E6B}.Debug|x64.ActiveCfg = Debug|x64 26 | {73072D21-AB06-4B80-B21D-BF5E70418E6B}.Debug|x64.Build.0 = Debug|x64 27 | {73072D21-AB06-4B80-B21D-BF5E70418E6B}.Debug|x86.ActiveCfg = Debug|x86 28 | {73072D21-AB06-4B80-B21D-BF5E70418E6B}.Debug|x86.Build.0 = Debug|x86 29 | {73072D21-AB06-4B80-B21D-BF5E70418E6B}.Release|Any CPU.ActiveCfg = Release|Any CPU 30 | {73072D21-AB06-4B80-B21D-BF5E70418E6B}.Release|Any CPU.Build.0 = Release|Any CPU 31 | {73072D21-AB06-4B80-B21D-BF5E70418E6B}.Release|x64.ActiveCfg = Release|x64 32 | {73072D21-AB06-4B80-B21D-BF5E70418E6B}.Release|x64.Build.0 = Release|x64 33 | {73072D21-AB06-4B80-B21D-BF5E70418E6B}.Release|x86.ActiveCfg = Release|x86 34 | {73072D21-AB06-4B80-B21D-BF5E70418E6B}.Release|x86.Build.0 = Release|x86 35 | {5A245A54-A71B-4934-94A0-8074BDA46DFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 36 | {5A245A54-A71B-4934-94A0-8074BDA46DFD}.Debug|Any CPU.Build.0 = Debug|Any CPU 37 | {5A245A54-A71B-4934-94A0-8074BDA46DFD}.Debug|x64.ActiveCfg = Debug|x64 38 | {5A245A54-A71B-4934-94A0-8074BDA46DFD}.Debug|x64.Build.0 = Debug|x64 39 | {5A245A54-A71B-4934-94A0-8074BDA46DFD}.Debug|x86.ActiveCfg = Debug|x86 40 | {5A245A54-A71B-4934-94A0-8074BDA46DFD}.Debug|x86.Build.0 = Debug|x86 41 | {5A245A54-A71B-4934-94A0-8074BDA46DFD}.Release|Any CPU.ActiveCfg = Release|Any CPU 42 | {5A245A54-A71B-4934-94A0-8074BDA46DFD}.Release|Any CPU.Build.0 = Release|Any CPU 43 | {5A245A54-A71B-4934-94A0-8074BDA46DFD}.Release|x64.ActiveCfg = Release|x64 44 | {5A245A54-A71B-4934-94A0-8074BDA46DFD}.Release|x64.Build.0 = Release|x64 45 | {5A245A54-A71B-4934-94A0-8074BDA46DFD}.Release|x86.ActiveCfg = Release|x86 46 | {5A245A54-A71B-4934-94A0-8074BDA46DFD}.Release|x86.Build.0 = Release|x86 47 | EndGlobalSection 48 | EndGlobal 49 | -------------------------------------------------------------------------------- /FsGlfw3/FsGlfw3.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | FsGlfw 9 | 3.2.1.0 10 | Wael El Oraiby 11 | Wael El Oraiby 12 | F# bindings for GLFW 3.2.1 13 | F# bindings for GLFW 3.2.1 14 | https://opensource.org/licenses/MIT 15 | 2015-2018 (c) Wael El Oraiby 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /FsGlfw3/Glfw3.fs: -------------------------------------------------------------------------------- 1 | (* 2 | ** F# GLFW binding 3 | ** Copyright (C) 2015-2016 Wael El Oraiby 4 | ** 5 | ** This program is free software: you can redistribute it and/or modify 6 | ** it under the terms of the GNU Affero General Public License as 7 | ** published by the Free Software Foundation, either version 3 of the 8 | ** License, or (at your option) any later version. 9 | ** 10 | ** This program is distributed in the hope that it will be useful, 11 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ** GNU Affero General Public License for more details. 14 | ** 15 | ** You should have received a copy of the GNU Affero General Public License 16 | ** along with this program. If not, see . 17 | *) 18 | module Glfw3 19 | 20 | open System 21 | open System.Runtime.InteropServices 22 | 23 | type Action = 24 | | RELEASE = 0 25 | | PRESS = 1 26 | | REPEAT = 2 27 | 28 | type Key = 29 | | KEY_UNKNOWN = -1 30 | | KEY_SPACE = 32 31 | | KEY_APOSTROPHE = 39 (* ' *) 32 | | KEY_COMMA = 44 (* , *) 33 | | KEY_MINUS = 45 (* - *) 34 | | KEY_PERIOD = 46 (* . *) 35 | | KEY_SLASH = 47 (* / *) 36 | | KEY_0 = 48 37 | | KEY_1 = 49 38 | | KEY_2 = 50 39 | | KEY_3 = 51 40 | | KEY_4 = 52 41 | | KEY_5 = 53 42 | | KEY_6 = 54 43 | | KEY_7 = 55 44 | | KEY_8 = 56 45 | | KEY_9 = 57 46 | | KEY_SEMICOLON = 59 (* ; *) 47 | | KEY_EQUAL = 61 (* = *) 48 | | KEY_A = 65 49 | | KEY_B = 66 50 | | KEY_C = 67 51 | | KEY_D = 68 52 | | KEY_E = 69 53 | | KEY_F = 70 54 | | KEY_G = 71 55 | | KEY_H = 72 56 | | KEY_I = 73 57 | | KEY_J = 74 58 | | KEY_K = 75 59 | | KEY_L = 76 60 | | KEY_M = 77 61 | | KEY_N = 78 62 | | KEY_O = 79 63 | | KEY_P = 80 64 | | KEY_Q = 81 65 | | KEY_R = 82 66 | | KEY_S = 83 67 | | KEY_T = 84 68 | | KEY_U = 85 69 | | KEY_V = 86 70 | | KEY_W = 87 71 | | KEY_X = 88 72 | | KEY_Y = 89 73 | | KEY_Z = 90 74 | | KEY_LEFT_BRACKET = 91 (* [ *) 75 | | KEY_BACKSLASH = 92 (* \ *) 76 | | KEY_RIGHT_BRACKET = 93 (* ] *) 77 | | KEY_GRAVE_ACCENT = 96 (* ` *) 78 | | KEY_WORLD_1 = 161 (* non-US #1 *) 79 | | KEY_WORLD_2 = 162 (* non-US #2 *) 80 | | KEY_ESCAPE = 256 81 | | KEY_ENTER = 257 82 | | KEY_TAB = 258 83 | | KEY_BACKSPACE = 259 84 | | KEY_INSERT = 260 85 | | KEY_DELETE = 261 86 | | KEY_RIGHT = 262 87 | | KEY_LEFT = 263 88 | | KEY_DOWN = 264 89 | | KEY_UP = 265 90 | | KEY_PAGE_UP = 266 91 | | KEY_PAGE_DOWN = 267 92 | | KEY_HOME = 268 93 | | KEY_END = 269 94 | | KEY_CAPS_LOCK = 280 95 | | KEY_SCROLL_LOCK = 281 96 | | KEY_NUM_LOCK = 282 97 | | KEY_PRINT_SCREEN = 283 98 | | KEY_PAUSE = 284 99 | | KEY_F1 = 290 100 | | KEY_F2 = 291 101 | | KEY_F3 = 292 102 | | KEY_F4 = 293 103 | | KEY_F5 = 294 104 | | KEY_F6 = 295 105 | | KEY_F7 = 296 106 | | KEY_F8 = 297 107 | | KEY_F9 = 298 108 | | KEY_F10 = 299 109 | | KEY_F11 = 300 110 | | KEY_F12 = 301 111 | | KEY_F13 = 302 112 | | KEY_F14 = 303 113 | | KEY_F15 = 304 114 | | KEY_F16 = 305 115 | | KEY_F17 = 306 116 | | KEY_F18 = 307 117 | | KEY_F19 = 308 118 | | KEY_F20 = 309 119 | | KEY_F21 = 310 120 | | KEY_F22 = 311 121 | | KEY_F23 = 312 122 | | KEY_F24 = 313 123 | | KEY_F25 = 314 124 | | KEY_KP_0 = 320 125 | | KEY_KP_1 = 321 126 | | KEY_KP_2 = 322 127 | | KEY_KP_3 = 323 128 | | KEY_KP_4 = 324 129 | | KEY_KP_5 = 325 130 | | KEY_KP_6 = 326 131 | | KEY_KP_7 = 327 132 | | KEY_KP_8 = 328 133 | | KEY_KP_9 = 329 134 | | KEY_KP_DECIMAL = 330 135 | | KEY_KP_DIVIDE = 331 136 | | KEY_KP_MULTIPLY = 332 137 | | KEY_KP_SUBTRACT = 333 138 | | KEY_KP_ADD = 334 139 | | KEY_KP_ENTER = 335 140 | | KEY_KP_EQUAL = 336 141 | | KEY_LEFT_SHIFT = 340 142 | | KEY_LEFT_CONTROL = 341 143 | | KEY_LEFT_ALT = 342 144 | | KEY_LEFT_SUPER = 343 145 | | KEY_RIGHT_SHIFT = 344 146 | | KEY_RIGHT_CONTROL = 345 147 | | KEY_RIGHT_ALT = 346 148 | | KEY_RIGHT_SUPER = 347 149 | | KEY_MENU = 348 150 | | KEY_LAST = 348 151 | 152 | type Mod = 153 | | MOD_NONE = 0x0000 154 | | MOD_SHIFT = 0x0001 155 | | MOD_CONTROL = 0x0002 156 | | MOD_ALT = 0x0004 157 | | MOD_SUPER = 0x0008 158 | 159 | type MouseButton = 160 | | BUTTON_1 = 0 161 | | BUTTON_2 = 1 162 | | BUTTON_3 = 2 163 | | BUTTON_4 = 3 164 | | BUTTON_5 = 4 165 | | BUTTON_6 = 5 166 | | BUTTON_7 = 6 167 | | BUTTON_8 = 7 168 | | BUTTON_LAST = 7 // GLFW_MOUSE_BUTTON_8 169 | | BUTTON_LEFT = 0 // GLFW_MOUSE_BUTTON_1 170 | | BUTTON_RIGHT = 1 // GLFW_MOUSE_BUTTON_2 171 | | BUTTON_MIDDLE = 2 // GLFW_MOUSE_BUTTON_3 172 | 173 | type Joystick = 174 | | JOYSTICK_1 = 0 175 | | JOYSTICK_2 = 1 176 | | JOYSTICK_3 = 2 177 | | JOYSTICK_4 = 3 178 | | JOYSTICK_5 = 4 179 | | JOYSTICK_6 = 5 180 | | JOYSTICK_7 = 6 181 | | JOYSTICK_8 = 7 182 | | JOYSTICK_9 = 8 183 | | JOYSTICK_10 = 9 184 | | JOYSTICK_11 = 10 185 | | JOYSTICK_12 = 11 186 | | JOYSTICK_13 = 12 187 | | JOYSTICK_14 = 13 188 | | JOYSTICK_15 = 14 189 | | JOYSTICK_16 = 15 190 | | JOYSTICK_LAST = 15 // GLFW_JOYSTICK_16 191 | 192 | type Error = 193 | | NOT_INITIALIZED = 0x00010001 194 | | NO_CURRENT_CONTEXT = 0x00010002 195 | | INVALID_ENUM = 0x00010003 196 | | INVALID_VALUE = 0x00010004 197 | | OUT_OF_MEMORY = 0x00010005 198 | | API_UNAVAILABLE = 0x00010006 199 | | VERSION_UNAVAILABLE = 0x00010007 200 | | PLATFORM_ERROR = 0x00010008 201 | | FORMAT_UNAVAILABLE = 0x00010009 202 | 203 | type WindowHint = 204 | | FOCUSED = 0x00020001 205 | | ICONIFIED = 0x00020002 206 | | RESIZABLE = 0x00020003 207 | | VISIBLE = 0x00020004 208 | | DECORATED = 0x00020005 209 | | AUTO_ICONIFY = 0x00020006 210 | | FLOATING = 0x00020007 211 | 212 | | RED_BITS = 0x00021001 213 | | GREEN_BITS = 0x00021002 214 | | BLUE_BITS = 0x00021003 215 | | ALPHA_BITS = 0x00021004 216 | | DEPTH_BITS = 0x00021005 217 | | STENCIL_BITS = 0x00021006 218 | | ACCUM_RED_BITS = 0x00021007 219 | | ACCUM_GREEN_BITS = 0x00021008 220 | | ACCUM_BLUE_BITS = 0x00021009 221 | | ACCUM_ALPHA_BITS = 0x0002100A 222 | | AUX_BUFFERS = 0x0002100B 223 | | STEREO = 0x0002100C 224 | | SAMPLES = 0x0002100D 225 | | SRGB_CAPABLE = 0x0002100E 226 | | REFRESH_RATE = 0x0002100F 227 | | DOUBLEBUFFER = 0x00021010 228 | 229 | | CLIENT_API = 0x00022001 230 | | CONTEXT_VERSION_MAJOR = 0x00022002 231 | | CONTEXT_VERSION_MINOR = 0x00022003 232 | | CONTEXT_REVISION = 0x00022004 233 | | CONTEXT_ROBUSTNESS = 0x00022005 234 | | OPENGL_FORWARD_COMPAT = 0x00022006 235 | | OPENGL_DEBUG_CONTEXT = 0x00022007 236 | | OPENGL_PROFILE = 0x00022008 237 | | CONTEXT_RELEASE_BEHAVIOR = 0x00022009 238 | | CONTEXT_CREATION_API = 0x0002200B 239 | 240 | 241 | | OPENGL_API = 0x00030001 242 | | OPENGL_ES_API = 0x00030002 243 | 244 | | NATIVE_CONTEXT_API = 0x00036001 245 | | EGL_CONTEXT_API = 0x00036002 246 | 247 | | NO_ROBUSTNESS = 0 248 | | NO_RESET_NOTIFICATION = 0x00031001 249 | | LOSE_CONTEXT_ON_RESET = 0x00031002 250 | 251 | | OPENGL_ANY_PROFILE = 0 252 | | OPENGL_CORE_PROFILE = 0x00032001 253 | | OPENGL_COMPAT_PROFILE = 0x00032002 254 | 255 | | ANY_RELEASE_BEHAVIOR = 0 256 | | RELEASE_BEHAVIOR_FLUSH = 0x00035001 257 | | RELEASE_BEHAVIOR_NONE = 0x00035002 258 | 259 | type CursorMode = 260 | | CURSOR_NORMAL = 0x00034001 261 | | CURSOR_HIDDEN = 0x00034002 262 | | CURSOR_DISABLED = 0x00034003 263 | 264 | type DefaultCursor = 265 | | ARROW_CURSOR = 0x00036001 266 | | IBEAM_CURSOR = 0x00036002 267 | | CROSSHAIR_CURSOR = 0x00036003 268 | | HAND_CURSOR = 0x00036004 269 | | HRESIZE_CURSOR = 0x00036005 270 | | VRESIZE_CURSOR = 0x00036006 271 | 272 | type GLProc = delegate of unit -> unit 273 | 274 | type Monitor(ptr: IntPtr) = 275 | member x.Value = ptr 276 | 277 | type Window(ptr: IntPtr) = 278 | member x.Value = ptr 279 | 280 | override x.Equals (o: obj) = 281 | let o = unbox o 282 | o.Value = ptr 283 | 284 | override x.GetHashCode () = ptr.GetHashCode() 285 | 286 | type Cursor(ptr: IntPtr) = 287 | member x.Value = ptr 288 | 289 | #nowarn "9" 290 | 291 | [] 292 | type VideoMode = 293 | val width : int 294 | val height : int 295 | val redBits : int 296 | val greenBits : int 297 | val blueBits : int 298 | val refreshRate : int 299 | 300 | [] 301 | type Image = 302 | val width : int 303 | val height : int 304 | val pixels : nativeptr 305 | 306 | [] 307 | type GammaRamp = 308 | val Red : int[] 309 | val Green : int[] 310 | val Blue : int[] 311 | 312 | new(r, g, b) = { Red = r; Green = g; Blue = b } 313 | 314 | [] 315 | module internal Native = 316 | #if WIN32 317 | let [] GLFW_DLL = @"native/glfw3" 318 | #else 319 | let [] GLFW_DLL = "glfw" 320 | #endif 321 | 322 | type InputMode = 323 | | CURSOR = 0x00033001 324 | | STICKY_KEYS = 0x00033002 325 | | STICKY_MOUSE_BUTTONS = 0x00033003 326 | 327 | 328 | type GLFWmonitor = IntPtr 329 | type GLFWwindow = IntPtr 330 | type GLFWcursor = IntPtr 331 | 332 | [] type GLFWglproc = delegate of unit -> unit 333 | [] type GLFWerrorfun = delegate of int * [] error: string -> unit 334 | [] type GLFWwindowposfun = delegate of GLFWwindow * int * int -> unit 335 | [] type GLFWwindowsizefun = delegate of GLFWwindow * int * int -> unit 336 | [] type GLFWwindowclosefun = delegate of GLFWwindow -> unit 337 | [] type GLFWwindowrefreshfun = delegate of GLFWwindow -> unit 338 | [] type GLFWwindowfocusfun = delegate of GLFWwindow * int -> unit 339 | [] type GLFWwindowiconifyfun = delegate of GLFWwindow * int -> unit 340 | [] type GLFWframebuffersizefun = delegate of GLFWwindow * int * int -> unit 341 | [] type GLFWmousebuttonfun = delegate of GLFWwindow * int * int * int -> unit 342 | [] type GLFWcursorposfun = delegate of GLFWwindow * double * double -> unit 343 | [] type GLFWcursorenterfun = delegate of GLFWwindow * int -> unit 344 | [] type GLFWscrollfun = delegate of GLFWwindow * double * double -> unit 345 | [] type GLFWkeyfun = delegate of GLFWwindow * int * int * int * int -> unit 346 | [] type GLFWcharfun = delegate of GLFWwindow * uint32 -> unit 347 | [] type GLFWcharmodsfun = delegate of GLFWwindow * uint32 * int -> unit 348 | [] type GLFWdropfun = delegate of GLFWwindow * int * IntPtr -> unit // const char** 349 | [] type GLFWmonitorfun = delegate of GLFWmonitor * int -> unit 350 | 351 | 352 | [] 353 | type GLFWgammaramp = 354 | val red : IntPtr 355 | val green : IntPtr 356 | val blue : IntPtr 357 | val size : uint16 358 | 359 | new(r, g, b, s) = { red = r; green = g; blue = b; size = s } 360 | 361 | [] 362 | extern int glfwInit() 363 | 364 | [] 365 | extern void glfwTerminate() 366 | 367 | [] 368 | extern void glfwGetVersion([] int& major, [] int& minor, [] int& rev) 369 | 370 | [] 371 | extern IntPtr glfwGetVersionString() 372 | 373 | [] 374 | extern IntPtr glfwGetMonitors([]int& count) 375 | 376 | [] 377 | extern GLFWmonitor glfwGetPrimaryMonitor() 378 | 379 | [] 380 | extern void glfwGetMonitorPos(GLFWmonitor monitor, []int& xpos, []int& ypos) 381 | 382 | [] 383 | extern void glfwGetMonitorPhysicalSize(GLFWmonitor monitor, []int& widthMM, []int& heightMM) 384 | 385 | [] 386 | extern IntPtr glfwGetMonitorName(GLFWmonitor monitor) 387 | 388 | [] 389 | extern GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun) 390 | 391 | [] 392 | extern GLFWmonitorfun glfwSetMonitorCallback(GLFWmonitorfun cbfun) 393 | 394 | [] 395 | extern IntPtr glfwGetVideoModes(GLFWmonitor monitor, [] int& count) 396 | 397 | [] 398 | extern IntPtr glfwGetVideoMode(GLFWmonitor monitor) 399 | 400 | [] 401 | extern void glfwSetGamma(GLFWmonitor monitor, float32 gamma) 402 | 403 | [] 404 | extern IntPtr glfwGetGammaRamp(GLFWmonitor monitor) 405 | 406 | [] 407 | extern void glfwSetGammaRamp(GLFWmonitor monitor, [] GLFWgammaramp& ramp); 408 | 409 | [] 410 | extern void glfwDefaultWindowHints() 411 | 412 | [] 413 | extern void glfwWindowHint(int target, int hint) 414 | 415 | [] 416 | extern GLFWwindow glfwCreateWindow(int width, int height, []string title, GLFWmonitor monitor, GLFWwindow share); 417 | 418 | [] 419 | extern void glfwDestroyWindow(GLFWwindow window) 420 | 421 | [] 422 | extern int glfwWindowShouldClose(GLFWwindow window) 423 | 424 | [] 425 | extern void glfwSetWindowShouldClose(GLFWwindow window, int value) 426 | 427 | [] 428 | extern void glfwSetWindowTitle(GLFWwindow window, []string title) 429 | 430 | [] 431 | extern void glfwGetWindowPos(GLFWwindow window, [] int& xpos, [] int& ypos) 432 | 433 | [] 434 | extern void glfwSetWindowPos(GLFWwindow window, int xpos, int ypos) 435 | 436 | [] 437 | extern void glfwGetWindowSize(GLFWwindow window, [] int& width, [] int& height) 438 | 439 | [] 440 | extern void glfwSetWindowSize(GLFWwindow window, int width, int height) 441 | 442 | [] 443 | extern void glfwGetFramebufferSize(GLFWwindow window, [] int& width, [] int& height) 444 | 445 | [] 446 | extern void glfwGetWindowFrameSize(GLFWwindow window, [] int& left, [] int& top, [] int& right, [] int& bottom) 447 | 448 | [] 449 | extern void glfwIconifyWindow(GLFWwindow window) 450 | 451 | [] 452 | extern void glfwRestoreWindow(GLFWwindow window) 453 | 454 | [] 455 | extern void glfwShowWindow(GLFWwindow window) 456 | 457 | [] 458 | extern void glfwHideWindow(GLFWwindow window) 459 | 460 | [] 461 | extern GLFWmonitor glfwGetWindowMonitor(GLFWwindow window) 462 | 463 | [] 464 | extern int glfwGetWindowAttrib(GLFWwindow window, int attrib) 465 | 466 | [] 467 | extern void glfwSetWindowUserPointer(GLFWwindow window, IntPtr pointer) 468 | 469 | [] 470 | extern IntPtr glfwGetWindowUserPointer(GLFWwindow window) 471 | 472 | [] 473 | extern GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow window, GLFWwindowposfun cbfun); 474 | 475 | [] 476 | extern GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow window, GLFWwindowsizefun cbfun) 477 | 478 | [] 479 | extern GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow window, GLFWwindowclosefun cbfun) 480 | 481 | [] 482 | extern GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow window, GLFWwindowrefreshfun cbfun) 483 | 484 | [] 485 | extern GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow window, GLFWwindowfocusfun cbfun) 486 | 487 | [] 488 | extern GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow window, GLFWwindowiconifyfun cbfun) 489 | 490 | [] 491 | extern GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow window, GLFWframebuffersizefun cbfun) 492 | 493 | [] 494 | extern void glfwPollEvents() 495 | 496 | [] 497 | extern void glfwWaitEvents() 498 | 499 | [] 500 | extern void glfwPostEmptyEvent() 501 | 502 | [] 503 | extern int glfwGetInputMode(GLFWwindow window, int mode) 504 | 505 | [] 506 | extern void glfwSetInputMode(GLFWwindow window, int mode, int value) 507 | 508 | [] 509 | extern int glfwGetKey(GLFWwindow window, int key) 510 | 511 | [] 512 | extern int glfwGetMouseButton(GLFWwindow window, int button) 513 | 514 | [] 515 | extern void glfwGetCursorPos(GLFWwindow window, [] double& xpos, [] double& ypos) 516 | 517 | [] 518 | extern void glfwSetCursorPos(GLFWwindow window, double xpos, double ypos) 519 | 520 | // extern GLFWcursor* glfwCreateCursor(const GLFWimage* image, int xhot, int yhot); 521 | 522 | [] 523 | extern GLFWcursor glfwCreateStandardCursor(int shape) 524 | 525 | [] 526 | extern void glfwDestroyCursor(GLFWcursor cursor) 527 | 528 | [] 529 | extern void glfwSetCursor(GLFWwindow window, GLFWcursor cursor) 530 | 531 | [] 532 | extern GLFWkeyfun glfwSetKeyCallback(GLFWwindow window, GLFWkeyfun cbfun) 533 | 534 | [] 535 | extern GLFWcharfun glfwSetCharCallback(GLFWwindow window, GLFWcharfun cbfun) 536 | 537 | [] 538 | extern GLFWcharmodsfun glfwSetCharModsCallback(GLFWwindow window, GLFWcharmodsfun cbfun) 539 | 540 | [] 541 | extern GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow window, GLFWmousebuttonfun cbfun) 542 | 543 | [] 544 | extern GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow window, GLFWcursorposfun cbfun) 545 | 546 | [] 547 | extern GLFWcursorenterfun glfwSetCursorEnterCallback(GLFWwindow window, GLFWcursorenterfun cbfun) 548 | 549 | [] 550 | extern GLFWscrollfun glfwSetScrollCallback(GLFWwindow window, GLFWscrollfun cbfun) 551 | 552 | [] 553 | extern GLFWdropfun glfwSetDropCallback(GLFWwindow window, GLFWdropfun cbfun) 554 | 555 | [] 556 | extern int glfwJoystickPresent(int joy) 557 | 558 | // extern const float* glfwGetJoystickAxes(int joy, int* count); 559 | 560 | [] 561 | extern IntPtr glfwGetJoystickButtons(int joy, [] int& count) 562 | 563 | [] 564 | extern IntPtr glfwGetJoystickName(int joy) 565 | 566 | [] 567 | extern void glfwSetClipboardString(GLFWwindow window, [] string str); 568 | 569 | [] 570 | extern IntPtr glfwGetClipboardString(GLFWwindow window) 571 | 572 | [] 573 | extern double glfwGetTime() 574 | 575 | [] 576 | extern void glfwSetTime(double time) 577 | 578 | [] 579 | extern void glfwMakeContextCurrent(GLFWwindow window) 580 | 581 | [] 582 | extern GLFWwindow glfwGetCurrentContext() 583 | 584 | [] 585 | extern void glfwSwapBuffers(GLFWwindow window) 586 | 587 | [] 588 | extern void glfwSwapInterval(int interval) 589 | 590 | // extern int glfwExtensionSupported(const char* extension); 591 | // extern GLFWglproc glfwGetProcAddress(const char* procname); 592 | 593 | let init() = glfwInit() 594 | let terminate() = glfwTerminate() 595 | let getVersion() = 596 | let mutable major = 0 597 | let mutable minor = 0 598 | let mutable rev = 0 599 | glfwGetVersion(&major, &minor, &rev) 600 | major, minor, rev 601 | 602 | let getVersionString() = Marshal.PtrToStringAnsi(glfwGetVersionString()) 603 | 604 | let getMonitors() = 605 | let mutable count = 0 606 | let ret = glfwGetMonitors(&count) 607 | let nativePtrs = Array.init count (fun i -> IntPtr.Zero) 608 | 609 | Marshal.Copy(ret, nativePtrs, 0, count) 610 | 611 | nativePtrs 612 | |> Array.map(fun m -> Monitor(m)) 613 | 614 | let getPrimaryMonitor() = Monitor(glfwGetPrimaryMonitor()) 615 | 616 | let getMonitorPos(m: Monitor) = 617 | let mutable x, y = 0, 0 618 | glfwGetMonitorPos(m.Value, &x, &y) 619 | x, y 620 | 621 | let getMonitorPhysicalSize (m: Monitor) = 622 | let mutable w, h = 0, 0 623 | glfwGetMonitorPhysicalSize(m.Value, &w, &h) 624 | w, h 625 | 626 | let getMonitorName (m: Monitor) = Marshal.PtrToStringAnsi(glfwGetMonitorName m.Value) 627 | 628 | let getVideoModes (m: Monitor) = 629 | let mutable count = 0 630 | let ret = glfwGetVideoModes(m.Value, &count) 631 | let vidModes = Array.init count (fun i -> VideoMode()) 632 | 633 | let modeSize = Marshal.SizeOf(typeof) 634 | 635 | for i in 0..count - 1 do 636 | vidModes.[i] <- unbox(Marshal.PtrToStructure(IntPtr.Add(ret, i * modeSize), typeof)) 637 | 638 | vidModes 639 | 640 | let getVideoMode (m: Monitor) = 641 | let ret = glfwGetVideoMode m.Value 642 | unbox(Marshal.PtrToStructure(ret, typeof)) 643 | 644 | let setGamma(m: Monitor, g: float32) = glfwSetGamma(m.Value, g) 645 | 646 | let getGammaramp (m: Monitor) = 647 | let ramp = unbox(Marshal.PtrToStructure(glfwGetGammaRamp(m.Value), typeof)) 648 | let redArr = Array.init (int ramp.size) (fun _ -> 0s) 649 | Marshal.Copy(ramp.red, redArr, 0, int ramp.size) 650 | let greenArr = Array.init (int ramp.size) (fun _ -> 0s) 651 | Marshal.Copy(ramp.green, greenArr, 0, int ramp.size) 652 | let blueArr = Array.init (int ramp.size) (fun _ -> 0s) 653 | Marshal.Copy(ramp.blue, blueArr, 0, int ramp.size) 654 | 655 | let s2i x = if x < 0s then (uint16 x) |> int else int x 656 | 657 | GammaRamp(redArr |> Array.map s2i, 658 | greenArr |> Array.map s2i, 659 | blueArr |> Array.map s2i) 660 | 661 | let setGammaramp (m: Monitor, gr: GammaRamp) = 662 | printfn "Gamma Ramp" 663 | let red = gr.Red |> Array.map uint16 664 | let blue = gr.Blue |> Array.map uint16 665 | let green = gr.Green |> Array.map uint16 666 | let rh = GCHandle.Alloc (red , GCHandleType.Pinned) 667 | let gh = GCHandle.Alloc (green, GCHandleType.Pinned) 668 | let bh = GCHandle.Alloc (blue , GCHandleType.Pinned) 669 | 670 | let mutable ramp = GLFWgammaramp(rh.AddrOfPinnedObject(), gh.AddrOfPinnedObject(), bh.AddrOfPinnedObject(), red.Length |> uint16) 671 | 672 | glfwSetGammaRamp(m.Value, &ramp) 673 | 674 | bh.Free() 675 | gh.Free() 676 | rh.Free() 677 | 678 | 679 | let defaultWindowHint () = glfwDefaultWindowHints () 680 | 681 | let windowHint(wh: WindowHint, v: int) = glfwWindowHint(wh |> int, v) 682 | 683 | let createWindow(width, height, title, monitor: Monitor option, share: Window option) = 684 | let share = 685 | match share with 686 | | Some s -> s.Value 687 | | None -> IntPtr.Zero 688 | 689 | let monitor = 690 | match monitor with 691 | | Some m -> m.Value 692 | | None -> IntPtr.Zero 693 | 694 | Window(glfwCreateWindow(width, height, title, monitor, share)) 695 | 696 | let destroyWindow (win: Window) = glfwDestroyWindow win.Value 697 | 698 | let windowShouldClose (win: Window) = glfwWindowShouldClose(win.Value) <> 0 699 | 700 | let setWindowShouldClose (win: Window, b: bool) = glfwSetWindowShouldClose(win.Value, if b then 1 else 0) 701 | 702 | let setWindowTitle (win: Window, title: string) = glfwSetWindowTitle(win.Value, title) 703 | 704 | let getWindowPos (win: Window) = 705 | let mutable x, y = 0, 0 706 | glfwGetWindowPos(win.Value, &x, &y) 707 | (x, y) 708 | 709 | let setWindowPos (win: Window, x: int, y: int) = glfwSetWindowPos(win.Value, x, y) 710 | 711 | let getWindowSize (win: Window) = 712 | let mutable x, y = 0, 0 713 | glfwGetWindowSize(win.Value, &x, &y) 714 | (x, y) 715 | 716 | let setWindowSize (win: Window, x, y) = glfwSetWindowSize (win.Value, x, y) 717 | 718 | let getFrameBufferSize(win: Window) = 719 | let mutable x, y = 0, 0 720 | glfwGetFramebufferSize(win.Value, &x, &y) 721 | (x, y) 722 | 723 | let getWindowFrameSize(win: Window) = 724 | let mutable top, left, bottom, right = 0, 0, 0, 0 725 | glfwGetWindowFrameSize(win.Value, &left, &top, &right, &bottom) 726 | (left, top, right, bottom) 727 | 728 | let iconifyWindow (win: Window) = glfwIconifyWindow win.Value 729 | 730 | let restoreWindow (win: Window) = glfwRestoreWindow win.Value 731 | 732 | let showWindow (win: Window) = glfwShowWindow win.Value 733 | 734 | let hideWindow (win: Window) = glfwHideWindow win.Value 735 | 736 | let getWindowMonitor (win: Window) = Monitor(glfwGetWindowMonitor win.Value) 737 | 738 | let pollEvents () = glfwPollEvents () 739 | let waitEvents () = glfwWaitEvents () 740 | 741 | type internal DisposableCallback<'A>(cb: 'A) = 742 | member internal x.CB = cb 743 | interface IDisposable with 744 | member x.Dispose () = () 745 | 746 | let setWindowShouldCloseCallback (win: Window, cb: Window -> bool) = 747 | let glfwCB (win: GLFWwindow) = 748 | let shouldClose = 749 | if cb (Window(win)) 750 | then 1 751 | else 0 752 | glfwSetWindowShouldClose (win, shouldClose) 753 | 754 | let disp = new DisposableCallback<_> (GLFWwindowclosefun (glfwCB)) 755 | glfwSetWindowCloseCallback (win.Value, disp.CB) |> ignore 756 | disp :> IDisposable 757 | 758 | let setWindowRefreshCallback (win: Window, cb: Window -> unit) = 759 | let glfwCB(win: GLFWwindow) = cb (Window win) 760 | let disp = new DisposableCallback<_> (GLFWwindowrefreshfun glfwCB) 761 | glfwSetWindowRefreshCallback(win.Value, disp.CB) |> ignore 762 | disp :> IDisposable 763 | 764 | let setWindowSizeCallback (win: Window, cb: Window * int * int -> unit) = 765 | let glfwCB(win: GLFWwindow) width height = cb (Window win, width, height) 766 | let disp = new DisposableCallback<_> (GLFWwindowsizefun glfwCB) 767 | glfwSetWindowSizeCallback(win.Value, disp.CB) |> ignore 768 | disp :> IDisposable 769 | 770 | let setWindowPosCallback (win: Window, cb: Window * int * int -> unit) = 771 | let glfwCB(win: GLFWwindow) x y = cb (Window win, x, y) 772 | let disp = new DisposableCallback<_> (GLFWwindowposfun glfwCB) 773 | glfwSetWindowPosCallback (win.Value, disp.CB) |> ignore 774 | disp :> IDisposable 775 | 776 | let setWindowFocusCallback (win: Window, cb: Window * bool -> unit) = 777 | let glfwCB (win: GLFWwindow) b = cb (Window win, b <> 0) 778 | let disp = new DisposableCallback<_> (GLFWwindowfocusfun glfwCB) 779 | glfwSetWindowFocusCallback (win.Value, disp.CB) |> ignore 780 | disp :> IDisposable 781 | 782 | let setWindowIconifyCallback (win: Window, cb: Window * bool -> unit) = 783 | let glfwCB (win: GLFWwindow) b = cb (Window win, b <> 0) 784 | let disp = new DisposableCallback<_> (GLFWwindowiconifyfun glfwCB) 785 | glfwSetWindowIconifyCallback (win.Value, disp.CB) |> ignore 786 | disp :> IDisposable 787 | 788 | let setFramebufferSizeCallback (win: Window, cb: Window * int * int -> unit) = 789 | let glfwCB(win: GLFWwindow) width height = cb (Window win, width, height) 790 | let disp = new DisposableCallback<_> (GLFWframebuffersizefun glfwCB) 791 | glfwSetFramebufferSizeCallback (win.Value, disp.CB) |> ignore 792 | disp :> IDisposable 793 | 794 | let setKeyCallback (win: Window, cb: Window * Key * int * Action * Mod -> unit) = 795 | let glfwCB(win: GLFWwindow) k s a m = cb (Window win, k |> enum, s, a |> enum, m |> enum) 796 | let disp = new DisposableCallback<_> (GLFWkeyfun glfwCB) 797 | glfwSetKeyCallback (win.Value, disp.CB) |> ignore 798 | disp :> IDisposable 799 | 800 | let setCharCallback (win: Window, cb: Window * char -> unit) = 801 | let glfwCB(win: GLFWwindow) (c: uint32) = cb (Window win, System.Convert.ToChar c) 802 | let disp = new DisposableCallback<_> (GLFWcharfun glfwCB) 803 | glfwSetCharCallback (win.Value, disp.CB) |> ignore 804 | disp :> IDisposable 805 | 806 | let setCharModsCallback (win: Window, cb: Window * char * Mod -> unit) = 807 | let glfwCB(win: GLFWwindow) (c: uint32) m = cb (Window win, System.Convert.ToChar c, m |> enum) 808 | let disp = new DisposableCallback<_> (GLFWcharmodsfun glfwCB) 809 | glfwSetCharModsCallback (win.Value, disp.CB) |> ignore 810 | disp :> IDisposable 811 | 812 | let setMouseButtonCallback (win: Window, cb: Window * MouseButton * Action * Mod -> unit) = 813 | let glfwCB (win: GLFWwindow) x y z = cb (Window win, x |> enum, y |> enum, z |> enum) 814 | let disp = new DisposableCallback<_> (GLFWmousebuttonfun glfwCB) 815 | glfwSetMouseButtonCallback(win.Value, disp.CB) |> ignore 816 | disp :> IDisposable 817 | 818 | let setCursorPosCallback (win: Window, cb: Window * float * float -> unit) = 819 | let glfwCB (win: GLFWwindow) x y = cb (Window win, x, y) 820 | let disp = new DisposableCallback<_> (GLFWcursorposfun glfwCB) 821 | glfwSetCursorPosCallback(win.Value, disp.CB) |> ignore 822 | disp :> IDisposable 823 | 824 | let setCursorEnterCallback (win: Window, cb: Window * bool -> unit) = 825 | let glfwCB (win: GLFWwindow) b = cb (Window win, b <> 0) 826 | let disp = new DisposableCallback<_> (GLFWcursorenterfun glfwCB) 827 | glfwSetCursorEnterCallback(win.Value, disp.CB) |> ignore 828 | disp :> IDisposable 829 | 830 | let setScrollCallback (win: Window, cb: Window * float * float -> unit) = 831 | let glfwCB (win: GLFWwindow) x y = cb (Window win, x, y) 832 | let disp = new DisposableCallback<_> (GLFWscrollfun glfwCB) 833 | glfwSetScrollCallback(win.Value, disp.CB) |> ignore 834 | disp :> IDisposable 835 | 836 | let setDropCallback (win: Window, cb: Window * string[] -> unit) = 837 | let glfwCB (win: GLFWwindow) (count: int) (s : IntPtr) = 838 | let strArr = Array.init count (fun i -> IntPtr.Zero) 839 | Marshal.Copy(s, strArr, 0, count) 840 | 841 | let strArr = 842 | strArr 843 | |> Array.map Marshal.PtrToStringAnsi 844 | 845 | cb (Window win, strArr) 846 | 847 | let disp = new DisposableCallback<_> (GLFWdropfun glfwCB) 848 | glfwSetDropCallback(win.Value, disp.CB) |> ignore 849 | disp :> IDisposable 850 | 851 | let getClipboardString (win: Window) = 852 | let ptr = glfwGetClipboardString win.Value 853 | if ptr = IntPtr.Zero 854 | then "" 855 | else Marshal.PtrToStringAnsi ptr 856 | 857 | let setClipboardString (win: Window, str) = glfwSetClipboardString (win.Value, str) 858 | 859 | let getWindowHit (win: Window, hint: WindowHint) = glfwGetWindowAttrib(win.Value, hint |> int) 860 | 861 | let setWindowUserPointer (win: Window, ptr: IntPtr) = glfwSetWindowUserPointer (win.Value, ptr) 862 | 863 | let getWindowUserPointer (win: Window) = glfwGetWindowUserPointer (win.Value) 864 | 865 | let postEmptyEvent = glfwPostEmptyEvent 866 | 867 | let getTime = glfwGetTime 868 | 869 | let setTime = glfwSetTime 870 | 871 | let getKey (win: Window, k: Key) = glfwGetKey(win.Value, k |> int) |> enum 872 | 873 | let setCursorMode (win: Window, cm: CursorMode) = glfwSetInputMode(win.Value, InputMode.CURSOR |> int, cm |> int) 874 | 875 | let getCursorMode (win: Window) = glfwGetInputMode(win.Value, InputMode.CURSOR |> int) |> enum 876 | 877 | let getCursorPos (win: Window) = 878 | let mutable x, y = 0.0, 0.0 879 | glfwGetCursorPos(win.Value, &x, &y) 880 | (x, y) 881 | 882 | let setCursorPos (win: Window, x, y) = glfwSetCursorPos(win.Value, x, y) 883 | 884 | let createStandardCursor(shape: DefaultCursor) = Cursor(glfwCreateStandardCursor (shape |> int)) 885 | 886 | let destroyCursor(cursor: Cursor) = glfwDestroyCursor cursor.Value 887 | 888 | let setCursor (win: Window, cursor: Cursor) = glfwSetCursor(win.Value, cursor.Value) 889 | 890 | let setStickyKeyMode (win: Window, b: bool) = glfwSetInputMode (win.Value, InputMode.STICKY_KEYS |> int, if b then 1 else 0) 891 | 892 | let getStickyKeyMode (win: Window) = glfwGetInputMode (win.Value, InputMode.STICKY_KEYS |> int) <> 0 893 | 894 | let setStickyMouseButtonMode (win: Window, b: bool) = glfwSetInputMode (win.Value, InputMode.STICKY_MOUSE_BUTTONS |> int, if b then 1 else 0) 895 | 896 | let getStickyMouseButtonMode (win: Window) = glfwGetInputMode (win.Value, InputMode.STICKY_MOUSE_BUTTONS |> int) <> 0 897 | 898 | let getMouseButton(win: Window, button: MouseButton) = glfwGetMouseButton(win.Value, button |> int) |> enum 899 | 900 | let isJoystickPresent(joy: Joystick) = glfwJoystickPresent (joy |> int) <> 0 901 | 902 | let getJoystickButtons (joy: Joystick) = 903 | let mutable count = 0 904 | let ptr = glfwGetJoystickButtons(joy |> int, &count) 905 | 906 | let chArr = Array.init count (fun i -> byte 0) 907 | Marshal.Copy (ptr, chArr, 0, count) 908 | 909 | chArr |> Array.map (fun c -> int c |> enum) 910 | 911 | let getJoystickName (joy: Joystick) = Marshal.PtrToStringAnsi (glfwGetJoystickName (joy |> int)) 912 | 913 | let makeContextCurrent (win: Window) = glfwMakeContextCurrent win.Value 914 | 915 | let getCurrentContext () = Window(glfwGetCurrentContext ()) 916 | 917 | let swapBuffers (win: Window) = glfwSwapBuffers win.Value 918 | 919 | let swapInterval = glfwSwapInterval 920 | 921 | let setWindowData<'T> (win: Window, data: 'T) = 922 | let handle = GCHandle.Alloc(data, GCHandleType.Pinned) 923 | glfwSetWindowUserPointer(win.Value, handle.AddrOfPinnedObject()) 924 | 925 | let releaseWindowData (win: Window) = 926 | let ptr = glfwGetWindowUserPointer (win.Value) 927 | let handle = GCHandle.FromIntPtr ptr 928 | handle.Free() -------------------------------------------------------------------------------- /FsGlfw3/lib/glfw3.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fsprojects/FsGlfw3/ef0aab95c3385a83b7bdd372d3333af2fe9f64ac/FsGlfw3/lib/glfw3.dll -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2015-2018(c) Wael El Oraiby 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 5 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 | 7 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 | 9 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 10 | 11 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FsGlfw3 2 | F# GLFW 3.2.1 Binding 3 | 4 | -------------------------------------------------------------------------------- /Sample/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Sample/Program.fs: -------------------------------------------------------------------------------- 1 | (* 2 | ** F# GLFW binding 3 | ** Copyright (C) 2015-2016 Wael El Oraiby 4 | ** 5 | ** This program is free software: you can redistribute it and/or modify 6 | ** it under the terms of the GNU Affero General Public License as 7 | ** published by the Free Software Foundation, either version 3 of the 8 | ** License, or (at your option) any later version. 9 | ** 10 | ** This program is distributed in the hope that it will be useful, 11 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ** GNU Affero General Public License for more details. 14 | ** 15 | ** You should have received a copy of the GNU Affero General Public License 16 | ** along with this program. If not, see . 17 | *) 18 | [] 19 | let main argv = 20 | 21 | printfn "init: %d" (Glfw3.init()) 22 | printfn "version: %A" (Glfw3.getVersion()) 23 | printfn "str version: %s" (Glfw3.getVersionString()) 24 | 25 | let monitors = Glfw3.getMonitors() 26 | printfn "monitors: %d" (monitors.Length) 27 | 28 | let primaryMonitor = Glfw3.getPrimaryMonitor() 29 | 30 | printfn "primary monitor position: %A" (Glfw3.getMonitorPos(primaryMonitor)) 31 | 32 | monitors 33 | |> Array.iter (fun m -> printfn "Name: %s, Pos: %A, Size: %A" (Glfw3.getMonitorName m) (Glfw3.getMonitorPos m) (Glfw3.getMonitorPhysicalSize m)) 34 | 35 | monitors 36 | |> Array.iteri 37 | (fun im m -> 38 | m 39 | |> Glfw3.getVideoModes 40 | |> Array.iteri 41 | (fun iv vm -> 42 | printfn "%dx%d - width: %d - height: %d - RGB: %d%d%d - rate: %d" im iv vm.width vm.height vm.redBits vm.greenBits vm.blueBits vm.refreshRate)) 43 | 44 | let vm = Glfw3.getVideoMode primaryMonitor 45 | printfn "Primary: width: %d - height: %d - RGB: %d%d%d - rate: %d" vm.width vm.height vm.redBits vm.greenBits vm.blueBits vm.refreshRate 46 | 47 | //Glfw3.setGamma(primaryMonitor, 1.0f) 48 | 49 | let gammaRamp0 = Glfw3.getGammaramp primaryMonitor 50 | Glfw3.setGammaramp(primaryMonitor, gammaRamp0) 51 | let gammaRamp1 = Glfw3.getGammaramp primaryMonitor 52 | 53 | gammaRamp0.Red 54 | |> Array.zip gammaRamp1.Red 55 | |> Array.iter(fun (r0, r1) -> printfn "r0: %d - r1: %d" r0 r1) 56 | 57 | let win = Glfw3.createWindow(640, 480, "Hello World", None, None) 58 | 59 | Glfw3.setWindowTitle(win, "Hahaha") 60 | Glfw3.setWindowPos(win, 100, 120) 61 | Glfw3.setWindowSize(win, 512, 512) 62 | 63 | printfn "Framebuffer %A" (Glfw3.getFrameBufferSize win) 64 | printfn "Window Frame size %A" (Glfw3.getWindowFrameSize win) 65 | 66 | Glfw3.iconifyWindow win 67 | Glfw3.restoreWindow win 68 | Glfw3.hideWindow win 69 | Glfw3.showWindow win 70 | 71 | let rnd = System.Random () 72 | 73 | let windowRefresh win = 74 | printfn "refresh: %d" (rnd.Next()) 75 | //GLES2.glClear ((GLenum.GL_COLOR_BUFFER_BIT ||| GLenum.GL_DEPTH_BUFFER_BIT) |> uint32) 76 | Glfw3.swapBuffers win 77 | 78 | Glfw3.setWindowRefreshCallback(win, windowRefresh) |> ignore 79 | Glfw3.setWindowSizeCallback (win, fun (win, w, h) -> printfn "w: %d, h: %d" w h) |> ignore 80 | Glfw3.setWindowPosCallback (win, fun (win, x, y) -> printfn "x: %d, y: %d" x y) |> ignore 81 | Glfw3.setWindowFocusCallback(win, fun (win, b) -> if b then printfn "focused" else printfn "unfocused") |> ignore 82 | Glfw3.setWindowIconifyCallback (win, fun (win, b) -> if b then printfn "iconified" else printfn "uniconified") |> ignore 83 | Glfw3.setFramebufferSizeCallback (win, fun (win, w, h) -> printfn "FB: w: %d, h: %d" w h) |> ignore 84 | Glfw3.setKeyCallback(win, fun (w, k, i, a, m) -> printfn "%A - %d - %A - %A" k i a m; printfn "Key State: %A" (Glfw3.getKey (w, k))) |> ignore 85 | Glfw3.setCharCallback(win, fun (w, c) -> printfn "%c" c) |> ignore 86 | Glfw3.setCharModsCallback(win, fun (w, c, m) -> printfn "%c - %A" c m) |> ignore 87 | Glfw3.setMouseButtonCallback(win, fun (w, b, a, m) -> printfn "mouse %A, %A, %A" b a m; printfn "clipboard: %s" (Glfw3.getClipboardString w)) |> ignore 88 | // Glfw3.setCursorPosCallback(win, fun (w, x, y) -> printfn "pos: %f, %f" x y) |> ignore 89 | Glfw3.setCursorEnterCallback(win, fun (w, b) -> printfn "Enter: %b" b) |> ignore 90 | Glfw3.setScrollCallback(win, fun (w, x, y) -> printfn "Scroll: %f %f" x y) |> ignore 91 | Glfw3.setDropCallback(win, fun (w, s) -> printfn "%A" s) |> ignore 92 | 93 | let rec loop () = 94 | if Glfw3.windowShouldClose win 95 | then () 96 | else 97 | 98 | Glfw3.pollEvents () 99 | loop () 100 | 101 | loop () 102 | printfn "Pos : %A" (Glfw3.getWindowPos win) 103 | printfn "Size: %A" (Glfw3.getWindowSize win) 104 | 105 | 0 // return an integer exit code 106 | -------------------------------------------------------------------------------- /Sample/Sample.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | netcoreapp2.0 6 | 7 | 8 | 9 | 3.2.1-alpha 10 | Wael El Oraiby 11 | Wael El Oraiby 12 | F# bindings for GLFW 3.2.1 13 | F# bindings for GLFW 3.2.1 14 | https://opensource.org/licenses/MIT 15 | 2015-2018 (c) Wael El Oraiby 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Sample/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | --------------------------------------------------------------------------------