Fortran · 14795 bytes Raw Blame History
1 module glfw_bindings
2 use, intrinsic :: iso_c_binding
3 use types
4 implicit none
5 public
6
7 ! GLFW constants
8 integer(c_int), parameter :: GLFW_TRUE = 1
9 integer(c_int), parameter :: GLFW_FALSE = 0
10
11 ! Window hints
12 integer(c_int), parameter :: GLFW_CONTEXT_VERSION_MAJOR = int(Z'00022002', c_int)
13 integer(c_int), parameter :: GLFW_CONTEXT_VERSION_MINOR = int(Z'00022003', c_int)
14 integer(c_int), parameter :: GLFW_OPENGL_PROFILE = int(Z'00022008', c_int)
15 integer(c_int), parameter :: GLFW_OPENGL_CORE_PROFILE = int(Z'00032001', c_int)
16 integer(c_int), parameter :: GLFW_OPENGL_FORWARD_COMPAT = int(Z'00022006', c_int)
17 integer(c_int), parameter :: GLFW_TRANSPARENT_FRAMEBUFFER = int(Z'0002000A', c_int)
18
19 ! Key constants
20 integer(c_int), parameter :: GLFW_KEY_ESCAPE = 256
21 integer(c_int), parameter :: GLFW_KEY_ENTER = 257
22 integer(c_int), parameter :: GLFW_KEY_TAB = 258
23 integer(c_int), parameter :: GLFW_KEY_BACKSPACE = 259
24 integer(c_int), parameter :: GLFW_KEY_INSERT = 260
25 integer(c_int), parameter :: GLFW_KEY_DELETE = 261
26 integer(c_int), parameter :: GLFW_KEY_RIGHT = 262
27 integer(c_int), parameter :: GLFW_KEY_LEFT = 263
28 integer(c_int), parameter :: GLFW_KEY_DOWN = 264
29 integer(c_int), parameter :: GLFW_KEY_UP = 265
30 integer(c_int), parameter :: GLFW_KEY_PAGE_UP = 266
31 integer(c_int), parameter :: GLFW_KEY_PAGE_DOWN = 267
32 integer(c_int), parameter :: GLFW_KEY_HOME = 268
33 integer(c_int), parameter :: GLFW_KEY_END = 269
34
35 ! Function keys
36 integer(c_int), parameter :: GLFW_KEY_F1 = 290
37 integer(c_int), parameter :: GLFW_KEY_F2 = 291
38 integer(c_int), parameter :: GLFW_KEY_F3 = 292
39 integer(c_int), parameter :: GLFW_KEY_F4 = 293
40 integer(c_int), parameter :: GLFW_KEY_F5 = 294
41 integer(c_int), parameter :: GLFW_KEY_F6 = 295
42 integer(c_int), parameter :: GLFW_KEY_F7 = 296
43 integer(c_int), parameter :: GLFW_KEY_F8 = 297
44 integer(c_int), parameter :: GLFW_KEY_F9 = 298
45 integer(c_int), parameter :: GLFW_KEY_F10 = 299
46 integer(c_int), parameter :: GLFW_KEY_F11 = 300
47 integer(c_int), parameter :: GLFW_KEY_F12 = 301
48
49 ! Letter keys (for Ctrl combinations)
50 integer(c_int), parameter :: GLFW_KEY_A = 65
51 integer(c_int), parameter :: GLFW_KEY_B = 66
52 integer(c_int), parameter :: GLFW_KEY_C = 67
53 integer(c_int), parameter :: GLFW_KEY_D = 68
54 integer(c_int), parameter :: GLFW_KEY_E = 69
55 integer(c_int), parameter :: GLFW_KEY_F = 70
56 integer(c_int), parameter :: GLFW_KEY_G = 71
57 integer(c_int), parameter :: GLFW_KEY_H = 72
58 integer(c_int), parameter :: GLFW_KEY_I = 73
59 integer(c_int), parameter :: GLFW_KEY_J = 74
60 integer(c_int), parameter :: GLFW_KEY_K = 75
61 integer(c_int), parameter :: GLFW_KEY_L = 76
62 integer(c_int), parameter :: GLFW_KEY_M = 77
63 integer(c_int), parameter :: GLFW_KEY_N = 78
64 integer(c_int), parameter :: GLFW_KEY_O = 79
65 integer(c_int), parameter :: GLFW_KEY_P = 80
66 integer(c_int), parameter :: GLFW_KEY_Q = 81
67 integer(c_int), parameter :: GLFW_KEY_R = 82
68 integer(c_int), parameter :: GLFW_KEY_S = 83
69 integer(c_int), parameter :: GLFW_KEY_T = 84
70 integer(c_int), parameter :: GLFW_KEY_U = 85
71 integer(c_int), parameter :: GLFW_KEY_V = 86
72 integer(c_int), parameter :: GLFW_KEY_W = 87
73 integer(c_int), parameter :: GLFW_KEY_X = 88
74 integer(c_int), parameter :: GLFW_KEY_Y = 89
75 integer(c_int), parameter :: GLFW_KEY_Z = 90
76
77 ! Number keys
78 integer(c_int), parameter :: GLFW_KEY_0 = 48
79
80 ! Symbol keys (for font size adjustment)
81 integer(c_int), parameter :: GLFW_KEY_MINUS = 45 ! '-' key
82 integer(c_int), parameter :: GLFW_KEY_EQUAL = 61 ! '=' key
83
84 ! Numpad keys
85 integer(c_int), parameter :: GLFW_KEY_KP_SUBTRACT = 333
86 integer(c_int), parameter :: GLFW_KEY_KP_ADD = 334
87
88 ! Bracket and backslash keys (for tab/pane keybindings)
89 integer(c_int), parameter :: GLFW_KEY_LEFT_BRACKET = 91 ! [
90 integer(c_int), parameter :: GLFW_KEY_BACKSLASH = 92 ! \
91 integer(c_int), parameter :: GLFW_KEY_RIGHT_BRACKET = 93 ! ]
92
93 ! Number keys 1-9 (for tab switching)
94 integer(c_int), parameter :: GLFW_KEY_1 = 49
95 integer(c_int), parameter :: GLFW_KEY_2 = 50
96 integer(c_int), parameter :: GLFW_KEY_3 = 51
97 integer(c_int), parameter :: GLFW_KEY_4 = 52
98 integer(c_int), parameter :: GLFW_KEY_5 = 53
99 integer(c_int), parameter :: GLFW_KEY_6 = 54
100 integer(c_int), parameter :: GLFW_KEY_7 = 55
101 integer(c_int), parameter :: GLFW_KEY_8 = 56
102 integer(c_int), parameter :: GLFW_KEY_9 = 57
103
104 ! Modifier masks
105 integer(c_int), parameter :: GLFW_MOD_SHIFT = 1
106 integer(c_int), parameter :: GLFW_MOD_CONTROL = 2
107 integer(c_int), parameter :: GLFW_MOD_ALT = 4
108 integer(c_int), parameter :: GLFW_MOD_SUPER = 8
109
110 ! Action constants
111 integer(c_int), parameter :: GLFW_RELEASE = 0
112 integer(c_int), parameter :: GLFW_PRESS = 1
113 integer(c_int), parameter :: GLFW_REPEAT = 2
114
115 ! Mouse button constants
116 integer(c_int), parameter :: GLFW_MOUSE_BUTTON_LEFT = 0
117 integer(c_int), parameter :: GLFW_MOUSE_BUTTON_RIGHT = 1
118 integer(c_int), parameter :: GLFW_MOUSE_BUTTON_MIDDLE = 2
119
120 ! Callback type for framebuffer size
121 abstract interface
122 subroutine glfw_framebuffer_size_callback(window, width, height) bind(C)
123 import :: c_ptr, c_int
124 type(c_ptr), value :: window
125 integer(c_int), value :: width, height
126 end subroutine glfw_framebuffer_size_callback
127
128 subroutine glfw_key_callback(window, key, scancode, action, mods) bind(C)
129 import :: c_ptr, c_int
130 type(c_ptr), value :: window
131 integer(c_int), value :: key, scancode, action, mods
132 end subroutine glfw_key_callback
133
134 subroutine glfw_error_callback(error_code, description) bind(C)
135 import :: c_int, c_ptr
136 integer(c_int), value :: error_code
137 type(c_ptr), value :: description
138 end subroutine glfw_error_callback
139
140 subroutine glfw_char_callback(window, codepoint) bind(C)
141 import :: c_ptr, c_int
142 type(c_ptr), value :: window
143 integer(c_int), value :: codepoint
144 end subroutine glfw_char_callback
145
146 subroutine glfw_scroll_callback(window, xoffset, yoffset) bind(C)
147 import :: c_ptr, c_double
148 type(c_ptr), value :: window
149 real(c_double), value :: xoffset, yoffset
150 end subroutine glfw_scroll_callback
151
152 subroutine glfw_mouse_button_callback(window, button, action, mods) bind(C)
153 import :: c_ptr, c_int
154 type(c_ptr), value :: window
155 integer(c_int), value :: button, action, mods
156 end subroutine glfw_mouse_button_callback
157
158 subroutine glfw_cursor_pos_callback(window, xpos, ypos) bind(C)
159 import :: c_ptr, c_double
160 type(c_ptr), value :: window
161 real(c_double), value :: xpos, ypos
162 end subroutine glfw_cursor_pos_callback
163
164 subroutine glfw_window_refresh_callback(window) bind(C)
165 import :: c_ptr
166 type(c_ptr), value :: window
167 end subroutine glfw_window_refresh_callback
168 end interface
169
170 interface
171 ! int glfwInit(void)
172 integer(c_int) function glfwInit() bind(C, name="glfwInit")
173 import :: c_int
174 end function glfwInit
175
176 ! void glfwTerminate(void)
177 subroutine glfwTerminate() bind(C, name="glfwTerminate")
178 end subroutine glfwTerminate
179
180 ! void glfwWindowHint(int hint, int value)
181 subroutine glfwWindowHint(hint, value) bind(C, name="glfwWindowHint")
182 import :: c_int
183 integer(c_int), value :: hint, value
184 end subroutine glfwWindowHint
185
186 ! GLFWwindow* glfwCreateWindow(int width, int height, const char* title,
187 ! GLFWmonitor* monitor, GLFWwindow* share)
188 type(c_ptr) function glfwCreateWindow(width, height, title, monitor, share) &
189 bind(C, name="glfwCreateWindow")
190 import :: c_int, c_ptr, c_char
191 integer(c_int), value :: width, height
192 character(kind=c_char), intent(in) :: title(*)
193 type(c_ptr), value :: monitor, share
194 end function glfwCreateWindow
195
196 ! void glfwDestroyWindow(GLFWwindow* window)
197 subroutine glfwDestroyWindow(window) bind(C, name="glfwDestroyWindow")
198 import :: c_ptr
199 type(c_ptr), value :: window
200 end subroutine glfwDestroyWindow
201
202 ! void glfwMakeContextCurrent(GLFWwindow* window)
203 subroutine glfwMakeContextCurrent(window) bind(C, name="glfwMakeContextCurrent")
204 import :: c_ptr
205 type(c_ptr), value :: window
206 end subroutine glfwMakeContextCurrent
207
208 ! int glfwWindowShouldClose(GLFWwindow* window)
209 integer(c_int) function glfwWindowShouldClose(window) bind(C, name="glfwWindowShouldClose")
210 import :: c_int, c_ptr
211 type(c_ptr), value :: window
212 end function glfwWindowShouldClose
213
214 ! void glfwSetWindowShouldClose(GLFWwindow* window, int value)
215 subroutine glfwSetWindowShouldClose(window, value) bind(C, name="glfwSetWindowShouldClose")
216 import :: c_int, c_ptr
217 type(c_ptr), value :: window
218 integer(c_int), value :: value
219 end subroutine glfwSetWindowShouldClose
220
221 ! void glfwSetWindowTitle(GLFWwindow* window, const char* title)
222 subroutine glfwSetWindowTitle(window, title) bind(C, name="glfwSetWindowTitle")
223 import :: c_ptr, c_char
224 type(c_ptr), value :: window
225 character(kind=c_char), intent(in) :: title(*)
226 end subroutine glfwSetWindowTitle
227
228 ! void glfwSwapBuffers(GLFWwindow* window)
229 subroutine glfwSwapBuffers(window) bind(C, name="glfwSwapBuffers")
230 import :: c_ptr
231 type(c_ptr), value :: window
232 end subroutine glfwSwapBuffers
233
234 ! void glfwPollEvents(void)
235 subroutine glfwPollEvents() bind(C, name="glfwPollEvents")
236 end subroutine glfwPollEvents
237
238 ! void glfwWaitEventsTimeout(double timeout)
239 ! Waits for events with timeout in seconds - critical for Wayland compositor
240 ! responsiveness when window is on inactive workspace
241 subroutine glfwWaitEventsTimeout(timeout) bind(C, name="glfwWaitEventsTimeout")
242 import :: c_double
243 real(c_double), value :: timeout
244 end subroutine glfwWaitEventsTimeout
245
246 ! double glfwGetTime(void)
247 real(c_double) function glfwGetTime() bind(C, name="glfwGetTime")
248 import :: c_double
249 end function glfwGetTime
250
251 ! void glfwGetFramebufferSize(GLFWwindow* window, int* width, int* height)
252 subroutine glfwGetFramebufferSize(window, width, height) bind(C, name="glfwGetFramebufferSize")
253 import :: c_int, c_ptr
254 type(c_ptr), value :: window
255 integer(c_int), intent(out) :: width, height
256 end subroutine glfwGetFramebufferSize
257
258 ! void glfwGetWindowSize(GLFWwindow* window, int* width, int* height)
259 subroutine glfwGetWindowSize(window, width, height) bind(C, name="glfwGetWindowSize")
260 import :: c_int, c_ptr
261 type(c_ptr), value :: window
262 integer(c_int), intent(out) :: width, height
263 end subroutine glfwGetWindowSize
264
265 ! GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* window,
266 ! GLFWframebuffersizefun callback)
267 type(c_funptr) function glfwSetFramebufferSizeCallback(window, callback) &
268 bind(C, name="glfwSetFramebufferSizeCallback")
269 import :: c_ptr, c_funptr
270 type(c_ptr), value :: window
271 type(c_funptr), value :: callback
272 end function glfwSetFramebufferSizeCallback
273
274 ! GLFWkeyfun glfwSetKeyCallback(GLFWwindow* window, GLFWkeyfun callback)
275 type(c_funptr) function glfwSetKeyCallback(window, callback) &
276 bind(C, name="glfwSetKeyCallback")
277 import :: c_ptr, c_funptr
278 type(c_ptr), value :: window
279 type(c_funptr), value :: callback
280 end function glfwSetKeyCallback
281
282 ! GLFWcharfun glfwSetCharCallback(GLFWwindow* window, GLFWcharfun callback)
283 type(c_funptr) function glfwSetCharCallback(window, callback) &
284 bind(C, name="glfwSetCharCallback")
285 import :: c_ptr, c_funptr
286 type(c_ptr), value :: window
287 type(c_funptr), value :: callback
288 end function glfwSetCharCallback
289
290 ! GLFWscrollfun glfwSetScrollCallback(GLFWwindow* window, GLFWscrollfun callback)
291 type(c_funptr) function glfwSetScrollCallback(window, callback) &
292 bind(C, name="glfwSetScrollCallback")
293 import :: c_ptr, c_funptr
294 type(c_ptr), value :: window
295 type(c_funptr), value :: callback
296 end function glfwSetScrollCallback
297
298 ! GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun callback)
299 type(c_funptr) function glfwSetErrorCallback(callback) &
300 bind(C, name="glfwSetErrorCallback")
301 import :: c_funptr
302 type(c_funptr), value :: callback
303 end function glfwSetErrorCallback
304
305 ! GLFWglproc glfwGetProcAddress(const char* procname)
306 type(c_funptr) function glfwGetProcAddress(procname) bind(C, name="glfwGetProcAddress")
307 import :: c_funptr, c_char
308 character(kind=c_char), intent(in) :: procname(*)
309 end function glfwGetProcAddress
310
311 ! GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* window, GLFWmousebuttonfun callback)
312 type(c_funptr) function glfwSetMouseButtonCallback(window, callback) &
313 bind(C, name="glfwSetMouseButtonCallback")
314 import :: c_ptr, c_funptr
315 type(c_ptr), value :: window
316 type(c_funptr), value :: callback
317 end function glfwSetMouseButtonCallback
318
319 ! GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow* window, GLFWcursorposfun callback)
320 type(c_funptr) function glfwSetCursorPosCallback(window, callback) &
321 bind(C, name="glfwSetCursorPosCallback")
322 import :: c_ptr, c_funptr
323 type(c_ptr), value :: window
324 type(c_funptr), value :: callback
325 end function glfwSetCursorPosCallback
326
327 ! void glfwGetCursorPos(GLFWwindow* window, double* xpos, double* ypos)
328 subroutine glfwGetCursorPos(window, xpos, ypos) bind(C, name="glfwGetCursorPos")
329 import :: c_ptr, c_double
330 type(c_ptr), value :: window
331 real(c_double), intent(out) :: xpos, ypos
332 end subroutine glfwGetCursorPos
333
334 ! const char* glfwGetClipboardString(GLFWwindow* window)
335 type(c_ptr) function glfwGetClipboardString(window) bind(C, name="glfwGetClipboardString")
336 import :: c_ptr
337 type(c_ptr), value :: window
338 end function glfwGetClipboardString
339
340 ! void glfwSetClipboardString(GLFWwindow* window, const char* string)
341 subroutine glfwSetClipboardString(window, string) bind(C, name="glfwSetClipboardString")
342 import :: c_ptr, c_char
343 type(c_ptr), value :: window
344 character(kind=c_char), intent(in) :: string(*)
345 end subroutine glfwSetClipboardString
346
347 ! GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* window, GLFWwindowrefreshfun callback)
348 type(c_funptr) function glfwSetWindowRefreshCallback(window, callback) &
349 bind(C, name="glfwSetWindowRefreshCallback")
350 import :: c_ptr, c_funptr
351 type(c_ptr), value :: window
352 type(c_funptr), value :: callback
353 end function glfwSetWindowRefreshCallback
354 end interface
355
356 end module glfw_bindings
357