├── .gitignore ├── LICENSE ├── preview.png ├── readme.md ├── tiny-gizmo-example ├── example-main.cpp ├── gl-api.hpp ├── teapot.h ├── third-party │ ├── .gitignore │ ├── glew │ │ ├── eglew.h │ │ ├── glew.h │ │ ├── glxew.h │ │ ├── lib │ │ │ ├── Win32 │ │ │ │ ├── glew32.lib │ │ │ │ └── glew32s.lib │ │ │ └── x64 │ │ │ │ ├── glew32.lib │ │ │ │ └── glew32s.lib │ │ └── wglew.h │ ├── glfw-3.1.2 │ │ ├── ALTERATIONS.txt │ │ ├── COPYING.txt │ │ ├── deps │ │ │ └── GL │ │ │ │ ├── glext.h │ │ │ │ └── wglext.h │ │ ├── glfw3.vcxproj │ │ ├── glfw3.vcxproj.filters │ │ ├── include │ │ │ └── GLFW │ │ │ │ ├── glfw3.h │ │ │ │ └── glfw3native.h │ │ └── src │ │ │ ├── context.c │ │ │ ├── glfw_config.h │ │ │ ├── init.c │ │ │ ├── input.c │ │ │ ├── internal.h │ │ │ ├── monitor.c │ │ │ ├── wgl_context.c │ │ │ ├── wgl_context.h │ │ │ ├── win32_init.c │ │ │ ├── win32_monitor.c │ │ │ ├── win32_platform.h │ │ │ ├── win32_time.c │ │ │ ├── win32_tls.c │ │ │ ├── win32_tls.h │ │ │ ├── win32_window.c │ │ │ ├── window.c │ │ │ ├── winmm_joystick.c │ │ │ └── winmm_joystick.h │ └── linalg.h ├── tiny-gizmo-example.sln ├── tiny-gizmo-example.vcxproj ├── tiny-gizmo-example.vcxproj.filters └── util.hpp ├── tiny-gizmo.cpp └── tiny-gizmo.hpp /.gitignore: -------------------------------------------------------------------------------- 1 | # User-specific files 2 | *.suo 3 | *.user 4 | 5 | # Build results 6 | [Dd]ebug/ 7 | [Rr]elease/ 8 | [Oo]bj/ 9 | 10 | *.ilk 11 | *.obj 12 | *.pch 13 | *.pdb 14 | *.log 15 | 16 | # Visual C++ cache files 17 | ipch/ 18 | *.opensdf 19 | *.sdf 20 | *.VC.* 21 | 22 | # Visual Studio profiler 23 | *.psess 24 | *.vsp 25 | *.vspx 26 | 27 | intermediate/ 28 | build/ 29 | assets/ 30 | *.mesh -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddiakopoulos/tinygizmo/99c1c418d169774b0b8052b57fd1680b4c4de444/preview.png -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # tinygizmo 2 | 3 |

4 | 5 |

6 | 7 | This project is a lightweight, self-contained library for gizmo editing commonly found in many game engines. It includes mechanisms for manipulating 3d position, rotation, and scale. Implemented in C++11, the library does not perform rendering directly and instead provides a per-frame buffer of world-space triangles. 8 | 9 | An included example is built on top of GLFW (with an OpenGL 3.3 context). Known limitations include hardcoded assumptions about a right-handed, Y-up coordinate system. While the gizmos are provided with vertex normals, the example does not perform any fancy shading. Furthermore, mouse-drag input with certain gizmos at extreme interaction grazing angles is known to produce anomalous output. 10 | 11 | # Motivation 12 | 13 | This project was born out of mild frustration with other immediate-mode gizmo libraries. Instead of 4x4 matrices and euler angles, the library exposes a `rigid_transform` consisting of a 3d position, rotation quaternion, and scale. The library is implemented in around 1200 lines of code, which also includes a complete 3d math library in ~400 LoC - [linalg.h](https://github.com/sgorsten/linalg). Alternatives include [ImGuizmo](https://github.com/CedricGuillemet/ImGuizmo) and [Im3D](https://github.com/john-chapman/im3d). Tinygizmo fits in-between these projects by being fully self-contained (no dependency on Dear ImGui), and by being provided in the public domain. 14 | 15 | # Features 16 | * Both axis-aligned global and object-local transform modes for translational and rotational gizmos 17 | * Optional ability draw the gizmos with a constant screen-space scale 18 | * Snap-to-unit (both linear and angular) 19 | * Set any of the `snap_` values in the `gizmo_application_state` struct. 20 | * VR ready (the user must call `update(...)` and `draw()` for each eye) 21 | * Hotkeys for transitioning between translation, rotation, and scaling: 22 | * `ctrl-t` to activate the translation gizmo 23 | * `ctrl-r` to activate the rotation gizmo 24 | * `ctrl-s` to activate the scale gizmo 25 | * `ctrl-l` to toggle between global and local transform modes 26 | 27 | # Attribution 28 | 29 | This project would not have been possible without reference implementations in the public-domain [workbench](https://github.com/sgorsten/workbench) project. 30 | 31 | # License 32 | 33 | This is free and unencumbered software released into the public domain. For more information, please refer to -------------------------------------------------------------------------------- /tiny-gizmo-example/example-main.cpp: -------------------------------------------------------------------------------- 1 | // This is free and unencumbered software released into the public domain. 2 | // For more information, please refer to 3 | 4 | #include 5 | #include 6 | 7 | #include "util.hpp" 8 | #include "gl-api.hpp" 9 | #include "teapot.h" 10 | 11 | using namespace tinygizmo; 12 | using namespace minalg; 13 | 14 | static inline uint64_t get_local_time_ns() 15 | { 16 | return std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()).count(); 17 | } 18 | 19 | const linalg::aliases::float4x4 identity4x4 = { { 1, 0, 0, 0 },{ 0, 1, 0, 0 },{ 0, 0, 1, 0 },{ 0, 0, 0, 1 } }; 20 | 21 | constexpr const char gizmo_vert[] = R"(#version 330 22 | layout(location = 0) in vec3 vertex; 23 | layout(location = 1) in vec3 normal; 24 | layout(location = 2) in vec4 color; 25 | out vec4 v_color; 26 | out vec3 v_world, v_normal; 27 | uniform mat4 u_mvp; 28 | void main() 29 | { 30 | gl_Position = u_mvp * vec4(vertex.xyz, 1); 31 | v_color = color; 32 | v_world = vertex; 33 | v_normal = normal; 34 | } 35 | )"; 36 | 37 | constexpr const char gizmo_frag[] = R"(#version 330 38 | in vec4 v_color; 39 | in vec3 v_world, v_normal; 40 | out vec4 f_color; 41 | uniform vec3 u_eye; 42 | void main() 43 | { 44 | vec3 light = vec3(1) * max(dot(v_normal, normalize(u_eye - v_world)), 0.50) + 0.25; 45 | f_color = v_color * vec4(light, 1); 46 | } 47 | )"; 48 | 49 | constexpr const char lit_vert[] = R"(#version 330 50 | uniform mat4 u_modelMatrix; 51 | uniform mat4 u_viewProj; 52 | 53 | layout(location = 0) in vec3 inPosition; 54 | layout(location = 1) in vec3 inNormal; 55 | 56 | out vec3 v_position, v_normal; 57 | 58 | void main() 59 | { 60 | vec4 worldPos = u_modelMatrix * vec4(inPosition, 1); 61 | v_position = worldPos.xyz; 62 | v_normal = normalize((u_modelMatrix * vec4(inNormal,0)).xyz); 63 | gl_Position = u_viewProj * worldPos; 64 | } 65 | )"; 66 | 67 | constexpr const char lit_frag[] = R"(#version 330 68 | uniform vec3 u_diffuse = vec3(1, 1, 1); 69 | uniform vec3 u_eye; 70 | 71 | in vec3 v_position; 72 | in vec3 v_normal; 73 | 74 | out vec4 f_color; 75 | 76 | vec3 compute_lighting(vec3 eyeDir, vec3 position, vec3 color) 77 | { 78 | vec3 light = vec3(0, 0, 0); 79 | vec3 lightDir = normalize(position - v_position); 80 | light += color * u_diffuse * max(dot(v_normal, lightDir), 0); 81 | vec3 halfDir = normalize(lightDir + eyeDir); 82 | light += color * u_diffuse * pow(max(dot(v_normal, halfDir), 0), 128); 83 | return light; 84 | } 85 | 86 | void main() 87 | { 88 | vec3 eyeDir = vec3(0, 1, -2); 89 | vec3 light = vec3(0, 0, 0); 90 | light += compute_lighting(eyeDir, vec3(+3, 1, 0), vec3(235.0/255.0, 43.0/255.0, 211.0/255.0)); 91 | light += compute_lighting(eyeDir, vec3(-3, 1, 0), vec3(43.0/255.0, 236.0/255.0, 234.0/255.0)); 92 | f_color = vec4(light + vec3(0.5, 0.5, 0.5), 1.0); 93 | } 94 | )"; 95 | 96 | ////////////////////////// 97 | // Main Application // 98 | ////////////////////////// 99 | 100 | geometry_mesh make_teapot() 101 | { 102 | geometry_mesh mesh; 103 | for (int i = 0; i < 4974; i+=6) 104 | { 105 | geometry_vertex v; 106 | v.position = float3(teapot_vertices[i + 0], teapot_vertices[i + 1], teapot_vertices[i + 2]); 107 | v.normal = float3(teapot_vertices[i + 3], teapot_vertices[i + 4], teapot_vertices[i + 5]); 108 | mesh.vertices.push_back(v); 109 | } 110 | for (int i = 0; i < 4680; i+=3) mesh.triangles.push_back(uint3(teapot_triangles[i + 0], teapot_triangles[i + 1], teapot_triangles[i + 2])); 111 | return mesh; 112 | } 113 | 114 | void draw_mesh(GlShader & shader, GlMesh & mesh, const linalg::aliases::float3 eye, const linalg::aliases::float4x4 & viewProj, const linalg::aliases::float4x4 & model) 115 | { 116 | linalg::aliases::float4x4 modelViewProjectionMatrix = mul(viewProj, model); 117 | shader.bind(); 118 | shader.uniform("u_mvp", modelViewProjectionMatrix); 119 | shader.uniform("u_eye", eye); 120 | mesh.draw_elements(); 121 | shader.unbind(); 122 | } 123 | 124 | void draw_lit_mesh(GlShader & shader, GlMesh & mesh, const linalg::aliases::float3 eye, const linalg::aliases::float4x4 & viewProj, const linalg::aliases::float4x4 & model) 125 | { 126 | shader.bind(); 127 | shader.uniform("u_viewProj", viewProj); 128 | shader.uniform("u_modelMatrix", model); 129 | shader.uniform("u_eye", eye); 130 | mesh.draw_elements(); 131 | shader.unbind(); 132 | } 133 | 134 | void upload_mesh(const geometry_mesh & cpu, GlMesh & gpu) 135 | { 136 | const auto & verts = reinterpret_cast &>(cpu.vertices); 137 | const auto & tris = reinterpret_cast &>(cpu.triangles); 138 | gpu.set_vertices(verts, GL_DYNAMIC_DRAW); 139 | gpu.set_attribute(0, 3, GL_FLOAT, GL_FALSE, sizeof(geometry_vertex), (GLvoid*) offsetof(geometry_vertex, position)); 140 | gpu.set_attribute(1, 3, GL_FLOAT, GL_FALSE, sizeof(geometry_vertex), (GLvoid*) offsetof(geometry_vertex, normal)); 141 | gpu.set_attribute(2, 4, GL_FLOAT, GL_FALSE, sizeof(geometry_vertex), (GLvoid*) offsetof(geometry_vertex, color)); 142 | gpu.set_elements(tris, GL_DYNAMIC_DRAW); 143 | } 144 | 145 | std::unique_ptr win; 146 | 147 | int main(int argc, char * argv[]) 148 | { 149 | bool ml = 0, mr = 0, bf = 0, bl = 0, bb = 0, br = 0; 150 | 151 | camera cam = {}; 152 | cam.yfov = 1.0f; 153 | cam.near_clip = 0.01f; 154 | cam.far_clip = 32.0f; 155 | cam.position = { 0,1.5f,4 }; 156 | 157 | gizmo_application_state gizmo_state; 158 | gizmo_context gizmo_ctx; 159 | 160 | try 161 | { 162 | win.reset(new Window(1280, 800, "tiny-gizmo-example-app")); 163 | glfwSwapInterval(1); 164 | } 165 | catch (const std::exception & e) 166 | { 167 | std::cout << "Caught GLFW window exception: " << e.what() << std::endl; 168 | } 169 | 170 | auto windowSize = win->get_window_size(); 171 | 172 | GlShader wireframeShader, litShader; 173 | GlMesh gizmoEditorMesh, teapotMesh; 174 | 175 | wireframeShader = GlShader(gizmo_vert, gizmo_frag); 176 | litShader = GlShader(lit_vert, lit_frag); 177 | 178 | geometry_mesh teapot = make_teapot(); 179 | upload_mesh(teapot, teapotMesh); 180 | 181 | gizmo_ctx.render = [&](const geometry_mesh & r) 182 | { 183 | upload_mesh(r, gizmoEditorMesh); 184 | draw_mesh(wireframeShader, gizmoEditorMesh, cam.position, cam.get_viewproj_matrix((float) windowSize.x / (float) windowSize.y), identity4x4); 185 | }; 186 | 187 | win->on_key = [&](int key, int action, int mods) 188 | { 189 | if (key == GLFW_KEY_LEFT_CONTROL) gizmo_state.hotkey_ctrl = (action != GLFW_RELEASE); 190 | if (key == GLFW_KEY_L) gizmo_state.hotkey_local = (action != GLFW_RELEASE); 191 | if (key == GLFW_KEY_T) gizmo_state.hotkey_translate = (action != GLFW_RELEASE); 192 | if (key == GLFW_KEY_R) gizmo_state.hotkey_rotate = (action != GLFW_RELEASE); 193 | if (key == GLFW_KEY_S) gizmo_state.hotkey_scale = (action != GLFW_RELEASE); 194 | if (key == GLFW_KEY_W) bf = (action != GLFW_RELEASE); 195 | if (key == GLFW_KEY_A) bl = (action != GLFW_RELEASE); 196 | if (key == GLFW_KEY_S) bb = (action != GLFW_RELEASE); 197 | if (key == GLFW_KEY_D) br = (action != GLFW_RELEASE); 198 | if (key == GLFW_KEY_ESCAPE) win->close(); 199 | }; 200 | 201 | win->on_mouse_button = [&](int button, int action, int mods) 202 | { 203 | if (button == GLFW_MOUSE_BUTTON_LEFT) gizmo_state.mouse_left = (action != GLFW_RELEASE); 204 | if (button == GLFW_MOUSE_BUTTON_LEFT) ml = (action != GLFW_RELEASE); 205 | if (button == GLFW_MOUSE_BUTTON_RIGHT) mr = (action != GLFW_RELEASE); 206 | }; 207 | 208 | minalg::float2 lastCursor; 209 | win->on_cursor_pos = [&](linalg::aliases::float2 position) 210 | { 211 | auto deltaCursorMotion = minalg::float2(position.x, position.y) - lastCursor; 212 | if (mr) 213 | { 214 | cam.yaw -= deltaCursorMotion.x * 0.01f; 215 | cam.pitch -= deltaCursorMotion.y * 0.01f; 216 | } 217 | lastCursor = minalg::float2(position.x, position.y); 218 | }; 219 | 220 | rigid_transform xform_a; 221 | xform_a.position = { -2, 0, 0 }; 222 | 223 | rigid_transform xform_a_last; 224 | 225 | rigid_transform xform_b; 226 | xform_b.position = { +2, 0, 0 }; 227 | 228 | auto t0 = std::chrono::high_resolution_clock::now(); 229 | while (!win->should_close()) 230 | { 231 | glfwPollEvents(); 232 | 233 | auto t1 = std::chrono::high_resolution_clock::now(); 234 | float timestep = std::chrono::duration(t1 - t0).count(); 235 | t0 = t1; 236 | 237 | if (mr) 238 | { 239 | const linalg::aliases::float4 orientation = cam.get_orientation(); 240 | linalg::aliases::float3 move; 241 | if (bf) move -= qzdir(orientation); 242 | if (bl) move -= qxdir(orientation); 243 | if (bb) move += qzdir(orientation); 244 | if (br) move += qxdir(orientation); 245 | if (length2(move) > 0) cam.position += normalize(move) * (timestep * 10); 246 | } 247 | 248 | glViewport(0, 0, windowSize.x, windowSize.y); 249 | 250 | glEnable(GL_DEPTH_TEST); 251 | glEnable(GL_BLEND); 252 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 253 | glClearColor(0.725f, 0.725f, 0.725f, 1.0f); 254 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 255 | 256 | auto cameraOrientation = cam.get_orientation(); 257 | 258 | const auto rayDir = get_ray_from_pixel({ lastCursor.x, lastCursor.y }, { 0, 0, windowSize.x, windowSize.y }, cam).direction; 259 | 260 | // Gizmo input interaction state populated via win->on_input(...) callback above. Update app parameters: 261 | gizmo_state.viewport_size = minalg::float2(windowSize.x, windowSize.y); 262 | gizmo_state.cam.near_clip = cam.near_clip; 263 | gizmo_state.cam.far_clip = cam.far_clip; 264 | gizmo_state.cam.yfov = cam.yfov; 265 | gizmo_state.cam.position = minalg::float3(cam.position.x, cam.position.y, cam.position.z); 266 | gizmo_state.cam.orientation = minalg::float4(cameraOrientation.x, cameraOrientation.y, cameraOrientation.z, cameraOrientation.w); 267 | gizmo_state.ray_origin = minalg::float3(cam.position.x, cam.position.y, cam.position.z); 268 | gizmo_state.ray_direction = minalg::float3(rayDir.x, rayDir.y, rayDir.z); 269 | //gizmo_state.screenspace_scale = 80.f; // optional flag to draw the gizmos at a constant screen-space scale 270 | 271 | glDisable(GL_CULL_FACE); 272 | auto teapotModelMatrix_a_tmp = xform_a.matrix(); 273 | auto teapotModelMatrix_a = reinterpret_cast(teapotModelMatrix_a_tmp); 274 | draw_lit_mesh(litShader, teapotMesh, cam.position, cam.get_viewproj_matrix((float)windowSize.x / (float)windowSize.y), teapotModelMatrix_a); 275 | 276 | auto teapotModelMatrix_b_tmp = xform_b.matrix(); 277 | auto teapotModelMatrix_b = reinterpret_cast(teapotModelMatrix_b_tmp); 278 | draw_lit_mesh(litShader, teapotMesh, cam.position, cam.get_viewproj_matrix((float)windowSize.x / (float)windowSize.y), teapotModelMatrix_b); 279 | 280 | glClear(GL_DEPTH_BUFFER_BIT); 281 | 282 | gizmo_ctx.update(gizmo_state); 283 | 284 | if (transform_gizmo("first-example-gizmo", gizmo_ctx, xform_a)) 285 | { 286 | std::cout << get_local_time_ns() << " - " << "First Gizmo Hovered..." << std::endl; 287 | if (xform_a != xform_a_last) std::cout << get_local_time_ns() << " - " << "First Gizmo Changed..." << std::endl; 288 | xform_a_last = xform_a; 289 | } 290 | 291 | transform_gizmo("second-example-gizmo", gizmo_ctx, xform_b); 292 | gizmo_ctx.draw(); 293 | 294 | gl_check_error(__FILE__, __LINE__); 295 | 296 | win->swap_buffers(); 297 | } 298 | return EXIT_SUCCESS; 299 | } 300 | -------------------------------------------------------------------------------- /tiny-gizmo-example/gl-api.hpp: -------------------------------------------------------------------------------- 1 | // This is free and unencumbered software released into the public domain. 2 | // For more information, please refer to 3 | 4 | #pragma once 5 | 6 | #ifndef gl_api_hpp 7 | #define gl_api_hpp 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "linalg.h" 14 | 15 | namespace 16 | { 17 | static bool gEnableGLDebugOutputErrorBreakpoints = false; 18 | 19 | inline void compile_shader(GLuint program, GLenum type, const char * source) 20 | { 21 | GLuint shader = glCreateShader(type); 22 | glShaderSource(shader, 1, &source, nullptr); 23 | glCompileShader(shader); 24 | 25 | GLint status, length; 26 | glGetShaderiv(shader, GL_COMPILE_STATUS, &status); 27 | 28 | if (status == GL_FALSE) 29 | { 30 | glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length); 31 | std::vector buffer(length); 32 | glGetShaderInfoLog(shader, (GLsizei)buffer.size(), nullptr, buffer.data()); 33 | glDeleteShader(shader); 34 | std::cerr << "GL Compile Error: " << buffer.data() << std::endl; 35 | std::cerr << "Source: " << source << std::endl; 36 | throw std::runtime_error("GLSL Compile Failure"); 37 | } 38 | 39 | glAttachShader(program, shader); 40 | glDeleteShader(shader); 41 | } 42 | 43 | std::string gl_src_to_str(GLenum source) 44 | { 45 | switch (source) 46 | { 47 | case GL_DEBUG_SOURCE_WINDOW_SYSTEM: return "WINDOW_SYSTEM"; 48 | case GL_DEBUG_SOURCE_SHADER_COMPILER: return "SHADER_COMPILER"; 49 | case GL_DEBUG_SOURCE_THIRD_PARTY: return "THIRD_PARTY"; 50 | case GL_DEBUG_SOURCE_APPLICATION: return "APPLICATION"; 51 | case GL_DEBUG_SOURCE_OTHER: return "OTHER"; 52 | case GL_DEBUG_SOURCE_API: return "API"; 53 | default: return "UNKNOWN"; 54 | } 55 | } 56 | 57 | std::string gl_enum_to_str(GLenum type) 58 | { 59 | switch (type) 60 | { 61 | case GL_DEBUG_TYPE_ERROR: return "ERROR"; 62 | case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: return "DEPRECATION"; 63 | case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: return "UNDEFINED_BEHAVIOR"; 64 | case GL_DEBUG_TYPE_PORTABILITY: return "PORTABILITY"; 65 | case GL_DEBUG_TYPE_PERFORMANCE: return "PERFORMANCE"; 66 | case GL_DEBUG_TYPE_OTHER: return "OTHER"; 67 | default: return "UNKNOWN"; 68 | } 69 | } 70 | 71 | std::string gl_severity_to_str(GLenum severity) 72 | { 73 | switch (severity) 74 | { 75 | case GL_DEBUG_SEVERITY_LOW: return "LOW"; 76 | case GL_DEBUG_SEVERITY_MEDIUM: return "MEDIUM"; 77 | case GL_DEBUG_SEVERITY_HIGH: return "HIGH"; 78 | default: return "UNKNOWN"; 79 | } 80 | } 81 | 82 | static void APIENTRY gl_debug_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar * message, GLvoid * userParam) 83 | { 84 | if (type != GL_DEBUG_TYPE_ERROR) return; 85 | auto sourceStr = gl_src_to_str(source); 86 | auto typeStr = gl_enum_to_str(type); 87 | auto severityStr = gl_severity_to_str(severity); 88 | std::cout << "gl_debug_callback: " << sourceStr << ", " << severityStr << ", " << typeStr << " , " << id << ", " << message << std::endl; 89 | if ((type == GL_DEBUG_TYPE_ERROR) && (gEnableGLDebugOutputErrorBreakpoints)) __debugbreak(); 90 | } 91 | 92 | inline void gl_check_error(const char * file, int32_t line) 93 | { 94 | #if defined(_DEBUG) || defined(DEBUG) 95 | GLint error = glGetError(); 96 | if (error) 97 | { 98 | const char * errorStr = 0; 99 | switch (error) 100 | { 101 | case GL_INVALID_ENUM: errorStr = "GL_INVALID_ENUM"; break; 102 | case GL_INVALID_VALUE: errorStr = "GL_INVALID_VALUE"; break; 103 | case GL_INVALID_OPERATION: errorStr = "GL_INVALID_OPERATION"; break; 104 | case GL_OUT_OF_MEMORY: errorStr = "GL_OUT_OF_MEMORY"; break; 105 | default: errorStr = "unknown error"; break; 106 | } 107 | printf("GL error : %s, line %d : %s\n", file, line, errorStr); 108 | error = 0; 109 | } 110 | #endif 111 | } 112 | 113 | inline size_t gl_size_bytes(GLenum type) 114 | { 115 | switch (type) 116 | { 117 | case GL_UNSIGNED_BYTE: return sizeof(uint8_t); 118 | case GL_UNSIGNED_SHORT: return sizeof(uint16_t); 119 | case GL_UNSIGNED_INT: return sizeof(uint32_t); 120 | default: throw std::logic_error("unknown element type"); break; 121 | } 122 | } 123 | } 124 | 125 | template 126 | class GlObject 127 | { 128 | mutable GLuint handle = 0; 129 | std::string n; 130 | public: 131 | GlObject() {} 132 | GlObject(GLuint h) : handle(g) {} 133 | ~GlObject() { if (handle) factory_t::destroy(handle); } 134 | GlObject(const GlObject & r) = delete; 135 | GlObject & operator = (GlObject && r) { std::swap(handle, r.handle); std::swap(n, r.n); return *this; } 136 | GlObject(GlObject && r) { *this = std::move(r); } 137 | operator GLuint () const { if (!handle) factory_t::create(handle); return handle; } 138 | GlObject & operator = (GLuint & other) { handle = other; return *this; } 139 | void set_name(const std::string & newName) { n = newName; } 140 | std::string name() const { return n; } 141 | GLuint id() const { return handle; }; 142 | }; 143 | 144 | struct GlBufferFactory { static void create(GLuint & x) { glGenBuffers(1, &x); }; static void destroy(GLuint x) { glDeleteBuffers(1, &x); }; }; 145 | struct GlTextureFactory { static void create(GLuint & x) { glGenTextures(1, &x); }; static void destroy(GLuint x) { glDeleteTextures(1, &x); }; }; 146 | struct GlVertexArrayFactory { static void create(GLuint & x) { glGenVertexArrays(1, &x); }; static void destroy(GLuint x) { glDeleteVertexArrays(1, &x); }; }; 147 | struct GlRenderbufferFactory { static void create(GLuint & x) { glGenRenderbuffers(1, &x); }; static void destroy(GLuint x) { glDeleteRenderbuffers(1, &x); }; }; 148 | struct GlFramebufferFactory { static void create(GLuint & x) { glGenFramebuffers(1, &x); }; static void destroy(GLuint x) { glDeleteFramebuffers(1, &x); }; }; 149 | struct GlQueryFactory { static void create(GLuint & x) { glGenQueries(1, &x); }; static void destroy(GLuint x) { glDeleteQueries(1, &x); }; }; 150 | struct GlSamplerFactory { static void create(GLuint & x) { glGenSamplers(1, &x); }; static void destroy(GLuint x) { glDeleteSamplers(1, &x); }; }; 151 | struct GlTransformFeedbacksFactory { static void create(GLuint & x) { glGenTransformFeedbacks(1, &x); }; static void destroy(GLuint x) { glDeleteTransformFeedbacks(1, &x); }; }; 152 | 153 | typedef GlObject GlBufferObject; 154 | typedef GlObject GlTextureObject; 155 | typedef GlObject GlVertexArrayObject; 156 | typedef GlObject GlRenderbufferObject; 157 | typedef GlObject GlFramebufferObject; 158 | typedef GlObject GlQueryObject; 159 | typedef GlObject GlSamplerObject; 160 | typedef GlObject GlTransformFeedbacksObject; 161 | 162 | ////////////////// 163 | // GlBuffer // 164 | ////////////////// 165 | 166 | struct GlBuffer : public GlBufferObject 167 | { 168 | GLsizeiptr size; 169 | GlBuffer() {} 170 | void set_buffer_data(const GLsizeiptr s, const GLvoid * data, const GLenum usage) { this->size = s; glNamedBufferDataEXT(*this, size, data, usage); } 171 | void set_buffer_data(const std::vector & bytes, const GLenum usage) { set_buffer_data(bytes.size(), bytes.data(), usage); } 172 | void set_buffer_sub_data(const GLsizeiptr s, const GLintptr offset, const GLvoid * data) { glNamedBufferSubDataEXT(*this, offset, s, data); } 173 | void set_buffer_sub_data(const std::vector & bytes, const GLintptr offset, const GLenum usage) { set_buffer_sub_data(bytes.size(), offset, bytes.data()); } 174 | }; 175 | 176 | //////////////////////// 177 | // GlRenderbuffer // 178 | //////////////////////// 179 | 180 | struct GlRenderbuffer : public GlRenderbufferObject 181 | { 182 | float width{ 0 }, height{ 0 }; 183 | GlRenderbuffer() {} 184 | GlRenderbuffer(float width, float height) : width(width), height(height) {} 185 | }; 186 | 187 | /////////////////////// 188 | // GlFramebuffer // 189 | /////////////////////// 190 | 191 | struct GlFramebuffer : public GlFramebufferObject 192 | { 193 | float width{ 0 }, height{ 0 }, depth{ 0 }; 194 | GlFramebuffer() {} 195 | GlFramebuffer(float width, float height) : width(width), height(height) {} 196 | GlFramebuffer(float width, float height, float depth) : width(width), height(height), depth(depth) {} 197 | void check_complete() { if (glCheckNamedFramebufferStatusEXT(*this, GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) throw std::runtime_error("fbo incomplete"); } 198 | }; 199 | 200 | /////////////////// 201 | // GlTexture // 202 | /////////////////// 203 | 204 | struct GlTexture2D : public GlTextureObject 205 | { 206 | float width{ 0 }, height{ 0 }; 207 | GlTexture2D() {} 208 | GlTexture2D(float width, float height) : width(width), height(height) {} 209 | 210 | void setup(GLsizei width, GLsizei height, GLenum internal_fmt, GLenum format, GLenum type, const GLvoid * pixels, bool createMipmap = false) 211 | { 212 | glTextureImage2DEXT(*this, GL_TEXTURE_2D, 0, internal_fmt, width, height, 0, format, type, pixels); 213 | if (createMipmap) glGenerateTextureMipmapEXT(*this, GL_TEXTURE_2D); 214 | glTextureParameteriEXT(*this, GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 215 | glTextureParameteriEXT(*this, GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, createMipmap ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR); 216 | glTextureParameteriEXT(*this, GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 217 | glTextureParameteriEXT(*this, GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 218 | this->width = width; 219 | this->height = height; 220 | } 221 | }; 222 | 223 | ///////////////////// 224 | // GlTexture3D // 225 | ///////////////////// 226 | 227 | // As either a 3D texture or 2D array 228 | struct GlTexture3D : public GlTextureObject 229 | { 230 | float width{ 0 }, height{ 0 }, depth{ 0 }; 231 | GlTexture3D() {} 232 | GlTexture3D(float width, float height, float depth) : width(width), height(height), depth(depth) {} 233 | 234 | void setup(GLenum target, GLsizei width, GLsizei height, GLsizei depth, GLenum internal_fmt, GLenum format, GLenum type, const GLvoid * pixels) 235 | { 236 | glTextureImage3DEXT(*this, target, 0, internal_fmt, width, height, depth, 0, format, type, pixels); 237 | glTextureParameteriEXT(*this, target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 238 | glTextureParameteriEXT(*this, target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 239 | glTextureParameteriEXT(*this, target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); 240 | glTextureParameteriEXT(*this, target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); 241 | glTextureParameteriEXT(*this, target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER); 242 | this->width = width; 243 | this->height = height; 244 | this->depth = depth; 245 | } 246 | }; 247 | 248 | ////////////////// 249 | // GlShader // 250 | ////////////////// 251 | 252 | class GlShader 253 | { 254 | GLuint program; 255 | bool enabled = false; 256 | 257 | protected: 258 | GlShader(const GlShader & r) = delete; 259 | GlShader & operator = (const GlShader & r) = delete; 260 | public: 261 | 262 | GlShader() : program() {} 263 | 264 | GlShader(const GLuint type, const std::string & src) 265 | { 266 | program = glCreateProgram(); 267 | 268 | ::compile_shader(program, type, src.c_str()); 269 | glProgramParameteri(program, GL_PROGRAM_SEPARABLE, GL_TRUE); 270 | 271 | glLinkProgram(program); 272 | 273 | GLint status, length; 274 | glGetProgramiv(program, GL_LINK_STATUS, &status); 275 | 276 | if (status == GL_FALSE) 277 | { 278 | glGetProgramiv(program, GL_INFO_LOG_LENGTH, &length); 279 | std::vector buffer(length); 280 | glGetProgramInfoLog(program, (GLsizei)buffer.size(), nullptr, buffer.data()); 281 | std::cerr << "GL Link Error: " << buffer.data() << std::endl; 282 | throw std::runtime_error("GLSL Link Failure"); 283 | } 284 | } 285 | 286 | GlShader(const std::string & vert, const std::string & frag, const std::string & geom = "") 287 | { 288 | program = glCreateProgram(); 289 | 290 | glProgramParameteri(program, GL_PROGRAM_SEPARABLE, GL_FALSE); 291 | 292 | ::compile_shader(program, GL_VERTEX_SHADER, vert.c_str()); 293 | ::compile_shader(program, GL_FRAGMENT_SHADER, frag.c_str()); 294 | 295 | if (geom.length() != 0) ::compile_shader(program, GL_GEOMETRY_SHADER, geom.c_str()); 296 | 297 | glLinkProgram(program); 298 | 299 | GLint status, length; 300 | glGetProgramiv(program, GL_LINK_STATUS, &status); 301 | 302 | if (status == GL_FALSE) 303 | { 304 | glGetProgramiv(program, GL_INFO_LOG_LENGTH, &length); 305 | std::vector buffer(length); 306 | glGetProgramInfoLog(program, (GLsizei)buffer.size(), nullptr, buffer.data()); 307 | std::cerr << "GL Link Error: " << buffer.data() << std::endl; 308 | throw std::runtime_error("GLSL Link Failure"); 309 | } 310 | } 311 | 312 | ~GlShader() { if (program) glDeleteProgram(program); } 313 | 314 | GlShader(GlShader && r) : GlShader() { *this = std::move(r); } 315 | 316 | GLuint handle() const { return program; } 317 | GLint get_uniform_location(const std::string & name) const { return glGetUniformLocation(program, name.c_str()); } 318 | 319 | GlShader & operator = (GlShader && r) { std::swap(program, r.program); return *this; } 320 | 321 | std::map reflect() 322 | { 323 | std::map locations; 324 | GLint count; 325 | glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &count); 326 | for (GLuint i = 0; i < static_cast(count); ++i) 327 | { 328 | char buffer[1024]; GLenum type; GLsizei length; GLint size, block_index; 329 | glGetActiveUniform(program, i, sizeof(buffer), &length, &size, &type, buffer); 330 | glGetActiveUniformsiv(program, 1, &i, GL_UNIFORM_BLOCK_INDEX, &block_index); 331 | if (block_index != -1) continue; 332 | GLint loc = glGetUniformLocation(program, buffer); 333 | locations[loc] = std::string(buffer); 334 | } 335 | return locations; 336 | } 337 | 338 | void uniform(const std::string & name, int scalar) const { glProgramUniform1i(program, get_uniform_location(name), scalar); } 339 | void uniform(const std::string & name, float scalar) const { glProgramUniform1f(program, get_uniform_location(name), scalar); } 340 | void uniform(const std::string & name, const linalg::aliases::float2 & vec) const { glProgramUniform2fv(program, get_uniform_location(name), 1, &vec.x); } 341 | void uniform(const std::string & name, const linalg::aliases::float3 & vec) const { glProgramUniform3fv(program, get_uniform_location(name), 1, &vec.x); } 342 | void uniform(const std::string & name, const linalg::aliases::float4 & vec) const { glProgramUniform4fv(program, get_uniform_location(name), 1, &vec.x); } 343 | void uniform(const std::string & name, const linalg::aliases::float3x3 & mat) const { glProgramUniformMatrix3fv(program, get_uniform_location(name), 1, GL_FALSE, &mat.x.x); } 344 | void uniform(const std::string & name, const linalg::aliases::float4x4 & mat) const { glProgramUniformMatrix4fv(program, get_uniform_location(name), 1, GL_FALSE, &mat.x.x); } 345 | 346 | void uniform(const std::string & name, const int elements, const std::vector & scalar) const { glProgramUniform1iv(program, get_uniform_location(name), elements, scalar.data()); } 347 | void uniform(const std::string & name, const int elements, const std::vector & scalar) const { glProgramUniform1fv(program, get_uniform_location(name), elements, scalar.data()); } 348 | void uniform(const std::string & name, const int elements, const std::vector & vec) const { glProgramUniform2fv(program, get_uniform_location(name), elements, &vec[0].x); } 349 | void uniform(const std::string & name, const int elements, const std::vector & vec) const { glProgramUniform3fv(program, get_uniform_location(name), elements, &vec[0].x); } 350 | void uniform(const std::string & name, const int elements, const std::vector & mat) const { glProgramUniformMatrix3fv(program, get_uniform_location(name), elements, GL_FALSE, &mat[0].x.x); } 351 | void uniform(const std::string & name, const int elements, const std::vector & mat) const { glProgramUniformMatrix4fv(program, get_uniform_location(name), elements, GL_FALSE, &mat[0].x.x); } 352 | 353 | void texture(GLint loc, GLenum target, int unit, GLuint tex) const 354 | { 355 | glBindMultiTextureEXT(GL_TEXTURE0 + unit, target, tex); 356 | glProgramUniform1i(program, loc, unit); 357 | } 358 | 359 | void texture(const char * name, int unit, GLuint tex, GLenum target) const { texture(get_uniform_location(name), target, unit, tex); } 360 | 361 | void bind() { if (program > 0) enabled = true; glUseProgram(program); } 362 | void unbind() { enabled = false; glUseProgram(0); } 363 | }; 364 | 365 | //////////////// 366 | // GlMesh // 367 | //////////////// 368 | 369 | class GlMesh 370 | { 371 | GlVertexArrayObject vao; 372 | GlBuffer vertexBuffer, instanceBuffer, indexBuffer; 373 | 374 | GLenum drawMode = GL_TRIANGLES; 375 | GLenum indexType = 0; 376 | GLsizei vertexStride = 0, instanceStride = 0, indexCount = 0; 377 | 378 | public: 379 | 380 | GlMesh() {} 381 | GlMesh(GlMesh && r) { *this = std::move(r); } 382 | GlMesh(const GlMesh & r) = delete; 383 | GlMesh & operator = (GlMesh && r) 384 | { 385 | char buffer[sizeof(GlMesh)]; 386 | memcpy(buffer, this, sizeof(buffer)); 387 | memcpy(this, &r, sizeof(buffer)); 388 | memcpy(&r, buffer, sizeof(buffer)); 389 | return *this; 390 | } 391 | GlMesh & operator = (const GlMesh & r) = delete; 392 | ~GlMesh() {}; 393 | 394 | void set_non_indexed(GLenum newMode) 395 | { 396 | drawMode = newMode; 397 | indexBuffer = {}; 398 | indexType = 0; 399 | indexCount = 0; 400 | } 401 | 402 | void draw_elements(int instances = 0) const 403 | { 404 | if (vertexBuffer.size) 405 | { 406 | glBindVertexArray(vao); 407 | if (indexCount) 408 | { 409 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); 410 | if (instances) glDrawElementsInstanced(drawMode, indexCount, indexType, 0, instances); 411 | else glDrawElements(drawMode, indexCount, indexType, nullptr); 412 | } 413 | else 414 | { 415 | if (instances) glDrawArraysInstanced(drawMode, 0, static_cast(vertexBuffer.size / vertexStride), instances); 416 | else glDrawArrays(drawMode, 0, static_cast(vertexBuffer.size / vertexStride)); 417 | } 418 | glBindVertexArray(0); 419 | } 420 | } 421 | 422 | void set_vertex_data(GLsizeiptr size, const GLvoid * data, GLenum usage) { vertexBuffer.set_buffer_data(size, data, usage); } 423 | GlBuffer & get_vertex_data_buffer() { return vertexBuffer; }; 424 | 425 | void set_instance_data(GLsizeiptr size, const GLvoid * data, GLenum usage) { instanceBuffer.set_buffer_data(size, data, usage); } 426 | 427 | void set_index_data(GLenum mode, GLenum type, GLsizei count, const GLvoid * data, GLenum usage) 428 | { 429 | size_t size = gl_size_bytes(type); 430 | indexBuffer.set_buffer_data(size * count, data, usage); 431 | drawMode = mode; 432 | indexType = type; 433 | indexCount = count; 434 | } 435 | GlBuffer & get_index_data_buffer() { return indexBuffer; }; 436 | 437 | void set_attribute(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * offset) 438 | { 439 | glEnableVertexArrayAttribEXT(vao, index); 440 | glVertexArrayVertexAttribOffsetEXT(vao, vertexBuffer, index, size, type, normalized, stride, (GLintptr)offset); 441 | vertexStride = stride; 442 | } 443 | 444 | void set_instance_attribute(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * offset) 445 | { 446 | glEnableVertexArrayAttribEXT(vao, index); 447 | glVertexArrayVertexAttribOffsetEXT(vao, instanceBuffer, index, size, type, normalized, stride, (GLintptr)offset); 448 | glVertexArrayVertexAttribDivisorEXT(vao, index, 1); 449 | instanceStride = stride; 450 | } 451 | 452 | void set_indices(GLenum mode, GLsizei count, const uint8_t * indices, GLenum usage) { set_index_data(mode, GL_UNSIGNED_BYTE, count, indices, usage); } 453 | void set_indices(GLenum mode, GLsizei count, const uint16_t * indices, GLenum usage) { set_index_data(mode, GL_UNSIGNED_SHORT, count, indices, usage); } 454 | void set_indices(GLenum mode, GLsizei count, const uint32_t * indices, GLenum usage) { set_index_data(mode, GL_UNSIGNED_INT, count, indices, usage); } 455 | 456 | template void set_vertices(size_t count, const T * vertices, GLenum usage) { set_vertex_data(count * sizeof(T), vertices, usage); } 457 | template void set_vertices(const std::vector & vertices, GLenum usage) { set_vertices(vertices.size(), vertices.data(), usage); } 458 | template void set_vertices(const T(&vertices)[N], GLenum usage) { set_vertices(N, vertices, usage); } 459 | 460 | template void set_attribute(GLuint index, float V::*field) { set_attribute(index, 1, GL_FLOAT, GL_FALSE, sizeof(V), &(((V*)0)->*field)); } 461 | template void set_attribute(GLuint index, linalg::vec V::*field) { set_attribute(index, N, GL_FLOAT, GL_FALSE, sizeof(V), &(((V*)0)->*field)); } 462 | 463 | template void set_elements(GLsizei count, const linalg::vec * elements, GLenum usage) { set_indices(GL_LINES, count * 2, &elements->x, usage); } 464 | template void set_elements(GLsizei count, const linalg::vec * elements, GLenum usage) { set_indices(GL_TRIANGLES, count * 3, &elements->x, usage); } 465 | template void set_elements(GLsizei count, const linalg::vec * elements, GLenum usage) { set_indices(GL_QUADS, count * 4, &elements->x, usage); } 466 | 467 | template void set_elements(const std::vector & elements, GLenum usage) { set_elements((GLsizei)elements.size(), elements.data(), usage); } 468 | 469 | template void set_elements(const T(&elements)[N], GLenum usage) { set_elements(N, elements, usage); } 470 | }; 471 | 472 | #endif // end gl_api_hpp 473 | -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/.gitignore: -------------------------------------------------------------------------------- 1 | fbxsdk/ -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/glew/lib/Win32/glew32.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddiakopoulos/tinygizmo/99c1c418d169774b0b8052b57fd1680b4c4de444/tiny-gizmo-example/third-party/glew/lib/Win32/glew32.lib -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/glew/lib/Win32/glew32s.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddiakopoulos/tinygizmo/99c1c418d169774b0b8052b57fd1680b4c4de444/tiny-gizmo-example/third-party/glew/lib/Win32/glew32s.lib -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/glew/lib/x64/glew32.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddiakopoulos/tinygizmo/99c1c418d169774b0b8052b57fd1680b4c4de444/tiny-gizmo-example/third-party/glew/lib/x64/glew32.lib -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/glew/lib/x64/glew32s.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddiakopoulos/tinygizmo/99c1c418d169774b0b8052b57fd1680b4c4de444/tiny-gizmo-example/third-party/glew/lib/x64/glew32s.lib -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/glfw-3.1.2/ALTERATIONS.txt: -------------------------------------------------------------------------------- 1 | In compliance with requirement 2 of the GLFW license, this file 2 | describes alterations that have been made to this distribution of 3 | GLFW. 4 | 5 | This folder uses a subset of the sources provided in the GLFW 3.1.2 6 | distribution from www.glfw.org. A Visual Studio 2013 project has 7 | been generated that is mostly equivalent to the output of the 8 | official CMake scripts, except that it supports both the Win32 and 9 | x64 platforms. 10 | 11 | For the official, up-to-date sources, please visit www.glfw.org. 12 | -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/glfw-3.1.2/COPYING.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002-2006 Marcus Geelnard 2 | Copyright (c) 2006-2010 Camilla Berglund 3 | 4 | This software is provided 'as-is', without any express or implied 5 | warranty. In no event will the authors be held liable for any damages 6 | arising from the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it 10 | freely, subject to the following restrictions: 11 | 12 | 1. The origin of this software must not be misrepresented; you must not 13 | claim that you wrote the original software. If you use this software 14 | in a product, an acknowledgment in the product documentation would 15 | be appreciated but is not required. 16 | 17 | 2. Altered source versions must be plainly marked as such, and must not 18 | be misrepresented as being the original software. 19 | 20 | 3. This notice may not be removed or altered from any source 21 | distribution. 22 | 23 | -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/glfw-3.1.2/glfw3.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | {BE423E72-28C2-4FB7-9FE1-42AA2F393BBC} 46 | Win32Proj 47 | glfw3 48 | 10.0.16299.0 49 | 50 | 51 | 52 | StaticLibrary 53 | true 54 | v141 55 | MultiByte 56 | 57 | 58 | StaticLibrary 59 | true 60 | v141 61 | MultiByte 62 | 63 | 64 | StaticLibrary 65 | false 66 | v141 67 | true 68 | MultiByte 69 | 70 | 71 | StaticLibrary 72 | false 73 | v141 74 | true 75 | MultiByte 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | intermediate\$(Configuration)-$(Platform)\ 95 | intermediate\$(Configuration)-$(Platform)\ 96 | 97 | 98 | intermediate\$(Configuration)-$(Platform)\ 99 | intermediate\$(Configuration)-$(Platform)\ 100 | 101 | 102 | intermediate\$(Configuration)-$(Platform)\ 103 | intermediate\$(Configuration)-$(Platform)\ 104 | 105 | 106 | intermediate\$(Configuration)-$(Platform)\ 107 | intermediate\$(Configuration)-$(Platform)\ 108 | 109 | 110 | 111 | 112 | 113 | Level3 114 | Disabled 115 | _CRT_SECURE_NO_WARNINGS;_GLFW_USE_CONFIG_H;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) 116 | 117 | 118 | Windows 119 | true 120 | 121 | 122 | 123 | 124 | 125 | 126 | Level3 127 | Disabled 128 | _CRT_SECURE_NO_WARNINGS;_GLFW_USE_CONFIG_H;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) 129 | 130 | 131 | Windows 132 | true 133 | 134 | 135 | 136 | 137 | Level3 138 | 139 | 140 | MaxSpeed 141 | true 142 | true 143 | _CRT_SECURE_NO_WARNINGS;_GLFW_USE_CONFIG_H;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) 144 | 145 | 146 | Windows 147 | true 148 | true 149 | true 150 | 151 | 152 | 153 | 154 | Level3 155 | 156 | 157 | MaxSpeed 158 | true 159 | true 160 | _CRT_SECURE_NO_WARNINGS;_GLFW_USE_CONFIG_H;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) 161 | 162 | 163 | Windows 164 | true 165 | true 166 | true 167 | 168 | 169 | 170 | 171 | 172 | -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/glfw-3.1.2/glfw3.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {df280eb1-0c53-480f-a114-c5c038736967} 6 | 7 | 8 | {5bcb7d5b-3542-440e-8600-6323cd69173a} 9 | 10 | 11 | 12 | 13 | src 14 | 15 | 16 | src 17 | 18 | 19 | src 20 | 21 | 22 | src 23 | 24 | 25 | src 26 | 27 | 28 | src 29 | 30 | 31 | src 32 | 33 | 34 | src 35 | 36 | 37 | src 38 | 39 | 40 | src 41 | 42 | 43 | src 44 | 45 | 46 | src 47 | 48 | 49 | 50 | 51 | src 52 | 53 | 54 | src 55 | 56 | 57 | src 58 | 59 | 60 | src 61 | 62 | 63 | src 64 | 65 | 66 | include 67 | 68 | 69 | include 70 | 71 | 72 | -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/glfw-3.1.2/include/GLFW/glfw3native.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * GLFW 3.1 - www.glfw.org 3 | * A library for OpenGL, window and input 4 | *------------------------------------------------------------------------ 5 | * Copyright (c) 2002-2006 Marcus Geelnard 6 | * Copyright (c) 2006-2010 Camilla Berglund 7 | * 8 | * This software is provided 'as-is', without any express or implied 9 | * warranty. In no event will the authors be held liable for any damages 10 | * arising from the use of this software. 11 | * 12 | * Permission is granted to anyone to use this software for any purpose, 13 | * including commercial applications, and to alter it and redistribute it 14 | * freely, subject to the following restrictions: 15 | * 16 | * 1. The origin of this software must not be misrepresented; you must not 17 | * claim that you wrote the original software. If you use this software 18 | * in a product, an acknowledgment in the product documentation would 19 | * be appreciated but is not required. 20 | * 21 | * 2. Altered source versions must be plainly marked as such, and must not 22 | * be misrepresented as being the original software. 23 | * 24 | * 3. This notice may not be removed or altered from any source 25 | * distribution. 26 | * 27 | *************************************************************************/ 28 | 29 | #ifndef _glfw3_native_h_ 30 | #define _glfw3_native_h_ 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | 37 | /************************************************************************* 38 | * Doxygen documentation 39 | *************************************************************************/ 40 | 41 | /*! @defgroup native Native access 42 | * 43 | * **By using the native access functions you assert that you know what you're 44 | * doing and how to fix problems caused by using them. If you don't, you 45 | * shouldn't be using them.** 46 | * 47 | * Before the inclusion of @ref glfw3native.h, you must define exactly one 48 | * window system API macro and exactly one context creation API macro. Failure 49 | * to do this will cause a compile-time error. 50 | * 51 | * The available window API macros are: 52 | * * `GLFW_EXPOSE_NATIVE_WIN32` 53 | * * `GLFW_EXPOSE_NATIVE_COCOA` 54 | * * `GLFW_EXPOSE_NATIVE_X11` 55 | * 56 | * The available context API macros are: 57 | * * `GLFW_EXPOSE_NATIVE_WGL` 58 | * * `GLFW_EXPOSE_NATIVE_NSGL` 59 | * * `GLFW_EXPOSE_NATIVE_GLX` 60 | * * `GLFW_EXPOSE_NATIVE_EGL` 61 | * 62 | * These macros select which of the native access functions that are declared 63 | * and which platform-specific headers to include. It is then up your (by 64 | * definition platform-specific) code to handle which of these should be 65 | * defined. 66 | */ 67 | 68 | 69 | /************************************************************************* 70 | * System headers and types 71 | *************************************************************************/ 72 | 73 | #if defined(GLFW_EXPOSE_NATIVE_WIN32) 74 | // This is a workaround for the fact that glfw3.h needs to export APIENTRY (for 75 | // example to allow applications to correctly declare a GL_ARB_debug_output 76 | // callback) but windows.h assumes no one will define APIENTRY before it does 77 | #undef APIENTRY 78 | #include 79 | #elif defined(GLFW_EXPOSE_NATIVE_COCOA) 80 | #include 81 | #if defined(__OBJC__) 82 | #import 83 | #else 84 | typedef void* id; 85 | #endif 86 | #elif defined(GLFW_EXPOSE_NATIVE_X11) 87 | #include 88 | #include 89 | #else 90 | #error "No window API selected" 91 | #endif 92 | 93 | #if defined(GLFW_EXPOSE_NATIVE_WGL) 94 | /* WGL is declared by windows.h */ 95 | #elif defined(GLFW_EXPOSE_NATIVE_NSGL) 96 | /* NSGL is declared by Cocoa.h */ 97 | #elif defined(GLFW_EXPOSE_NATIVE_GLX) 98 | #include 99 | #elif defined(GLFW_EXPOSE_NATIVE_EGL) 100 | #include 101 | #else 102 | #error "No context API selected" 103 | #endif 104 | 105 | 106 | /************************************************************************* 107 | * Functions 108 | *************************************************************************/ 109 | 110 | #if defined(GLFW_EXPOSE_NATIVE_WIN32) 111 | /*! @brief Returns the adapter device name of the specified monitor. 112 | * 113 | * @return The UTF-8 encoded adapter device name (for example `\\.\DISPLAY1`) 114 | * of the specified monitor, or `NULL` if an [error](@ref error_handling) 115 | * occurred. 116 | * 117 | * @par Thread Safety 118 | * This function may be called from any thread. Access is not synchronized. 119 | * 120 | * @par History 121 | * Added in GLFW 3.1. 122 | * 123 | * @ingroup native 124 | */ 125 | GLFWAPI const char* glfwGetWin32Adapter(GLFWmonitor* monitor); 126 | 127 | /*! @brief Returns the display device name of the specified monitor. 128 | * 129 | * @return The UTF-8 encoded display device name (for example 130 | * `\\.\DISPLAY1\Monitor0`) of the specified monitor, or `NULL` if an 131 | * [error](@ref error_handling) occurred. 132 | * 133 | * @par Thread Safety 134 | * This function may be called from any thread. Access is not synchronized. 135 | * 136 | * @par History 137 | * Added in GLFW 3.1. 138 | * 139 | * @ingroup native 140 | */ 141 | GLFWAPI const char* glfwGetWin32Monitor(GLFWmonitor* monitor); 142 | 143 | /*! @brief Returns the `HWND` of the specified window. 144 | * 145 | * @return The `HWND` of the specified window, or `NULL` if an 146 | * [error](@ref error_handling) occurred. 147 | * 148 | * @par Thread Safety 149 | * This function may be called from any thread. Access is not synchronized. 150 | * 151 | * @par History 152 | * Added in GLFW 3.0. 153 | * 154 | * @ingroup native 155 | */ 156 | GLFWAPI HWND glfwGetWin32Window(GLFWwindow* window); 157 | #endif 158 | 159 | #if defined(GLFW_EXPOSE_NATIVE_WGL) 160 | /*! @brief Returns the `HGLRC` of the specified window. 161 | * 162 | * @return The `HGLRC` of the specified window, or `NULL` if an 163 | * [error](@ref error_handling) occurred. 164 | * 165 | * @par Thread Safety 166 | * This function may be called from any thread. Access is not synchronized. 167 | * 168 | * @par History 169 | * Added in GLFW 3.0. 170 | * 171 | * @ingroup native 172 | */ 173 | GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* window); 174 | #endif 175 | 176 | #if defined(GLFW_EXPOSE_NATIVE_COCOA) 177 | /*! @brief Returns the `CGDirectDisplayID` of the specified monitor. 178 | * 179 | * @return The `CGDirectDisplayID` of the specified monitor, or 180 | * `kCGNullDirectDisplay` if an [error](@ref error_handling) occurred. 181 | * 182 | * @par Thread Safety 183 | * This function may be called from any thread. Access is not synchronized. 184 | * 185 | * @par History 186 | * Added in GLFW 3.1. 187 | * 188 | * @ingroup native 189 | */ 190 | GLFWAPI CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* monitor); 191 | 192 | /*! @brief Returns the `NSWindow` of the specified window. 193 | * 194 | * @return The `NSWindow` of the specified window, or `nil` if an 195 | * [error](@ref error_handling) occurred. 196 | * 197 | * @par Thread Safety 198 | * This function may be called from any thread. Access is not synchronized. 199 | * 200 | * @par History 201 | * Added in GLFW 3.0. 202 | * 203 | * @ingroup native 204 | */ 205 | GLFWAPI id glfwGetCocoaWindow(GLFWwindow* window); 206 | #endif 207 | 208 | #if defined(GLFW_EXPOSE_NATIVE_NSGL) 209 | /*! @brief Returns the `NSOpenGLContext` of the specified window. 210 | * 211 | * @return The `NSOpenGLContext` of the specified window, or `nil` if an 212 | * [error](@ref error_handling) occurred. 213 | * 214 | * @par Thread Safety 215 | * This function may be called from any thread. Access is not synchronized. 216 | * 217 | * @par History 218 | * Added in GLFW 3.0. 219 | * 220 | * @ingroup native 221 | */ 222 | GLFWAPI id glfwGetNSGLContext(GLFWwindow* window); 223 | #endif 224 | 225 | #if defined(GLFW_EXPOSE_NATIVE_X11) 226 | /*! @brief Returns the `Display` used by GLFW. 227 | * 228 | * @return The `Display` used by GLFW, or `NULL` if an 229 | * [error](@ref error_handling) occurred. 230 | * 231 | * @par Thread Safety 232 | * This function may be called from any thread. Access is not synchronized. 233 | * 234 | * @par History 235 | * Added in GLFW 3.0. 236 | * 237 | * @ingroup native 238 | */ 239 | GLFWAPI Display* glfwGetX11Display(void); 240 | 241 | /*! @brief Returns the `RRCrtc` of the specified monitor. 242 | * 243 | * @return The `RRCrtc` of the specified monitor, or `None` if an 244 | * [error](@ref error_handling) occurred. 245 | * 246 | * @par Thread Safety 247 | * This function may be called from any thread. Access is not synchronized. 248 | * 249 | * @par History 250 | * Added in GLFW 3.1. 251 | * 252 | * @ingroup native 253 | */ 254 | GLFWAPI RRCrtc glfwGetX11Adapter(GLFWmonitor* monitor); 255 | 256 | /*! @brief Returns the `RROutput` of the specified monitor. 257 | * 258 | * @return The `RROutput` of the specified monitor, or `None` if an 259 | * [error](@ref error_handling) occurred. 260 | * 261 | * @par Thread Safety 262 | * This function may be called from any thread. Access is not synchronized. 263 | * 264 | * @par History 265 | * Added in GLFW 3.1. 266 | * 267 | * @ingroup native 268 | */ 269 | GLFWAPI RROutput glfwGetX11Monitor(GLFWmonitor* monitor); 270 | 271 | /*! @brief Returns the `Window` of the specified window. 272 | * 273 | * @return The `Window` of the specified window, or `None` if an 274 | * [error](@ref error_handling) occurred. 275 | * 276 | * @par Thread Safety 277 | * This function may be called from any thread. Access is not synchronized. 278 | * 279 | * @par History 280 | * Added in GLFW 3.0. 281 | * 282 | * @ingroup native 283 | */ 284 | GLFWAPI Window glfwGetX11Window(GLFWwindow* window); 285 | #endif 286 | 287 | #if defined(GLFW_EXPOSE_NATIVE_GLX) 288 | /*! @brief Returns the `GLXContext` of the specified window. 289 | * 290 | * @return The `GLXContext` of the specified window, or `NULL` if an 291 | * [error](@ref error_handling) occurred. 292 | * 293 | * @par Thread Safety 294 | * This function may be called from any thread. Access is not synchronized. 295 | * 296 | * @par History 297 | * Added in GLFW 3.0. 298 | * 299 | * @ingroup native 300 | */ 301 | GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* window); 302 | #endif 303 | 304 | #if defined(GLFW_EXPOSE_NATIVE_EGL) 305 | /*! @brief Returns the `EGLDisplay` used by GLFW. 306 | * 307 | * @return The `EGLDisplay` used by GLFW, or `EGL_NO_DISPLAY` if an 308 | * [error](@ref error_handling) occurred. 309 | * 310 | * @par Thread Safety 311 | * This function may be called from any thread. Access is not synchronized. 312 | * 313 | * @par History 314 | * Added in GLFW 3.0. 315 | * 316 | * @ingroup native 317 | */ 318 | GLFWAPI EGLDisplay glfwGetEGLDisplay(void); 319 | 320 | /*! @brief Returns the `EGLContext` of the specified window. 321 | * 322 | * @return The `EGLContext` of the specified window, or `EGL_NO_CONTEXT` if an 323 | * [error](@ref error_handling) occurred. 324 | * 325 | * @par Thread Safety 326 | * This function may be called from any thread. Access is not synchronized. 327 | * 328 | * @par History 329 | * Added in GLFW 3.0. 330 | * 331 | * @ingroup native 332 | */ 333 | GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* window); 334 | 335 | /*! @brief Returns the `EGLSurface` of the specified window. 336 | * 337 | * @return The `EGLSurface` of the specified window, or `EGL_NO_SURFACE` if an 338 | * [error](@ref error_handling) occurred. 339 | * 340 | * @par Thread Safety 341 | * This function may be called from any thread. Access is not synchronized. 342 | * 343 | * @par History 344 | * Added in GLFW 3.0. 345 | * 346 | * @ingroup native 347 | */ 348 | GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* window); 349 | #endif 350 | 351 | #ifdef __cplusplus 352 | } 353 | #endif 354 | 355 | #endif /* _glfw3_native_h_ */ 356 | 357 | -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/glfw-3.1.2/src/context.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 Camilla Berglund 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | 36 | // Parses the client API version string and extracts the version number 37 | // 38 | static GLboolean parseVersionString(int* api, int* major, int* minor, int* rev) 39 | { 40 | int i; 41 | _GLFWwindow* window; 42 | const char* version; 43 | const char* prefixes[] = 44 | { 45 | "OpenGL ES-CM ", 46 | "OpenGL ES-CL ", 47 | "OpenGL ES ", 48 | NULL 49 | }; 50 | 51 | *api = GLFW_OPENGL_API; 52 | 53 | window = _glfwPlatformGetCurrentContext(); 54 | 55 | version = (const char*) window->GetString(GL_VERSION); 56 | if (!version) 57 | { 58 | _glfwInputError(GLFW_PLATFORM_ERROR, 59 | "Failed to retrieve context version string"); 60 | return GL_FALSE; 61 | } 62 | 63 | for (i = 0; prefixes[i]; i++) 64 | { 65 | const size_t length = strlen(prefixes[i]); 66 | 67 | if (strncmp(version, prefixes[i], length) == 0) 68 | { 69 | version += length; 70 | *api = GLFW_OPENGL_ES_API; 71 | break; 72 | } 73 | } 74 | 75 | if (!sscanf(version, "%d.%d.%d", major, minor, rev)) 76 | { 77 | _glfwInputError(GLFW_PLATFORM_ERROR, 78 | "No version found in context version string"); 79 | return GL_FALSE; 80 | } 81 | 82 | return GL_TRUE; 83 | } 84 | 85 | 86 | ////////////////////////////////////////////////////////////////////////// 87 | ////// GLFW internal API ////// 88 | ////////////////////////////////////////////////////////////////////////// 89 | 90 | GLboolean _glfwIsValidContextConfig(const _GLFWctxconfig* ctxconfig) 91 | { 92 | if (ctxconfig->api != GLFW_OPENGL_API && 93 | ctxconfig->api != GLFW_OPENGL_ES_API) 94 | { 95 | _glfwInputError(GLFW_INVALID_ENUM, "Invalid client API"); 96 | return GL_FALSE; 97 | } 98 | 99 | if (ctxconfig->api == GLFW_OPENGL_API) 100 | { 101 | if ((ctxconfig->major < 1 || ctxconfig->minor < 0) || 102 | (ctxconfig->major == 1 && ctxconfig->minor > 5) || 103 | (ctxconfig->major == 2 && ctxconfig->minor > 1) || 104 | (ctxconfig->major == 3 && ctxconfig->minor > 3)) 105 | { 106 | // OpenGL 1.0 is the smallest valid version 107 | // OpenGL 1.x series ended with version 1.5 108 | // OpenGL 2.x series ended with version 2.1 109 | // OpenGL 3.x series ended with version 3.3 110 | // For now, let everything else through 111 | 112 | _glfwInputError(GLFW_INVALID_VALUE, 113 | "Invalid OpenGL version %i.%i", 114 | ctxconfig->major, ctxconfig->minor); 115 | return GL_FALSE; 116 | } 117 | 118 | if (ctxconfig->profile) 119 | { 120 | if (ctxconfig->profile != GLFW_OPENGL_CORE_PROFILE && 121 | ctxconfig->profile != GLFW_OPENGL_COMPAT_PROFILE) 122 | { 123 | _glfwInputError(GLFW_INVALID_ENUM, 124 | "Invalid OpenGL profile"); 125 | return GL_FALSE; 126 | } 127 | 128 | if (ctxconfig->major < 3 || 129 | (ctxconfig->major == 3 && ctxconfig->minor < 2)) 130 | { 131 | // Desktop OpenGL context profiles are only defined for version 3.2 132 | // and above 133 | 134 | _glfwInputError(GLFW_INVALID_VALUE, 135 | "Context profiles are only defined for OpenGL version 3.2 and above"); 136 | return GL_FALSE; 137 | } 138 | } 139 | 140 | if (ctxconfig->forward && ctxconfig->major < 3) 141 | { 142 | // Forward-compatible contexts are only defined for OpenGL version 3.0 and above 143 | _glfwInputError(GLFW_INVALID_VALUE, 144 | "Forward-compatibility is only defined for OpenGL version 3.0 and above"); 145 | return GL_FALSE; 146 | } 147 | } 148 | else if (ctxconfig->api == GLFW_OPENGL_ES_API) 149 | { 150 | if (ctxconfig->major < 1 || ctxconfig->minor < 0 || 151 | (ctxconfig->major == 1 && ctxconfig->minor > 1) || 152 | (ctxconfig->major == 2 && ctxconfig->minor > 0)) 153 | { 154 | // OpenGL ES 1.0 is the smallest valid version 155 | // OpenGL ES 1.x series ended with version 1.1 156 | // OpenGL ES 2.x series ended with version 2.0 157 | // For now, let everything else through 158 | 159 | _glfwInputError(GLFW_INVALID_VALUE, 160 | "Invalid OpenGL ES version %i.%i", 161 | ctxconfig->major, ctxconfig->minor); 162 | return GL_FALSE; 163 | } 164 | } 165 | 166 | if (ctxconfig->robustness) 167 | { 168 | if (ctxconfig->robustness != GLFW_NO_RESET_NOTIFICATION && 169 | ctxconfig->robustness != GLFW_LOSE_CONTEXT_ON_RESET) 170 | { 171 | _glfwInputError(GLFW_INVALID_ENUM, 172 | "Invalid context robustness mode"); 173 | return GL_FALSE; 174 | } 175 | } 176 | 177 | if (ctxconfig->release) 178 | { 179 | if (ctxconfig->release != GLFW_RELEASE_BEHAVIOR_NONE && 180 | ctxconfig->release != GLFW_RELEASE_BEHAVIOR_FLUSH) 181 | { 182 | _glfwInputError(GLFW_INVALID_ENUM, 183 | "Invalid context release behavior"); 184 | return GL_FALSE; 185 | } 186 | } 187 | 188 | return GL_TRUE; 189 | } 190 | 191 | const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired, 192 | const _GLFWfbconfig* alternatives, 193 | unsigned int count) 194 | { 195 | unsigned int i; 196 | unsigned int missing, leastMissing = UINT_MAX; 197 | unsigned int colorDiff, leastColorDiff = UINT_MAX; 198 | unsigned int extraDiff, leastExtraDiff = UINT_MAX; 199 | const _GLFWfbconfig* current; 200 | const _GLFWfbconfig* closest = NULL; 201 | 202 | for (i = 0; i < count; i++) 203 | { 204 | current = alternatives + i; 205 | 206 | if (desired->stereo > 0 && current->stereo == 0) 207 | { 208 | // Stereo is a hard constraint 209 | continue; 210 | } 211 | 212 | if (desired->doublebuffer != current->doublebuffer) 213 | { 214 | // Double buffering is a hard constraint 215 | continue; 216 | } 217 | 218 | // Count number of missing buffers 219 | { 220 | missing = 0; 221 | 222 | if (desired->alphaBits > 0 && current->alphaBits == 0) 223 | missing++; 224 | 225 | if (desired->depthBits > 0 && current->depthBits == 0) 226 | missing++; 227 | 228 | if (desired->stencilBits > 0 && current->stencilBits == 0) 229 | missing++; 230 | 231 | if (desired->auxBuffers > 0 && 232 | current->auxBuffers < desired->auxBuffers) 233 | { 234 | missing += desired->auxBuffers - current->auxBuffers; 235 | } 236 | 237 | if (desired->samples > 0 && current->samples == 0) 238 | { 239 | // Technically, several multisampling buffers could be 240 | // involved, but that's a lower level implementation detail and 241 | // not important to us here, so we count them as one 242 | missing++; 243 | } 244 | } 245 | 246 | // These polynomials make many small channel size differences matter 247 | // less than one large channel size difference 248 | 249 | // Calculate color channel size difference value 250 | { 251 | colorDiff = 0; 252 | 253 | if (desired->redBits != GLFW_DONT_CARE) 254 | { 255 | colorDiff += (desired->redBits - current->redBits) * 256 | (desired->redBits - current->redBits); 257 | } 258 | 259 | if (desired->greenBits != GLFW_DONT_CARE) 260 | { 261 | colorDiff += (desired->greenBits - current->greenBits) * 262 | (desired->greenBits - current->greenBits); 263 | } 264 | 265 | if (desired->blueBits != GLFW_DONT_CARE) 266 | { 267 | colorDiff += (desired->blueBits - current->blueBits) * 268 | (desired->blueBits - current->blueBits); 269 | } 270 | } 271 | 272 | // Calculate non-color channel size difference value 273 | { 274 | extraDiff = 0; 275 | 276 | if (desired->alphaBits != GLFW_DONT_CARE) 277 | { 278 | extraDiff += (desired->alphaBits - current->alphaBits) * 279 | (desired->alphaBits - current->alphaBits); 280 | } 281 | 282 | if (desired->depthBits != GLFW_DONT_CARE) 283 | { 284 | extraDiff += (desired->depthBits - current->depthBits) * 285 | (desired->depthBits - current->depthBits); 286 | } 287 | 288 | if (desired->stencilBits != GLFW_DONT_CARE) 289 | { 290 | extraDiff += (desired->stencilBits - current->stencilBits) * 291 | (desired->stencilBits - current->stencilBits); 292 | } 293 | 294 | if (desired->accumRedBits != GLFW_DONT_CARE) 295 | { 296 | extraDiff += (desired->accumRedBits - current->accumRedBits) * 297 | (desired->accumRedBits - current->accumRedBits); 298 | } 299 | 300 | if (desired->accumGreenBits != GLFW_DONT_CARE) 301 | { 302 | extraDiff += (desired->accumGreenBits - current->accumGreenBits) * 303 | (desired->accumGreenBits - current->accumGreenBits); 304 | } 305 | 306 | if (desired->accumBlueBits != GLFW_DONT_CARE) 307 | { 308 | extraDiff += (desired->accumBlueBits - current->accumBlueBits) * 309 | (desired->accumBlueBits - current->accumBlueBits); 310 | } 311 | 312 | if (desired->accumAlphaBits != GLFW_DONT_CARE) 313 | { 314 | extraDiff += (desired->accumAlphaBits - current->accumAlphaBits) * 315 | (desired->accumAlphaBits - current->accumAlphaBits); 316 | } 317 | 318 | if (desired->samples != GLFW_DONT_CARE) 319 | { 320 | extraDiff += (desired->samples - current->samples) * 321 | (desired->samples - current->samples); 322 | } 323 | 324 | if (desired->sRGB && !current->sRGB) 325 | extraDiff++; 326 | } 327 | 328 | // Figure out if the current one is better than the best one found so far 329 | // Least number of missing buffers is the most important heuristic, 330 | // then color buffer size match and lastly size match for other buffers 331 | 332 | if (missing < leastMissing) 333 | closest = current; 334 | else if (missing == leastMissing) 335 | { 336 | if ((colorDiff < leastColorDiff) || 337 | (colorDiff == leastColorDiff && extraDiff < leastExtraDiff)) 338 | { 339 | closest = current; 340 | } 341 | } 342 | 343 | if (current == closest) 344 | { 345 | leastMissing = missing; 346 | leastColorDiff = colorDiff; 347 | leastExtraDiff = extraDiff; 348 | } 349 | } 350 | 351 | return closest; 352 | } 353 | 354 | GLboolean _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig) 355 | { 356 | _GLFWwindow* window = _glfwPlatformGetCurrentContext(); 357 | 358 | window->GetIntegerv = (PFNGLGETINTEGERVPROC) glfwGetProcAddress("glGetIntegerv"); 359 | window->GetString = (PFNGLGETSTRINGPROC) glfwGetProcAddress("glGetString"); 360 | window->Clear = (PFNGLCLEARPROC) glfwGetProcAddress("glClear"); 361 | 362 | if (!parseVersionString(&window->context.api, 363 | &window->context.major, 364 | &window->context.minor, 365 | &window->context.revision)) 366 | { 367 | return GL_FALSE; 368 | } 369 | 370 | #if defined(_GLFW_USE_OPENGL) 371 | if (window->context.major > 2) 372 | { 373 | // OpenGL 3.0+ uses a different function for extension string retrieval 374 | // We cache it here instead of in glfwExtensionSupported mostly to alert 375 | // users as early as possible that their build may be broken 376 | 377 | window->GetStringi = (PFNGLGETSTRINGIPROC) glfwGetProcAddress("glGetStringi"); 378 | if (!window->GetStringi) 379 | { 380 | _glfwInputError(GLFW_PLATFORM_ERROR, 381 | "Entry point retrieval is broken"); 382 | return GL_FALSE; 383 | } 384 | } 385 | 386 | if (window->context.api == GLFW_OPENGL_API) 387 | { 388 | // Read back context flags (OpenGL 3.0 and above) 389 | if (window->context.major >= 3) 390 | { 391 | GLint flags; 392 | window->GetIntegerv(GL_CONTEXT_FLAGS, &flags); 393 | 394 | if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT) 395 | window->context.forward = GL_TRUE; 396 | 397 | if (flags & GL_CONTEXT_FLAG_DEBUG_BIT) 398 | window->context.debug = GL_TRUE; 399 | else if (glfwExtensionSupported("GL_ARB_debug_output") && 400 | ctxconfig->debug) 401 | { 402 | // HACK: This is a workaround for older drivers (pre KHR_debug) 403 | // not setting the debug bit in the context flags for 404 | // debug contexts 405 | window->context.debug = GL_TRUE; 406 | } 407 | } 408 | 409 | // Read back OpenGL context profile (OpenGL 3.2 and above) 410 | if (window->context.major > 3 || 411 | (window->context.major == 3 && window->context.minor >= 2)) 412 | { 413 | GLint mask; 414 | window->GetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask); 415 | 416 | if (mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) 417 | window->context.profile = GLFW_OPENGL_COMPAT_PROFILE; 418 | else if (mask & GL_CONTEXT_CORE_PROFILE_BIT) 419 | window->context.profile = GLFW_OPENGL_CORE_PROFILE; 420 | else if (glfwExtensionSupported("GL_ARB_compatibility")) 421 | { 422 | // HACK: This is a workaround for the compatibility profile bit 423 | // not being set in the context flags if an OpenGL 3.2+ 424 | // context was created without having requested a specific 425 | // version 426 | window->context.profile = GLFW_OPENGL_COMPAT_PROFILE; 427 | } 428 | } 429 | 430 | // Read back robustness strategy 431 | if (glfwExtensionSupported("GL_ARB_robustness")) 432 | { 433 | // NOTE: We avoid using the context flags for detection, as they are 434 | // only present from 3.0 while the extension applies from 1.1 435 | 436 | GLint strategy; 437 | window->GetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &strategy); 438 | 439 | if (strategy == GL_LOSE_CONTEXT_ON_RESET_ARB) 440 | window->context.robustness = GLFW_LOSE_CONTEXT_ON_RESET; 441 | else if (strategy == GL_NO_RESET_NOTIFICATION_ARB) 442 | window->context.robustness = GLFW_NO_RESET_NOTIFICATION; 443 | } 444 | } 445 | else 446 | { 447 | // Read back robustness strategy 448 | if (glfwExtensionSupported("GL_EXT_robustness")) 449 | { 450 | // NOTE: The values of these constants match those of the OpenGL ARB 451 | // one, so we can reuse them here 452 | 453 | GLint strategy; 454 | window->GetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &strategy); 455 | 456 | if (strategy == GL_LOSE_CONTEXT_ON_RESET_ARB) 457 | window->context.robustness = GLFW_LOSE_CONTEXT_ON_RESET; 458 | else if (strategy == GL_NO_RESET_NOTIFICATION_ARB) 459 | window->context.robustness = GLFW_NO_RESET_NOTIFICATION; 460 | } 461 | } 462 | 463 | if (glfwExtensionSupported("GL_KHR_context_flush_control")) 464 | { 465 | GLint behavior; 466 | window->GetIntegerv(GL_CONTEXT_RELEASE_BEHAVIOR, &behavior); 467 | 468 | if (behavior == GL_NONE) 469 | window->context.release = GLFW_RELEASE_BEHAVIOR_NONE; 470 | else if (behavior == GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH) 471 | window->context.release = GLFW_RELEASE_BEHAVIOR_FLUSH; 472 | } 473 | #endif // _GLFW_USE_OPENGL 474 | 475 | return GL_TRUE; 476 | } 477 | 478 | GLboolean _glfwIsValidContext(const _GLFWctxconfig* ctxconfig) 479 | { 480 | _GLFWwindow* window = _glfwPlatformGetCurrentContext(); 481 | 482 | if (window->context.major < ctxconfig->major || 483 | (window->context.major == ctxconfig->major && 484 | window->context.minor < ctxconfig->minor)) 485 | { 486 | // The desired OpenGL version is greater than the actual version 487 | // This only happens if the machine lacks {GLX|WGL}_ARB_create_context 488 | // /and/ the user has requested an OpenGL version greater than 1.0 489 | 490 | // For API consistency, we emulate the behavior of the 491 | // {GLX|WGL}_ARB_create_context extension and fail here 492 | 493 | _glfwInputError(GLFW_VERSION_UNAVAILABLE, NULL); 494 | return GL_FALSE; 495 | } 496 | 497 | return GL_TRUE; 498 | } 499 | 500 | int _glfwStringInExtensionString(const char* string, const char* extensions) 501 | { 502 | const char* start = extensions; 503 | 504 | for (;;) 505 | { 506 | const char* where; 507 | const char* terminator; 508 | 509 | where = strstr(start, string); 510 | if (!where) 511 | return GL_FALSE; 512 | 513 | terminator = where + strlen(string); 514 | if (where == start || *(where - 1) == ' ') 515 | { 516 | if (*terminator == ' ' || *terminator == '\0') 517 | break; 518 | } 519 | 520 | start = terminator; 521 | } 522 | 523 | return GL_TRUE; 524 | } 525 | 526 | 527 | ////////////////////////////////////////////////////////////////////////// 528 | ////// GLFW public API ////// 529 | ////////////////////////////////////////////////////////////////////////// 530 | 531 | GLFWAPI void glfwMakeContextCurrent(GLFWwindow* handle) 532 | { 533 | _GLFWwindow* window = (_GLFWwindow*) handle; 534 | _GLFW_REQUIRE_INIT(); 535 | _glfwPlatformMakeContextCurrent(window); 536 | } 537 | 538 | GLFWAPI GLFWwindow* glfwGetCurrentContext(void) 539 | { 540 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 541 | return (GLFWwindow*) _glfwPlatformGetCurrentContext(); 542 | } 543 | 544 | GLFWAPI void glfwSwapBuffers(GLFWwindow* handle) 545 | { 546 | _GLFWwindow* window = (_GLFWwindow*) handle; 547 | _GLFW_REQUIRE_INIT(); 548 | _glfwPlatformSwapBuffers(window); 549 | } 550 | 551 | GLFWAPI void glfwSwapInterval(int interval) 552 | { 553 | _GLFW_REQUIRE_INIT(); 554 | 555 | if (!_glfwPlatformGetCurrentContext()) 556 | { 557 | _glfwInputError(GLFW_NO_CURRENT_CONTEXT, NULL); 558 | return; 559 | } 560 | 561 | _glfwPlatformSwapInterval(interval); 562 | } 563 | 564 | GLFWAPI int glfwExtensionSupported(const char* extension) 565 | { 566 | _GLFWwindow* window; 567 | 568 | _GLFW_REQUIRE_INIT_OR_RETURN(GL_FALSE); 569 | 570 | window = _glfwPlatformGetCurrentContext(); 571 | if (!window) 572 | { 573 | _glfwInputError(GLFW_NO_CURRENT_CONTEXT, NULL); 574 | return GL_FALSE; 575 | } 576 | 577 | if (*extension == '\0') 578 | { 579 | _glfwInputError(GLFW_INVALID_VALUE, NULL); 580 | return GL_FALSE; 581 | } 582 | 583 | #if defined(_GLFW_USE_OPENGL) 584 | if (window->context.major >= 3) 585 | { 586 | int i; 587 | GLint count; 588 | 589 | // Check if extension is in the modern OpenGL extensions string list 590 | 591 | window->GetIntegerv(GL_NUM_EXTENSIONS, &count); 592 | 593 | for (i = 0; i < count; i++) 594 | { 595 | const char* en = (const char*) window->GetStringi(GL_EXTENSIONS, i); 596 | if (!en) 597 | { 598 | _glfwInputError(GLFW_PLATFORM_ERROR, 599 | "Failed to retrieve extension string %i", i); 600 | return GL_FALSE; 601 | } 602 | 603 | if (strcmp(en, extension) == 0) 604 | return GL_TRUE; 605 | } 606 | } 607 | else 608 | #endif // _GLFW_USE_OPENGL 609 | { 610 | // Check if extension is in the old style OpenGL extensions string 611 | 612 | const char* extensions = (const char*) window->GetString(GL_EXTENSIONS); 613 | if (!extensions) 614 | { 615 | _glfwInputError(GLFW_PLATFORM_ERROR, 616 | "Failed to retrieve extension string"); 617 | return GL_FALSE; 618 | } 619 | 620 | if (_glfwStringInExtensionString(extension, extensions)) 621 | return GL_TRUE; 622 | } 623 | 624 | // Check if extension is in the platform-specific string 625 | return _glfwPlatformExtensionSupported(extension); 626 | } 627 | 628 | GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname) 629 | { 630 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 631 | 632 | if (!_glfwPlatformGetCurrentContext()) 633 | { 634 | _glfwInputError(GLFW_NO_CURRENT_CONTEXT, NULL); 635 | return NULL; 636 | } 637 | 638 | return _glfwPlatformGetProcAddress(procname); 639 | } 640 | 641 | -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/glfw-3.1.2/src/glfw_config.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2010 Camilla Berglund 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // As glfw_config.h.in, this file is used by CMake to produce the 27 | // glfw_config.h configuration header file. If you are adding a feature 28 | // requiring conditional compilation, this is where to add the macro. 29 | //======================================================================== 30 | // As glfw_config.h, this file defines compile-time option macros for a 31 | // specific platform and development environment. If you are using the 32 | // GLFW CMake files, modify glfw_config.h.in instead of this file. If you 33 | // are using your own build system, make this file define the appropriate 34 | // macros in whatever way is suitable. 35 | //======================================================================== 36 | 37 | // Define this to 1 if building GLFW for X11 38 | /* #undef _GLFW_X11 */ 39 | // Define this to 1 if building GLFW for Win32 40 | #define _GLFW_WIN32 41 | // Define this to 1 if building GLFW for Cocoa 42 | /* #undef _GLFW_COCOA */ 43 | // Define this to 1 if building GLFW for Wayland 44 | /* #undef _GLFW_WAYLAND */ 45 | // Define this to 1 if building GLFW for Mir 46 | /* #undef _GLFW_MIR */ 47 | 48 | // Define this to 1 if building GLFW for EGL 49 | /* #undef _GLFW_EGL */ 50 | // Define this to 1 if building GLFW for GLX 51 | /* #undef _GLFW_GLX */ 52 | // Define this to 1 if building GLFW for WGL 53 | #define _GLFW_WGL 54 | // Define this to 1 if building GLFW for NSGL 55 | /* #undef _GLFW_NSGL */ 56 | 57 | // Define this to 1 if building as a shared library / dynamic library / DLL 58 | #define _GLFW_BUILD_DLL 59 | 60 | // Define this to 1 to force use of high-performance GPU on hybrid systems 61 | /* #undef _GLFW_USE_HYBRID_HPG */ 62 | 63 | // Define this to 1 if the XInput X11 extension is available 64 | /* #undef _GLFW_HAS_XINPUT */ 65 | // Define this to 1 if the Xxf86vm X11 extension is available 66 | /* #undef _GLFW_HAS_XF86VM */ 67 | 68 | // Define this to 1 if glfwInit should change the current directory 69 | /* #undef _GLFW_USE_CHDIR */ 70 | // Define this to 1 if glfwCreateWindow should populate the menu bar 71 | /* #undef _GLFW_USE_MENUBAR */ 72 | // Define this to 1 if windows should use full resolution on Retina displays 73 | /* #undef _GLFW_USE_RETINA */ 74 | 75 | // Define this to 1 if using OpenGL as the client library 76 | #define _GLFW_USE_OPENGL 77 | // Define this to 1 if using OpenGL ES 1.1 as the client library 78 | /* #undef _GLFW_USE_GLESV1 */ 79 | // Define this to 1 if using OpenGL ES 2.0 as the client library 80 | /* #undef _GLFW_USE_GLESV2 */ 81 | 82 | -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/glfw-3.1.2/src/init.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 Camilla Berglund 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | 36 | // The three global variables below comprise all global data in GLFW. 37 | // Any other global variable is a bug. 38 | 39 | // Global state shared between compilation units of GLFW 40 | // These are documented in internal.h 41 | // 42 | GLboolean _glfwInitialized = GL_FALSE; 43 | _GLFWlibrary _glfw; 44 | 45 | // This is outside of _glfw so it can be initialized and usable before 46 | // glfwInit is called, which lets that function report errors 47 | // 48 | static GLFWerrorfun _glfwErrorCallback = NULL; 49 | 50 | 51 | // Returns a generic string representation of the specified error 52 | // 53 | static const char* getErrorString(int error) 54 | { 55 | switch (error) 56 | { 57 | case GLFW_NOT_INITIALIZED: 58 | return "The GLFW library is not initialized"; 59 | case GLFW_NO_CURRENT_CONTEXT: 60 | return "There is no current context"; 61 | case GLFW_INVALID_ENUM: 62 | return "Invalid argument for enum parameter"; 63 | case GLFW_INVALID_VALUE: 64 | return "Invalid value for parameter"; 65 | case GLFW_OUT_OF_MEMORY: 66 | return "Out of memory"; 67 | case GLFW_API_UNAVAILABLE: 68 | return "The requested client API is unavailable"; 69 | case GLFW_VERSION_UNAVAILABLE: 70 | return "The requested client API version is unavailable"; 71 | case GLFW_PLATFORM_ERROR: 72 | return "A platform-specific error occurred"; 73 | case GLFW_FORMAT_UNAVAILABLE: 74 | return "The requested format is unavailable"; 75 | } 76 | 77 | return "ERROR: UNKNOWN ERROR TOKEN PASSED TO glfwErrorString"; 78 | } 79 | 80 | 81 | ////////////////////////////////////////////////////////////////////////// 82 | ////// GLFW event API ////// 83 | ////////////////////////////////////////////////////////////////////////// 84 | 85 | void _glfwInputError(int error, const char* format, ...) 86 | { 87 | if (_glfwErrorCallback) 88 | { 89 | char buffer[8192]; 90 | const char* description; 91 | 92 | if (format) 93 | { 94 | int count; 95 | va_list vl; 96 | 97 | va_start(vl, format); 98 | count = vsnprintf(buffer, sizeof(buffer), format, vl); 99 | va_end(vl); 100 | 101 | if (count < 0) 102 | buffer[sizeof(buffer) - 1] = '\0'; 103 | 104 | description = buffer; 105 | } 106 | else 107 | description = getErrorString(error); 108 | 109 | _glfwErrorCallback(error, description); 110 | } 111 | } 112 | 113 | 114 | ////////////////////////////////////////////////////////////////////////// 115 | ////// GLFW public API ////// 116 | ////////////////////////////////////////////////////////////////////////// 117 | 118 | GLFWAPI int glfwInit(void) 119 | { 120 | if (_glfwInitialized) 121 | return GL_TRUE; 122 | 123 | memset(&_glfw, 0, sizeof(_glfw)); 124 | 125 | if (!_glfwPlatformInit()) 126 | { 127 | _glfwPlatformTerminate(); 128 | return GL_FALSE; 129 | } 130 | 131 | _glfw.monitors = _glfwPlatformGetMonitors(&_glfw.monitorCount); 132 | _glfwInitialized = GL_TRUE; 133 | 134 | // Not all window hints have zero as their default value 135 | glfwDefaultWindowHints(); 136 | 137 | return GL_TRUE; 138 | } 139 | 140 | GLFWAPI void glfwTerminate(void) 141 | { 142 | int i; 143 | 144 | if (!_glfwInitialized) 145 | return; 146 | 147 | memset(&_glfw.callbacks, 0, sizeof(_glfw.callbacks)); 148 | 149 | while (_glfw.windowListHead) 150 | glfwDestroyWindow((GLFWwindow*) _glfw.windowListHead); 151 | 152 | while (_glfw.cursorListHead) 153 | glfwDestroyCursor((GLFWcursor*) _glfw.cursorListHead); 154 | 155 | for (i = 0; i < _glfw.monitorCount; i++) 156 | { 157 | _GLFWmonitor* monitor = _glfw.monitors[i]; 158 | if (monitor->originalRamp.size) 159 | _glfwPlatformSetGammaRamp(monitor, &monitor->originalRamp); 160 | } 161 | 162 | _glfwFreeMonitors(_glfw.monitors, _glfw.monitorCount); 163 | _glfw.monitors = NULL; 164 | _glfw.monitorCount = 0; 165 | 166 | _glfwPlatformTerminate(); 167 | 168 | memset(&_glfw, 0, sizeof(_glfw)); 169 | _glfwInitialized = GL_FALSE; 170 | } 171 | 172 | GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev) 173 | { 174 | if (major != NULL) 175 | *major = GLFW_VERSION_MAJOR; 176 | 177 | if (minor != NULL) 178 | *minor = GLFW_VERSION_MINOR; 179 | 180 | if (rev != NULL) 181 | *rev = GLFW_VERSION_REVISION; 182 | } 183 | 184 | GLFWAPI const char* glfwGetVersionString(void) 185 | { 186 | return _glfwPlatformGetVersionString(); 187 | } 188 | 189 | GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun) 190 | { 191 | _GLFW_SWAP_POINTERS(_glfwErrorCallback, cbfun); 192 | return cbfun; 193 | } 194 | 195 | -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/glfw-3.1.2/src/input.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 Camilla Berglund 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | 30 | #include 31 | #if defined(_MSC_VER) 32 | #include 33 | #endif 34 | 35 | // Internal key state used for sticky keys 36 | #define _GLFW_STICK 3 37 | 38 | 39 | // Sets the cursor mode for the specified window 40 | // 41 | static void setCursorMode(_GLFWwindow* window, int newMode) 42 | { 43 | const int oldMode = window->cursorMode; 44 | 45 | if (newMode != GLFW_CURSOR_NORMAL && 46 | newMode != GLFW_CURSOR_HIDDEN && 47 | newMode != GLFW_CURSOR_DISABLED) 48 | { 49 | _glfwInputError(GLFW_INVALID_ENUM, "Invalid cursor mode"); 50 | return; 51 | } 52 | 53 | if (oldMode == newMode) 54 | return; 55 | 56 | window->cursorMode = newMode; 57 | 58 | if (_glfw.cursorWindow == window) 59 | { 60 | if (oldMode == GLFW_CURSOR_DISABLED) 61 | { 62 | _glfwPlatformSetCursorPos(window, 63 | _glfw.cursorPosX, 64 | _glfw.cursorPosY); 65 | } 66 | else if (newMode == GLFW_CURSOR_DISABLED) 67 | { 68 | int width, height; 69 | 70 | _glfwPlatformGetCursorPos(window, 71 | &_glfw.cursorPosX, 72 | &_glfw.cursorPosY); 73 | 74 | window->cursorPosX = _glfw.cursorPosX; 75 | window->cursorPosY = _glfw.cursorPosY; 76 | 77 | _glfwPlatformGetWindowSize(window, &width, &height); 78 | _glfwPlatformSetCursorPos(window, width / 2, height / 2); 79 | } 80 | 81 | _glfwPlatformApplyCursorMode(window); 82 | } 83 | } 84 | 85 | // Set sticky keys mode for the specified window 86 | // 87 | static void setStickyKeys(_GLFWwindow* window, int enabled) 88 | { 89 | if (window->stickyKeys == enabled) 90 | return; 91 | 92 | if (!enabled) 93 | { 94 | int i; 95 | 96 | // Release all sticky keys 97 | for (i = 0; i <= GLFW_KEY_LAST; i++) 98 | { 99 | if (window->keys[i] == _GLFW_STICK) 100 | window->keys[i] = GLFW_RELEASE; 101 | } 102 | } 103 | 104 | window->stickyKeys = enabled; 105 | } 106 | 107 | // Set sticky mouse buttons mode for the specified window 108 | // 109 | static void setStickyMouseButtons(_GLFWwindow* window, int enabled) 110 | { 111 | if (window->stickyMouseButtons == enabled) 112 | return; 113 | 114 | if (!enabled) 115 | { 116 | int i; 117 | 118 | // Release all sticky mouse buttons 119 | for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++) 120 | { 121 | if (window->mouseButtons[i] == _GLFW_STICK) 122 | window->mouseButtons[i] = GLFW_RELEASE; 123 | } 124 | } 125 | 126 | window->stickyMouseButtons = enabled; 127 | } 128 | 129 | 130 | ////////////////////////////////////////////////////////////////////////// 131 | ////// GLFW event API ////// 132 | ////////////////////////////////////////////////////////////////////////// 133 | 134 | void _glfwInputKey(_GLFWwindow* window, int key, int scancode, int action, int mods) 135 | { 136 | if (key >= 0 && key <= GLFW_KEY_LAST) 137 | { 138 | GLboolean repeated = GL_FALSE; 139 | 140 | if (action == GLFW_RELEASE && window->keys[key] == GLFW_RELEASE) 141 | return; 142 | 143 | if (action == GLFW_PRESS && window->keys[key] == GLFW_PRESS) 144 | repeated = GL_TRUE; 145 | 146 | if (action == GLFW_RELEASE && window->stickyKeys) 147 | window->keys[key] = _GLFW_STICK; 148 | else 149 | window->keys[key] = (char) action; 150 | 151 | if (repeated) 152 | action = GLFW_REPEAT; 153 | } 154 | 155 | if (window->callbacks.key) 156 | window->callbacks.key((GLFWwindow*) window, key, scancode, action, mods); 157 | } 158 | 159 | void _glfwInputChar(_GLFWwindow* window, unsigned int codepoint, int mods, int plain) 160 | { 161 | if (codepoint < 32 || (codepoint > 126 && codepoint < 160)) 162 | return; 163 | 164 | if (window->callbacks.charmods) 165 | window->callbacks.charmods((GLFWwindow*) window, codepoint, mods); 166 | 167 | if (plain) 168 | { 169 | if (window->callbacks.character) 170 | window->callbacks.character((GLFWwindow*) window, codepoint); 171 | } 172 | } 173 | 174 | void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset) 175 | { 176 | if (window->callbacks.scroll) 177 | window->callbacks.scroll((GLFWwindow*) window, xoffset, yoffset); 178 | } 179 | 180 | void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods) 181 | { 182 | if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST) 183 | return; 184 | 185 | // Register mouse button action 186 | if (action == GLFW_RELEASE && window->stickyMouseButtons) 187 | window->mouseButtons[button] = _GLFW_STICK; 188 | else 189 | window->mouseButtons[button] = (char) action; 190 | 191 | if (window->callbacks.mouseButton) 192 | window->callbacks.mouseButton((GLFWwindow*) window, button, action, mods); 193 | } 194 | 195 | void _glfwInputCursorMotion(_GLFWwindow* window, double x, double y) 196 | { 197 | if (window->cursorMode == GLFW_CURSOR_DISABLED) 198 | { 199 | if (x == 0.0 && y == 0.0) 200 | return; 201 | 202 | window->cursorPosX += x; 203 | window->cursorPosY += y; 204 | 205 | x = window->cursorPosX; 206 | y = window->cursorPosY; 207 | } 208 | 209 | if (window->callbacks.cursorPos) 210 | window->callbacks.cursorPos((GLFWwindow*) window, x, y); 211 | } 212 | 213 | void _glfwInputCursorEnter(_GLFWwindow* window, int entered) 214 | { 215 | if (window->callbacks.cursorEnter) 216 | window->callbacks.cursorEnter((GLFWwindow*) window, entered); 217 | } 218 | 219 | void _glfwInputDrop(_GLFWwindow* window, int count, const char** paths) 220 | { 221 | if (window->callbacks.drop) 222 | window->callbacks.drop((GLFWwindow*) window, count, paths); 223 | } 224 | 225 | 226 | ////////////////////////////////////////////////////////////////////////// 227 | ////// GLFW public API ////// 228 | ////////////////////////////////////////////////////////////////////////// 229 | 230 | GLFWAPI int glfwGetInputMode(GLFWwindow* handle, int mode) 231 | { 232 | _GLFWwindow* window = (_GLFWwindow*) handle; 233 | 234 | _GLFW_REQUIRE_INIT_OR_RETURN(0); 235 | 236 | switch (mode) 237 | { 238 | case GLFW_CURSOR: 239 | return window->cursorMode; 240 | case GLFW_STICKY_KEYS: 241 | return window->stickyKeys; 242 | case GLFW_STICKY_MOUSE_BUTTONS: 243 | return window->stickyMouseButtons; 244 | default: 245 | _glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode"); 246 | return 0; 247 | } 248 | } 249 | 250 | GLFWAPI void glfwSetInputMode(GLFWwindow* handle, int mode, int value) 251 | { 252 | _GLFWwindow* window = (_GLFWwindow*) handle; 253 | 254 | _GLFW_REQUIRE_INIT(); 255 | 256 | switch (mode) 257 | { 258 | case GLFW_CURSOR: 259 | setCursorMode(window, value); 260 | break; 261 | case GLFW_STICKY_KEYS: 262 | setStickyKeys(window, value ? GL_TRUE : GL_FALSE); 263 | break; 264 | case GLFW_STICKY_MOUSE_BUTTONS: 265 | setStickyMouseButtons(window, value ? GL_TRUE : GL_FALSE); 266 | break; 267 | default: 268 | _glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode"); 269 | break; 270 | } 271 | } 272 | 273 | GLFWAPI int glfwGetKey(GLFWwindow* handle, int key) 274 | { 275 | _GLFWwindow* window = (_GLFWwindow*) handle; 276 | 277 | _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_RELEASE); 278 | 279 | if (key < 0 || key > GLFW_KEY_LAST) 280 | { 281 | _glfwInputError(GLFW_INVALID_ENUM, "Invalid key"); 282 | return GLFW_RELEASE; 283 | } 284 | 285 | if (window->keys[key] == _GLFW_STICK) 286 | { 287 | // Sticky mode: release key now 288 | window->keys[key] = GLFW_RELEASE; 289 | return GLFW_PRESS; 290 | } 291 | 292 | return (int) window->keys[key]; 293 | } 294 | 295 | GLFWAPI int glfwGetMouseButton(GLFWwindow* handle, int button) 296 | { 297 | _GLFWwindow* window = (_GLFWwindow*) handle; 298 | 299 | _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_RELEASE); 300 | 301 | if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST) 302 | { 303 | _glfwInputError(GLFW_INVALID_ENUM, 304 | "Invalid mouse button"); 305 | return GLFW_RELEASE; 306 | } 307 | 308 | if (window->mouseButtons[button] == _GLFW_STICK) 309 | { 310 | // Sticky mode: release mouse button now 311 | window->mouseButtons[button] = GLFW_RELEASE; 312 | return GLFW_PRESS; 313 | } 314 | 315 | return (int) window->mouseButtons[button]; 316 | } 317 | 318 | GLFWAPI void glfwGetCursorPos(GLFWwindow* handle, double* xpos, double* ypos) 319 | { 320 | _GLFWwindow* window = (_GLFWwindow*) handle; 321 | 322 | if (xpos) 323 | *xpos = 0; 324 | if (ypos) 325 | *ypos = 0; 326 | 327 | _GLFW_REQUIRE_INIT(); 328 | 329 | if (window->cursorMode == GLFW_CURSOR_DISABLED) 330 | { 331 | if (xpos) 332 | *xpos = window->cursorPosX; 333 | if (ypos) 334 | *ypos = window->cursorPosY; 335 | } 336 | else 337 | _glfwPlatformGetCursorPos(window, xpos, ypos); 338 | } 339 | 340 | GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, double xpos, double ypos) 341 | { 342 | _GLFWwindow* window = (_GLFWwindow*) handle; 343 | 344 | _GLFW_REQUIRE_INIT(); 345 | 346 | if (_glfw.cursorWindow != window) 347 | return; 348 | 349 | if (window->cursorMode == GLFW_CURSOR_DISABLED) 350 | { 351 | // Only update the accumulated position if the cursor is disabled 352 | window->cursorPosX = xpos; 353 | window->cursorPosY = ypos; 354 | } 355 | else 356 | { 357 | // Update system cursor position 358 | _glfwPlatformSetCursorPos(window, xpos, ypos); 359 | } 360 | } 361 | 362 | GLFWAPI GLFWcursor* glfwCreateCursor(const GLFWimage* image, int xhot, int yhot) 363 | { 364 | _GLFWcursor* cursor; 365 | 366 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 367 | 368 | cursor = calloc(1, sizeof(_GLFWcursor)); 369 | cursor->next = _glfw.cursorListHead; 370 | _glfw.cursorListHead = cursor; 371 | 372 | if (!_glfwPlatformCreateCursor(cursor, image, xhot, yhot)) 373 | { 374 | glfwDestroyCursor((GLFWcursor*) cursor); 375 | return NULL; 376 | } 377 | 378 | return (GLFWcursor*) cursor; 379 | } 380 | 381 | GLFWAPI GLFWcursor* glfwCreateStandardCursor(int shape) 382 | { 383 | _GLFWcursor* cursor; 384 | 385 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 386 | 387 | if (shape != GLFW_ARROW_CURSOR && 388 | shape != GLFW_IBEAM_CURSOR && 389 | shape != GLFW_CROSSHAIR_CURSOR && 390 | shape != GLFW_HAND_CURSOR && 391 | shape != GLFW_HRESIZE_CURSOR && 392 | shape != GLFW_VRESIZE_CURSOR) 393 | { 394 | _glfwInputError(GLFW_INVALID_ENUM, "Invalid standard cursor"); 395 | return NULL; 396 | } 397 | 398 | cursor = calloc(1, sizeof(_GLFWcursor)); 399 | cursor->next = _glfw.cursorListHead; 400 | _glfw.cursorListHead = cursor; 401 | 402 | if (!_glfwPlatformCreateStandardCursor(cursor, shape)) 403 | { 404 | glfwDestroyCursor((GLFWcursor*) cursor); 405 | return NULL; 406 | } 407 | 408 | return (GLFWcursor*) cursor; 409 | } 410 | 411 | GLFWAPI void glfwDestroyCursor(GLFWcursor* handle) 412 | { 413 | _GLFWcursor* cursor = (_GLFWcursor*) handle; 414 | 415 | _GLFW_REQUIRE_INIT(); 416 | 417 | if (cursor == NULL) 418 | return; 419 | 420 | // Make sure the cursor is not being used by any window 421 | { 422 | _GLFWwindow* window; 423 | 424 | for (window = _glfw.windowListHead; window; window = window->next) 425 | { 426 | if (window->cursor == cursor) 427 | glfwSetCursor((GLFWwindow*) window, NULL); 428 | } 429 | } 430 | 431 | _glfwPlatformDestroyCursor(cursor); 432 | 433 | // Unlink cursor from global linked list 434 | { 435 | _GLFWcursor** prev = &_glfw.cursorListHead; 436 | 437 | while (*prev != cursor) 438 | prev = &((*prev)->next); 439 | 440 | *prev = cursor->next; 441 | } 442 | 443 | free(cursor); 444 | } 445 | 446 | GLFWAPI void glfwSetCursor(GLFWwindow* windowHandle, GLFWcursor* cursorHandle) 447 | { 448 | _GLFWwindow* window = (_GLFWwindow*) windowHandle; 449 | _GLFWcursor* cursor = (_GLFWcursor*) cursorHandle; 450 | 451 | _GLFW_REQUIRE_INIT(); 452 | 453 | _glfwPlatformSetCursor(window, cursor); 454 | 455 | window->cursor = cursor; 456 | } 457 | 458 | GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwindow* handle, GLFWkeyfun cbfun) 459 | { 460 | _GLFWwindow* window = (_GLFWwindow*) handle; 461 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 462 | _GLFW_SWAP_POINTERS(window->callbacks.key, cbfun); 463 | return cbfun; 464 | } 465 | 466 | GLFWAPI GLFWcharfun glfwSetCharCallback(GLFWwindow* handle, GLFWcharfun cbfun) 467 | { 468 | _GLFWwindow* window = (_GLFWwindow*) handle; 469 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 470 | _GLFW_SWAP_POINTERS(window->callbacks.character, cbfun); 471 | return cbfun; 472 | } 473 | 474 | GLFWAPI GLFWcharmodsfun glfwSetCharModsCallback(GLFWwindow* handle, GLFWcharmodsfun cbfun) 475 | { 476 | _GLFWwindow* window = (_GLFWwindow*) handle; 477 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 478 | _GLFW_SWAP_POINTERS(window->callbacks.charmods, cbfun); 479 | return cbfun; 480 | } 481 | 482 | GLFWAPI GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* handle, 483 | GLFWmousebuttonfun cbfun) 484 | { 485 | _GLFWwindow* window = (_GLFWwindow*) handle; 486 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 487 | _GLFW_SWAP_POINTERS(window->callbacks.mouseButton, cbfun); 488 | return cbfun; 489 | } 490 | 491 | GLFWAPI GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow* handle, 492 | GLFWcursorposfun cbfun) 493 | { 494 | _GLFWwindow* window = (_GLFWwindow*) handle; 495 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 496 | _GLFW_SWAP_POINTERS(window->callbacks.cursorPos, cbfun); 497 | return cbfun; 498 | } 499 | 500 | GLFWAPI GLFWcursorenterfun glfwSetCursorEnterCallback(GLFWwindow* handle, 501 | GLFWcursorenterfun cbfun) 502 | { 503 | _GLFWwindow* window = (_GLFWwindow*) handle; 504 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 505 | _GLFW_SWAP_POINTERS(window->callbacks.cursorEnter, cbfun); 506 | return cbfun; 507 | } 508 | 509 | GLFWAPI GLFWscrollfun glfwSetScrollCallback(GLFWwindow* handle, 510 | GLFWscrollfun cbfun) 511 | { 512 | _GLFWwindow* window = (_GLFWwindow*) handle; 513 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 514 | _GLFW_SWAP_POINTERS(window->callbacks.scroll, cbfun); 515 | return cbfun; 516 | } 517 | 518 | GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* handle, GLFWdropfun cbfun) 519 | { 520 | _GLFWwindow* window = (_GLFWwindow*) handle; 521 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 522 | _GLFW_SWAP_POINTERS(window->callbacks.drop, cbfun); 523 | return cbfun; 524 | } 525 | 526 | GLFWAPI int glfwJoystickPresent(int joy) 527 | { 528 | _GLFW_REQUIRE_INIT_OR_RETURN(0); 529 | 530 | if (joy < 0 || joy > GLFW_JOYSTICK_LAST) 531 | { 532 | _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick"); 533 | return 0; 534 | } 535 | 536 | return _glfwPlatformJoystickPresent(joy); 537 | } 538 | 539 | GLFWAPI const float* glfwGetJoystickAxes(int joy, int* count) 540 | { 541 | *count = 0; 542 | 543 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 544 | 545 | if (joy < 0 || joy > GLFW_JOYSTICK_LAST) 546 | { 547 | _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick"); 548 | return NULL; 549 | } 550 | 551 | return _glfwPlatformGetJoystickAxes(joy, count); 552 | } 553 | 554 | GLFWAPI const unsigned char* glfwGetJoystickButtons(int joy, int* count) 555 | { 556 | *count = 0; 557 | 558 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 559 | 560 | if (joy < 0 || joy > GLFW_JOYSTICK_LAST) 561 | { 562 | _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick"); 563 | return NULL; 564 | } 565 | 566 | return _glfwPlatformGetJoystickButtons(joy, count); 567 | } 568 | 569 | GLFWAPI const char* glfwGetJoystickName(int joy) 570 | { 571 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 572 | 573 | if (joy < 0 || joy > GLFW_JOYSTICK_LAST) 574 | { 575 | _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick"); 576 | return NULL; 577 | } 578 | 579 | return _glfwPlatformGetJoystickName(joy); 580 | } 581 | 582 | GLFWAPI void glfwSetClipboardString(GLFWwindow* handle, const char* string) 583 | { 584 | _GLFWwindow* window = (_GLFWwindow*) handle; 585 | _GLFW_REQUIRE_INIT(); 586 | _glfwPlatformSetClipboardString(window, string); 587 | } 588 | 589 | GLFWAPI const char* glfwGetClipboardString(GLFWwindow* handle) 590 | { 591 | _GLFWwindow* window = (_GLFWwindow*) handle; 592 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 593 | return _glfwPlatformGetClipboardString(window); 594 | } 595 | 596 | GLFWAPI double glfwGetTime(void) 597 | { 598 | _GLFW_REQUIRE_INIT_OR_RETURN(0.0); 599 | return _glfwPlatformGetTime(); 600 | } 601 | 602 | GLFWAPI void glfwSetTime(double time) 603 | { 604 | _GLFW_REQUIRE_INIT(); 605 | 606 | if (time != time || time < 0.0 || time > 18446744073.0) 607 | { 608 | _glfwInputError(GLFW_INVALID_VALUE, "Invalid time"); 609 | return; 610 | } 611 | 612 | _glfwPlatformSetTime(time); 613 | } 614 | 615 | -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/glfw-3.1.2/src/monitor.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 Camilla Berglund 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | 37 | // Lexical comparison function for GLFW video modes, used by qsort 38 | // 39 | static int compareVideoModes(const void* firstPtr, const void* secondPtr) 40 | { 41 | int firstBPP, secondBPP, firstSize, secondSize; 42 | const GLFWvidmode* first = firstPtr; 43 | const GLFWvidmode* second = secondPtr; 44 | 45 | // First sort on color bits per pixel 46 | firstBPP = first->redBits + first->greenBits + first->blueBits; 47 | secondBPP = second->redBits + second->greenBits + second->blueBits; 48 | if (firstBPP != secondBPP) 49 | return firstBPP - secondBPP; 50 | 51 | // Then sort on screen area, in pixels 52 | firstSize = first->width * first->height; 53 | secondSize = second->width * second->height; 54 | if (firstSize != secondSize) 55 | return firstSize - secondSize; 56 | 57 | // Lastly sort on refresh rate 58 | return first->refreshRate - second->refreshRate; 59 | } 60 | 61 | // Retrieves the available modes for the specified monitor 62 | // 63 | static int refreshVideoModes(_GLFWmonitor* monitor) 64 | { 65 | int modeCount; 66 | GLFWvidmode* modes; 67 | 68 | if (monitor->modes) 69 | return GL_TRUE; 70 | 71 | modes = _glfwPlatformGetVideoModes(monitor, &modeCount); 72 | if (!modes) 73 | return GL_FALSE; 74 | 75 | qsort(modes, modeCount, sizeof(GLFWvidmode), compareVideoModes); 76 | 77 | free(monitor->modes); 78 | monitor->modes = modes; 79 | monitor->modeCount = modeCount; 80 | 81 | return GL_TRUE; 82 | } 83 | 84 | 85 | ////////////////////////////////////////////////////////////////////////// 86 | ////// GLFW event API ////// 87 | ////////////////////////////////////////////////////////////////////////// 88 | 89 | void _glfwInputMonitorChange(void) 90 | { 91 | int i, j, monitorCount = _glfw.monitorCount; 92 | _GLFWmonitor** monitors = _glfw.monitors; 93 | 94 | _glfw.monitors = _glfwPlatformGetMonitors(&_glfw.monitorCount); 95 | 96 | // Re-use still connected monitor objects 97 | 98 | for (i = 0; i < _glfw.monitorCount; i++) 99 | { 100 | for (j = 0; j < monitorCount; j++) 101 | { 102 | if (_glfwPlatformIsSameMonitor(_glfw.monitors[i], monitors[j])) 103 | { 104 | _glfwFreeMonitor(_glfw.monitors[i]); 105 | _glfw.monitors[i] = monitors[j]; 106 | break; 107 | } 108 | } 109 | } 110 | 111 | // Find and report disconnected monitors (not in the new list) 112 | 113 | for (i = 0; i < monitorCount; i++) 114 | { 115 | _GLFWwindow* window; 116 | 117 | for (j = 0; j < _glfw.monitorCount; j++) 118 | { 119 | if (monitors[i] == _glfw.monitors[j]) 120 | break; 121 | } 122 | 123 | if (j < _glfw.monitorCount) 124 | continue; 125 | 126 | for (window = _glfw.windowListHead; window; window = window->next) 127 | { 128 | if (window->monitor == monitors[i]) 129 | window->monitor = NULL; 130 | } 131 | 132 | if (_glfw.callbacks.monitor) 133 | _glfw.callbacks.monitor((GLFWmonitor*) monitors[i], GLFW_DISCONNECTED); 134 | } 135 | 136 | // Find and report newly connected monitors (not in the old list) 137 | // Re-used monitor objects are then removed from the old list to avoid 138 | // having them destroyed at the end of this function 139 | 140 | for (i = 0; i < _glfw.monitorCount; i++) 141 | { 142 | for (j = 0; j < monitorCount; j++) 143 | { 144 | if (_glfw.monitors[i] == monitors[j]) 145 | { 146 | monitors[j] = NULL; 147 | break; 148 | } 149 | } 150 | 151 | if (j < monitorCount) 152 | continue; 153 | 154 | if (_glfw.callbacks.monitor) 155 | _glfw.callbacks.monitor((GLFWmonitor*) _glfw.monitors[i], GLFW_CONNECTED); 156 | } 157 | 158 | _glfwFreeMonitors(monitors, monitorCount); 159 | } 160 | 161 | 162 | ////////////////////////////////////////////////////////////////////////// 163 | ////// GLFW internal API ////// 164 | ////////////////////////////////////////////////////////////////////////// 165 | 166 | _GLFWmonitor* _glfwAllocMonitor(const char* name, int widthMM, int heightMM) 167 | { 168 | _GLFWmonitor* monitor = calloc(1, sizeof(_GLFWmonitor)); 169 | monitor->name = strdup(name); 170 | monitor->widthMM = widthMM; 171 | monitor->heightMM = heightMM; 172 | 173 | return monitor; 174 | } 175 | 176 | void _glfwFreeMonitor(_GLFWmonitor* monitor) 177 | { 178 | if (monitor == NULL) 179 | return; 180 | 181 | _glfwFreeGammaArrays(&monitor->originalRamp); 182 | _glfwFreeGammaArrays(&monitor->currentRamp); 183 | 184 | free(monitor->modes); 185 | free(monitor->name); 186 | free(monitor); 187 | } 188 | 189 | void _glfwAllocGammaArrays(GLFWgammaramp* ramp, unsigned int size) 190 | { 191 | ramp->red = calloc(size, sizeof(unsigned short)); 192 | ramp->green = calloc(size, sizeof(unsigned short)); 193 | ramp->blue = calloc(size, sizeof(unsigned short)); 194 | ramp->size = size; 195 | } 196 | 197 | void _glfwFreeGammaArrays(GLFWgammaramp* ramp) 198 | { 199 | free(ramp->red); 200 | free(ramp->green); 201 | free(ramp->blue); 202 | 203 | memset(ramp, 0, sizeof(GLFWgammaramp)); 204 | } 205 | 206 | void _glfwFreeMonitors(_GLFWmonitor** monitors, int count) 207 | { 208 | int i; 209 | 210 | for (i = 0; i < count; i++) 211 | _glfwFreeMonitor(monitors[i]); 212 | 213 | free(monitors); 214 | } 215 | 216 | const GLFWvidmode* _glfwChooseVideoMode(_GLFWmonitor* monitor, 217 | const GLFWvidmode* desired) 218 | { 219 | int i; 220 | unsigned int sizeDiff, leastSizeDiff = UINT_MAX; 221 | unsigned int rateDiff, leastRateDiff = UINT_MAX; 222 | unsigned int colorDiff, leastColorDiff = UINT_MAX; 223 | const GLFWvidmode* current; 224 | const GLFWvidmode* closest = NULL; 225 | 226 | if (!refreshVideoModes(monitor)) 227 | return NULL; 228 | 229 | for (i = 0; i < monitor->modeCount; i++) 230 | { 231 | current = monitor->modes + i; 232 | 233 | colorDiff = 0; 234 | 235 | if (desired->redBits != GLFW_DONT_CARE) 236 | colorDiff += abs(current->redBits - desired->redBits); 237 | if (desired->greenBits != GLFW_DONT_CARE) 238 | colorDiff += abs(current->greenBits - desired->greenBits); 239 | if (desired->blueBits != GLFW_DONT_CARE) 240 | colorDiff += abs(current->blueBits - desired->blueBits); 241 | 242 | sizeDiff = abs((current->width - desired->width) * 243 | (current->width - desired->width) + 244 | (current->height - desired->height) * 245 | (current->height - desired->height)); 246 | 247 | if (desired->refreshRate != GLFW_DONT_CARE) 248 | rateDiff = abs(current->refreshRate - desired->refreshRate); 249 | else 250 | rateDiff = UINT_MAX - current->refreshRate; 251 | 252 | if ((colorDiff < leastColorDiff) || 253 | (colorDiff == leastColorDiff && sizeDiff < leastSizeDiff) || 254 | (colorDiff == leastColorDiff && sizeDiff == leastSizeDiff && rateDiff < leastRateDiff)) 255 | { 256 | closest = current; 257 | leastSizeDiff = sizeDiff; 258 | leastRateDiff = rateDiff; 259 | leastColorDiff = colorDiff; 260 | } 261 | } 262 | 263 | return closest; 264 | } 265 | 266 | int _glfwCompareVideoModes(const GLFWvidmode* first, const GLFWvidmode* second) 267 | { 268 | return compareVideoModes(first, second); 269 | } 270 | 271 | void _glfwSplitBPP(int bpp, int* red, int* green, int* blue) 272 | { 273 | int delta; 274 | 275 | // We assume that by 32 the user really meant 24 276 | if (bpp == 32) 277 | bpp = 24; 278 | 279 | // Convert "bits per pixel" to red, green & blue sizes 280 | 281 | *red = *green = *blue = bpp / 3; 282 | delta = bpp - (*red * 3); 283 | if (delta >= 1) 284 | *green = *green + 1; 285 | 286 | if (delta == 2) 287 | *red = *red + 1; 288 | } 289 | 290 | 291 | ////////////////////////////////////////////////////////////////////////// 292 | ////// GLFW public API ////// 293 | ////////////////////////////////////////////////////////////////////////// 294 | 295 | GLFWAPI GLFWmonitor** glfwGetMonitors(int* count) 296 | { 297 | *count = 0; 298 | 299 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 300 | 301 | *count = _glfw.monitorCount; 302 | return (GLFWmonitor**) _glfw.monitors; 303 | } 304 | 305 | GLFWAPI GLFWmonitor* glfwGetPrimaryMonitor(void) 306 | { 307 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 308 | 309 | if (!_glfw.monitorCount) 310 | return NULL; 311 | 312 | return (GLFWmonitor*) _glfw.monitors[0]; 313 | } 314 | 315 | GLFWAPI void glfwGetMonitorPos(GLFWmonitor* handle, int* xpos, int* ypos) 316 | { 317 | _GLFWmonitor* monitor = (_GLFWmonitor*) handle; 318 | 319 | if (xpos) 320 | *xpos = 0; 321 | if (ypos) 322 | *ypos = 0; 323 | 324 | _GLFW_REQUIRE_INIT(); 325 | 326 | _glfwPlatformGetMonitorPos(monitor, xpos, ypos); 327 | } 328 | 329 | GLFWAPI void glfwGetMonitorPhysicalSize(GLFWmonitor* handle, int* widthMM, int* heightMM) 330 | { 331 | _GLFWmonitor* monitor = (_GLFWmonitor*) handle; 332 | 333 | if (widthMM) 334 | *widthMM = 0; 335 | if (heightMM) 336 | *heightMM = 0; 337 | 338 | _GLFW_REQUIRE_INIT(); 339 | 340 | if (widthMM) 341 | *widthMM = monitor->widthMM; 342 | if (heightMM) 343 | *heightMM = monitor->heightMM; 344 | } 345 | 346 | GLFWAPI const char* glfwGetMonitorName(GLFWmonitor* handle) 347 | { 348 | _GLFWmonitor* monitor = (_GLFWmonitor*) handle; 349 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 350 | return monitor->name; 351 | } 352 | 353 | GLFWAPI GLFWmonitorfun glfwSetMonitorCallback(GLFWmonitorfun cbfun) 354 | { 355 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 356 | _GLFW_SWAP_POINTERS(_glfw.callbacks.monitor, cbfun); 357 | return cbfun; 358 | } 359 | 360 | GLFWAPI const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* handle, int* count) 361 | { 362 | _GLFWmonitor* monitor = (_GLFWmonitor*) handle; 363 | 364 | *count = 0; 365 | 366 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 367 | 368 | if (!refreshVideoModes(monitor)) 369 | return NULL; 370 | 371 | *count = monitor->modeCount; 372 | return monitor->modes; 373 | } 374 | 375 | GLFWAPI const GLFWvidmode* glfwGetVideoMode(GLFWmonitor* handle) 376 | { 377 | _GLFWmonitor* monitor = (_GLFWmonitor*) handle; 378 | 379 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 380 | 381 | _glfwPlatformGetVideoMode(monitor, &monitor->currentMode); 382 | return &monitor->currentMode; 383 | } 384 | 385 | GLFWAPI void glfwSetGamma(GLFWmonitor* handle, float gamma) 386 | { 387 | int i; 388 | unsigned short values[256]; 389 | GLFWgammaramp ramp; 390 | 391 | _GLFW_REQUIRE_INIT(); 392 | 393 | if (gamma != gamma || gamma <= 0.f || gamma > FLT_MAX) 394 | { 395 | _glfwInputError(GLFW_INVALID_VALUE, "Invalid gamma value"); 396 | return; 397 | } 398 | 399 | for (i = 0; i < 256; i++) 400 | { 401 | double value; 402 | 403 | // Calculate intensity 404 | value = i / 255.0; 405 | // Apply gamma curve 406 | value = pow(value, 1.0 / gamma) * 65535.0 + 0.5; 407 | 408 | // Clamp to value range 409 | if (value > 65535.0) 410 | value = 65535.0; 411 | 412 | values[i] = (unsigned short) value; 413 | } 414 | 415 | ramp.red = values; 416 | ramp.green = values; 417 | ramp.blue = values; 418 | ramp.size = 256; 419 | 420 | glfwSetGammaRamp(handle, &ramp); 421 | } 422 | 423 | GLFWAPI const GLFWgammaramp* glfwGetGammaRamp(GLFWmonitor* handle) 424 | { 425 | _GLFWmonitor* monitor = (_GLFWmonitor*) handle; 426 | 427 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 428 | 429 | _glfwFreeGammaArrays(&monitor->currentRamp); 430 | _glfwPlatformGetGammaRamp(monitor, &monitor->currentRamp); 431 | 432 | return &monitor->currentRamp; 433 | } 434 | 435 | GLFWAPI void glfwSetGammaRamp(GLFWmonitor* handle, const GLFWgammaramp* ramp) 436 | { 437 | _GLFWmonitor* monitor = (_GLFWmonitor*) handle; 438 | 439 | _GLFW_REQUIRE_INIT(); 440 | 441 | if (!monitor->originalRamp.size) 442 | _glfwPlatformGetGammaRamp(monitor, &monitor->originalRamp); 443 | 444 | _glfwPlatformSetGammaRamp(monitor, ramp); 445 | } 446 | 447 | -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/glfw-3.1.2/src/wgl_context.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 WGL - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 Camilla Berglund 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #ifndef _glfw3_wgl_context_h_ 29 | #define _glfw3_wgl_context_h_ 30 | 31 | // This path may need to be changed if you build GLFW using your own setup 32 | // We ship and use our own copy of wglext.h since GLFW uses fairly new 33 | // extensions and not all operating systems come with an up-to-date version 34 | #include "../deps/GL/wglext.h" 35 | 36 | // opengl32.dll function pointer typedefs 37 | typedef HGLRC (WINAPI * WGLCREATECONTEXT_T)(HDC); 38 | typedef BOOL (WINAPI * WGLDELETECONTEXT_T)(HGLRC); 39 | typedef PROC (WINAPI * WGLGETPROCADDRESS_T)(LPCSTR); 40 | typedef BOOL (WINAPI * WGLMAKECURRENT_T)(HDC,HGLRC); 41 | typedef BOOL (WINAPI * WGLSHARELISTS_T)(HGLRC,HGLRC); 42 | #define _glfw_wglCreateContext _glfw.wgl.opengl32.CreateContext 43 | #define _glfw_wglDeleteContext _glfw.wgl.opengl32.DeleteContext 44 | #define _glfw_wglGetProcAddress _glfw.wgl.opengl32.GetProcAddress 45 | #define _glfw_wglMakeCurrent _glfw.wgl.opengl32.MakeCurrent 46 | #define _glfw_wglShareLists _glfw.wgl.opengl32.ShareLists 47 | 48 | #define _GLFW_PLATFORM_FBCONFIG int wgl 49 | #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextWGL wgl 50 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryWGL wgl 51 | 52 | 53 | // WGL-specific per-context data 54 | // 55 | typedef struct _GLFWcontextWGL 56 | { 57 | HDC dc; // Private GDI device context 58 | HGLRC context; // Permanent rendering context 59 | int interval; 60 | 61 | // WGL extensions (context specific) 62 | PFNWGLSWAPINTERVALEXTPROC SwapIntervalEXT; 63 | PFNWGLGETPIXELFORMATATTRIBIVARBPROC GetPixelFormatAttribivARB; 64 | PFNWGLGETEXTENSIONSSTRINGEXTPROC GetExtensionsStringEXT; 65 | PFNWGLGETEXTENSIONSSTRINGARBPROC GetExtensionsStringARB; 66 | PFNWGLCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB; 67 | GLboolean EXT_swap_control; 68 | GLboolean ARB_multisample; 69 | GLboolean ARB_framebuffer_sRGB; 70 | GLboolean EXT_framebuffer_sRGB; 71 | GLboolean ARB_pixel_format; 72 | GLboolean ARB_create_context; 73 | GLboolean ARB_create_context_profile; 74 | GLboolean EXT_create_context_es2_profile; 75 | GLboolean ARB_create_context_robustness; 76 | GLboolean ARB_context_flush_control; 77 | 78 | } _GLFWcontextWGL; 79 | 80 | 81 | // WGL-specific global data 82 | // 83 | typedef struct _GLFWlibraryWGL 84 | { 85 | struct { 86 | HINSTANCE instance; 87 | WGLCREATECONTEXT_T CreateContext; 88 | WGLDELETECONTEXT_T DeleteContext; 89 | WGLGETPROCADDRESS_T GetProcAddress; 90 | WGLMAKECURRENT_T MakeCurrent; 91 | WGLSHARELISTS_T ShareLists; 92 | } opengl32; 93 | 94 | } _GLFWlibraryWGL; 95 | 96 | 97 | int _glfwInitContextAPI(void); 98 | void _glfwTerminateContextAPI(void); 99 | int _glfwCreateContext(_GLFWwindow* window, 100 | const _GLFWctxconfig* ctxconfig, 101 | const _GLFWfbconfig* fbconfig); 102 | void _glfwDestroyContext(_GLFWwindow* window); 103 | int _glfwAnalyzeContext(const _GLFWwindow* window, 104 | const _GLFWctxconfig* ctxconfig, 105 | const _GLFWfbconfig* fbconfig); 106 | 107 | #endif // _glfw3_wgl_context_h_ 108 | -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/glfw-3.1.2/src/win32_init.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 Camilla Berglund 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | 30 | #include 31 | #include 32 | 33 | 34 | #if defined(_GLFW_USE_HYBRID_HPG) || defined(_GLFW_USE_OPTIMUS_HPG) 35 | 36 | // Applications exporting this symbol with this value will be automatically 37 | // directed to the high-performance GPU on Nvidia Optimus systems with 38 | // up-to-date drivers 39 | // 40 | __declspec(dllexport) DWORD NvOptimusEnablement = 1; 41 | 42 | // Applications exporting this symbol with this value will be automatically 43 | // directed to the high-performance GPU on AMD PowerXpress systems with 44 | // up-to-date drivers 45 | // 46 | __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; 47 | 48 | #endif // _GLFW_USE_HYBRID_HPG 49 | 50 | #if defined(_GLFW_BUILD_DLL) 51 | 52 | // GLFW DLL entry point 53 | // 54 | BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) 55 | { 56 | return TRUE; 57 | } 58 | 59 | #endif // _GLFW_BUILD_DLL 60 | 61 | // Load necessary libraries (DLLs) 62 | // 63 | static GLboolean initLibraries(void) 64 | { 65 | _glfw.win32.winmm.instance = LoadLibraryW(L"winmm.dll"); 66 | if (!_glfw.win32.winmm.instance) 67 | { 68 | _glfwInputError(GLFW_PLATFORM_ERROR, 69 | "Win32: Failed to load winmm.dll"); 70 | return GL_FALSE; 71 | } 72 | 73 | _glfw.win32.winmm.joyGetDevCaps = (JOYGETDEVCAPS_T) 74 | GetProcAddress(_glfw.win32.winmm.instance, "joyGetDevCapsW"); 75 | _glfw.win32.winmm.joyGetPos = (JOYGETPOS_T) 76 | GetProcAddress(_glfw.win32.winmm.instance, "joyGetPos"); 77 | _glfw.win32.winmm.joyGetPosEx = (JOYGETPOSEX_T) 78 | GetProcAddress(_glfw.win32.winmm.instance, "joyGetPosEx"); 79 | _glfw.win32.winmm.timeGetTime = (TIMEGETTIME_T) 80 | GetProcAddress(_glfw.win32.winmm.instance, "timeGetTime"); 81 | 82 | if (!_glfw.win32.winmm.joyGetDevCaps || 83 | !_glfw.win32.winmm.joyGetPos || 84 | !_glfw.win32.winmm.joyGetPosEx || 85 | !_glfw.win32.winmm.timeGetTime) 86 | { 87 | _glfwInputError(GLFW_PLATFORM_ERROR, 88 | "Win32: Failed to load winmm functions"); 89 | return GL_FALSE; 90 | } 91 | 92 | _glfw.win32.user32.instance = LoadLibraryW(L"user32.dll"); 93 | if (_glfw.win32.user32.instance) 94 | { 95 | _glfw.win32.user32.SetProcessDPIAware = (SETPROCESSDPIAWARE_T) 96 | GetProcAddress(_glfw.win32.user32.instance, "SetProcessDPIAware"); 97 | _glfw.win32.user32.ChangeWindowMessageFilterEx = (CHANGEWINDOWMESSAGEFILTEREX_T) 98 | GetProcAddress(_glfw.win32.user32.instance, "ChangeWindowMessageFilterEx"); 99 | } 100 | 101 | _glfw.win32.dwmapi.instance = LoadLibraryW(L"dwmapi.dll"); 102 | if (_glfw.win32.dwmapi.instance) 103 | { 104 | _glfw.win32.dwmapi.DwmIsCompositionEnabled = (DWMISCOMPOSITIONENABLED_T) 105 | GetProcAddress(_glfw.win32.dwmapi.instance, "DwmIsCompositionEnabled"); 106 | _glfw.win32.dwmapi.DwmFlush = (DWMFLUSH_T) 107 | GetProcAddress(_glfw.win32.dwmapi.instance, "DwmFlush"); 108 | } 109 | 110 | return GL_TRUE; 111 | } 112 | 113 | // Unload used libraries (DLLs) 114 | // 115 | static void terminateLibraries(void) 116 | { 117 | if (_glfw.win32.winmm.instance) 118 | FreeLibrary(_glfw.win32.winmm.instance); 119 | 120 | if (_glfw.win32.user32.instance) 121 | FreeLibrary(_glfw.win32.user32.instance); 122 | 123 | if (_glfw.win32.dwmapi.instance) 124 | FreeLibrary(_glfw.win32.dwmapi.instance); 125 | } 126 | 127 | // Create key code translation tables 128 | // 129 | static void createKeyTables(void) 130 | { 131 | memset(_glfw.win32.publicKeys, -1, sizeof(_glfw.win32.publicKeys)); 132 | 133 | _glfw.win32.publicKeys[0x00B] = GLFW_KEY_0; 134 | _glfw.win32.publicKeys[0x002] = GLFW_KEY_1; 135 | _glfw.win32.publicKeys[0x003] = GLFW_KEY_2; 136 | _glfw.win32.publicKeys[0x004] = GLFW_KEY_3; 137 | _glfw.win32.publicKeys[0x005] = GLFW_KEY_4; 138 | _glfw.win32.publicKeys[0x006] = GLFW_KEY_5; 139 | _glfw.win32.publicKeys[0x007] = GLFW_KEY_6; 140 | _glfw.win32.publicKeys[0x008] = GLFW_KEY_7; 141 | _glfw.win32.publicKeys[0x009] = GLFW_KEY_8; 142 | _glfw.win32.publicKeys[0x00A] = GLFW_KEY_9; 143 | _glfw.win32.publicKeys[0x01E] = GLFW_KEY_A; 144 | _glfw.win32.publicKeys[0x030] = GLFW_KEY_B; 145 | _glfw.win32.publicKeys[0x02E] = GLFW_KEY_C; 146 | _glfw.win32.publicKeys[0x020] = GLFW_KEY_D; 147 | _glfw.win32.publicKeys[0x012] = GLFW_KEY_E; 148 | _glfw.win32.publicKeys[0x021] = GLFW_KEY_F; 149 | _glfw.win32.publicKeys[0x022] = GLFW_KEY_G; 150 | _glfw.win32.publicKeys[0x023] = GLFW_KEY_H; 151 | _glfw.win32.publicKeys[0x017] = GLFW_KEY_I; 152 | _glfw.win32.publicKeys[0x024] = GLFW_KEY_J; 153 | _glfw.win32.publicKeys[0x025] = GLFW_KEY_K; 154 | _glfw.win32.publicKeys[0x026] = GLFW_KEY_L; 155 | _glfw.win32.publicKeys[0x032] = GLFW_KEY_M; 156 | _glfw.win32.publicKeys[0x031] = GLFW_KEY_N; 157 | _glfw.win32.publicKeys[0x018] = GLFW_KEY_O; 158 | _glfw.win32.publicKeys[0x019] = GLFW_KEY_P; 159 | _glfw.win32.publicKeys[0x010] = GLFW_KEY_Q; 160 | _glfw.win32.publicKeys[0x013] = GLFW_KEY_R; 161 | _glfw.win32.publicKeys[0x01F] = GLFW_KEY_S; 162 | _glfw.win32.publicKeys[0x014] = GLFW_KEY_T; 163 | _glfw.win32.publicKeys[0x016] = GLFW_KEY_U; 164 | _glfw.win32.publicKeys[0x02F] = GLFW_KEY_V; 165 | _glfw.win32.publicKeys[0x011] = GLFW_KEY_W; 166 | _glfw.win32.publicKeys[0x02D] = GLFW_KEY_X; 167 | _glfw.win32.publicKeys[0x015] = GLFW_KEY_Y; 168 | _glfw.win32.publicKeys[0x02C] = GLFW_KEY_Z; 169 | 170 | _glfw.win32.publicKeys[0x028] = GLFW_KEY_APOSTROPHE; 171 | _glfw.win32.publicKeys[0x02B] = GLFW_KEY_BACKSLASH; 172 | _glfw.win32.publicKeys[0x033] = GLFW_KEY_COMMA; 173 | _glfw.win32.publicKeys[0x00D] = GLFW_KEY_EQUAL; 174 | _glfw.win32.publicKeys[0x029] = GLFW_KEY_GRAVE_ACCENT; 175 | _glfw.win32.publicKeys[0x01A] = GLFW_KEY_LEFT_BRACKET; 176 | _glfw.win32.publicKeys[0x00C] = GLFW_KEY_MINUS; 177 | _glfw.win32.publicKeys[0x034] = GLFW_KEY_PERIOD; 178 | _glfw.win32.publicKeys[0x01B] = GLFW_KEY_RIGHT_BRACKET; 179 | _glfw.win32.publicKeys[0x027] = GLFW_KEY_SEMICOLON; 180 | _glfw.win32.publicKeys[0x035] = GLFW_KEY_SLASH; 181 | _glfw.win32.publicKeys[0x056] = GLFW_KEY_WORLD_2; 182 | 183 | _glfw.win32.publicKeys[0x00E] = GLFW_KEY_BACKSPACE; 184 | _glfw.win32.publicKeys[0x153] = GLFW_KEY_DELETE; 185 | _glfw.win32.publicKeys[0x14F] = GLFW_KEY_END; 186 | _glfw.win32.publicKeys[0x01C] = GLFW_KEY_ENTER; 187 | _glfw.win32.publicKeys[0x001] = GLFW_KEY_ESCAPE; 188 | _glfw.win32.publicKeys[0x147] = GLFW_KEY_HOME; 189 | _glfw.win32.publicKeys[0x152] = GLFW_KEY_INSERT; 190 | _glfw.win32.publicKeys[0x15D] = GLFW_KEY_MENU; 191 | _glfw.win32.publicKeys[0x151] = GLFW_KEY_PAGE_DOWN; 192 | _glfw.win32.publicKeys[0x149] = GLFW_KEY_PAGE_UP; 193 | _glfw.win32.publicKeys[0x045] = GLFW_KEY_PAUSE; 194 | _glfw.win32.publicKeys[0x039] = GLFW_KEY_SPACE; 195 | _glfw.win32.publicKeys[0x00F] = GLFW_KEY_TAB; 196 | _glfw.win32.publicKeys[0x03A] = GLFW_KEY_CAPS_LOCK; 197 | _glfw.win32.publicKeys[0x145] = GLFW_KEY_NUM_LOCK; 198 | _glfw.win32.publicKeys[0x046] = GLFW_KEY_SCROLL_LOCK; 199 | _glfw.win32.publicKeys[0x03B] = GLFW_KEY_F1; 200 | _glfw.win32.publicKeys[0x03C] = GLFW_KEY_F2; 201 | _glfw.win32.publicKeys[0x03D] = GLFW_KEY_F3; 202 | _glfw.win32.publicKeys[0x03E] = GLFW_KEY_F4; 203 | _glfw.win32.publicKeys[0x03F] = GLFW_KEY_F5; 204 | _glfw.win32.publicKeys[0x040] = GLFW_KEY_F6; 205 | _glfw.win32.publicKeys[0x041] = GLFW_KEY_F7; 206 | _glfw.win32.publicKeys[0x042] = GLFW_KEY_F8; 207 | _glfw.win32.publicKeys[0x043] = GLFW_KEY_F9; 208 | _glfw.win32.publicKeys[0x044] = GLFW_KEY_F10; 209 | _glfw.win32.publicKeys[0x057] = GLFW_KEY_F11; 210 | _glfw.win32.publicKeys[0x058] = GLFW_KEY_F12; 211 | _glfw.win32.publicKeys[0x064] = GLFW_KEY_F13; 212 | _glfw.win32.publicKeys[0x065] = GLFW_KEY_F14; 213 | _glfw.win32.publicKeys[0x066] = GLFW_KEY_F15; 214 | _glfw.win32.publicKeys[0x067] = GLFW_KEY_F16; 215 | _glfw.win32.publicKeys[0x068] = GLFW_KEY_F17; 216 | _glfw.win32.publicKeys[0x069] = GLFW_KEY_F18; 217 | _glfw.win32.publicKeys[0x06A] = GLFW_KEY_F19; 218 | _glfw.win32.publicKeys[0x06B] = GLFW_KEY_F20; 219 | _glfw.win32.publicKeys[0x06C] = GLFW_KEY_F21; 220 | _glfw.win32.publicKeys[0x06D] = GLFW_KEY_F22; 221 | _glfw.win32.publicKeys[0x06E] = GLFW_KEY_F23; 222 | _glfw.win32.publicKeys[0x076] = GLFW_KEY_F24; 223 | _glfw.win32.publicKeys[0x038] = GLFW_KEY_LEFT_ALT; 224 | _glfw.win32.publicKeys[0x01D] = GLFW_KEY_LEFT_CONTROL; 225 | _glfw.win32.publicKeys[0x02A] = GLFW_KEY_LEFT_SHIFT; 226 | _glfw.win32.publicKeys[0x15B] = GLFW_KEY_LEFT_SUPER; 227 | _glfw.win32.publicKeys[0x137] = GLFW_KEY_PRINT_SCREEN; 228 | _glfw.win32.publicKeys[0x138] = GLFW_KEY_RIGHT_ALT; 229 | _glfw.win32.publicKeys[0x11D] = GLFW_KEY_RIGHT_CONTROL; 230 | _glfw.win32.publicKeys[0x036] = GLFW_KEY_RIGHT_SHIFT; 231 | _glfw.win32.publicKeys[0x15C] = GLFW_KEY_RIGHT_SUPER; 232 | _glfw.win32.publicKeys[0x150] = GLFW_KEY_DOWN; 233 | _glfw.win32.publicKeys[0x14B] = GLFW_KEY_LEFT; 234 | _glfw.win32.publicKeys[0x14D] = GLFW_KEY_RIGHT; 235 | _glfw.win32.publicKeys[0x148] = GLFW_KEY_UP; 236 | 237 | _glfw.win32.publicKeys[0x052] = GLFW_KEY_KP_0; 238 | _glfw.win32.publicKeys[0x04F] = GLFW_KEY_KP_1; 239 | _glfw.win32.publicKeys[0x050] = GLFW_KEY_KP_2; 240 | _glfw.win32.publicKeys[0x051] = GLFW_KEY_KP_3; 241 | _glfw.win32.publicKeys[0x04B] = GLFW_KEY_KP_4; 242 | _glfw.win32.publicKeys[0x04C] = GLFW_KEY_KP_5; 243 | _glfw.win32.publicKeys[0x04D] = GLFW_KEY_KP_6; 244 | _glfw.win32.publicKeys[0x047] = GLFW_KEY_KP_7; 245 | _glfw.win32.publicKeys[0x048] = GLFW_KEY_KP_8; 246 | _glfw.win32.publicKeys[0x049] = GLFW_KEY_KP_9; 247 | _glfw.win32.publicKeys[0x04E] = GLFW_KEY_KP_ADD; 248 | _glfw.win32.publicKeys[0x053] = GLFW_KEY_KP_DECIMAL; 249 | _glfw.win32.publicKeys[0x135] = GLFW_KEY_KP_DIVIDE; 250 | _glfw.win32.publicKeys[0x11C] = GLFW_KEY_KP_ENTER; 251 | _glfw.win32.publicKeys[0x037] = GLFW_KEY_KP_MULTIPLY; 252 | _glfw.win32.publicKeys[0x04A] = GLFW_KEY_KP_SUBTRACT; 253 | } 254 | 255 | 256 | ////////////////////////////////////////////////////////////////////////// 257 | ////// GLFW internal API ////// 258 | ////////////////////////////////////////////////////////////////////////// 259 | 260 | // Returns whether desktop compositing is enabled 261 | // 262 | BOOL _glfwIsCompositionEnabled(void) 263 | { 264 | BOOL enabled; 265 | 266 | if (!_glfw_DwmIsCompositionEnabled) 267 | return FALSE; 268 | 269 | if (_glfw_DwmIsCompositionEnabled(&enabled) != S_OK) 270 | return FALSE; 271 | 272 | return enabled; 273 | } 274 | 275 | // Returns a wide string version of the specified UTF-8 string 276 | // 277 | WCHAR* _glfwCreateWideStringFromUTF8(const char* source) 278 | { 279 | WCHAR* target; 280 | int length; 281 | 282 | length = MultiByteToWideChar(CP_UTF8, 0, source, -1, NULL, 0); 283 | if (!length) 284 | return NULL; 285 | 286 | target = calloc(length, sizeof(WCHAR)); 287 | 288 | if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, length)) 289 | { 290 | free(target); 291 | return NULL; 292 | } 293 | 294 | return target; 295 | } 296 | 297 | // Returns a UTF-8 string version of the specified wide string 298 | // 299 | char* _glfwCreateUTF8FromWideString(const WCHAR* source) 300 | { 301 | char* target; 302 | int length; 303 | 304 | length = WideCharToMultiByte(CP_UTF8, 0, source, -1, NULL, 0, NULL, NULL); 305 | if (!length) 306 | return NULL; 307 | 308 | target = calloc(length, sizeof(char)); 309 | 310 | if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, length, NULL, NULL)) 311 | { 312 | free(target); 313 | return NULL; 314 | } 315 | 316 | return target; 317 | } 318 | 319 | 320 | ////////////////////////////////////////////////////////////////////////// 321 | ////// GLFW platform API ////// 322 | ////////////////////////////////////////////////////////////////////////// 323 | 324 | int _glfwPlatformInit(void) 325 | { 326 | // To make SetForegroundWindow work as we want, we need to fiddle 327 | // with the FOREGROUNDLOCKTIMEOUT system setting (we do this as early 328 | // as possible in the hope of still being the foreground process) 329 | SystemParametersInfoW(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, 330 | &_glfw.win32.foregroundLockTimeout, 0); 331 | SystemParametersInfoW(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, UIntToPtr(0), 332 | SPIF_SENDCHANGE); 333 | 334 | if (!initLibraries()) 335 | return GL_FALSE; 336 | 337 | createKeyTables(); 338 | 339 | if (_glfw_SetProcessDPIAware) 340 | _glfw_SetProcessDPIAware(); 341 | 342 | if (!_glfwRegisterWindowClass()) 343 | return GL_FALSE; 344 | 345 | if (!_glfwInitContextAPI()) 346 | return GL_FALSE; 347 | 348 | _glfwInitTimer(); 349 | _glfwInitJoysticks(); 350 | 351 | return GL_TRUE; 352 | } 353 | 354 | void _glfwPlatformTerminate(void) 355 | { 356 | _glfwUnregisterWindowClass(); 357 | 358 | // Restore previous foreground lock timeout system setting 359 | SystemParametersInfoW(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, 360 | UIntToPtr(_glfw.win32.foregroundLockTimeout), 361 | SPIF_SENDCHANGE); 362 | 363 | free(_glfw.win32.clipboardString); 364 | 365 | _glfwTerminateJoysticks(); 366 | _glfwTerminateContextAPI(); 367 | terminateLibraries(); 368 | } 369 | 370 | const char* _glfwPlatformGetVersionString(void) 371 | { 372 | return _GLFW_VERSION_NUMBER " Win32" 373 | #if defined(_GLFW_WGL) 374 | " WGL" 375 | #elif defined(_GLFW_EGL) 376 | " EGL" 377 | #endif 378 | #if defined(__MINGW32__) 379 | " MinGW" 380 | #elif defined(_MSC_VER) 381 | " VisualC" 382 | #endif 383 | #if defined(_GLFW_USE_HYBRID_HPG) || defined(_GLFW_USE_OPTIMUS_HPG) 384 | " hybrid-GPU" 385 | #endif 386 | #if defined(_GLFW_BUILD_DLL) 387 | " DLL" 388 | #endif 389 | ; 390 | } 391 | 392 | -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/glfw-3.1.2/src/win32_monitor.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 Camilla Berglund 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | // These constants are missing on MinGW 36 | #ifndef EDS_ROTATEDMODE 37 | #define EDS_ROTATEDMODE 0x00000004 38 | #endif 39 | #ifndef DISPLAY_DEVICE_ACTIVE 40 | #define DISPLAY_DEVICE_ACTIVE 0x00000001 41 | #endif 42 | 43 | 44 | ////////////////////////////////////////////////////////////////////////// 45 | ////// GLFW internal API ////// 46 | ////////////////////////////////////////////////////////////////////////// 47 | 48 | // Change the current video mode 49 | // 50 | GLboolean _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired) 51 | { 52 | GLFWvidmode current; 53 | const GLFWvidmode* best; 54 | DEVMODEW dm; 55 | 56 | best = _glfwChooseVideoMode(monitor, desired); 57 | _glfwPlatformGetVideoMode(monitor, ¤t); 58 | if (_glfwCompareVideoModes(¤t, best) == 0) 59 | return GL_TRUE; 60 | 61 | ZeroMemory(&dm, sizeof(dm)); 62 | dm.dmSize = sizeof(DEVMODEW); 63 | dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | 64 | DM_DISPLAYFREQUENCY; 65 | dm.dmPelsWidth = best->width; 66 | dm.dmPelsHeight = best->height; 67 | dm.dmBitsPerPel = best->redBits + best->greenBits + best->blueBits; 68 | dm.dmDisplayFrequency = best->refreshRate; 69 | 70 | if (dm.dmBitsPerPel < 15 || dm.dmBitsPerPel >= 24) 71 | dm.dmBitsPerPel = 32; 72 | 73 | if (ChangeDisplaySettingsExW(monitor->win32.adapterName, 74 | &dm, 75 | NULL, 76 | CDS_FULLSCREEN, 77 | NULL) != DISP_CHANGE_SUCCESSFUL) 78 | { 79 | _glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to set video mode"); 80 | return GL_FALSE; 81 | } 82 | 83 | monitor->win32.modeChanged = GL_TRUE; 84 | return GL_TRUE; 85 | } 86 | 87 | // Restore the previously saved (original) video mode 88 | // 89 | void _glfwRestoreVideoMode(_GLFWmonitor* monitor) 90 | { 91 | if (monitor->win32.modeChanged) 92 | { 93 | ChangeDisplaySettingsExW(monitor->win32.adapterName, 94 | NULL, NULL, CDS_FULLSCREEN, NULL); 95 | monitor->win32.modeChanged = GL_FALSE; 96 | } 97 | } 98 | 99 | 100 | ////////////////////////////////////////////////////////////////////////// 101 | ////// GLFW platform API ////// 102 | ////////////////////////////////////////////////////////////////////////// 103 | 104 | _GLFWmonitor** _glfwPlatformGetMonitors(int* count) 105 | { 106 | int found = 0; 107 | _GLFWmonitor** monitors = NULL; 108 | DWORD adapterIndex, displayIndex; 109 | 110 | *count = 0; 111 | 112 | for (adapterIndex = 0; ; adapterIndex++) 113 | { 114 | DISPLAY_DEVICEW adapter; 115 | 116 | ZeroMemory(&adapter, sizeof(DISPLAY_DEVICEW)); 117 | adapter.cb = sizeof(DISPLAY_DEVICEW); 118 | 119 | if (!EnumDisplayDevicesW(NULL, adapterIndex, &adapter, 0)) 120 | break; 121 | 122 | if (!(adapter.StateFlags & DISPLAY_DEVICE_ACTIVE)) 123 | continue; 124 | 125 | for (displayIndex = 0; ; displayIndex++) 126 | { 127 | DISPLAY_DEVICEW display; 128 | _GLFWmonitor* monitor; 129 | char* name; 130 | HDC dc; 131 | 132 | ZeroMemory(&display, sizeof(DISPLAY_DEVICEW)); 133 | display.cb = sizeof(DISPLAY_DEVICEW); 134 | 135 | if (!EnumDisplayDevicesW(adapter.DeviceName, displayIndex, &display, 0)) 136 | break; 137 | 138 | name = _glfwCreateUTF8FromWideString(display.DeviceString); 139 | if (!name) 140 | { 141 | _glfwInputError(GLFW_PLATFORM_ERROR, 142 | "Win32: Failed to convert string to UTF-8"); 143 | continue; 144 | } 145 | 146 | dc = CreateDCW(L"DISPLAY", adapter.DeviceName, NULL, NULL); 147 | 148 | monitor = _glfwAllocMonitor(name, 149 | GetDeviceCaps(dc, HORZSIZE), 150 | GetDeviceCaps(dc, VERTSIZE)); 151 | 152 | DeleteDC(dc); 153 | free(name); 154 | 155 | if (adapter.StateFlags & DISPLAY_DEVICE_MODESPRUNED) 156 | monitor->win32.modesPruned = GL_TRUE; 157 | 158 | wcscpy(monitor->win32.adapterName, adapter.DeviceName); 159 | wcscpy(monitor->win32.displayName, display.DeviceName); 160 | 161 | WideCharToMultiByte(CP_UTF8, 0, 162 | adapter.DeviceName, -1, 163 | monitor->win32.publicAdapterName, 164 | sizeof(monitor->win32.publicAdapterName), 165 | NULL, NULL); 166 | 167 | WideCharToMultiByte(CP_UTF8, 0, 168 | display.DeviceName, -1, 169 | monitor->win32.publicDisplayName, 170 | sizeof(monitor->win32.publicDisplayName), 171 | NULL, NULL); 172 | 173 | found++; 174 | monitors = realloc(monitors, sizeof(_GLFWmonitor*) * found); 175 | monitors[found - 1] = monitor; 176 | 177 | if (adapter.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE && 178 | displayIndex == 0) 179 | { 180 | _GLFW_SWAP_POINTERS(monitors[0], monitors[found - 1]); 181 | } 182 | } 183 | } 184 | 185 | *count = found; 186 | return monitors; 187 | } 188 | 189 | GLboolean _glfwPlatformIsSameMonitor(_GLFWmonitor* first, _GLFWmonitor* second) 190 | { 191 | return wcscmp(first->win32.displayName, second->win32.displayName) == 0; 192 | } 193 | 194 | void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) 195 | { 196 | DEVMODEW settings; 197 | ZeroMemory(&settings, sizeof(DEVMODEW)); 198 | settings.dmSize = sizeof(DEVMODEW); 199 | 200 | EnumDisplaySettingsExW(monitor->win32.adapterName, 201 | ENUM_CURRENT_SETTINGS, 202 | &settings, 203 | EDS_ROTATEDMODE); 204 | 205 | if (xpos) 206 | *xpos = settings.dmPosition.x; 207 | if (ypos) 208 | *ypos = settings.dmPosition.y; 209 | } 210 | 211 | GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count) 212 | { 213 | int modeIndex = 0, size = 0; 214 | GLFWvidmode* result = NULL; 215 | 216 | *count = 0; 217 | 218 | for (;;) 219 | { 220 | int i; 221 | GLFWvidmode mode; 222 | DEVMODEW dm; 223 | 224 | ZeroMemory(&dm, sizeof(DEVMODEW)); 225 | dm.dmSize = sizeof(DEVMODEW); 226 | 227 | if (!EnumDisplaySettingsW(monitor->win32.adapterName, modeIndex, &dm)) 228 | break; 229 | 230 | modeIndex++; 231 | 232 | // Skip modes with less than 15 BPP 233 | if (dm.dmBitsPerPel < 15) 234 | continue; 235 | 236 | mode.width = dm.dmPelsWidth; 237 | mode.height = dm.dmPelsHeight; 238 | mode.refreshRate = dm.dmDisplayFrequency; 239 | _glfwSplitBPP(dm.dmBitsPerPel, 240 | &mode.redBits, 241 | &mode.greenBits, 242 | &mode.blueBits); 243 | 244 | for (i = 0; i < *count; i++) 245 | { 246 | if (_glfwCompareVideoModes(result + i, &mode) == 0) 247 | break; 248 | } 249 | 250 | // Skip duplicate modes 251 | if (i < *count) 252 | continue; 253 | 254 | if (monitor->win32.modesPruned) 255 | { 256 | // Skip modes not supported by the connected displays 257 | if (ChangeDisplaySettingsExW(monitor->win32.adapterName, 258 | &dm, 259 | NULL, 260 | CDS_TEST, 261 | NULL) != DISP_CHANGE_SUCCESSFUL) 262 | { 263 | continue; 264 | } 265 | } 266 | 267 | if (*count == size) 268 | { 269 | if (*count) 270 | size *= 2; 271 | else 272 | size = 128; 273 | 274 | result = (GLFWvidmode*) realloc(result, size * sizeof(GLFWvidmode)); 275 | } 276 | 277 | (*count)++; 278 | result[*count - 1] = mode; 279 | } 280 | 281 | return result; 282 | } 283 | 284 | void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) 285 | { 286 | DEVMODEW dm; 287 | 288 | ZeroMemory(&dm, sizeof(DEVMODEW)); 289 | dm.dmSize = sizeof(DEVMODEW); 290 | 291 | EnumDisplaySettingsW(monitor->win32.adapterName, ENUM_CURRENT_SETTINGS, &dm); 292 | 293 | mode->width = dm.dmPelsWidth; 294 | mode->height = dm.dmPelsHeight; 295 | mode->refreshRate = dm.dmDisplayFrequency; 296 | _glfwSplitBPP(dm.dmBitsPerPel, 297 | &mode->redBits, 298 | &mode->greenBits, 299 | &mode->blueBits); 300 | } 301 | 302 | void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) 303 | { 304 | HDC dc; 305 | WORD values[768]; 306 | 307 | dc = CreateDCW(L"DISPLAY", monitor->win32.adapterName, NULL, NULL); 308 | GetDeviceGammaRamp(dc, values); 309 | DeleteDC(dc); 310 | 311 | _glfwAllocGammaArrays(ramp, 256); 312 | 313 | memcpy(ramp->red, values + 0, 256 * sizeof(unsigned short)); 314 | memcpy(ramp->green, values + 256, 256 * sizeof(unsigned short)); 315 | memcpy(ramp->blue, values + 512, 256 * sizeof(unsigned short)); 316 | } 317 | 318 | void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) 319 | { 320 | HDC dc; 321 | WORD values[768]; 322 | 323 | if (ramp->size != 256) 324 | { 325 | _glfwInputError(GLFW_PLATFORM_ERROR, 326 | "Win32: Gamma ramp size must be 256"); 327 | return; 328 | } 329 | 330 | memcpy(values + 0, ramp->red, 256 * sizeof(unsigned short)); 331 | memcpy(values + 256, ramp->green, 256 * sizeof(unsigned short)); 332 | memcpy(values + 512, ramp->blue, 256 * sizeof(unsigned short)); 333 | 334 | dc = CreateDCW(L"DISPLAY", monitor->win32.adapterName, NULL, NULL); 335 | SetDeviceGammaRamp(dc, values); 336 | DeleteDC(dc); 337 | } 338 | 339 | 340 | ////////////////////////////////////////////////////////////////////////// 341 | ////// GLFW native API ////// 342 | ////////////////////////////////////////////////////////////////////////// 343 | 344 | GLFWAPI const char* glfwGetWin32Adapter(GLFWmonitor* handle) 345 | { 346 | _GLFWmonitor* monitor = (_GLFWmonitor*) handle; 347 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 348 | return monitor->win32.publicAdapterName; 349 | } 350 | 351 | GLFWAPI const char* glfwGetWin32Monitor(GLFWmonitor* handle) 352 | { 353 | _GLFWmonitor* monitor = (_GLFWmonitor*) handle; 354 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 355 | return monitor->win32.publicDisplayName; 356 | } 357 | 358 | -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/glfw-3.1.2/src/win32_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 Camilla Berglund 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #ifndef _glfw3_win32_platform_h_ 29 | #define _glfw3_win32_platform_h_ 30 | 31 | // We don't need all the fancy stuff 32 | #ifndef NOMINMAX 33 | #define NOMINMAX 34 | #endif 35 | 36 | #ifndef VC_EXTRALEAN 37 | #define VC_EXTRALEAN 38 | #endif 39 | 40 | #ifndef WIN32_LEAN_AND_MEAN 41 | #define WIN32_LEAN_AND_MEAN 42 | #endif 43 | 44 | // This is a workaround for the fact that glfw3.h needs to export APIENTRY (for 45 | // example to allow applications to correctly declare a GL_ARB_debug_output 46 | // callback) but windows.h assumes no one will define APIENTRY before it does 47 | #undef APIENTRY 48 | 49 | // GLFW on Windows is Unicode only and does not work in MBCS mode 50 | #ifndef UNICODE 51 | #define UNICODE 52 | #endif 53 | 54 | // GLFW requires Windows XP or later 55 | #if WINVER < 0x0501 56 | #undef WINVER 57 | #define WINVER 0x0501 58 | #endif 59 | #if _WIN32_WINNT < 0x0501 60 | #undef _WIN32_WINNT 61 | #define _WIN32_WINNT 0x0501 62 | #endif 63 | 64 | #include 65 | #include 66 | #include 67 | 68 | #if defined(_MSC_VER) 69 | #include 70 | #define strdup _strdup 71 | #endif 72 | 73 | // HACK: Define macros that some older windows.h variants don't 74 | #ifndef WM_MOUSEHWHEEL 75 | #define WM_MOUSEHWHEEL 0x020E 76 | #endif 77 | #ifndef WM_DWMCOMPOSITIONCHANGED 78 | #define WM_DWMCOMPOSITIONCHANGED 0x031E 79 | #endif 80 | #ifndef WM_COPYGLOBALDATA 81 | #define WM_COPYGLOBALDATA 0x0049 82 | #endif 83 | #ifndef WM_UNICHAR 84 | #define WM_UNICHAR 0x0109 85 | #endif 86 | #ifndef UNICODE_NOCHAR 87 | #define UNICODE_NOCHAR 0xFFFF 88 | #endif 89 | 90 | #if WINVER < 0x0601 91 | typedef struct tagCHANGEFILTERSTRUCT 92 | { 93 | DWORD cbSize; 94 | DWORD ExtStatus; 95 | 96 | } CHANGEFILTERSTRUCT, *PCHANGEFILTERSTRUCT; 97 | #ifndef MSGFLT_ALLOW 98 | #define MSGFLT_ALLOW 1 99 | #endif 100 | #endif /*Windows 7*/ 101 | 102 | // winmm.dll function pointer typedefs 103 | typedef MMRESULT (WINAPI * JOYGETDEVCAPS_T)(UINT,LPJOYCAPS,UINT); 104 | typedef MMRESULT (WINAPI * JOYGETPOS_T)(UINT,LPJOYINFO); 105 | typedef MMRESULT (WINAPI * JOYGETPOSEX_T)(UINT,LPJOYINFOEX); 106 | typedef DWORD (WINAPI * TIMEGETTIME_T)(void); 107 | #define _glfw_joyGetDevCaps _glfw.win32.winmm.joyGetDevCaps 108 | #define _glfw_joyGetPos _glfw.win32.winmm.joyGetPos 109 | #define _glfw_joyGetPosEx _glfw.win32.winmm.joyGetPosEx 110 | #define _glfw_timeGetTime _glfw.win32.winmm.timeGetTime 111 | 112 | // user32.dll function pointer typedefs 113 | typedef BOOL (WINAPI * SETPROCESSDPIAWARE_T)(void); 114 | typedef BOOL (WINAPI * CHANGEWINDOWMESSAGEFILTEREX_T)(HWND,UINT,DWORD,PCHANGEFILTERSTRUCT); 115 | #define _glfw_SetProcessDPIAware _glfw.win32.user32.SetProcessDPIAware 116 | #define _glfw_ChangeWindowMessageFilterEx _glfw.win32.user32.ChangeWindowMessageFilterEx 117 | 118 | // dwmapi.dll function pointer typedefs 119 | typedef HRESULT (WINAPI * DWMISCOMPOSITIONENABLED_T)(BOOL*); 120 | typedef HRESULT (WINAPI * DWMFLUSH_T)(VOID); 121 | #define _glfw_DwmIsCompositionEnabled _glfw.win32.dwmapi.DwmIsCompositionEnabled 122 | #define _glfw_DwmFlush _glfw.win32.dwmapi.DwmFlush 123 | 124 | #define _GLFW_RECREATION_NOT_NEEDED 0 125 | #define _GLFW_RECREATION_REQUIRED 1 126 | #define _GLFW_RECREATION_IMPOSSIBLE 2 127 | 128 | #include "win32_tls.h" 129 | #include "winmm_joystick.h" 130 | 131 | #if defined(_GLFW_WGL) 132 | #include "wgl_context.h" 133 | #elif defined(_GLFW_EGL) 134 | #define _GLFW_EGL_NATIVE_WINDOW window->win32.handle 135 | #define _GLFW_EGL_NATIVE_DISPLAY EGL_DEFAULT_DISPLAY 136 | #include "egl_context.h" 137 | #else 138 | #error "No supported context creation API selected" 139 | #endif 140 | 141 | #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 win32 142 | #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWin32 win32 143 | #define _GLFW_PLATFORM_LIBRARY_TIME_STATE _GLFWtimeWin32 win32_time 144 | #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorWin32 win32 145 | #define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorWin32 win32 146 | 147 | 148 | // Win32-specific per-window data 149 | // 150 | typedef struct _GLFWwindowWin32 151 | { 152 | HWND handle; 153 | 154 | GLboolean cursorTracked; 155 | GLboolean iconified; 156 | 157 | // The last received cursor position, regardless of source 158 | int cursorPosX, cursorPosY; 159 | 160 | } _GLFWwindowWin32; 161 | 162 | 163 | // Win32-specific global data 164 | // 165 | typedef struct _GLFWlibraryWin32 166 | { 167 | DWORD foregroundLockTimeout; 168 | char* clipboardString; 169 | short int publicKeys[512]; 170 | 171 | // winmm.dll 172 | struct { 173 | HINSTANCE instance; 174 | JOYGETDEVCAPS_T joyGetDevCaps; 175 | JOYGETPOS_T joyGetPos; 176 | JOYGETPOSEX_T joyGetPosEx; 177 | TIMEGETTIME_T timeGetTime; 178 | } winmm; 179 | 180 | // user32.dll 181 | struct { 182 | HINSTANCE instance; 183 | SETPROCESSDPIAWARE_T SetProcessDPIAware; 184 | CHANGEWINDOWMESSAGEFILTEREX_T ChangeWindowMessageFilterEx; 185 | } user32; 186 | 187 | // dwmapi.dll 188 | struct { 189 | HINSTANCE instance; 190 | DWMISCOMPOSITIONENABLED_T DwmIsCompositionEnabled; 191 | DWMFLUSH_T DwmFlush; 192 | } dwmapi; 193 | 194 | } _GLFWlibraryWin32; 195 | 196 | 197 | // Win32-specific per-monitor data 198 | // 199 | typedef struct _GLFWmonitorWin32 200 | { 201 | // This size matches the static size of DISPLAY_DEVICE.DeviceName 202 | WCHAR adapterName[32]; 203 | WCHAR displayName[32]; 204 | char publicAdapterName[64]; 205 | char publicDisplayName[64]; 206 | GLboolean modesPruned; 207 | GLboolean modeChanged; 208 | 209 | } _GLFWmonitorWin32; 210 | 211 | 212 | // Win32-specific per-cursor data 213 | // 214 | typedef struct _GLFWcursorWin32 215 | { 216 | HCURSOR handle; 217 | 218 | } _GLFWcursorWin32; 219 | 220 | 221 | // Win32-specific global timer data 222 | // 223 | typedef struct _GLFWtimeWin32 224 | { 225 | GLboolean hasPC; 226 | double resolution; 227 | unsigned __int64 base; 228 | 229 | } _GLFWtimeWin32; 230 | 231 | 232 | GLboolean _glfwRegisterWindowClass(void); 233 | void _glfwUnregisterWindowClass(void); 234 | 235 | BOOL _glfwIsCompositionEnabled(void); 236 | 237 | WCHAR* _glfwCreateWideStringFromUTF8(const char* source); 238 | char* _glfwCreateUTF8FromWideString(const WCHAR* source); 239 | 240 | void _glfwInitTimer(void); 241 | 242 | GLboolean _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired); 243 | void _glfwRestoreVideoMode(_GLFWmonitor* monitor); 244 | 245 | #endif // _glfw3_win32_platform_h_ 246 | -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/glfw-3.1.2/src/win32_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 Camilla Berglund 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | 30 | 31 | // Return raw time 32 | // 33 | static unsigned __int64 getRawTime(void) 34 | { 35 | if (_glfw.win32_time.hasPC) 36 | { 37 | unsigned __int64 time; 38 | QueryPerformanceCounter((LARGE_INTEGER*) &time); 39 | return time; 40 | } 41 | else 42 | return (unsigned __int64) _glfw_timeGetTime(); 43 | } 44 | 45 | 46 | ////////////////////////////////////////////////////////////////////////// 47 | ////// GLFW internal API ////// 48 | ////////////////////////////////////////////////////////////////////////// 49 | 50 | // Initialise timer 51 | // 52 | void _glfwInitTimer(void) 53 | { 54 | unsigned __int64 frequency; 55 | 56 | if (QueryPerformanceFrequency((LARGE_INTEGER*) &frequency)) 57 | { 58 | _glfw.win32_time.hasPC = GL_TRUE; 59 | _glfw.win32_time.resolution = 1.0 / (double) frequency; 60 | } 61 | else 62 | { 63 | _glfw.win32_time.hasPC = GL_FALSE; 64 | _glfw.win32_time.resolution = 0.001; // winmm resolution is 1 ms 65 | } 66 | 67 | _glfw.win32_time.base = getRawTime(); 68 | } 69 | 70 | 71 | ////////////////////////////////////////////////////////////////////////// 72 | ////// GLFW platform API ////// 73 | ////////////////////////////////////////////////////////////////////////// 74 | 75 | double _glfwPlatformGetTime(void) 76 | { 77 | return (double) (getRawTime() - _glfw.win32_time.base) * 78 | _glfw.win32_time.resolution; 79 | } 80 | 81 | void _glfwPlatformSetTime(double time) 82 | { 83 | _glfw.win32_time.base = getRawTime() - 84 | (unsigned __int64) (time / _glfw.win32_time.resolution); 85 | } 86 | 87 | -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/glfw-3.1.2/src/win32_tls.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 Camilla Berglund 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | 30 | 31 | ////////////////////////////////////////////////////////////////////////// 32 | ////// GLFW internal API ////// 33 | ////////////////////////////////////////////////////////////////////////// 34 | 35 | int _glfwCreateContextTLS(void) 36 | { 37 | _glfw.win32_tls.context = TlsAlloc(); 38 | if (_glfw.win32_tls.context == TLS_OUT_OF_INDEXES) 39 | { 40 | _glfwInputError(GLFW_PLATFORM_ERROR, 41 | "Win32: Failed to allocate TLS index"); 42 | return GL_FALSE; 43 | } 44 | 45 | _glfw.win32_tls.allocated = GL_TRUE; 46 | return GL_TRUE; 47 | } 48 | 49 | void _glfwDestroyContextTLS(void) 50 | { 51 | if (_glfw.win32_tls.allocated) 52 | TlsFree(_glfw.win32_tls.context); 53 | } 54 | 55 | void _glfwSetContextTLS(_GLFWwindow* context) 56 | { 57 | TlsSetValue(_glfw.win32_tls.context, context); 58 | } 59 | 60 | 61 | ////////////////////////////////////////////////////////////////////////// 62 | ////// GLFW platform API ////// 63 | ////////////////////////////////////////////////////////////////////////// 64 | 65 | _GLFWwindow* _glfwPlatformGetCurrentContext(void) 66 | { 67 | return TlsGetValue(_glfw.win32_tls.context); 68 | } 69 | 70 | -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/glfw-3.1.2/src/win32_tls.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 Camilla Berglund 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #ifndef _glfw3_win32_tls_h_ 29 | #define _glfw3_win32_tls_h_ 30 | 31 | #define _GLFW_PLATFORM_LIBRARY_TLS_STATE _GLFWtlsWin32 win32_tls 32 | 33 | 34 | // Win32-specific global TLS data 35 | // 36 | typedef struct _GLFWtlsWin32 37 | { 38 | GLboolean allocated; 39 | DWORD context; 40 | 41 | } _GLFWtlsWin32; 42 | 43 | 44 | int _glfwCreateContextTLS(void); 45 | void _glfwDestroyContextTLS(void); 46 | void _glfwSetContextTLS(_GLFWwindow* context); 47 | 48 | #endif // _glfw3_win32_tls_h_ 49 | -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/glfw-3.1.2/src/winmm_joystick.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 WinMM - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 Camilla Berglund 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | 30 | #include 31 | 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | ////// GLFW internal API ////// 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | // Convert axis value to the [-1,1] range 38 | // 39 | static float normalizeAxis(DWORD pos, DWORD min, DWORD max) 40 | { 41 | float fpos = (float) pos; 42 | float fmin = (float) min; 43 | float fmax = (float) max; 44 | 45 | return (2.f * (fpos - fmin) / (fmax - fmin)) - 1.f; 46 | } 47 | 48 | 49 | ////////////////////////////////////////////////////////////////////////// 50 | ////// GLFW internal API ////// 51 | ////////////////////////////////////////////////////////////////////////// 52 | 53 | // Initialize joystick interface 54 | // 55 | void _glfwInitJoysticks(void) 56 | { 57 | } 58 | 59 | // Close all opened joystick handles 60 | // 61 | void _glfwTerminateJoysticks(void) 62 | { 63 | int i; 64 | 65 | for (i = 0; i < GLFW_JOYSTICK_LAST; i++) 66 | free(_glfw.winmm_js[i].name); 67 | } 68 | 69 | 70 | ////////////////////////////////////////////////////////////////////////// 71 | ////// GLFW platform API ////// 72 | ////////////////////////////////////////////////////////////////////////// 73 | 74 | int _glfwPlatformJoystickPresent(int joy) 75 | { 76 | JOYINFO ji; 77 | 78 | if (_glfw_joyGetPos(joy, &ji) != JOYERR_NOERROR) 79 | return GL_FALSE; 80 | 81 | return GL_TRUE; 82 | } 83 | 84 | const float* _glfwPlatformGetJoystickAxes(int joy, int* count) 85 | { 86 | JOYCAPS jc; 87 | JOYINFOEX ji; 88 | float* axes = _glfw.winmm_js[joy].axes; 89 | 90 | if (_glfw_joyGetDevCaps(joy, &jc, sizeof(JOYCAPS)) != JOYERR_NOERROR) 91 | return NULL; 92 | 93 | ji.dwSize = sizeof(JOYINFOEX); 94 | ji.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNZ | 95 | JOY_RETURNR | JOY_RETURNU | JOY_RETURNV; 96 | if (_glfw_joyGetPosEx(joy, &ji) != JOYERR_NOERROR) 97 | return NULL; 98 | 99 | axes[(*count)++] = normalizeAxis(ji.dwXpos, jc.wXmin, jc.wXmax); 100 | axes[(*count)++] = normalizeAxis(ji.dwYpos, jc.wYmin, jc.wYmax); 101 | 102 | if (jc.wCaps & JOYCAPS_HASZ) 103 | axes[(*count)++] = normalizeAxis(ji.dwZpos, jc.wZmin, jc.wZmax); 104 | 105 | if (jc.wCaps & JOYCAPS_HASR) 106 | axes[(*count)++] = normalizeAxis(ji.dwRpos, jc.wRmin, jc.wRmax); 107 | 108 | if (jc.wCaps & JOYCAPS_HASU) 109 | axes[(*count)++] = normalizeAxis(ji.dwUpos, jc.wUmin, jc.wUmax); 110 | 111 | if (jc.wCaps & JOYCAPS_HASV) 112 | axes[(*count)++] = normalizeAxis(ji.dwVpos, jc.wVmin, jc.wVmax); 113 | 114 | return axes; 115 | } 116 | 117 | const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count) 118 | { 119 | JOYCAPS jc; 120 | JOYINFOEX ji; 121 | unsigned char* buttons = _glfw.winmm_js[joy].buttons; 122 | 123 | if (_glfw_joyGetDevCaps(joy, &jc, sizeof(JOYCAPS)) != JOYERR_NOERROR) 124 | return NULL; 125 | 126 | ji.dwSize = sizeof(JOYINFOEX); 127 | ji.dwFlags = JOY_RETURNBUTTONS | JOY_RETURNPOV; 128 | if (_glfw_joyGetPosEx(joy, &ji) != JOYERR_NOERROR) 129 | return NULL; 130 | 131 | while (*count < (int) jc.wNumButtons) 132 | { 133 | buttons[*count] = (unsigned char) 134 | (ji.dwButtons & (1UL << *count) ? GLFW_PRESS : GLFW_RELEASE); 135 | (*count)++; 136 | } 137 | 138 | // Virtual buttons - Inject data from hats 139 | // Each hat is exposed as 4 buttons which exposes 8 directions with 140 | // concurrent button presses 141 | // NOTE: this API exposes only one hat 142 | 143 | if ((jc.wCaps & JOYCAPS_HASPOV) && (jc.wCaps & JOYCAPS_POV4DIR)) 144 | { 145 | int i, value = ji.dwPOV / 100 / 45; 146 | 147 | // Bit fields of button presses for each direction, including nil 148 | const int directions[9] = { 1, 3, 2, 6, 4, 12, 8, 9, 0 }; 149 | 150 | if (value < 0 || value > 8) 151 | value = 8; 152 | 153 | for (i = 0; i < 4; i++) 154 | { 155 | if (directions[value] & (1 << i)) 156 | buttons[(*count)++] = GLFW_PRESS; 157 | else 158 | buttons[(*count)++] = GLFW_RELEASE; 159 | } 160 | } 161 | 162 | return buttons; 163 | } 164 | 165 | const char* _glfwPlatformGetJoystickName(int joy) 166 | { 167 | JOYCAPS jc; 168 | 169 | if (_glfw_joyGetDevCaps(joy, &jc, sizeof(JOYCAPS)) != JOYERR_NOERROR) 170 | return NULL; 171 | 172 | free(_glfw.winmm_js[joy].name); 173 | _glfw.winmm_js[joy].name = _glfwCreateUTF8FromWideString(jc.szPname); 174 | 175 | return _glfw.winmm_js[joy].name; 176 | } 177 | 178 | -------------------------------------------------------------------------------- /tiny-gizmo-example/third-party/glfw-3.1.2/src/winmm_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.1 WinMM - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2014 Camilla Berglund 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #ifndef _glfw3_winmm_joystick_h_ 28 | #define _glfw3_winmm_joystick_h_ 29 | 30 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE \ 31 | _GLFWjoystickWinMM winmm_js[GLFW_JOYSTICK_LAST + 1] 32 | 33 | 34 | // WinMM-specific per-joystick data 35 | // 36 | typedef struct _GLFWjoystickWinMM 37 | { 38 | float axes[6]; 39 | unsigned char buttons[36]; // 32 buttons plus one hat 40 | char* name; 41 | } _GLFWjoystickWinMM; 42 | 43 | 44 | void _glfwInitJoysticks(void); 45 | void _glfwTerminateJoysticks(void); 46 | 47 | #endif // _glfw3_winmm_joystick_h_ 48 | -------------------------------------------------------------------------------- /tiny-gizmo-example/tiny-gizmo-example.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tiny-gizmo-example", "tiny-gizmo-example.vcxproj", "{E8595BE1-022E-46B2-9079-A12C655C5E4B}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "glfw3", "third-party\glfw-3.1.2\glfw3.vcxproj", "{BE423E72-28C2-4FB7-9FE1-42AA2F393BBC}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|x64 = Debug|x64 13 | Debug|x86 = Debug|x86 14 | Release|x64 = Release|x64 15 | Release|x86 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {E8595BE1-022E-46B2-9079-A12C655C5E4B}.Debug|x64.ActiveCfg = Debug|x64 19 | {E8595BE1-022E-46B2-9079-A12C655C5E4B}.Debug|x64.Build.0 = Debug|x64 20 | {E8595BE1-022E-46B2-9079-A12C655C5E4B}.Debug|x86.ActiveCfg = Debug|Win32 21 | {E8595BE1-022E-46B2-9079-A12C655C5E4B}.Debug|x86.Build.0 = Debug|Win32 22 | {E8595BE1-022E-46B2-9079-A12C655C5E4B}.Release|x64.ActiveCfg = Release|x64 23 | {E8595BE1-022E-46B2-9079-A12C655C5E4B}.Release|x64.Build.0 = Release|x64 24 | {E8595BE1-022E-46B2-9079-A12C655C5E4B}.Release|x86.ActiveCfg = Release|Win32 25 | {E8595BE1-022E-46B2-9079-A12C655C5E4B}.Release|x86.Build.0 = Release|Win32 26 | {BE423E72-28C2-4FB7-9FE1-42AA2F393BBC}.Debug|x64.ActiveCfg = Debug|x64 27 | {BE423E72-28C2-4FB7-9FE1-42AA2F393BBC}.Debug|x64.Build.0 = Debug|x64 28 | {BE423E72-28C2-4FB7-9FE1-42AA2F393BBC}.Debug|x86.ActiveCfg = Debug|Win32 29 | {BE423E72-28C2-4FB7-9FE1-42AA2F393BBC}.Debug|x86.Build.0 = Debug|Win32 30 | {BE423E72-28C2-4FB7-9FE1-42AA2F393BBC}.Release|x64.ActiveCfg = Release|x64 31 | {BE423E72-28C2-4FB7-9FE1-42AA2F393BBC}.Release|x64.Build.0 = Release|x64 32 | {BE423E72-28C2-4FB7-9FE1-42AA2F393BBC}.Release|x86.ActiveCfg = Release|Win32 33 | {BE423E72-28C2-4FB7-9FE1-42AA2F393BBC}.Release|x86.Build.0 = Release|Win32 34 | EndGlobalSection 35 | GlobalSection(SolutionProperties) = preSolution 36 | HideSolutionNode = FALSE 37 | EndGlobalSection 38 | EndGlobal 39 | -------------------------------------------------------------------------------- /tiny-gizmo-example/tiny-gizmo-example.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | {be423e72-28c2-4fb7-9fe1-42aa2f393bbc} 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | {E8595BE1-022E-46B2-9079-A12C655C5E4B} 38 | xlab_cpp 39 | 10.0.16299.0 40 | tiny-gizmo-example 41 | 42 | 43 | 44 | Application 45 | true 46 | v141 47 | MultiByte 48 | 49 | 50 | Application 51 | false 52 | v141 53 | true 54 | MultiByte 55 | 56 | 57 | Application 58 | true 59 | v141 60 | MultiByte 61 | 62 | 63 | Application 64 | false 65 | v141 66 | true 67 | MultiByte 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | $(ProjectDir)\build\ 89 | $(ProjectDir)\build\obj\ 90 | 91 | 92 | $(ProjectDir)\build\ 93 | $(ProjectDir)\build\obj\ 94 | 95 | 96 | $(ProjectDir)\build\ 97 | $(ProjectDir)\build\obj\ 98 | 99 | 100 | $(ProjectDir)\build\ 101 | $(ProjectDir)\build\obj\ 102 | 103 | 104 | 105 | Level3 106 | Disabled 107 | true 108 | $(SolutionDir)third-party;$(SolutionDir)third-party\glew;$(SolutionDir)third-party\glfw-3.1.2\include;%(AdditionalIncludeDirectories) 109 | _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 110 | 111 | 112 | $(SolutionDir)third-party\glew\lib\$(Platform);$(SolutionDir)third-party\fbxsdk\lib\x64\$(Configuration);%(AdditionalLibraryDirectories) 113 | glew32s.lib;opengl32.lib;%(AdditionalDependencies) 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | Level3 123 | Disabled 124 | true 125 | $(SolutionDir)third-party;$(SolutionDir)third-party\glew;$(SolutionDir)third-party\glfw-3.1.2\include;%(AdditionalIncludeDirectories) 126 | _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 127 | 128 | 129 | $(SolutionDir)third-party\glew\lib\$(Platform);$(SolutionDir)third-party\fbxsdk\lib\x64\$(Configuration);%(AdditionalLibraryDirectories) 130 | glew32s.lib;opengl32.lib;%(AdditionalDependencies) 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | Level3 140 | MaxSpeed 141 | true 142 | true 143 | true 144 | $(SolutionDir)third-party;$(SolutionDir)third-party\glew;$(SolutionDir)third-party\glfw-3.1.2\include;%(AdditionalIncludeDirectories) 145 | _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 146 | 147 | 148 | true 149 | true 150 | $(SolutionDir)third-party\glew\lib\$(Platform);$(SolutionDir)third-party\fbxsdk\lib\x64\$(Configuration);%(AdditionalLibraryDirectories) 151 | glew32s.lib;opengl32.lib;%(AdditionalDependencies) 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | Level3 161 | MaxSpeed 162 | true 163 | true 164 | true 165 | $(SolutionDir)third-party;$(SolutionDir)third-party\glew;$(SolutionDir)third-party\glfw-3.1.2\include;%(AdditionalIncludeDirectories) 166 | _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 167 | 168 | 169 | true 170 | true 171 | $(SolutionDir)third-party\glew\lib\$(Platform);$(SolutionDir)third-party\fbxsdk\lib\x64\$(Configuration);%(AdditionalLibraryDirectories) 172 | glew32s.lib;opengl32.lib;%(AdditionalDependencies) 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | -------------------------------------------------------------------------------- /tiny-gizmo-example/tiny-gizmo-example.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {886b3b0e-2a37-489f-b0cf-7ab0efe1bdb1} 6 | 7 | 8 | {0bceb5fb-0b9d-4b04-842b-5da21648b39d} 9 | 10 | 11 | 12 | 13 | 14 | gizmo 15 | 16 | 17 | 18 | 19 | extra 20 | 21 | 22 | extra 23 | 24 | 25 | extra 26 | 27 | 28 | gizmo 29 | 30 | 31 | -------------------------------------------------------------------------------- /tiny-gizmo-example/util.hpp: -------------------------------------------------------------------------------- 1 | // This is free and unencumbered software released into the public domain. 2 | // For more information, please refer to 3 | 4 | #pragma once 5 | 6 | #ifndef tinygizmo_example_util_hpp 7 | #define tinygizmo_example_util_hpp 8 | 9 | #include 10 | #include 11 | 12 | #define GLEW_STATIC 13 | #define GL_GLEXT_PROTOTYPES 14 | #include "glew.h" 15 | 16 | #define GLFW_INCLUDE_GLU 17 | #include "GLFW\glfw3.h" 18 | 19 | #include "../tiny-gizmo.hpp" 20 | #include "linalg.h" 21 | 22 | /////////////////////////////////// 23 | // Windowing & App Lifecycle // 24 | /////////////////////////////////// 25 | 26 | struct ray { linalg::aliases::float3 origin; linalg::aliases::float3 direction; }; 27 | 28 | struct rect 29 | { 30 | int x0, y0, x1, y1; 31 | int width() const { return x1 - x0; } 32 | int height() const { return y1 - y0; } 33 | linalg::aliases::int2 dims() const { return{ width(), height() }; } 34 | float aspect_ratio() const { return (float)width() / height(); } 35 | }; 36 | 37 | struct camera 38 | { 39 | float yfov, near_clip, far_clip; 40 | linalg::aliases::float3 position; 41 | float pitch, yaw; 42 | linalg::aliases::float4 get_orientation() const { return qmul(rotation_quat(linalg::aliases::float3(0, 1, 0), yaw), rotation_quat(linalg::aliases::float3(1, 0, 0), pitch)); } 43 | linalg::aliases::float4x4 get_view_matrix() const { return mul(rotation_matrix(qconj(get_orientation())), translation_matrix(-position)); } 44 | linalg::aliases::float4x4 get_projection_matrix(const float aspectRatio) const { return linalg::perspective_matrix(yfov, aspectRatio, near_clip, far_clip); } 45 | linalg::aliases::float4x4 get_viewproj_matrix(const float aspectRatio) const { return mul(get_projection_matrix(aspectRatio), get_view_matrix()); } 46 | }; 47 | 48 | // Returns a world-space ray through the given pixel, originating at the camera 49 | ray get_ray_from_pixel(const linalg::aliases::float2 & pixel, const rect & viewport, const camera & cam) 50 | { 51 | const float x = 2 * (pixel.x - viewport.x0) / viewport.width() - 1, y = 1 - 2 * (pixel.y - viewport.y0) / viewport.height(); 52 | const linalg::aliases::float4x4 inv_view_proj = inverse(cam.get_viewproj_matrix(viewport.aspect_ratio())); 53 | const linalg::aliases::float4 p0 = mul(inv_view_proj, linalg::aliases::float4(x, y, -1, 1)), p1 = mul(inv_view_proj, linalg::aliases::float4(x, y, +1, 1)); 54 | return{ cam.position, p1.xyz()*p0.w - p0.xyz()*p1.w }; 55 | } 56 | 57 | class Window 58 | { 59 | GLFWwindow * window; 60 | public: 61 | std::function on_char; 62 | std::function on_key; 63 | std::function on_mouse_button; 64 | std::function on_cursor_pos; 65 | std::function on_drop; 66 | 67 | Window(int width, int height, const char * title) 68 | { 69 | if (glfwInit() == GL_FALSE) throw std::runtime_error("glfwInit() failed"); 70 | window = glfwCreateWindow(width, height, title, nullptr, nullptr); 71 | if (!window) throw std::runtime_error("glfwCreateWindow() failed"); 72 | 73 | glfwMakeContextCurrent(window); 74 | 75 | if (GLenum err = glewInit()) 76 | { 77 | throw std::runtime_error(std::string("glewInit() failed - ") + (const char *)glewGetErrorString(err)); 78 | } 79 | 80 | glfwSetCharCallback(window, [](GLFWwindow * window, unsigned int codepoint) { 81 | auto w = (Window *)glfwGetWindowUserPointer(window); if (w->on_char) w->on_char(codepoint); 82 | }); 83 | 84 | glfwSetKeyCallback(window, [](GLFWwindow * window, int key, int, int action, int mods) { 85 | auto w = (Window *)glfwGetWindowUserPointer(window); if (w->on_key) w->on_key(key, action, mods); 86 | }); 87 | 88 | glfwSetMouseButtonCallback(window, [](GLFWwindow * window, int button, int action, int mods) { 89 | auto w = (Window *)glfwGetWindowUserPointer(window); if (w->on_mouse_button) w->on_mouse_button(button, action, mods); 90 | }); 91 | 92 | glfwSetCursorPosCallback(window, [](GLFWwindow * window, double xpos, double ypos) { 93 | auto w = (Window *)glfwGetWindowUserPointer(window); if (w->on_cursor_pos) w->on_cursor_pos(linalg::aliases::float2(linalg::aliases::double2(xpos, ypos))); 94 | }); 95 | 96 | glfwSetDropCallback(window, [](GLFWwindow * window, int numFiles, const char ** paths) { 97 | auto w = (Window *)glfwGetWindowUserPointer(window); if (w->on_drop) w->on_drop(numFiles, paths); 98 | }); 99 | 100 | glfwSetWindowUserPointer(window, this); 101 | } 102 | 103 | ~Window() 104 | { 105 | glfwMakeContextCurrent(window); 106 | glfwDestroyWindow(window); 107 | glfwTerminate(); 108 | } 109 | 110 | Window(const Window &) = delete; 111 | Window(Window &&) = delete; 112 | Window & operator = (const Window &) = delete; 113 | Window & operator = (Window &&) = delete; 114 | 115 | GLFWwindow * get_glfw_window_handle() { return window; }; 116 | bool should_close() const { return !!glfwWindowShouldClose(window); } 117 | int get_window_attrib(int attrib) const { return glfwGetWindowAttrib(window, attrib); } 118 | linalg::aliases::int2 get_window_size() const { linalg::aliases::int2 size; glfwGetWindowSize(window, &size.x, &size.y); return size; } 119 | void set_window_size(linalg::aliases::int2 newSize) { glfwSetWindowSize(window, newSize.x, newSize.y); } 120 | linalg::aliases::int2 get_framebuffer_size() const { linalg::aliases::int2 size; glfwGetFramebufferSize(window, &size.x, &size.y); return size; } 121 | linalg::aliases::float2 get_cursor_pos() const { linalg::aliases::double2 pos; glfwGetCursorPos(window, &pos.x, &pos.y); return linalg::aliases::float2(pos); } 122 | 123 | void swap_buffers() { glfwSwapBuffers(window); } 124 | void close() { glfwSetWindowShouldClose(window, 1); } 125 | }; 126 | 127 | #endif // end tinygizmo_example_util_hpp 128 | -------------------------------------------------------------------------------- /tiny-gizmo.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddiakopoulos/tinygizmo/99c1c418d169774b0b8052b57fd1680b4c4de444/tiny-gizmo.cpp --------------------------------------------------------------------------------