Fortran · 5706 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
18 ! Key constants
19 integer(c_int), parameter :: GLFW_KEY_ESCAPE = 256
20
21 ! Action constants
22 integer(c_int), parameter :: GLFW_RELEASE = 0
23 integer(c_int), parameter :: GLFW_PRESS = 1
24 integer(c_int), parameter :: GLFW_REPEAT = 2
25
26 ! Callback type for framebuffer size
27 abstract interface
28 subroutine glfw_framebuffer_size_callback(window, width, height) bind(C)
29 import :: c_ptr, c_int
30 type(c_ptr), value :: window
31 integer(c_int), value :: width, height
32 end subroutine glfw_framebuffer_size_callback
33
34 subroutine glfw_key_callback(window, key, scancode, action, mods) bind(C)
35 import :: c_ptr, c_int
36 type(c_ptr), value :: window
37 integer(c_int), value :: key, scancode, action, mods
38 end subroutine glfw_key_callback
39
40 subroutine glfw_error_callback(error_code, description) bind(C)
41 import :: c_int, c_ptr
42 integer(c_int), value :: error_code
43 type(c_ptr), value :: description
44 end subroutine glfw_error_callback
45 end interface
46
47 interface
48 ! int glfwInit(void)
49 integer(c_int) function glfwInit() bind(C, name="glfwInit")
50 import :: c_int
51 end function glfwInit
52
53 ! void glfwTerminate(void)
54 subroutine glfwTerminate() bind(C, name="glfwTerminate")
55 end subroutine glfwTerminate
56
57 ! void glfwWindowHint(int hint, int value)
58 subroutine glfwWindowHint(hint, value) bind(C, name="glfwWindowHint")
59 import :: c_int
60 integer(c_int), value :: hint, value
61 end subroutine glfwWindowHint
62
63 ! GLFWwindow* glfwCreateWindow(int width, int height, const char* title,
64 ! GLFWmonitor* monitor, GLFWwindow* share)
65 type(c_ptr) function glfwCreateWindow(width, height, title, monitor, share) &
66 bind(C, name="glfwCreateWindow")
67 import :: c_int, c_ptr, c_char
68 integer(c_int), value :: width, height
69 character(kind=c_char), intent(in) :: title(*)
70 type(c_ptr), value :: monitor, share
71 end function glfwCreateWindow
72
73 ! void glfwDestroyWindow(GLFWwindow* window)
74 subroutine glfwDestroyWindow(window) bind(C, name="glfwDestroyWindow")
75 import :: c_ptr
76 type(c_ptr), value :: window
77 end subroutine glfwDestroyWindow
78
79 ! void glfwMakeContextCurrent(GLFWwindow* window)
80 subroutine glfwMakeContextCurrent(window) bind(C, name="glfwMakeContextCurrent")
81 import :: c_ptr
82 type(c_ptr), value :: window
83 end subroutine glfwMakeContextCurrent
84
85 ! int glfwWindowShouldClose(GLFWwindow* window)
86 integer(c_int) function glfwWindowShouldClose(window) bind(C, name="glfwWindowShouldClose")
87 import :: c_int, c_ptr
88 type(c_ptr), value :: window
89 end function glfwWindowShouldClose
90
91 ! void glfwSetWindowShouldClose(GLFWwindow* window, int value)
92 subroutine glfwSetWindowShouldClose(window, value) bind(C, name="glfwSetWindowShouldClose")
93 import :: c_int, c_ptr
94 type(c_ptr), value :: window
95 integer(c_int), value :: value
96 end subroutine glfwSetWindowShouldClose
97
98 ! void glfwSwapBuffers(GLFWwindow* window)
99 subroutine glfwSwapBuffers(window) bind(C, name="glfwSwapBuffers")
100 import :: c_ptr
101 type(c_ptr), value :: window
102 end subroutine glfwSwapBuffers
103
104 ! void glfwPollEvents(void)
105 subroutine glfwPollEvents() bind(C, name="glfwPollEvents")
106 end subroutine glfwPollEvents
107
108 ! void glfwGetFramebufferSize(GLFWwindow* window, int* width, int* height)
109 subroutine glfwGetFramebufferSize(window, width, height) bind(C, name="glfwGetFramebufferSize")
110 import :: c_int, c_ptr
111 type(c_ptr), value :: window
112 integer(c_int), intent(out) :: width, height
113 end subroutine glfwGetFramebufferSize
114
115 ! GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* window,
116 ! GLFWframebuffersizefun callback)
117 type(c_funptr) function glfwSetFramebufferSizeCallback(window, callback) &
118 bind(C, name="glfwSetFramebufferSizeCallback")
119 import :: c_ptr, c_funptr
120 type(c_ptr), value :: window
121 type(c_funptr), value :: callback
122 end function glfwSetFramebufferSizeCallback
123
124 ! GLFWkeyfun glfwSetKeyCallback(GLFWwindow* window, GLFWkeyfun callback)
125 type(c_funptr) function glfwSetKeyCallback(window, callback) &
126 bind(C, name="glfwSetKeyCallback")
127 import :: c_ptr, c_funptr
128 type(c_ptr), value :: window
129 type(c_funptr), value :: callback
130 end function glfwSetKeyCallback
131
132 ! GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun callback)
133 type(c_funptr) function glfwSetErrorCallback(callback) &
134 bind(C, name="glfwSetErrorCallback")
135 import :: c_funptr
136 type(c_funptr), value :: callback
137 end function glfwSetErrorCallback
138
139 ! GLFWglproc glfwGetProcAddress(const char* procname)
140 type(c_funptr) function glfwGetProcAddress(procname) bind(C, name="glfwGetProcAddress")
141 import :: c_funptr, c_char
142 character(kind=c_char), intent(in) :: procname(*)
143 end function glfwGetProcAddress
144 end interface
145
146 end module glfw_bindings
147