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