| | 45 | |
|---|
| | 46 | private HXModule hglfw; |
|---|
| | 47 | |
|---|
| | 48 | private void* getProc(char[] procname) |
|---|
| | 49 | { |
|---|
| | 50 | void* symbol = ExeModule_GetSymbol(hglfw, procname); |
|---|
| | 51 | if (symbol is null) |
|---|
| | 52 | throw new Exception("Failed to load glfw proc address " ~ procname); |
|---|
| | 53 | return symbol; |
|---|
| | 54 | } |
|---|
| | 55 | |
|---|
| | 56 | private bit exeModuleInited = false; |
|---|
| | 57 | |
|---|
| | 58 | public void DerelictGLFW_Load(char[] libName) |
|---|
| | 59 | { |
|---|
| | 60 | if(hglfw !== null) |
|---|
| | 61 | return; |
|---|
| | 62 | |
|---|
| | 63 | // there's no guarantee this will be used in together with DerelictGL, |
|---|
| | 64 | // could be used with another OpenGL binding, so initialize std.loader |
|---|
| | 65 | // (even though it doesn't do anything). |
|---|
| | 66 | if(ExeModule_Init() == -1) |
|---|
| | 67 | throw new Exception("ExeModule initialization failed"); |
|---|
| | 68 | |
|---|
| | 69 | exeModuleInited = true; |
|---|
| | 70 | |
|---|
| | 71 | hglfw = ExeModule_Load(libName); |
|---|
| | 72 | |
|---|
| | 73 | if(hglfw is null) |
|---|
| | 74 | throw new Exception("Failed to load the GLFW shared library."); |
|---|
| | 75 | |
|---|
| | 76 | load(); |
|---|
| | 77 | } |
|---|
| | 78 | |
|---|
| | 79 | public void DerelictGLFW_Load() |
|---|
| | 80 | { |
|---|
| | 81 | version(Windows) |
|---|
| | 82 | DerelictGLFW_Load("glfw.dll"); |
|---|
| | 83 | version(linux) |
|---|
| | 84 | DerelictGLFW_Load("libglfw.so"); |
|---|
| | 85 | } |
|---|
| | 86 | |
|---|
| | 87 | static ~this() |
|---|
| | 88 | { |
|---|
| | 89 | if(exeModuleInited) |
|---|
| | 90 | { |
|---|
| | 91 | ExeModule_Release(hglfw); |
|---|
| | 92 | ExeModule_Uninit(); |
|---|
| | 93 | } |
|---|
| | 94 | } |
|---|
| | 95 | |
|---|
| | 96 | version(Windows) |
|---|
| | 97 | extern(Windows): |
|---|
| | 98 | else |
|---|
| | 99 | extern(C): |
|---|
| 201 | | extern(Windows) |
|---|
| 202 | | { |
|---|
| 203 | | // Intrinsic glfw funtion pointer types |
|---|
| 204 | | typedef void function(int, int) GLFWwindowsizefun; |
|---|
| 205 | | typedef void function(int, int) GLFWmousebuttonfun; |
|---|
| 206 | | typedef void function(int, int) GLFWmouseposfun; |
|---|
| 207 | | typedef void function(int) GLFWmousewheelfun; |
|---|
| 208 | | typedef void function(int, int) GLFWkeyfun; |
|---|
| 209 | | typedef void function(int, int) GLFWcharfun; |
|---|
| 210 | | alias void function(void*) GLFWthreadfun; |
|---|
| 211 | | } |
|---|
| 212 | | |
|---|
| 521 | | private void* getProc(char[] procname) |
|---|
| 522 | | { |
|---|
| 523 | | void* symbol = ExeModule_GetSymbol(hglfw, procname); |
|---|
| 524 | | if (symbol is null) |
|---|
| 525 | | throw new Exception("Failed to load glfw proc address " ~ procname); |
|---|
| 526 | | return symbol; |
|---|
| 527 | | } |
|---|
| 528 | | |
|---|
| 529 | | private bit exeModuleInited = false; |
|---|
| 530 | | |
|---|
| 531 | | public void DerelictGLFW_Load(char[] libName) |
|---|
| 532 | | { |
|---|
| 533 | | if(hglfw !== null) |
|---|
| 534 | | return; |
|---|
| 535 | | |
|---|
| 536 | | // there's no guarantee this will be used in together with DerelictGL, |
|---|
| 537 | | // could be used with another OpenGL binding, so initialize std.loader |
|---|
| 538 | | // (even though it doesn't do anything). |
|---|
| 539 | | if(ExeModule_Init() == -1) |
|---|
| 540 | | throw new Exception("ExeModule initialization failed"); |
|---|
| 541 | | |
|---|
| 542 | | exeModuleInited = true; |
|---|
| 543 | | |
|---|
| 544 | | hglfw = ExeModule_Load(libName); |
|---|
| 545 | | |
|---|
| 546 | | if(hglfw is null) |
|---|
| 547 | | throw new Exception("Failed to load the GLFW shared library."); |
|---|
| 548 | | |
|---|
| 549 | | load(); |
|---|
| 550 | | } |
|---|
| 551 | | |
|---|
| 552 | | public void DerelictGLFW_Load() |
|---|
| 553 | | { |
|---|
| 554 | | version(Windows) |
|---|
| 555 | | DerelictGLFW_Load("glfw.dll"); |
|---|
| 556 | | version(linux) |
|---|
| 557 | | DerelictGLFW_Load("libglfw-2.4.2.so.0"); |
|---|
| 558 | | } |
|---|
| 559 | | |
|---|
| 560 | | static ~this() |
|---|
| 561 | | { |
|---|
| 562 | | if(exeModuleInited) |
|---|
| 563 | | { |
|---|
| 564 | | ExeModule_Release(hglfw); |
|---|
| 565 | | ExeModule_Uninit(); |
|---|
| 566 | | } |
|---|
| 567 | | } |
|---|
| 568 | | |
|---|
| 569 | | version(Windows) |
|---|
| 570 | | extern(Windows): |
|---|
| 571 | | else |
|---|
| 572 | | extern(C): |
|---|
| 573 | | |
|---|
| 574 | | // GLFW initialization and version query |
|---|
| | 562 | // GLFW initialization and version query |
|---|
| | 647 | |
|---|
| | 648 | // Intrinsic glfw funtion pointer types |
|---|
| | 649 | |
|---|
| | 650 | typedef void function(int, int) GLFWwindowsizefun; |
|---|
| | 651 | typedef void function(int, int) GLFWmousebuttonfun; |
|---|
| | 652 | typedef void function(int, int) GLFWmouseposfun; |
|---|
| | 653 | typedef void function(int) GLFWmousewheelfun; |
|---|
| | 654 | typedef void function(int, int) GLFWkeyfun; |
|---|
| | 655 | typedef void function(int, int) GLFWcharfun; |
|---|
| | 656 | typedef void function(void*) GLFWthreadfun; |
|---|