1 | #include "GLFW/glfw3.h"
|
2 |
|
3 | #ifdef __MINGW32__
|
4 | #include <windows.h>
|
5 | #endif
|
6 |
|
7 | static GLFWwindow *sliProgramWindow = NULL;
|
8 | static int sliWindowWidth = 0;
|
9 | static int sliWindowHeight = 0;
|
10 |
|
11 | void sliOpenWindow(int width, int height, const char *title, int fullScreen)
|
12 | {
|
13 | // types enabling us to access WGL functionality for enabling vsync in Windows
|
14 | //#ifdef __MINGW32__
|
15 | //typedef BOOL (WINAPI *PFNWGLSWAPINTERVALEXTPROC)(int interval);
|
16 | //PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = NULL;
|
17 | //#endif
|
18 |
|
19 | // start up GLFW
|
20 | glfwInit();
|
21 |
|
22 | // set our OpenGL context to something that doesn't support any old-school shit
|
23 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
24 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
|
25 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
26 | glfwWindowHint(GLFW_REFRESH_RATE, 60);
|
27 |
|
28 | // create our OpenGL window
|
29 | sliProgramWindow = glfwCreateWindow(width, height, title, fullScreen ? glfwGetPrimaryMonitor() : NULL, NULL);
|
30 | glfwMakeContextCurrent(sliProgramWindow);
|
31 | glfwSwapInterval(1);
|
32 |
|
33 | // record window size
|
34 | sliWindowWidth = width;
|
35 | sliWindowHeight = height;
|
36 |
|
37 | // GLFW doesn't handle vsync well in all cases, so we have to go straight to WGL to do this
|
38 | //#ifdef __MINGW32__
|
39 | //wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
|
40 | //wglSwapIntervalEXT(1);
|
41 | //#endif
|
42 |
|
43 | // enable OpenGL debugging context if we're in a debug build
|
44 | #ifdef DEBUG
|
45 | glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
|
46 | #endif
|
47 | }
|
48 |
|
49 | void sliShowCursor(int showCursor)
|
50 | {
|
51 | glfwSetInputMode(sliProgramWindow, GLFW_CURSOR, showCursor ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN);
|
52 | }
|
53 |
|
54 | void sliCloseWindow()
|
55 | {
|
56 | glfwDestroyWindow(sliProgramWindow);
|
57 | glfwTerminate();
|
58 | sliProgramWindow = NULL;
|
59 | }
|
60 |
|
61 | int sliIsWindowOpen()
|
62 | {
|
63 | return sliProgramWindow != NULL;
|
64 | }
|
65 |
|
66 | int sliShouldClose()
|
67 | {
|
68 | return glfwWindowShouldClose(sliProgramWindow);
|
69 | }
|
70 |
|
71 | int sliGetKey(int key)
|
72 | {
|
73 | return glfwGetKey(sliProgramWindow, key) == GLFW_PRESS;
|
74 | }
|
75 |
|
76 | int sliGetMouseButton(int button)
|
77 | {
|
78 | return glfwGetMouseButton(sliProgramWindow, button) == GLFW_PRESS;
|
79 | }
|
80 |
|
81 | void sliGetMousePos(int *posX, int *posY)
|
82 | {
|
83 | double x, y;
|
84 | glfwGetCursorPos(sliProgramWindow, &x, &y);
|
85 | *posX = (int)x;
|
86 | *posY = sliWindowHeight - (int)y;
|
87 | }
|
88 |
|
89 | double sliGetTime()
|
90 | {
|
91 | return glfwGetTime();
|
92 | }
|
93 |
|
94 | void sliPollAndSwap()
|
95 | {
|
96 | glfwPollEvents();
|
97 | glfwSwapBuffers(sliProgramWindow);
|
98 | }
|
99 | |