Fortran · 12458 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 ! Modifier masks
78 integer(c_int), parameter :: GLFW_MOD_SHIFT = 1
79 integer(c_int), parameter :: GLFW_MOD_CONTROL = 2
80 integer(c_int), parameter :: GLFW_MOD_ALT = 4
81 integer(c_int), parameter :: GLFW_MOD_SUPER = 8
82
83 ! Action constants
84 integer(c_int), parameter :: GLFW_RELEASE = 0
85 integer(c_int), parameter :: GLFW_PRESS = 1
86 integer(c_int), parameter :: GLFW_REPEAT = 2
87
88 ! Mouse button constants
89 integer(c_int), parameter :: GLFW_MOUSE_BUTTON_LEFT = 0
90 integer(c_int), parameter :: GLFW_MOUSE_BUTTON_RIGHT = 1
91 integer(c_int), parameter :: GLFW_MOUSE_BUTTON_MIDDLE = 2
92
93 ! Callback type for framebuffer size
94 abstract interface
95 subroutine glfw_framebuffer_size_callback(window, width, height) bind(C)
96 import :: c_ptr, c_int
97 type(c_ptr), value :: window
98 integer(c_int), value :: width, height
99 end subroutine glfw_framebuffer_size_callback
100
101 subroutine glfw_key_callback(window, key, scancode, action, mods) bind(C)
102 import :: c_ptr, c_int
103 type(c_ptr), value :: window
104 integer(c_int), value :: key, scancode, action, mods
105 end subroutine glfw_key_callback
106
107 subroutine glfw_error_callback(error_code, description) bind(C)
108 import :: c_int, c_ptr
109 integer(c_int), value :: error_code
110 type(c_ptr), value :: description
111 end subroutine glfw_error_callback
112
113 subroutine glfw_char_callback(window, codepoint) bind(C)
114 import :: c_ptr, c_int
115 type(c_ptr), value :: window
116 integer(c_int), value :: codepoint
117 end subroutine glfw_char_callback
118
119 subroutine glfw_scroll_callback(window, xoffset, yoffset) bind(C)
120 import :: c_ptr, c_double
121 type(c_ptr), value :: window
122 real(c_double), value :: xoffset, yoffset
123 end subroutine glfw_scroll_callback
124
125 subroutine glfw_mouse_button_callback(window, button, action, mods) bind(C)
126 import :: c_ptr, c_int
127 type(c_ptr), value :: window
128 integer(c_int), value :: button, action, mods
129 end subroutine glfw_mouse_button_callback
130
131 subroutine glfw_cursor_pos_callback(window, xpos, ypos) bind(C)
132 import :: c_ptr, c_double
133 type(c_ptr), value :: window
134 real(c_double), value :: xpos, ypos
135 end subroutine glfw_cursor_pos_callback
136 end interface
137
138 interface
139 ! int glfwInit(void)
140 integer(c_int) function glfwInit() bind(C, name="glfwInit")
141 import :: c_int
142 end function glfwInit
143
144 ! void glfwTerminate(void)
145 subroutine glfwTerminate() bind(C, name="glfwTerminate")
146 end subroutine glfwTerminate
147
148 ! void glfwWindowHint(int hint, int value)
149 subroutine glfwWindowHint(hint, value) bind(C, name="glfwWindowHint")
150 import :: c_int
151 integer(c_int), value :: hint, value
152 end subroutine glfwWindowHint
153
154 ! GLFWwindow* glfwCreateWindow(int width, int height, const char* title,
155 ! GLFWmonitor* monitor, GLFWwindow* share)
156 type(c_ptr) function glfwCreateWindow(width, height, title, monitor, share) &
157 bind(C, name="glfwCreateWindow")
158 import :: c_int, c_ptr, c_char
159 integer(c_int), value :: width, height
160 character(kind=c_char), intent(in) :: title(*)
161 type(c_ptr), value :: monitor, share
162 end function glfwCreateWindow
163
164 ! void glfwDestroyWindow(GLFWwindow* window)
165 subroutine glfwDestroyWindow(window) bind(C, name="glfwDestroyWindow")
166 import :: c_ptr
167 type(c_ptr), value :: window
168 end subroutine glfwDestroyWindow
169
170 ! void glfwMakeContextCurrent(GLFWwindow* window)
171 subroutine glfwMakeContextCurrent(window) bind(C, name="glfwMakeContextCurrent")
172 import :: c_ptr
173 type(c_ptr), value :: window
174 end subroutine glfwMakeContextCurrent
175
176 ! int glfwWindowShouldClose(GLFWwindow* window)
177 integer(c_int) function glfwWindowShouldClose(window) bind(C, name="glfwWindowShouldClose")
178 import :: c_int, c_ptr
179 type(c_ptr), value :: window
180 end function glfwWindowShouldClose
181
182 ! void glfwSetWindowShouldClose(GLFWwindow* window, int value)
183 subroutine glfwSetWindowShouldClose(window, value) bind(C, name="glfwSetWindowShouldClose")
184 import :: c_int, c_ptr
185 type(c_ptr), value :: window
186 integer(c_int), value :: value
187 end subroutine glfwSetWindowShouldClose
188
189 ! void glfwSetWindowTitle(GLFWwindow* window, const char* title)
190 subroutine glfwSetWindowTitle(window, title) bind(C, name="glfwSetWindowTitle")
191 import :: c_ptr, c_char
192 type(c_ptr), value :: window
193 character(kind=c_char), intent(in) :: title(*)
194 end subroutine glfwSetWindowTitle
195
196 ! void glfwSwapBuffers(GLFWwindow* window)
197 subroutine glfwSwapBuffers(window) bind(C, name="glfwSwapBuffers")
198 import :: c_ptr
199 type(c_ptr), value :: window
200 end subroutine glfwSwapBuffers
201
202 ! void glfwPollEvents(void)
203 subroutine glfwPollEvents() bind(C, name="glfwPollEvents")
204 end subroutine glfwPollEvents
205
206 ! double glfwGetTime(void)
207 real(c_double) function glfwGetTime() bind(C, name="glfwGetTime")
208 import :: c_double
209 end function glfwGetTime
210
211 ! void glfwGetFramebufferSize(GLFWwindow* window, int* width, int* height)
212 subroutine glfwGetFramebufferSize(window, width, height) bind(C, name="glfwGetFramebufferSize")
213 import :: c_int, c_ptr
214 type(c_ptr), value :: window
215 integer(c_int), intent(out) :: width, height
216 end subroutine glfwGetFramebufferSize
217
218 ! GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* window,
219 ! GLFWframebuffersizefun callback)
220 type(c_funptr) function glfwSetFramebufferSizeCallback(window, callback) &
221 bind(C, name="glfwSetFramebufferSizeCallback")
222 import :: c_ptr, c_funptr
223 type(c_ptr), value :: window
224 type(c_funptr), value :: callback
225 end function glfwSetFramebufferSizeCallback
226
227 ! GLFWkeyfun glfwSetKeyCallback(GLFWwindow* window, GLFWkeyfun callback)
228 type(c_funptr) function glfwSetKeyCallback(window, callback) &
229 bind(C, name="glfwSetKeyCallback")
230 import :: c_ptr, c_funptr
231 type(c_ptr), value :: window
232 type(c_funptr), value :: callback
233 end function glfwSetKeyCallback
234
235 ! GLFWcharfun glfwSetCharCallback(GLFWwindow* window, GLFWcharfun callback)
236 type(c_funptr) function glfwSetCharCallback(window, callback) &
237 bind(C, name="glfwSetCharCallback")
238 import :: c_ptr, c_funptr
239 type(c_ptr), value :: window
240 type(c_funptr), value :: callback
241 end function glfwSetCharCallback
242
243 ! GLFWscrollfun glfwSetScrollCallback(GLFWwindow* window, GLFWscrollfun callback)
244 type(c_funptr) function glfwSetScrollCallback(window, callback) &
245 bind(C, name="glfwSetScrollCallback")
246 import :: c_ptr, c_funptr
247 type(c_ptr), value :: window
248 type(c_funptr), value :: callback
249 end function glfwSetScrollCallback
250
251 ! GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun callback)
252 type(c_funptr) function glfwSetErrorCallback(callback) &
253 bind(C, name="glfwSetErrorCallback")
254 import :: c_funptr
255 type(c_funptr), value :: callback
256 end function glfwSetErrorCallback
257
258 ! GLFWglproc glfwGetProcAddress(const char* procname)
259 type(c_funptr) function glfwGetProcAddress(procname) bind(C, name="glfwGetProcAddress")
260 import :: c_funptr, c_char
261 character(kind=c_char), intent(in) :: procname(*)
262 end function glfwGetProcAddress
263
264 ! GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* window, GLFWmousebuttonfun callback)
265 type(c_funptr) function glfwSetMouseButtonCallback(window, callback) &
266 bind(C, name="glfwSetMouseButtonCallback")
267 import :: c_ptr, c_funptr
268 type(c_ptr), value :: window
269 type(c_funptr), value :: callback
270 end function glfwSetMouseButtonCallback
271
272 ! GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow* window, GLFWcursorposfun callback)
273 type(c_funptr) function glfwSetCursorPosCallback(window, callback) &
274 bind(C, name="glfwSetCursorPosCallback")
275 import :: c_ptr, c_funptr
276 type(c_ptr), value :: window
277 type(c_funptr), value :: callback
278 end function glfwSetCursorPosCallback
279
280 ! void glfwGetCursorPos(GLFWwindow* window, double* xpos, double* ypos)
281 subroutine glfwGetCursorPos(window, xpos, ypos) bind(C, name="glfwGetCursorPos")
282 import :: c_ptr, c_double
283 type(c_ptr), value :: window
284 real(c_double), intent(out) :: xpos, ypos
285 end subroutine glfwGetCursorPos
286
287 ! const char* glfwGetClipboardString(GLFWwindow* window)
288 type(c_ptr) function glfwGetClipboardString(window) bind(C, name="glfwGetClipboardString")
289 import :: c_ptr
290 type(c_ptr), value :: window
291 end function glfwGetClipboardString
292
293 ! void glfwSetClipboardString(GLFWwindow* window, const char* string)
294 subroutine glfwSetClipboardString(window, string) bind(C, name="glfwSetClipboardString")
295 import :: c_ptr, c_char
296 type(c_ptr), value :: window
297 character(kind=c_char), intent(in) :: string(*)
298 end subroutine glfwSetClipboardString
299 end interface
300
301 end module glfw_bindings
302