├── .clang_complete ├── .gitignore ├── CMakeLists.txt ├── README.md ├── checkpoints ├── 1_lines.cpp ├── 2_triangles.cpp ├── 3_transformations.cpp ├── 4_blending.cpp ├── 5_mesh.cpp ├── 6_mvp.cpp └── 7_lighting.cpp ├── glfw ├── .appveyor.yml ├── .github │ └── CONTRIBUTING.md ├── .travis.yml ├── CMake │ ├── MacOSXBundleInfo.plist.in │ ├── amd64-mingw32msvc.cmake │ ├── i586-mingw32msvc.cmake │ ├── i686-pc-mingw32.cmake │ ├── i686-w64-mingw32.cmake │ ├── modules │ │ ├── FindMir.cmake │ │ ├── FindVulkan.cmake │ │ ├── FindWaylandProtocols.cmake │ │ └── FindXKBCommon.cmake │ └── x86_64-w64-mingw32.cmake ├── CMakeLists.txt ├── COPYING.txt ├── README.md ├── cmake_uninstall.cmake.in ├── deps │ ├── KHR │ │ └── khrplatform.h │ ├── getopt.c │ ├── getopt.h │ ├── glad.c │ ├── glad │ │ └── glad.h │ ├── linmath.h │ ├── mingw │ │ ├── _mingw_dxhelper.h │ │ ├── dinput.h │ │ └── xinput.h │ ├── tinycthread.c │ ├── tinycthread.h │ └── vulkan │ │ ├── vk_platform.h │ │ └── vulkan.h ├── include │ └── GLFW │ │ ├── glfw3.h │ │ └── glfw3native.h ├── src │ ├── CMakeLists.txt │ ├── cocoa_init.m │ ├── cocoa_joystick.h │ ├── cocoa_joystick.m │ ├── cocoa_monitor.m │ ├── cocoa_platform.h │ ├── cocoa_time.c │ ├── cocoa_window.m │ ├── context.c │ ├── egl_context.c │ ├── egl_context.h │ ├── glfw3.pc.in │ ├── glfw3Config.cmake.in │ ├── glfw_config.h.in │ ├── glx_context.c │ ├── glx_context.h │ ├── init.c │ ├── input.c │ ├── internal.h │ ├── linux_joystick.c │ ├── linux_joystick.h │ ├── mir_init.c │ ├── mir_monitor.c │ ├── mir_platform.h │ ├── mir_window.c │ ├── monitor.c │ ├── nsgl_context.h │ ├── nsgl_context.m │ ├── posix_time.c │ ├── posix_time.h │ ├── posix_tls.c │ ├── posix_tls.h │ ├── vulkan.c │ ├── wgl_context.c │ ├── wgl_context.h │ ├── win32_init.c │ ├── win32_joystick.c │ ├── win32_joystick.h │ ├── win32_monitor.c │ ├── win32_platform.h │ ├── win32_time.c │ ├── win32_tls.c │ ├── win32_window.c │ ├── window.c │ ├── wl_init.c │ ├── wl_monitor.c │ ├── wl_platform.h │ ├── wl_window.c │ ├── x11_init.c │ ├── x11_monitor.c │ ├── x11_platform.h │ ├── x11_window.c │ ├── xkb_unicode.c │ └── xkb_unicode.h └── tests │ ├── CMakeLists.txt │ ├── clipboard.c │ ├── cursor.c │ ├── empty.c │ ├── events.c │ ├── gamma.c │ ├── glfwinfo.c │ ├── icon.c │ ├── iconify.c │ ├── joysticks.c │ ├── monitors.c │ ├── msaa.c │ ├── reopen.c │ ├── sharing.c │ ├── tearing.c │ ├── threads.c │ ├── timeout.c │ ├── title.c │ ├── vulkan.c │ └── windows.c ├── gltutorial.sublime-project ├── obj ├── circle.obj └── utah-teapot.obj └── src ├── CMakeLists.txt ├── Color.hpp ├── GraphicsManager.cpp ├── GraphicsManager.hpp ├── Mesh.cpp ├── Mesh.hpp └── main.cpp /.clang_complete: -------------------------------------------------------------------------------- 1 | -Iinclude 2 | -Iglfw/include -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | 3 | *.sublime-workspace 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | project (GLTutorial) 3 | 4 | # Cmake Configuration # 5 | 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | set(CMAKE_CXX_EXTENSIONS OFF) 9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") 10 | 11 | set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin") 12 | 13 | # OpenGL Configuration # 14 | 15 | find_package(OpenGL REQUIRED) 16 | find_package(glm REQUIRED) 17 | 18 | set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) 19 | set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) 20 | set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) 21 | 22 | # GLFW Configuration # 23 | 24 | if( APPLE ) 25 | # Set deploy target to macOS 10.8 to supress deprecation 26 | # warnings 27 | set(CMAKE_OSX_DEPLOYMENT_TARGET "10.8") 28 | endif() 29 | 30 | # Includes # 31 | 32 | include_directories(${OPENGL_INCLUDE_DIR}) 33 | 34 | add_subdirectory(glfw) 35 | 36 | add_subdirectory(src) 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenGL Tutorial Environment 2 | 3 | This codebase was developed for 15-462 Computer Graphics at CMU to 4 | demonstrate basic OpenGL API functionality. You can use the included 5 | Sublime Text project, which has a build system already set up. 6 | 7 | ## Building 8 | 9 | Starting in the root directory: 10 | 11 | $ mkdir build 12 | $ cd build 13 | $ cmake .. 14 | $ make 15 | 16 | I haven't checked support on Windows / Linux (only macOS), but it 17 | should build correctly because GLFW, GLM, and OpenGL are cross platform. 18 | 19 | ## Modifying the code 20 | 21 | `GraphicsManager.cpp` handles most of the boilerplate GLFW / GL code as 22 | well as the main render loop. The `Mesh.cpp` can load basic .obj files 23 | directly (make sure to only export triangles and disable materials and UV 24 | data). 25 | 26 | You can throw your rendering code in the `render()` function inside of 27 | `main.cpp`. 28 | 29 | ## References 30 | 31 | I used this starter code to teach a recitation on OpenGL. You can find 32 | some examples inside of the `checkpoints/` folder. 33 | -------------------------------------------------------------------------------- /checkpoints/1_lines.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "GraphicsManager.hpp" 14 | #include "Mesh.hpp" 15 | 16 | void render(double current_time, GraphicsManager *gm) { 17 | /** Drawing Code Goes Here! **/ 18 | 19 | /** 1. Drawing lines, and lines with thickness **/ 20 | glColor4f(1.0f, 1.0f, 1.0f, 1.0f); 21 | glLineWidth(1.0f); 22 | glBegin(GL_LINES); 23 | glVertex3f(-0.5f, 0, 0); 24 | glVertex3f(0.5f, 0, 0); 25 | glEnd(); 26 | 27 | glLineWidth(5.0f); 28 | glBegin(GL_LINES); 29 | glColor4f(1.0f, 0, 0, 1.0f); 30 | glVertex3f(-0.2f, -0.4, 0); 31 | glColor4f(0, 0, 1.0f, 1.0f); 32 | glVertex3f(0.2f, 0.4, 0); 33 | glEnd(); 34 | } 35 | 36 | int main(int argc, char **argv) { 37 | std::string title = "OpenGL Tutorial"; 38 | std::function pass = &render; 39 | 40 | GraphicsManager *gm = new GraphicsManager(title, pass); 41 | 42 | gm->set_gl_version(2, 1); // Set OpenGL profile to 2.1 43 | gm->execute(); 44 | 45 | return 0; 46 | } -------------------------------------------------------------------------------- /checkpoints/2_triangles.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "GraphicsManager.hpp" 14 | #include "Mesh.hpp" 15 | 16 | void render(double current_time, GraphicsManager *gm) { 17 | /** Drawing Code Goes Here! **/ 18 | 19 | /** 2. Drawing Triangles w/ Color **/ 20 | glBegin(GL_TRIANGLES); 21 | glVertex3f(-0.5f, -0.5f, 0); 22 | glVertex3f(-0.5f, 0.5f, 0); 23 | glVertex3f(0.5f, -0.5f, 0); 24 | 25 | //glColor4f(0.0f, 1.0f, 1.0f, 1.0f); 26 | glVertex3f(-0.5f, 0.5f, 0); 27 | glVertex3f(0.5f, 0.5f, 0); 28 | glVertex3f(0.5f, -0.5f, 0); 29 | glEnd(); 30 | } 31 | 32 | int main(int argc, char **argv) { 33 | std::string title = "OpenGL Tutorial"; 34 | std::function pass = &render; 35 | 36 | GraphicsManager *gm = new GraphicsManager(title, pass); 37 | 38 | gm->set_gl_version(2, 1); // Set OpenGL profile to 2.1 39 | gm->execute(); 40 | 41 | return 0; 42 | } -------------------------------------------------------------------------------- /checkpoints/3_transformations.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "GraphicsManager.hpp" 14 | #include "Mesh.hpp" 15 | 16 | void draw_box() { 17 | glBegin(GL_TRIANGLES); 18 | glVertex3f(-0.5f, -0.5f, 0); 19 | glVertex3f(-0.5f, 0.5f, 0); 20 | glVertex3f(0.5f, -0.5f, 0); 21 | glVertex3f(-0.5f, 0.5f, 0); 22 | glVertex3f(0.5f, 0.5f, 0); 23 | glVertex3f(0.5f, -0.5f, 0); 24 | glEnd(); 25 | } 26 | 27 | void render(double current_time, GraphicsManager *gm) { 28 | /** Drawing Code Goes Here! **/ 29 | 30 | /** 3. Transformations **/ 31 | glTranslatef(0.0f, 0.2f, 0.0f); // applied in all cases 32 | glPushMatrix(); 33 | // Transformations are in reverse order 34 | glTranslatef(-0.5f, 0, 0); 35 | glRotatef(45.0f, 0, 0, 1); 36 | glScalef(0.2f, 0.2f, 0.2f); 37 | 38 | glColor4f(1.0f, 0.0f, 0.0f, 1.0f); 39 | draw_box(); 40 | glPopMatrix(); 41 | glPushMatrix(); 42 | glTranslatef(0.5f, 0, 0); 43 | glRotatef(20.0f, 0, 0, 1); 44 | glScalef(0.2f, 0.4f, 0.2f); 45 | 46 | glColor4f(0.0f, 1.0f, 0.0f, 1.0f); 47 | draw_box(); 48 | 49 | // Nested transformations 50 | glPushMatrix(); 51 | glScalef(0.5f, 0.5f, 0.5f); 52 | 53 | glColor4f(0.0f, 0.0f, 1.0f, 1.0f); 54 | draw_box(); 55 | glPopMatrix(); 56 | glPopMatrix(); 57 | 58 | glPushMatrix(); 59 | glm::mat4 custom_rot(1.0f); // identity 60 | custom_rot = glm::rotate(custom_rot, (float)glm::radians(10.0f * current_time), glm::vec3(0,0,1)); 61 | custom_rot = glm::scale(custom_rot, glm::vec3(0.2f, 0.2f, 0.2f)); 62 | // glLoadMatrixf replaces the current matrix on the stack 63 | glLoadMatrixf(glm::value_ptr(custom_rot)); 64 | // glMultMatrixf multiplies the current matrix by this one 65 | // glMultMatrixf(glm::value_ptr(custom_rot)); 66 | 67 | glColor4f(1.0f, 1.0f, 1.0f, 1.0f); 68 | draw_box(); 69 | glPopMatrix(); 70 | } 71 | 72 | int main(int argc, char **argv) { 73 | std::string title = "OpenGL Tutorial"; 74 | std::function pass = &render; 75 | 76 | GraphicsManager *gm = new GraphicsManager(title, pass); 77 | 78 | gm->set_gl_version(2, 1); // Set OpenGL profile to 2.1 79 | gm->execute(); 80 | 81 | return 0; 82 | } -------------------------------------------------------------------------------- /checkpoints/4_blending.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "GraphicsManager.hpp" 14 | #include "Mesh.hpp" 15 | 16 | void draw_box() { 17 | glBegin(GL_TRIANGLES); 18 | glVertex3f(-0.5f, -0.5f, 0); 19 | glVertex3f(-0.5f, 0.5f, 0); 20 | glVertex3f(0.5f, -0.5f, 0); 21 | glVertex3f(-0.5f, 0.5f, 0); 22 | glVertex3f(0.5f, 0.5f, 0); 23 | glVertex3f(0.5f, -0.5f, 0); 24 | glEnd(); 25 | } 26 | 27 | void render(double current_time, GraphicsManager *gm) { 28 | /** Drawing Code Goes Here! **/ 29 | 30 | /** 4. Blend modes **/ 31 | glEnable(GL_BLEND); 32 | // Alpha blending (more on this in later lectures!) 33 | // Final color evaluates to [s.rgb * s.a + d.rgb * (1 - s.a)] 34 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 35 | 36 | glPushMatrix(); 37 | 38 | glScalef(0.5f, 0.5f, 0.5f); 39 | 40 | glPushMatrix(); 41 | 42 | glColor4f(1.0f, 0, 0, 0.5f); 43 | glTranslatef(-0.1f, -0.1f, 0); 44 | draw_box(); 45 | 46 | glPopMatrix(); 47 | 48 | glColor4f(0, 0, 1.0f, 0.5f); 49 | glTranslatef(0.1f, 0.1f, 0); 50 | draw_box(); 51 | 52 | glPopMatrix(); 53 | 54 | glDisable(GL_BLEND); 55 | } 56 | 57 | int main(int argc, char **argv) { 58 | std::string title = "OpenGL Tutorial"; 59 | std::function pass = &render; 60 | 61 | GraphicsManager *gm = new GraphicsManager(title, pass); 62 | 63 | gm->set_gl_version(2, 1); // Set OpenGL profile to 2.1 64 | gm->execute(); 65 | 66 | return 0; 67 | } -------------------------------------------------------------------------------- /checkpoints/5_mesh.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "GraphicsManager.hpp" 14 | #include "Mesh.hpp" 15 | 16 | Mesh *display; 17 | 18 | void render(double current_time, GraphicsManager *gm) { 19 | /** Drawing Code Goes Here! **/ 20 | 21 | /** 5. Drawing objects using Mesh.cpp **/ 22 | glColor4f(0.7f, 0.8f, 0.8f, 1.0f); 23 | display->draw(); 24 | } 25 | 26 | int main(int argc, char **argv) { 27 | std::string title = "OpenGL Tutorial"; 28 | std::function pass = &render; 29 | 30 | const char *path = argc > 1 ? argv[1] : "../../obj/utah-teapot.obj"; 31 | 32 | display = new Mesh(path); 33 | 34 | GraphicsManager *gm = new GraphicsManager(title, pass); 35 | 36 | gm->set_gl_version(2, 1); // Set OpenGL profile to 2.1 37 | gm->execute(); 38 | 39 | return 0; 40 | } -------------------------------------------------------------------------------- /checkpoints/6_mvp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "GraphicsManager.hpp" 14 | #include "Mesh.hpp" 15 | 16 | Mesh *display; 17 | 18 | void draw_box() { 19 | glBegin(GL_TRIANGLES); 20 | glVertex3f(-0.5f, -0.5f, 0); 21 | glVertex3f(-0.5f, 0.5f, 0); 22 | glVertex3f(0.5f, -0.5f, 0); 23 | glVertex3f(-0.5f, 0.5f, 0); 24 | glVertex3f(0.5f, 0.5f, 0); 25 | glVertex3f(0.5f, -0.5f, 0); 26 | glEnd(); 27 | } 28 | 29 | void render(double current_time, GraphicsManager *gm) { 30 | /** Drawing Code Goes Here! **/ 31 | 32 | /** 6. Example Model / View / Projection matrix config for scene **/ 33 | glColor4f(0.7f, 0.8f, 0.8f, 1.0f); 34 | // Model matrix encodes object position 35 | glm::mat4 model(1.0f); 36 | model = glm::scale(model, glm::vec3(5, 5, 5)); 37 | model = glm::rotate(model, (float)glm::radians(-25.0f * current_time), glm::vec3(0, 1, 0)); 38 | model = glm::translate(model, glm::vec3(0, 0, 0)); 39 | // View matrix encodes camera position / orientation 40 | glm::mat4 view(1.0f); 41 | view = glm::rotate(view, glm::radians(35.0f), glm::vec3(1, 0, 0)); 42 | view = glm::rotate(view, glm::radians(-90.0f), glm::vec3(0, 1, 0)); 43 | view = glm::translate(view, glm::vec3(-2.0f, -1.0f, 0)); 44 | // Projection matrix encodes perspective matrix 45 | glm::mat4 projection = glm::perspective(glm::radians(90.0f), gm->aspect(), 0.1f, 40.0f); 46 | 47 | // We can call this once per frame 48 | glMatrixMode(GL_PROJECTION); 49 | glLoadMatrixf(glm::value_ptr(projection)); 50 | // We need to call this once per object rendered 51 | glMatrixMode(GL_MODELVIEW); 52 | glLoadMatrixf(glm::value_ptr(view * model)); 53 | 54 | display->draw(); 55 | } 56 | 57 | int main(int argc, char **argv) { 58 | std::string title = "OpenGL Tutorial"; 59 | std::function pass = &render; 60 | 61 | const char *path = argc > 1 ? argv[1] : "../../obj/utah-teapot.obj"; 62 | 63 | display = new Mesh(path); 64 | 65 | GraphicsManager *gm = new GraphicsManager(title, pass); 66 | 67 | gm->set_gl_version(2, 1); // Set OpenGL profile to 2.1 68 | gm->execute(); 69 | 70 | return 0; 71 | } -------------------------------------------------------------------------------- /checkpoints/7_lighting.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "GraphicsManager.hpp" 14 | #include "Mesh.hpp" 15 | 16 | Mesh *display; 17 | 18 | void draw_box() { 19 | glBegin(GL_TRIANGLES); 20 | glVertex3f(-0.5f, -0.5f, 0); 21 | glVertex3f(-0.5f, 0.5f, 0); 22 | glVertex3f(0.5f, -0.5f, 0); 23 | glVertex3f(-0.5f, 0.5f, 0); 24 | glVertex3f(0.5f, 0.5f, 0); 25 | glVertex3f(0.5f, -0.5f, 0); 26 | glEnd(); 27 | } 28 | 29 | void render(double current_time, GraphicsManager *gm) { 30 | /** Drawing Code Goes Here! **/ 31 | 32 | /** 7. Same as ex6 (up to before display->draw), but with lighting and depth **/ 33 | glColor4f(0.7f, 0.8f, 0.8f, 1.0f); 34 | // Model matrix encodes object position 35 | glm::mat4 model(1.0f); 36 | model = glm::scale(model, glm::vec3(5, 5, 5)); 37 | model = glm::rotate(model, (float)glm::radians(-25.0f * current_time), glm::vec3(0, 1, 0)); 38 | model = glm::translate(model, glm::vec3(0, 0, 0)); 39 | // View matrix encodes camera position / orientation 40 | glm::mat4 view(1.0f); 41 | view = glm::rotate(view, glm::radians(35.0f), glm::vec3(1, 0, 0)); 42 | view = glm::rotate(view, glm::radians(-90.0f), glm::vec3(0, 1, 0)); 43 | view = glm::translate(view, glm::vec3(-2.0f, -1.0f, 0)); 44 | // Projection matrix encodes perspective matrix 45 | glm::mat4 projection = glm::perspective(glm::radians(90.0f), gm->aspect(), 0.1f, 40.0f); 46 | 47 | // We can call this once per frame 48 | glMatrixMode(GL_PROJECTION); 49 | glLoadMatrixf(glm::value_ptr(projection)); 50 | // We need to call this once per object rendered 51 | glMatrixMode(GL_MODELVIEW); 52 | glLoadMatrixf(glm::value_ptr(view * model)); 53 | 54 | /** Code diverges from ex6 here **/ 55 | 56 | glm::vec3 light_pos = glm::vec3(0, sinf(current_time), cosf(current_time)) * 0.17f; 57 | 58 | glEnable(GL_LIGHTING); 59 | glEnable(GL_COLOR_MATERIAL); 60 | glEnable(GL_LIGHT0); 61 | glEnable(GL_DEPTH_TEST); 62 | 63 | GLfloat light_ambient[] = { 0.1, 0.1, 0.1, 1.0 }; 64 | GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; 65 | GLfloat light_specular[] = { 0, 0, 0, 1.0 }; 66 | GLfloat light_position[] = { light_pos.x, light_pos.y, light_pos.z, 1.0 }; 67 | glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); 68 | glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); 69 | glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); 70 | glLightfv(GL_LIGHT0, GL_POSITION, light_position); 71 | 72 | glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.0f); 73 | glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.0f); 74 | glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 1.0f); 75 | 76 | glColorMaterial (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); 77 | glShadeModel (GL_SMOOTH); 78 | 79 | glColor4f(0.7f, 0.8f, 0.8f, 1.0f); 80 | display->draw(); 81 | glDisable(GL_LIGHT0); 82 | glDisable(GL_LIGHTING); 83 | glDisable(GL_COLOR_MATERIAL); 84 | 85 | glPointSize(5); 86 | glBegin(GL_POINTS); 87 | glColor4f(1.0, 1.0, 1.0, 1.0f); 88 | glVertex3f(light_pos.x, light_pos.y, light_pos.z); 89 | glEnd(); 90 | 91 | glDisable(GL_DEPTH_TEST); 92 | } 93 | 94 | int main(int argc, char **argv) { 95 | std::string title = "OpenGL Tutorial"; 96 | std::function pass = &render; 97 | 98 | const char *path = argc > 1 ? argv[1] : "../../obj/utah-teapot.obj"; 99 | 100 | display = new Mesh(path); 101 | 102 | GraphicsManager *gm = new GraphicsManager(title, pass); 103 | 104 | gm->set_gl_version(2, 1); // Set OpenGL profile to 2.1 105 | gm->execute(); 106 | 107 | return 0; 108 | } -------------------------------------------------------------------------------- /glfw/.appveyor.yml: -------------------------------------------------------------------------------- 1 | branches: 2 | only: 3 | - ci 4 | - master 5 | skip_tags: true 6 | environment: 7 | matrix: 8 | - BUILD_SHARED_LIBS: ON 9 | - BUILD_SHARED_LIBS: OFF 10 | matrix: 11 | fast_finish: true 12 | build_script: 13 | - mkdir build 14 | - cd build 15 | - cmake -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% .. 16 | - cmake --build . 17 | notifications: 18 | - provider: Email 19 | to: 20 | - ci@glfw.org 21 | - on_build_failure: true 22 | - on_build_success: false 23 | -------------------------------------------------------------------------------- /glfw/.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | compiler: clang 3 | branches: 4 | only: 5 | - ci 6 | - master 7 | os: 8 | - linux 9 | - osx 10 | sudo: false 11 | addons: 12 | apt: 13 | sources: 14 | - kubuntu-backports 15 | packages: 16 | - cmake 17 | env: 18 | - BUILD_SHARED_LIBS=ON 19 | - BUILD_SHARED_LIBS=OFF 20 | script: 21 | - mkdir build 22 | - cd build 23 | - cmake -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} .. 24 | - cmake --build . 25 | notifications: 26 | email: 27 | recipients: 28 | - ci@glfw.org 29 | on_success: never 30 | on_failure: always 31 | -------------------------------------------------------------------------------- /glfw/CMake/MacOSXBundleInfo.plist.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${MACOSX_BUNDLE_EXECUTABLE_NAME} 9 | CFBundleGetInfoString 10 | ${MACOSX_BUNDLE_INFO_STRING} 11 | CFBundleIconFile 12 | ${MACOSX_BUNDLE_ICON_FILE} 13 | CFBundleIdentifier 14 | ${MACOSX_BUNDLE_GUI_IDENTIFIER} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleLongVersionString 18 | ${MACOSX_BUNDLE_LONG_VERSION_STRING} 19 | CFBundleName 20 | ${MACOSX_BUNDLE_BUNDLE_NAME} 21 | CFBundlePackageType 22 | APPL 23 | CFBundleShortVersionString 24 | ${MACOSX_BUNDLE_SHORT_VERSION_STRING} 25 | CFBundleSignature 26 | ???? 27 | CFBundleVersion 28 | ${MACOSX_BUNDLE_BUNDLE_VERSION} 29 | CSResourcesFileMapped 30 | 31 | LSRequiresCarbon 32 | 33 | NSHumanReadableCopyright 34 | ${MACOSX_BUNDLE_COPYRIGHT} 35 | NSHighResolutionCapable 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /glfw/CMake/amd64-mingw32msvc.cmake: -------------------------------------------------------------------------------- 1 | # Define the environment for cross compiling from Linux to Win64 2 | SET(CMAKE_SYSTEM_NAME Windows) 3 | SET(CMAKE_SYSTEM_VERSION 1) 4 | SET(CMAKE_C_COMPILER "amd64-mingw32msvc-gcc") 5 | SET(CMAKE_CXX_COMPILER "amd64-mingw32msvc-g++") 6 | SET(CMAKE_RC_COMPILER "amd64-mingw32msvc-windres") 7 | SET(CMAKE_RANLIB "amd64-mingw32msvc-ranlib") 8 | 9 | # Configure the behaviour of the find commands 10 | SET(CMAKE_FIND_ROOT_PATH "/usr/amd64-mingw32msvc") 11 | SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 12 | SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 13 | SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 14 | -------------------------------------------------------------------------------- /glfw/CMake/i586-mingw32msvc.cmake: -------------------------------------------------------------------------------- 1 | # Define the environment for cross compiling from Linux to Win32 2 | SET(CMAKE_SYSTEM_NAME Windows) 3 | SET(CMAKE_SYSTEM_VERSION 1) 4 | SET(CMAKE_C_COMPILER "i586-mingw32msvc-gcc") 5 | SET(CMAKE_CXX_COMPILER "i586-mingw32msvc-g++") 6 | SET(CMAKE_RC_COMPILER "i586-mingw32msvc-windres") 7 | SET(CMAKE_RANLIB "i586-mingw32msvc-ranlib") 8 | 9 | # Configure the behaviour of the find commands 10 | SET(CMAKE_FIND_ROOT_PATH "/usr/i586-mingw32msvc") 11 | SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 12 | SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 13 | SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 14 | -------------------------------------------------------------------------------- /glfw/CMake/i686-pc-mingw32.cmake: -------------------------------------------------------------------------------- 1 | # Define the environment for cross compiling from Linux to Win32 2 | SET(CMAKE_SYSTEM_NAME Windows) # Target system name 3 | SET(CMAKE_SYSTEM_VERSION 1) 4 | SET(CMAKE_C_COMPILER "i686-pc-mingw32-gcc") 5 | SET(CMAKE_CXX_COMPILER "i686-pc-mingw32-g++") 6 | SET(CMAKE_RC_COMPILER "i686-pc-mingw32-windres") 7 | SET(CMAKE_RANLIB "i686-pc-mingw32-ranlib") 8 | 9 | #Configure the behaviour of the find commands 10 | SET(CMAKE_FIND_ROOT_PATH "/opt/mingw/usr/i686-pc-mingw32") 11 | SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 12 | SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 13 | SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 14 | -------------------------------------------------------------------------------- /glfw/CMake/i686-w64-mingw32.cmake: -------------------------------------------------------------------------------- 1 | # Define the environment for cross compiling from Linux to Win32 2 | SET(CMAKE_SYSTEM_NAME Windows) # Target system name 3 | SET(CMAKE_SYSTEM_VERSION 1) 4 | SET(CMAKE_C_COMPILER "i686-w64-mingw32-gcc") 5 | SET(CMAKE_CXX_COMPILER "i686-w64-mingw32-g++") 6 | SET(CMAKE_RC_COMPILER "i686-w64-mingw32-windres") 7 | SET(CMAKE_RANLIB "i686-w64-mingw32-ranlib") 8 | 9 | # Configure the behaviour of the find commands 10 | SET(CMAKE_FIND_ROOT_PATH "/usr/i686-w64-mingw32") 11 | SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 12 | SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 13 | SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 14 | -------------------------------------------------------------------------------- /glfw/CMake/modules/FindMir.cmake: -------------------------------------------------------------------------------- 1 | # Try to find Mir on a Unix system 2 | # 3 | # This will define: 4 | # 5 | # MIR_LIBRARIES - Link these to use Wayland 6 | # MIR_INCLUDE_DIR - Include directory for Wayland 7 | # 8 | # Copyright (c) 2014 Brandon Schaefer 9 | 10 | if (NOT WIN32) 11 | 12 | find_package (PkgConfig) 13 | pkg_check_modules (PKG_MIR QUIET mirclient) 14 | 15 | set (MIR_INCLUDE_DIR ${PKG_MIR_INCLUDE_DIRS}) 16 | set (MIR_LIBRARIES ${PKG_MIR_LIBRARIES}) 17 | 18 | endif () 19 | -------------------------------------------------------------------------------- /glfw/CMake/modules/FindVulkan.cmake: -------------------------------------------------------------------------------- 1 | # Find Vulkan 2 | # 3 | # VULKAN_INCLUDE_DIR 4 | # VULKAN_LIBRARY 5 | # VULKAN_FOUND 6 | 7 | if (WIN32) 8 | find_path(VULKAN_INCLUDE_DIR NAMES vulkan/vulkan.h HINTS 9 | "$ENV{VULKAN_SDK}/Include" 10 | "$ENV{VK_SDK_PATH}/Include") 11 | if (CMAKE_CL_64) 12 | find_library(VULKAN_LIBRARY NAMES vulkan-1 HINTS 13 | "$ENV{VULKAN_SDK}/Bin" 14 | "$ENV{VK_SDK_PATH}/Bin") 15 | find_library(VULKAN_STATIC_LIBRARY NAMES vkstatic.1 HINTS 16 | "$ENV{VULKAN_SDK}/Bin" 17 | "$ENV{VK_SDK_PATH}/Bin") 18 | else() 19 | find_library(VULKAN_LIBRARY NAMES vulkan-1 HINTS 20 | "$ENV{VULKAN_SDK}/Bin32" 21 | "$ENV{VK_SDK_PATH}/Bin32") 22 | endif() 23 | else() 24 | find_path(VULKAN_INCLUDE_DIR NAMES vulkan/vulkan.h HINTS 25 | "$ENV{VULKAN_SDK}/include") 26 | find_library(VULKAN_LIBRARY NAMES vulkan HINTS 27 | "$ENV{VULKAN_SDK}/lib") 28 | endif() 29 | 30 | include(FindPackageHandleStandardArgs) 31 | find_package_handle_standard_args(Vulkan DEFAULT_MSG VULKAN_LIBRARY VULKAN_INCLUDE_DIR) 32 | 33 | mark_as_advanced(VULKAN_INCLUDE_DIR VULKAN_LIBRARY VULKAN_STATIC_LIBRARY) 34 | 35 | -------------------------------------------------------------------------------- /glfw/CMake/modules/FindWaylandProtocols.cmake: -------------------------------------------------------------------------------- 1 | find_package(PkgConfig) 2 | 3 | pkg_check_modules(WaylandProtocols QUIET wayland-protocols>=${WaylandProtocols_FIND_VERSION}) 4 | 5 | execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=pkgdatadir wayland-protocols 6 | OUTPUT_VARIABLE WaylandProtocols_PKGDATADIR 7 | RESULT_VARIABLE _pkgconfig_failed) 8 | if (_pkgconfig_failed) 9 | message(FATAL_ERROR "Missing wayland-protocols pkgdatadir") 10 | endif() 11 | 12 | string(REGEX REPLACE "[\r\n]" "" WaylandProtocols_PKGDATADIR "${WaylandProtocols_PKGDATADIR}") 13 | 14 | find_package_handle_standard_args(WaylandProtocols 15 | FOUND_VAR 16 | WaylandProtocols_FOUND 17 | REQUIRED_VARS 18 | WaylandProtocols_PKGDATADIR 19 | VERSION_VAR 20 | WaylandProtocols_VERSION 21 | HANDLE_COMPONENTS 22 | ) 23 | 24 | set(WAYLAND_PROTOCOLS_FOUND ${WaylandProtocols_FOUND}) 25 | set(WAYLAND_PROTOCOLS_PKGDATADIR ${WaylandProtocols_PKGDATADIR}) 26 | set(WAYLAND_PROTOCOLS_VERSION ${WaylandProtocols_VERSION}) 27 | -------------------------------------------------------------------------------- /glfw/CMake/modules/FindXKBCommon.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find XKBCommon 2 | # Once done, this will define 3 | # 4 | # XKBCOMMON_FOUND - System has XKBCommon 5 | # XKBCOMMON_INCLUDE_DIRS - The XKBCommon include directories 6 | # XKBCOMMON_LIBRARIES - The libraries needed to use XKBCommon 7 | # XKBCOMMON_DEFINITIONS - Compiler switches required for using XKBCommon 8 | 9 | find_package(PkgConfig) 10 | pkg_check_modules(PC_XKBCOMMON QUIET xkbcommon) 11 | set(XKBCOMMON_DEFINITIONS ${PC_XKBCOMMON_CFLAGS_OTHER}) 12 | 13 | find_path(XKBCOMMON_INCLUDE_DIR 14 | NAMES xkbcommon/xkbcommon.h 15 | HINTS ${PC_XKBCOMMON_INCLUDE_DIR} ${PC_XKBCOMMON_INCLUDE_DIRS} 16 | ) 17 | 18 | find_library(XKBCOMMON_LIBRARY 19 | NAMES xkbcommon 20 | HINTS ${PC_XKBCOMMON_LIBRARY} ${PC_XKBCOMMON_LIBRARY_DIRS} 21 | ) 22 | 23 | set(XKBCOMMON_LIBRARIES ${XKBCOMMON_LIBRARY}) 24 | set(XKBCOMMON_LIBRARY_DIRS ${XKBCOMMON_LIBRARY_DIRS}) 25 | set(XKBCOMMON_INCLUDE_DIRS ${XKBCOMMON_INCLUDE_DIR}) 26 | 27 | include(FindPackageHandleStandardArgs) 28 | find_package_handle_standard_args(XKBCommon DEFAULT_MSG 29 | XKBCOMMON_LIBRARY 30 | XKBCOMMON_INCLUDE_DIR 31 | ) 32 | 33 | mark_as_advanced(XKBCOMMON_LIBRARY XKBCOMMON_INCLUDE_DIR) 34 | 35 | -------------------------------------------------------------------------------- /glfw/CMake/x86_64-w64-mingw32.cmake: -------------------------------------------------------------------------------- 1 | # Define the environment for cross compiling from Linux to Win32 2 | SET(CMAKE_SYSTEM_NAME Windows) # Target system name 3 | SET(CMAKE_SYSTEM_VERSION 1) 4 | SET(CMAKE_C_COMPILER "x86_64-w64-mingw32-gcc") 5 | SET(CMAKE_CXX_COMPILER "x86_64-w64-mingw32-g++") 6 | SET(CMAKE_RC_COMPILER "x86_64-w64-mingw32-windres") 7 | SET(CMAKE_RANLIB "x86_64-w64-mingw32-ranlib") 8 | 9 | # Configure the behaviour of the find commands 10 | SET(CMAKE_FIND_ROOT_PATH "/usr/x86_64-w64-mingw32") 11 | SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 12 | SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 13 | SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 14 | -------------------------------------------------------------------------------- /glfw/COPYING.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002-2006 Marcus Geelnard 2 | Copyright (c) 2006-2016 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 | -------------------------------------------------------------------------------- /glfw/cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | 2 | if (NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 3 | message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") 4 | endif() 5 | 6 | file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) 7 | string(REGEX REPLACE "\n" ";" files "${files}") 8 | 9 | foreach (file ${files}) 10 | message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") 11 | if (EXISTS "$ENV{DESTDIR}${file}") 12 | exec_program("@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" 13 | OUTPUT_VARIABLE rm_out 14 | RETURN_VALUE rm_retval) 15 | if (NOT "${rm_retval}" STREQUAL 0) 16 | MESSAGE(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") 17 | endif() 18 | elseif (IS_SYMLINK "$ENV{DESTDIR}${file}") 19 | EXEC_PROGRAM("@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" 20 | OUTPUT_VARIABLE rm_out 21 | RETURN_VALUE rm_retval) 22 | if (NOT "${rm_retval}" STREQUAL 0) 23 | message(FATAL_ERROR "Problem when removing symlink \"$ENV{DESTDIR}${file}\"") 24 | endif() 25 | else() 26 | message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.") 27 | endif() 28 | endforeach() 29 | 30 | -------------------------------------------------------------------------------- /glfw/deps/getopt.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012, Kim Gräsman 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright notice, 7 | * this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright notice, 9 | * this list of conditions and the following disclaimer in the documentation 10 | * and/or other materials provided with the distribution. 11 | * * Neither the name of Kim Gräsman nor the names of contributors may be used 12 | * to endorse or promote products derived from this software without specific 13 | * prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL KIM GRÄSMAN BE LIABLE FOR ANY DIRECT, 19 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef INCLUDED_GETOPT_PORT_H 28 | #define INCLUDED_GETOPT_PORT_H 29 | 30 | #if defined(__cplusplus) 31 | extern "C" { 32 | #endif 33 | 34 | extern const int no_argument; 35 | extern const int required_argument; 36 | extern const int optional_argument; 37 | 38 | extern char* optarg; 39 | extern int optind, opterr, optopt; 40 | 41 | struct option { 42 | const char* name; 43 | int has_arg; 44 | int* flag; 45 | int val; 46 | }; 47 | 48 | int getopt(int argc, char* const argv[], const char* optstring); 49 | 50 | int getopt_long(int argc, char* const argv[], 51 | const char* optstring, const struct option* longopts, int* longindex); 52 | 53 | #if defined(__cplusplus) 54 | } 55 | #endif 56 | 57 | #endif // INCLUDED_GETOPT_PORT_H 58 | -------------------------------------------------------------------------------- /glfw/deps/mingw/_mingw_dxhelper.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the mingw-w64 runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | 7 | #if defined(_MSC_VER) && !defined(_MSC_EXTENSIONS) 8 | #define NONAMELESSUNION 1 9 | #endif 10 | #if defined(NONAMELESSSTRUCT) && \ 11 | !defined(NONAMELESSUNION) 12 | #define NONAMELESSUNION 1 13 | #endif 14 | #if defined(NONAMELESSUNION) && \ 15 | !defined(NONAMELESSSTRUCT) 16 | #define NONAMELESSSTRUCT 1 17 | #endif 18 | #if !defined(__GNU_EXTENSION) 19 | #if defined(__GNUC__) || defined(__GNUG__) 20 | #define __GNU_EXTENSION __extension__ 21 | #else 22 | #define __GNU_EXTENSION 23 | #endif 24 | #endif /* __extension__ */ 25 | 26 | #ifndef __ANONYMOUS_DEFINED 27 | #define __ANONYMOUS_DEFINED 28 | #if defined(__GNUC__) || defined(__GNUG__) 29 | #define _ANONYMOUS_UNION __extension__ 30 | #define _ANONYMOUS_STRUCT __extension__ 31 | #else 32 | #define _ANONYMOUS_UNION 33 | #define _ANONYMOUS_STRUCT 34 | #endif 35 | #ifndef NONAMELESSUNION 36 | #define _UNION_NAME(x) 37 | #define _STRUCT_NAME(x) 38 | #else /* NONAMELESSUNION */ 39 | #define _UNION_NAME(x) x 40 | #define _STRUCT_NAME(x) x 41 | #endif 42 | #endif /* __ANONYMOUS_DEFINED */ 43 | 44 | #ifndef DUMMYUNIONNAME 45 | # ifdef NONAMELESSUNION 46 | # define DUMMYUNIONNAME u 47 | # define DUMMYUNIONNAME1 u1 /* Wine uses this variant */ 48 | # define DUMMYUNIONNAME2 u2 49 | # define DUMMYUNIONNAME3 u3 50 | # define DUMMYUNIONNAME4 u4 51 | # define DUMMYUNIONNAME5 u5 52 | # define DUMMYUNIONNAME6 u6 53 | # define DUMMYUNIONNAME7 u7 54 | # define DUMMYUNIONNAME8 u8 55 | # define DUMMYUNIONNAME9 u9 56 | # else /* NONAMELESSUNION */ 57 | # define DUMMYUNIONNAME 58 | # define DUMMYUNIONNAME1 /* Wine uses this variant */ 59 | # define DUMMYUNIONNAME2 60 | # define DUMMYUNIONNAME3 61 | # define DUMMYUNIONNAME4 62 | # define DUMMYUNIONNAME5 63 | # define DUMMYUNIONNAME6 64 | # define DUMMYUNIONNAME7 65 | # define DUMMYUNIONNAME8 66 | # define DUMMYUNIONNAME9 67 | # endif 68 | #endif /* DUMMYUNIONNAME */ 69 | 70 | #if !defined(DUMMYUNIONNAME1) /* MinGW does not define this one */ 71 | # ifdef NONAMELESSUNION 72 | # define DUMMYUNIONNAME1 u1 /* Wine uses this variant */ 73 | # else 74 | # define DUMMYUNIONNAME1 /* Wine uses this variant */ 75 | # endif 76 | #endif /* DUMMYUNIONNAME1 */ 77 | 78 | #ifndef DUMMYSTRUCTNAME 79 | # ifdef NONAMELESSUNION 80 | # define DUMMYSTRUCTNAME s 81 | # define DUMMYSTRUCTNAME1 s1 /* Wine uses this variant */ 82 | # define DUMMYSTRUCTNAME2 s2 83 | # define DUMMYSTRUCTNAME3 s3 84 | # define DUMMYSTRUCTNAME4 s4 85 | # define DUMMYSTRUCTNAME5 s5 86 | # else 87 | # define DUMMYSTRUCTNAME 88 | # define DUMMYSTRUCTNAME1 /* Wine uses this variant */ 89 | # define DUMMYSTRUCTNAME2 90 | # define DUMMYSTRUCTNAME3 91 | # define DUMMYSTRUCTNAME4 92 | # define DUMMYSTRUCTNAME5 93 | # endif 94 | #endif /* DUMMYSTRUCTNAME */ 95 | 96 | /* These are for compatibility with the Wine source tree */ 97 | 98 | #ifndef WINELIB_NAME_AW 99 | # ifdef __MINGW_NAME_AW 100 | # define WINELIB_NAME_AW __MINGW_NAME_AW 101 | # else 102 | # ifdef UNICODE 103 | # define WINELIB_NAME_AW(func) func##W 104 | # else 105 | # define WINELIB_NAME_AW(func) func##A 106 | # endif 107 | # endif 108 | #endif /* WINELIB_NAME_AW */ 109 | 110 | #ifndef DECL_WINELIB_TYPE_AW 111 | # ifdef __MINGW_TYPEDEF_AW 112 | # define DECL_WINELIB_TYPE_AW __MINGW_TYPEDEF_AW 113 | # else 114 | # define DECL_WINELIB_TYPE_AW(type) typedef WINELIB_NAME_AW(type) type; 115 | # endif 116 | #endif /* DECL_WINELIB_TYPE_AW */ 117 | 118 | -------------------------------------------------------------------------------- /glfw/deps/mingw/xinput.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The Wine project - Xinput Joystick Library 3 | * Copyright 2008 Andrew Fenn 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 18 | */ 19 | 20 | #ifndef __WINE_XINPUT_H 21 | #define __WINE_XINPUT_H 22 | 23 | #include 24 | 25 | /* 26 | * Bitmasks for the joysticks buttons, determines what has 27 | * been pressed on the joystick, these need to be mapped 28 | * to whatever device you're using instead of an xbox 360 29 | * joystick 30 | */ 31 | 32 | #define XINPUT_GAMEPAD_DPAD_UP 0x0001 33 | #define XINPUT_GAMEPAD_DPAD_DOWN 0x0002 34 | #define XINPUT_GAMEPAD_DPAD_LEFT 0x0004 35 | #define XINPUT_GAMEPAD_DPAD_RIGHT 0x0008 36 | #define XINPUT_GAMEPAD_START 0x0010 37 | #define XINPUT_GAMEPAD_BACK 0x0020 38 | #define XINPUT_GAMEPAD_LEFT_THUMB 0x0040 39 | #define XINPUT_GAMEPAD_RIGHT_THUMB 0x0080 40 | #define XINPUT_GAMEPAD_LEFT_SHOULDER 0x0100 41 | #define XINPUT_GAMEPAD_RIGHT_SHOULDER 0x0200 42 | #define XINPUT_GAMEPAD_A 0x1000 43 | #define XINPUT_GAMEPAD_B 0x2000 44 | #define XINPUT_GAMEPAD_X 0x4000 45 | #define XINPUT_GAMEPAD_Y 0x8000 46 | 47 | /* 48 | * Defines the flags used to determine if the user is pushing 49 | * down on a button, not holding a button, etc 50 | */ 51 | 52 | #define XINPUT_KEYSTROKE_KEYDOWN 0x0001 53 | #define XINPUT_KEYSTROKE_KEYUP 0x0002 54 | #define XINPUT_KEYSTROKE_REPEAT 0x0004 55 | 56 | /* 57 | * Defines the codes which are returned by XInputGetKeystroke 58 | */ 59 | 60 | #define VK_PAD_A 0x5800 61 | #define VK_PAD_B 0x5801 62 | #define VK_PAD_X 0x5802 63 | #define VK_PAD_Y 0x5803 64 | #define VK_PAD_RSHOULDER 0x5804 65 | #define VK_PAD_LSHOULDER 0x5805 66 | #define VK_PAD_LTRIGGER 0x5806 67 | #define VK_PAD_RTRIGGER 0x5807 68 | #define VK_PAD_DPAD_UP 0x5810 69 | #define VK_PAD_DPAD_DOWN 0x5811 70 | #define VK_PAD_DPAD_LEFT 0x5812 71 | #define VK_PAD_DPAD_RIGHT 0x5813 72 | #define VK_PAD_START 0x5814 73 | #define VK_PAD_BACK 0x5815 74 | #define VK_PAD_LTHUMB_PRESS 0x5816 75 | #define VK_PAD_RTHUMB_PRESS 0x5817 76 | #define VK_PAD_LTHUMB_UP 0x5820 77 | #define VK_PAD_LTHUMB_DOWN 0x5821 78 | #define VK_PAD_LTHUMB_RIGHT 0x5822 79 | #define VK_PAD_LTHUMB_LEFT 0x5823 80 | #define VK_PAD_LTHUMB_UPLEFT 0x5824 81 | #define VK_PAD_LTHUMB_UPRIGHT 0x5825 82 | #define VK_PAD_LTHUMB_DOWNRIGHT 0x5826 83 | #define VK_PAD_LTHUMB_DOWNLEFT 0x5827 84 | #define VK_PAD_RTHUMB_UP 0x5830 85 | #define VK_PAD_RTHUMB_DOWN 0x5831 86 | #define VK_PAD_RTHUMB_RIGHT 0x5832 87 | #define VK_PAD_RTHUMB_LEFT 0x5833 88 | #define VK_PAD_RTHUMB_UPLEFT 0x5834 89 | #define VK_PAD_RTHUMB_UPRIGHT 0x5835 90 | #define VK_PAD_RTHUMB_DOWNRIGHT 0x5836 91 | #define VK_PAD_RTHUMB_DOWNLEFT 0x5837 92 | 93 | /* 94 | * Deadzones are for analogue joystick controls on the joypad 95 | * which determine when input should be assumed to be in the 96 | * middle of the pad. This is a threshold to stop a joypad 97 | * controlling the game when the player isn't touching the 98 | * controls. 99 | */ 100 | 101 | #define XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE 7849 102 | #define XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE 8689 103 | #define XINPUT_GAMEPAD_TRIGGER_THRESHOLD 30 104 | 105 | 106 | /* 107 | * Defines what type of abilities the type of joystick has 108 | * DEVTYPE_GAMEPAD is available for all joysticks, however 109 | * there may be more specific identifiers for other joysticks 110 | * which are being used. 111 | */ 112 | 113 | #define XINPUT_DEVTYPE_GAMEPAD 0x01 114 | #define XINPUT_DEVSUBTYPE_GAMEPAD 0x01 115 | #define XINPUT_DEVSUBTYPE_WHEEL 0x02 116 | #define XINPUT_DEVSUBTYPE_ARCADE_STICK 0x03 117 | #define XINPUT_DEVSUBTYPE_FLIGHT_SICK 0x04 118 | #define XINPUT_DEVSUBTYPE_DANCE_PAD 0x05 119 | #define XINPUT_DEVSUBTYPE_GUITAR 0x06 120 | #define XINPUT_DEVSUBTYPE_DRUM_KIT 0x08 121 | 122 | /* 123 | * These are used with the XInputGetCapabilities function to 124 | * determine the abilities to the joystick which has been 125 | * plugged in. 126 | */ 127 | 128 | #define XINPUT_CAPS_VOICE_SUPPORTED 0x0004 129 | #define XINPUT_FLAG_GAMEPAD 0x00000001 130 | 131 | /* 132 | * Defines the status of the battery if one is used in the 133 | * attached joystick. The first two define if the joystick 134 | * supports a battery. Disconnected means that the joystick 135 | * isn't connected. Wired shows that the joystick is a wired 136 | * joystick. 137 | */ 138 | 139 | #define BATTERY_DEVTYPE_GAMEPAD 0x00 140 | #define BATTERY_DEVTYPE_HEADSET 0x01 141 | #define BATTERY_TYPE_DISCONNECTED 0x00 142 | #define BATTERY_TYPE_WIRED 0x01 143 | #define BATTERY_TYPE_ALKALINE 0x02 144 | #define BATTERY_TYPE_NIMH 0x03 145 | #define BATTERY_TYPE_UNKNOWN 0xFF 146 | #define BATTERY_LEVEL_EMPTY 0x00 147 | #define BATTERY_LEVEL_LOW 0x01 148 | #define BATTERY_LEVEL_MEDIUM 0x02 149 | #define BATTERY_LEVEL_FULL 0x03 150 | 151 | /* 152 | * How many joysticks can be used with this library. Games that 153 | * use the xinput library will not go over this number. 154 | */ 155 | 156 | #define XUSER_MAX_COUNT 4 157 | #define XUSER_INDEX_ANY 0x000000FF 158 | 159 | /* 160 | * Defines the structure of an xbox 360 joystick. 161 | */ 162 | 163 | typedef struct _XINPUT_GAMEPAD { 164 | WORD wButtons; 165 | BYTE bLeftTrigger; 166 | BYTE bRightTrigger; 167 | SHORT sThumbLX; 168 | SHORT sThumbLY; 169 | SHORT sThumbRX; 170 | SHORT sThumbRY; 171 | } XINPUT_GAMEPAD, *PXINPUT_GAMEPAD; 172 | 173 | typedef struct _XINPUT_STATE { 174 | DWORD dwPacketNumber; 175 | XINPUT_GAMEPAD Gamepad; 176 | } XINPUT_STATE, *PXINPUT_STATE; 177 | 178 | /* 179 | * Defines the structure of how much vibration is set on both the 180 | * right and left motors in a joystick. If you're not using a 360 181 | * joystick you will have to map these to your device. 182 | */ 183 | 184 | typedef struct _XINPUT_VIBRATION { 185 | WORD wLeftMotorSpeed; 186 | WORD wRightMotorSpeed; 187 | } XINPUT_VIBRATION, *PXINPUT_VIBRATION; 188 | 189 | /* 190 | * Defines the structure for what kind of abilities the joystick has 191 | * such abilities are things such as if the joystick has the ability 192 | * to send and receive audio, if the joystick is in fact a driving 193 | * wheel or perhaps if the joystick is some kind of dance pad or 194 | * guitar. 195 | */ 196 | 197 | typedef struct _XINPUT_CAPABILITIES { 198 | BYTE Type; 199 | BYTE SubType; 200 | WORD Flags; 201 | XINPUT_GAMEPAD Gamepad; 202 | XINPUT_VIBRATION Vibration; 203 | } XINPUT_CAPABILITIES, *PXINPUT_CAPABILITIES; 204 | 205 | /* 206 | * Defines the structure for a joystick input event which is 207 | * retrieved using the function XInputGetKeystroke 208 | */ 209 | typedef struct _XINPUT_KEYSTROKE { 210 | WORD VirtualKey; 211 | WCHAR Unicode; 212 | WORD Flags; 213 | BYTE UserIndex; 214 | BYTE HidCode; 215 | } XINPUT_KEYSTROKE, *PXINPUT_KEYSTROKE; 216 | 217 | typedef struct _XINPUT_BATTERY_INFORMATION 218 | { 219 | BYTE BatteryType; 220 | BYTE BatteryLevel; 221 | } XINPUT_BATTERY_INFORMATION, *PXINPUT_BATTERY_INFORMATION; 222 | 223 | #ifdef __cplusplus 224 | extern "C" { 225 | #endif 226 | 227 | void WINAPI XInputEnable(WINBOOL); 228 | DWORD WINAPI XInputSetState(DWORD, XINPUT_VIBRATION*); 229 | DWORD WINAPI XInputGetState(DWORD, XINPUT_STATE*); 230 | DWORD WINAPI XInputGetKeystroke(DWORD, DWORD, PXINPUT_KEYSTROKE); 231 | DWORD WINAPI XInputGetCapabilities(DWORD, DWORD, XINPUT_CAPABILITIES*); 232 | DWORD WINAPI XInputGetDSoundAudioDeviceGuids(DWORD, GUID*, GUID*); 233 | DWORD WINAPI XInputGetBatteryInformation(DWORD, BYTE, XINPUT_BATTERY_INFORMATION*); 234 | 235 | #ifdef __cplusplus 236 | } 237 | #endif 238 | 239 | #endif /* __WINE_XINPUT_H */ 240 | -------------------------------------------------------------------------------- /glfw/deps/vulkan/vk_platform.h: -------------------------------------------------------------------------------- 1 | // 2 | // File: vk_platform.h 3 | // 4 | /* 5 | ** Copyright (c) 2014-2015 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | 21 | #ifndef VK_PLATFORM_H_ 22 | #define VK_PLATFORM_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" 26 | { 27 | #endif // __cplusplus 28 | 29 | /* 30 | *************************************************************************************************** 31 | * Platform-specific directives and type declarations 32 | *************************************************************************************************** 33 | */ 34 | 35 | /* Platform-specific calling convention macros. 36 | * 37 | * Platforms should define these so that Vulkan clients call Vulkan commands 38 | * with the same calling conventions that the Vulkan implementation expects. 39 | * 40 | * VKAPI_ATTR - Placed before the return type in function declarations. 41 | * Useful for C++11 and GCC/Clang-style function attribute syntax. 42 | * VKAPI_CALL - Placed after the return type in function declarations. 43 | * Useful for MSVC-style calling convention syntax. 44 | * VKAPI_PTR - Placed between the '(' and '*' in function pointer types. 45 | * 46 | * Function declaration: VKAPI_ATTR void VKAPI_CALL vkCommand(void); 47 | * Function pointer type: typedef void (VKAPI_PTR *PFN_vkCommand)(void); 48 | */ 49 | #if defined(_WIN32) 50 | // On Windows, Vulkan commands use the stdcall convention 51 | #define VKAPI_ATTR 52 | #define VKAPI_CALL __stdcall 53 | #define VKAPI_PTR VKAPI_CALL 54 | #elif defined(__ANDROID__) && defined(__ARM_EABI__) && !defined(__ARM_ARCH_7A__) 55 | // Android does not support Vulkan in native code using the "armeabi" ABI. 56 | #error "Vulkan requires the 'armeabi-v7a' or 'armeabi-v7a-hard' ABI on 32-bit ARM CPUs" 57 | #elif defined(__ANDROID__) && defined(__ARM_ARCH_7A__) 58 | // On Android/ARMv7a, Vulkan functions use the armeabi-v7a-hard calling 59 | // convention, even if the application's native code is compiled with the 60 | // armeabi-v7a calling convention. 61 | #define VKAPI_ATTR __attribute__((pcs("aapcs-vfp"))) 62 | #define VKAPI_CALL 63 | #define VKAPI_PTR VKAPI_ATTR 64 | #else 65 | // On other platforms, use the default calling convention 66 | #define VKAPI_ATTR 67 | #define VKAPI_CALL 68 | #define VKAPI_PTR 69 | #endif 70 | 71 | #include 72 | 73 | #if !defined(VK_NO_STDINT_H) 74 | #if defined(_MSC_VER) && (_MSC_VER < 1600) 75 | typedef signed __int8 int8_t; 76 | typedef unsigned __int8 uint8_t; 77 | typedef signed __int16 int16_t; 78 | typedef unsigned __int16 uint16_t; 79 | typedef signed __int32 int32_t; 80 | typedef unsigned __int32 uint32_t; 81 | typedef signed __int64 int64_t; 82 | typedef unsigned __int64 uint64_t; 83 | #else 84 | #include 85 | #endif 86 | #endif // !defined(VK_NO_STDINT_H) 87 | 88 | #ifdef __cplusplus 89 | } // extern "C" 90 | #endif // __cplusplus 91 | 92 | // Platform-specific headers required by platform window system extensions. 93 | // These are enabled prior to #including "vulkan.h". The same enable then 94 | // controls inclusion of the extension interfaces in vulkan.h. 95 | 96 | #ifdef VK_USE_PLATFORM_ANDROID_KHR 97 | #include 98 | #endif 99 | 100 | #ifdef VK_USE_PLATFORM_MIR_KHR 101 | #include 102 | #endif 103 | 104 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR 105 | #include 106 | #endif 107 | 108 | #ifdef VK_USE_PLATFORM_WIN32_KHR 109 | #include 110 | #endif 111 | 112 | #ifdef VK_USE_PLATFORM_XLIB_KHR 113 | #include 114 | #endif 115 | 116 | #ifdef VK_USE_PLATFORM_XCB_KHR 117 | #include 118 | #endif 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /glfw/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(common_HEADERS internal.h 3 | "${GLFW_BINARY_DIR}/src/glfw_config.h" 4 | "${GLFW_SOURCE_DIR}/include/GLFW/glfw3.h" 5 | "${GLFW_SOURCE_DIR}/include/GLFW/glfw3native.h") 6 | set(common_SOURCES context.c init.c input.c monitor.c vulkan.c window.c) 7 | 8 | if (_GLFW_COCOA) 9 | set(glfw_HEADERS ${common_HEADERS} cocoa_platform.h cocoa_joystick.h 10 | posix_tls.h nsgl_context.h) 11 | set(glfw_SOURCES ${common_SOURCES} cocoa_init.m cocoa_joystick.m 12 | cocoa_monitor.m cocoa_window.m cocoa_time.c posix_tls.c 13 | nsgl_context.m) 14 | elseif (_GLFW_WIN32) 15 | set(glfw_HEADERS ${common_HEADERS} win32_platform.h win32_joystick.h 16 | wgl_context.h egl_context.h) 17 | set(glfw_SOURCES ${common_SOURCES} win32_init.c win32_joystick.c 18 | win32_monitor.c win32_time.c win32_tls.c win32_window.c 19 | wgl_context.c egl_context.c) 20 | elseif (_GLFW_X11) 21 | set(glfw_HEADERS ${common_HEADERS} x11_platform.h xkb_unicode.h 22 | linux_joystick.h posix_time.h posix_tls.h glx_context.h 23 | egl_context.h) 24 | set(glfw_SOURCES ${common_SOURCES} x11_init.c x11_monitor.c x11_window.c 25 | xkb_unicode.c linux_joystick.c posix_time.c posix_tls.c 26 | glx_context.c egl_context.c) 27 | elseif (_GLFW_WAYLAND) 28 | set(glfw_HEADERS ${common_HEADERS} wl_platform.h linux_joystick.h 29 | posix_time.h posix_tls.h xkb_unicode.h egl_context.h) 30 | set(glfw_SOURCES ${common_SOURCES} wl_init.c wl_monitor.c wl_window.c 31 | linux_joystick.c posix_time.c posix_tls.c xkb_unicode.c 32 | egl_context.c) 33 | 34 | ecm_add_wayland_client_protocol(glfw_SOURCES 35 | PROTOCOL 36 | ${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/relative-pointer/relative-pointer-unstable-v1.xml 37 | BASENAME relative-pointer-unstable-v1) 38 | ecm_add_wayland_client_protocol(glfw_SOURCES 39 | PROTOCOL 40 | ${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml 41 | BASENAME pointer-constraints-unstable-v1) 42 | elseif (_GLFW_MIR) 43 | set(glfw_HEADERS ${common_HEADERS} mir_platform.h linux_joystick.h 44 | posix_time.h posix_tls.h xkb_unicode.h egl_context.h) 45 | set(glfw_SOURCES ${common_SOURCES} mir_init.c mir_monitor.c mir_window.c 46 | linux_joystick.c posix_time.c posix_tls.c xkb_unicode.c 47 | egl_context.c) 48 | endif() 49 | 50 | if (APPLE) 51 | # For some reason, CMake doesn't know about .m 52 | set_source_files_properties(${glfw_SOURCES} PROPERTIES LANGUAGE C) 53 | endif() 54 | 55 | add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS}) 56 | set_target_properties(glfw PROPERTIES 57 | OUTPUT_NAME ${GLFW_LIB_NAME} 58 | VERSION ${GLFW_VERSION} 59 | SOVERSION ${GLFW_VERSION_MAJOR} 60 | POSITION_INDEPENDENT_CODE ON 61 | FOLDER "GLFW3") 62 | 63 | target_compile_definitions(glfw PRIVATE -D_GLFW_USE_CONFIG_H) 64 | target_include_directories(glfw PUBLIC 65 | $ 66 | $/include>) 67 | target_include_directories(glfw PRIVATE 68 | "${GLFW_SOURCE_DIR}/src" 69 | "${GLFW_BINARY_DIR}/src" 70 | ${glfw_INCLUDE_DIRS}) 71 | 72 | # HACK: When building on MinGW, WINVER and UNICODE need to be defined before 73 | # the inclusion of stddef.h (by glfw3.h), which is itself included before 74 | # win32_platform.h. We define them here until a saner solution can be found 75 | # NOTE: MinGW-w64 and Visual C++ do /not/ need this hack. 76 | target_compile_definitions(glfw PRIVATE 77 | "$<$:UNICODE;WINVER=0x0501>") 78 | 79 | # Enable a reasonable set of warnings (no, -Wextra is not reasonable) 80 | target_compile_options(glfw PRIVATE 81 | "$<$:-Wall>" 82 | "$<$:-Wall>") 83 | 84 | if (BUILD_SHARED_LIBS) 85 | if (WIN32) 86 | if (MINGW) 87 | # Remove the lib prefix on the DLL (but not the import library 88 | set_target_properties(glfw PROPERTIES PREFIX "") 89 | 90 | # Add a suffix to the import library to avoid naming conflicts 91 | set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.a") 92 | else() 93 | # Add a suffix to the import library to avoid naming conflicts 94 | set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.lib") 95 | endif() 96 | elseif (APPLE) 97 | # Add -fno-common to work around a bug in Apple's GCC 98 | target_compile_options(glfw PRIVATE "-fno-common") 99 | 100 | set_target_properties(glfw PROPERTIES 101 | INSTALL_NAME_DIR "lib${LIB_SUFFIX}") 102 | elseif (UNIX) 103 | # Hide symbols not explicitly tagged for export from the shared library 104 | target_compile_options(glfw PRIVATE "-fvisibility=hidden") 105 | endif() 106 | 107 | target_compile_definitions(glfw INTERFACE -DGLFW_DLL) 108 | target_link_libraries(glfw PRIVATE ${glfw_LIBRARIES}) 109 | else() 110 | target_link_libraries(glfw INTERFACE ${glfw_LIBRARIES}) 111 | endif() 112 | 113 | if (MSVC) 114 | target_compile_definitions(glfw PRIVATE _CRT_SECURE_NO_WARNINGS) 115 | endif() 116 | 117 | if (GLFW_INSTALL) 118 | install(TARGETS glfw EXPORT glfwTargets DESTINATION lib${LIB_SUFFIX}) 119 | endif() 120 | 121 | -------------------------------------------------------------------------------- /glfw/src/cocoa_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 Cocoa - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2016 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_cocoa_joystick_h_ 28 | #define _glfw3_cocoa_joystick_h_ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE \ 36 | _GLFWjoystickNS ns_js[GLFW_JOYSTICK_LAST + 1] 37 | 38 | 39 | // Cocoa-specific per-joystick data 40 | // 41 | typedef struct _GLFWjoystickNS 42 | { 43 | GLFWbool present; 44 | char name[256]; 45 | 46 | IOHIDDeviceRef deviceRef; 47 | 48 | CFMutableArrayRef axisElements; 49 | CFMutableArrayRef buttonElements; 50 | CFMutableArrayRef hatElements; 51 | 52 | float* axes; 53 | unsigned char* buttons; 54 | } _GLFWjoystickNS; 55 | 56 | 57 | void _glfwInitJoysticksNS(void); 58 | void _glfwTerminateJoysticksNS(void); 59 | 60 | #endif // _glfw3_cocoa_joystick_h_ 61 | -------------------------------------------------------------------------------- /glfw/src/cocoa_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 OS X - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2016 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_cocoa_platform_h_ 28 | #define _glfw3_cocoa_platform_h_ 29 | 30 | #include 31 | #include 32 | 33 | #if defined(__OBJC__) 34 | #import 35 | #import 36 | #else 37 | #include 38 | #include 39 | typedef void* id; 40 | #endif 41 | 42 | #include "posix_tls.h" 43 | #include "cocoa_joystick.h" 44 | #include "nsgl_context.h" 45 | 46 | #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL) 47 | #define _glfw_dlclose(handle) dlclose(handle) 48 | #define _glfw_dlsym(handle, name) dlsym(handle, name) 49 | 50 | #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS ns 51 | #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryNS ns 52 | #define _GLFW_PLATFORM_LIBRARY_TIME_STATE _GLFWtimeNS ns_time 53 | #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorNS ns 54 | #define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorNS ns 55 | 56 | #define _GLFW_EGL_CONTEXT_STATE 57 | #define _GLFW_EGL_LIBRARY_CONTEXT_STATE 58 | 59 | // HIToolbox.framework pointer typedefs 60 | #define kTISPropertyUnicodeKeyLayoutData _glfw.ns.tis.kPropertyUnicodeKeyLayoutData 61 | #define kTISNotifySelectedKeyboardInputSourceChanged _glfw.ns.tis.kNotifySelectedKeyboardInputSourceChanged 62 | typedef TISInputSourceRef (*PFN_TISCopyCurrentKeyboardLayoutInputSource)(void); 63 | #define TISCopyCurrentKeyboardLayoutInputSource _glfw.ns.tis.CopyCurrentKeyboardLayoutInputSource 64 | typedef void* (*PFN_TISGetInputSourceProperty)(TISInputSourceRef,CFStringRef); 65 | #define TISGetInputSourceProperty _glfw.ns.tis.GetInputSourceProperty 66 | typedef UInt8 (*PFN_LMGetKbdType)(void); 67 | #define LMGetKbdType _glfw.ns.tis.GetKbdType 68 | 69 | 70 | // Cocoa-specific per-window data 71 | // 72 | typedef struct _GLFWwindowNS 73 | { 74 | id object; 75 | id delegate; 76 | id view; 77 | 78 | // The total sum of the distances the cursor has been warped 79 | // since the last cursor motion event was processed 80 | // This is kept to counteract Cocoa doing the same internally 81 | double cursorWarpDeltaX, cursorWarpDeltaY; 82 | 83 | } _GLFWwindowNS; 84 | 85 | // Cocoa-specific global data 86 | // 87 | typedef struct _GLFWlibraryNS 88 | { 89 | CGEventSourceRef eventSource; 90 | id delegate; 91 | id autoreleasePool; 92 | id cursor; 93 | TISInputSourceRef inputSource; 94 | IOHIDManagerRef hidManager; 95 | id unicodeData; 96 | id listener; 97 | 98 | char keyName[64]; 99 | short int publicKeys[256]; 100 | short int nativeKeys[GLFW_KEY_LAST + 1]; 101 | char* clipboardString; 102 | // Where to place the cursor when re-enabled 103 | double restoreCursorPosX, restoreCursorPosY; 104 | // The window whose disabled cursor mode is active 105 | _GLFWwindow* disabledCursorWindow; 106 | 107 | struct { 108 | CFBundleRef bundle; 109 | PFN_TISCopyCurrentKeyboardLayoutInputSource CopyCurrentKeyboardLayoutInputSource; 110 | PFN_TISGetInputSourceProperty GetInputSourceProperty; 111 | PFN_LMGetKbdType GetKbdType; 112 | CFStringRef kPropertyUnicodeKeyLayoutData; 113 | CFStringRef kNotifySelectedKeyboardInputSourceChanged; 114 | } tis; 115 | 116 | } _GLFWlibraryNS; 117 | 118 | // Cocoa-specific per-monitor data 119 | // 120 | typedef struct _GLFWmonitorNS 121 | { 122 | CGDirectDisplayID displayID; 123 | CGDisplayModeRef previousMode; 124 | uint32_t unitNumber; 125 | 126 | } _GLFWmonitorNS; 127 | 128 | // Cocoa-specific per-cursor data 129 | // 130 | typedef struct _GLFWcursorNS 131 | { 132 | id object; 133 | 134 | } _GLFWcursorNS; 135 | 136 | // Cocoa-specific global timer data 137 | // 138 | typedef struct _GLFWtimeNS 139 | { 140 | uint64_t frequency; 141 | 142 | } _GLFWtimeNS; 143 | 144 | 145 | void _glfwInitTimerNS(void); 146 | 147 | GLFWbool _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired); 148 | void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor); 149 | 150 | #endif // _glfw3_cocoa_platform_h_ 151 | -------------------------------------------------------------------------------- /glfw/src/cocoa_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 OS X - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2016 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 | #include "internal.h" 28 | 29 | #include 30 | 31 | 32 | ////////////////////////////////////////////////////////////////////////// 33 | ////// GLFW internal API ////// 34 | ////////////////////////////////////////////////////////////////////////// 35 | 36 | // Initialise timer 37 | // 38 | void _glfwInitTimerNS(void) 39 | { 40 | mach_timebase_info_data_t info; 41 | mach_timebase_info(&info); 42 | 43 | _glfw.ns_time.frequency = (info.denom * 1e9) / info.numer; 44 | } 45 | 46 | 47 | ////////////////////////////////////////////////////////////////////////// 48 | ////// GLFW platform API ////// 49 | ////////////////////////////////////////////////////////////////////////// 50 | 51 | uint64_t _glfwPlatformGetTimerValue(void) 52 | { 53 | return mach_absolute_time(); 54 | } 55 | 56 | uint64_t _glfwPlatformGetTimerFrequency(void) 57 | { 58 | return _glfw.ns_time.frequency; 59 | } 60 | 61 | -------------------------------------------------------------------------------- /glfw/src/glfw3.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | includedir=${prefix}/include 4 | libdir=${exec_prefix}/lib@LIB_SUFFIX@ 5 | 6 | Name: GLFW 7 | Description: A multi-platform library for OpenGL, window and input 8 | Version: @GLFW_VERSION_FULL@ 9 | URL: http://www.glfw.org/ 10 | Requires.private: @GLFW_PKG_DEPS@ 11 | Libs: -L${libdir} -l@GLFW_LIB_NAME@ 12 | Libs.private: @GLFW_PKG_LIBS@ 13 | Cflags: -I${includedir} 14 | -------------------------------------------------------------------------------- /glfw/src/glfw3Config.cmake.in: -------------------------------------------------------------------------------- 1 | include("${CMAKE_CURRENT_LIST_DIR}/glfw3Targets.cmake") 2 | -------------------------------------------------------------------------------- /glfw/src/glfw_config.h.in: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2010-2016 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 | #cmakedefine _GLFW_X11 39 | // Define this to 1 if building GLFW for Win32 40 | #cmakedefine _GLFW_WIN32 41 | // Define this to 1 if building GLFW for Cocoa 42 | #cmakedefine _GLFW_COCOA 43 | // Define this to 1 if building GLFW for Wayland 44 | #cmakedefine _GLFW_WAYLAND 45 | // Define this to 1 if building GLFW for Mir 46 | #cmakedefine _GLFW_MIR 47 | 48 | // Define this to 1 if building as a shared library / dynamic library / DLL 49 | #cmakedefine _GLFW_BUILD_DLL 50 | // Define this to 1 to use Vulkan loader linked statically into application 51 | #cmakedefine _GLFW_VULKAN_STATIC 52 | 53 | // Define this to 1 to force use of high-performance GPU on hybrid systems 54 | #cmakedefine _GLFW_USE_HYBRID_HPG 55 | 56 | // Define this to 1 if the Xxf86vm X11 extension is available 57 | #cmakedefine _GLFW_HAS_XF86VM 58 | 59 | // Define this to 1 if glfwInit should change the current directory 60 | #cmakedefine _GLFW_USE_CHDIR 61 | // Define this to 1 if glfwCreateWindow should populate the menu bar 62 | #cmakedefine _GLFW_USE_MENUBAR 63 | // Define this to 1 if windows should use full resolution on Retina displays 64 | #cmakedefine _GLFW_USE_RETINA 65 | 66 | -------------------------------------------------------------------------------- /glfw/src/glx_context.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 GLX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 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_glx_context_h_ 29 | #define _glfw3_glx_context_h_ 30 | 31 | #define GLX_VENDOR 1 32 | #define GLX_RGBA_BIT 0x00000001 33 | #define GLX_WINDOW_BIT 0x00000001 34 | #define GLX_DRAWABLE_TYPE 0x8010 35 | #define GLX_RENDER_TYPE 0x8011 36 | #define GLX_RGBA_TYPE 0x8014 37 | #define GLX_DOUBLEBUFFER 5 38 | #define GLX_STEREO 6 39 | #define GLX_AUX_BUFFERS 7 40 | #define GLX_RED_SIZE 8 41 | #define GLX_GREEN_SIZE 9 42 | #define GLX_BLUE_SIZE 10 43 | #define GLX_ALPHA_SIZE 11 44 | #define GLX_DEPTH_SIZE 12 45 | #define GLX_STENCIL_SIZE 13 46 | #define GLX_ACCUM_RED_SIZE 14 47 | #define GLX_ACCUM_GREEN_SIZE 15 48 | #define GLX_ACCUM_BLUE_SIZE 16 49 | #define GLX_ACCUM_ALPHA_SIZE 17 50 | #define GLX_SAMPLES 0x186a1 51 | #define GLX_VISUAL_ID 0x800b 52 | 53 | #define GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20b2 54 | #define GLX_CONTEXT_DEBUG_BIT_ARB 0x00000001 55 | #define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 56 | #define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 57 | #define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126 58 | #define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 59 | #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 60 | #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 61 | #define GLX_CONTEXT_FLAGS_ARB 0x2094 62 | #define GLX_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004 63 | #define GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004 64 | #define GLX_LOSE_CONTEXT_ON_RESET_ARB 0x8252 65 | #define GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 66 | #define GLX_NO_RESET_NOTIFICATION_ARB 0x8261 67 | #define GLX_CONTEXT_RELEASE_BEHAVIOR_ARB 0x2097 68 | #define GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB 0 69 | #define GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB 0x2098 70 | 71 | typedef XID GLXWindow; 72 | typedef XID GLXDrawable; 73 | typedef struct __GLXFBConfig* GLXFBConfig; 74 | typedef struct __GLXcontext* GLXContext; 75 | typedef void (*__GLXextproc)(void); 76 | 77 | typedef int (*PFNGLXGETFBCONFIGATTRIBPROC)(Display*,GLXFBConfig,int,int*); 78 | typedef const char* (*PFNGLXGETCLIENTSTRINGPROC)(Display*,int); 79 | typedef Bool (*PFNGLXQUERYEXTENSIONPROC)(Display*,int*,int*); 80 | typedef Bool (*PFNGLXQUERYVERSIONPROC)(Display*,int*,int*); 81 | typedef void (*PFNGLXDESTROYCONTEXTPROC)(Display*,GLXContext); 82 | typedef Bool (*PFNGLXMAKECURRENTPROC)(Display*,GLXDrawable,GLXContext); 83 | typedef void (*PFNGLXSWAPBUFFERSPROC)(Display*,GLXDrawable); 84 | typedef const char* (*PFNGLXQUERYEXTENSIONSSTRINGPROC)(Display*,int); 85 | typedef GLXFBConfig* (*PFNGLXGETFBCONFIGSPROC)(Display*,int,int*); 86 | typedef GLXContext (*PFNGLXCREATENEWCONTEXTPROC)(Display*,GLXFBConfig,int,GLXContext,Bool); 87 | typedef __GLXextproc (* PFNGLXGETPROCADDRESSPROC)(const GLubyte *procName); 88 | typedef int (*PFNGLXSWAPINTERVALMESAPROC)(int); 89 | typedef int (*PFNGLXSWAPINTERVALSGIPROC)(int); 90 | typedef void (*PFNGLXSWAPINTERVALEXTPROC)(Display*,GLXDrawable,int); 91 | typedef GLXContext (*PFNGLXCREATECONTEXTATTRIBSARBPROC)(Display*,GLXFBConfig,GLXContext,Bool,const int*); 92 | typedef XVisualInfo* (*PFNGLXGETVISUALFROMFBCONFIGPROC)(Display*,GLXFBConfig); 93 | typedef GLXWindow (*PFNGLXCREATEWINDOWPROC)(Display*,GLXFBConfig,Window,const int*); 94 | typedef void (*PFNGLXDESTROYWINDOWPROC)(Display*,GLXWindow); 95 | 96 | // libGL.so function pointer typedefs 97 | #define glXGetFBConfigs _glfw.glx.GetFBConfigs 98 | #define glXGetFBConfigAttrib _glfw.glx.GetFBConfigAttrib 99 | #define glXGetClientString _glfw.glx.GetClientString 100 | #define glXQueryExtension _glfw.glx.QueryExtension 101 | #define glXQueryVersion _glfw.glx.QueryVersion 102 | #define glXDestroyContext _glfw.glx.DestroyContext 103 | #define glXMakeCurrent _glfw.glx.MakeCurrent 104 | #define glXSwapBuffers _glfw.glx.SwapBuffers 105 | #define glXQueryExtensionsString _glfw.glx.QueryExtensionsString 106 | #define glXCreateNewContext _glfw.glx.CreateNewContext 107 | #define glXGetVisualFromFBConfig _glfw.glx.GetVisualFromFBConfig 108 | #define glXCreateWindow _glfw.glx.CreateWindow 109 | #define glXDestroyWindow _glfw.glx.DestroyWindow 110 | 111 | #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX glx 112 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryGLX glx 113 | 114 | 115 | // GLX-specific per-context data 116 | // 117 | typedef struct _GLFWcontextGLX 118 | { 119 | GLXContext handle; 120 | GLXWindow window; 121 | 122 | } _GLFWcontextGLX; 123 | 124 | // GLX-specific global data 125 | // 126 | typedef struct _GLFWlibraryGLX 127 | { 128 | int major, minor; 129 | int eventBase; 130 | int errorBase; 131 | 132 | // dlopen handle for libGL.so.1 133 | void* handle; 134 | 135 | // GLX 1.3 functions 136 | PFNGLXGETFBCONFIGSPROC GetFBConfigs; 137 | PFNGLXGETFBCONFIGATTRIBPROC GetFBConfigAttrib; 138 | PFNGLXGETCLIENTSTRINGPROC GetClientString; 139 | PFNGLXQUERYEXTENSIONPROC QueryExtension; 140 | PFNGLXQUERYVERSIONPROC QueryVersion; 141 | PFNGLXDESTROYCONTEXTPROC DestroyContext; 142 | PFNGLXMAKECURRENTPROC MakeCurrent; 143 | PFNGLXSWAPBUFFERSPROC SwapBuffers; 144 | PFNGLXQUERYEXTENSIONSSTRINGPROC QueryExtensionsString; 145 | PFNGLXCREATENEWCONTEXTPROC CreateNewContext; 146 | PFNGLXGETVISUALFROMFBCONFIGPROC GetVisualFromFBConfig; 147 | PFNGLXCREATEWINDOWPROC CreateWindow; 148 | PFNGLXDESTROYWINDOWPROC DestroyWindow; 149 | 150 | // GLX 1.4 and extension functions 151 | PFNGLXGETPROCADDRESSPROC GetProcAddress; 152 | PFNGLXGETPROCADDRESSPROC GetProcAddressARB; 153 | PFNGLXSWAPINTERVALSGIPROC SwapIntervalSGI; 154 | PFNGLXSWAPINTERVALEXTPROC SwapIntervalEXT; 155 | PFNGLXSWAPINTERVALMESAPROC SwapIntervalMESA; 156 | PFNGLXCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB; 157 | GLFWbool SGI_swap_control; 158 | GLFWbool EXT_swap_control; 159 | GLFWbool MESA_swap_control; 160 | GLFWbool ARB_multisample; 161 | GLFWbool ARB_framebuffer_sRGB; 162 | GLFWbool EXT_framebuffer_sRGB; 163 | GLFWbool ARB_create_context; 164 | GLFWbool ARB_create_context_profile; 165 | GLFWbool ARB_create_context_robustness; 166 | GLFWbool EXT_create_context_es2_profile; 167 | GLFWbool ARB_context_flush_control; 168 | 169 | } _GLFWlibraryGLX; 170 | 171 | 172 | GLFWbool _glfwInitGLX(void); 173 | void _glfwTerminateGLX(void); 174 | GLFWbool _glfwCreateContextGLX(_GLFWwindow* window, 175 | const _GLFWctxconfig* ctxconfig, 176 | const _GLFWfbconfig* fbconfig); 177 | void _glfwDestroyContextGLX(_GLFWwindow* window); 178 | GLFWbool _glfwChooseVisualGLX(const _GLFWctxconfig* ctxconfig, 179 | const _GLFWfbconfig* fbconfig, 180 | Visual** visual, int* depth); 181 | 182 | #endif // _glfw3_glx_context_h_ 183 | -------------------------------------------------------------------------------- /glfw/src/init.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 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 | GLFWbool _glfwInitialized = GLFW_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 API is unavailable"; 69 | case GLFW_VERSION_UNAVAILABLE: 70 | return "The requested 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 | case GLFW_NO_WINDOW_CONTEXT: 76 | return "The specified window has no context"; 77 | default: 78 | return "ERROR: UNKNOWN GLFW ERROR"; 79 | } 80 | } 81 | 82 | 83 | ////////////////////////////////////////////////////////////////////////// 84 | ////// GLFW event API ////// 85 | ////////////////////////////////////////////////////////////////////////// 86 | 87 | void _glfwInputError(int error, const char* format, ...) 88 | { 89 | if (_glfwErrorCallback) 90 | { 91 | char buffer[8192]; 92 | const char* description; 93 | 94 | if (format) 95 | { 96 | int count; 97 | va_list vl; 98 | 99 | va_start(vl, format); 100 | count = vsnprintf(buffer, sizeof(buffer), format, vl); 101 | va_end(vl); 102 | 103 | if (count < 0) 104 | buffer[sizeof(buffer) - 1] = '\0'; 105 | 106 | description = buffer; 107 | } 108 | else 109 | description = getErrorString(error); 110 | 111 | _glfwErrorCallback(error, description); 112 | } 113 | } 114 | 115 | 116 | ////////////////////////////////////////////////////////////////////////// 117 | ////// GLFW public API ////// 118 | ////////////////////////////////////////////////////////////////////////// 119 | 120 | GLFWAPI int glfwInit(void) 121 | { 122 | if (_glfwInitialized) 123 | return GLFW_TRUE; 124 | 125 | memset(&_glfw, 0, sizeof(_glfw)); 126 | 127 | if (!_glfwPlatformInit()) 128 | { 129 | _glfwPlatformTerminate(); 130 | return GLFW_FALSE; 131 | } 132 | 133 | _glfw.monitors = _glfwPlatformGetMonitors(&_glfw.monitorCount); 134 | _glfwInitialized = GLFW_TRUE; 135 | 136 | _glfw.timerOffset = _glfwPlatformGetTimerValue(); 137 | 138 | // Not all window hints have zero as their default value 139 | glfwDefaultWindowHints(); 140 | 141 | return GLFW_TRUE; 142 | } 143 | 144 | GLFWAPI void glfwTerminate(void) 145 | { 146 | int i; 147 | 148 | if (!_glfwInitialized) 149 | return; 150 | 151 | memset(&_glfw.callbacks, 0, sizeof(_glfw.callbacks)); 152 | 153 | while (_glfw.windowListHead) 154 | glfwDestroyWindow((GLFWwindow*) _glfw.windowListHead); 155 | 156 | while (_glfw.cursorListHead) 157 | glfwDestroyCursor((GLFWcursor*) _glfw.cursorListHead); 158 | 159 | for (i = 0; i < _glfw.monitorCount; i++) 160 | { 161 | _GLFWmonitor* monitor = _glfw.monitors[i]; 162 | if (monitor->originalRamp.size) 163 | _glfwPlatformSetGammaRamp(monitor, &monitor->originalRamp); 164 | } 165 | 166 | _glfwTerminateVulkan(); 167 | 168 | _glfwFreeMonitors(_glfw.monitors, _glfw.monitorCount); 169 | _glfw.monitors = NULL; 170 | _glfw.monitorCount = 0; 171 | 172 | _glfwPlatformTerminate(); 173 | 174 | memset(&_glfw, 0, sizeof(_glfw)); 175 | _glfwInitialized = GLFW_FALSE; 176 | } 177 | 178 | GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev) 179 | { 180 | if (major != NULL) 181 | *major = GLFW_VERSION_MAJOR; 182 | 183 | if (minor != NULL) 184 | *minor = GLFW_VERSION_MINOR; 185 | 186 | if (rev != NULL) 187 | *rev = GLFW_VERSION_REVISION; 188 | } 189 | 190 | GLFWAPI const char* glfwGetVersionString(void) 191 | { 192 | return _glfwPlatformGetVersionString(); 193 | } 194 | 195 | GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun) 196 | { 197 | _GLFW_SWAP_POINTERS(_glfwErrorCallback, cbfun); 198 | return cbfun; 199 | } 200 | 201 | -------------------------------------------------------------------------------- /glfw/src/linux_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 Linux - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 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_linux_joystick_h_ 28 | #define _glfw3_linux_joystick_h_ 29 | 30 | #include 31 | 32 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE _GLFWjoylistLinux linux_js 33 | 34 | 35 | // Linux-specific joystick data 36 | // 37 | typedef struct _GLFWjoystickLinux 38 | { 39 | GLFWbool present; 40 | int fd; 41 | float* axes; 42 | int axisCount; 43 | unsigned char* buttons; 44 | int buttonCount; 45 | char* name; 46 | char* path; 47 | } _GLFWjoystickLinux; 48 | 49 | // Linux-specific joystick API data 50 | // 51 | typedef struct _GLFWjoylistLinux 52 | { 53 | _GLFWjoystickLinux js[GLFW_JOYSTICK_LAST + 1]; 54 | 55 | #if defined(__linux__) 56 | int inotify; 57 | int watch; 58 | regex_t regex; 59 | #endif /*__linux__*/ 60 | } _GLFWjoylistLinux; 61 | 62 | 63 | GLFWbool _glfwInitJoysticksLinux(void); 64 | void _glfwTerminateJoysticksLinux(void); 65 | 66 | void _glfwPollJoystickEvents(void); 67 | 68 | #endif // _glfw3_linux_joystick_h_ 69 | -------------------------------------------------------------------------------- /glfw/src/mir_monitor.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 Mir - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014-2015 Brandon Schaefer 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 | #include "internal.h" 28 | 29 | #include 30 | 31 | 32 | ////////////////////////////////////////////////////////////////////////// 33 | ////// GLFW platform API ////// 34 | ////////////////////////////////////////////////////////////////////////// 35 | 36 | _GLFWmonitor** _glfwPlatformGetMonitors(int* count) 37 | { 38 | int i, found = 0; 39 | _GLFWmonitor** monitors = NULL; 40 | MirDisplayConfiguration* displayConfig = 41 | mir_connection_create_display_config(_glfw.mir.connection); 42 | 43 | *count = 0; 44 | 45 | for (i = 0; i < displayConfig->num_outputs; i++) 46 | { 47 | const MirDisplayOutput* out = displayConfig->outputs + i; 48 | 49 | if (out->used && 50 | out->connected && 51 | out->num_modes && 52 | out->current_mode < out->num_modes) 53 | { 54 | found++; 55 | monitors = realloc(monitors, sizeof(_GLFWmonitor*) * found); 56 | monitors[i] = _glfwAllocMonitor("Unknown", 57 | out->physical_width_mm, 58 | out->physical_height_mm); 59 | 60 | monitors[i]->mir.x = out->position_x; 61 | monitors[i]->mir.y = out->position_y; 62 | monitors[i]->mir.output_id = out->output_id; 63 | monitors[i]->mir.cur_mode = out->current_mode; 64 | 65 | monitors[i]->modes = _glfwPlatformGetVideoModes(monitors[i], 66 | &monitors[i]->modeCount); 67 | } 68 | } 69 | 70 | mir_display_config_destroy(displayConfig); 71 | 72 | *count = found; 73 | return monitors; 74 | } 75 | 76 | GLFWbool _glfwPlatformIsSameMonitor(_GLFWmonitor* first, _GLFWmonitor* second) 77 | { 78 | return first->mir.output_id == second->mir.output_id; 79 | } 80 | 81 | void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) 82 | { 83 | if (xpos) 84 | *xpos = monitor->mir.x; 85 | if (ypos) 86 | *ypos = monitor->mir.y; 87 | } 88 | 89 | void FillInRGBBitsFromPixelFormat(GLFWvidmode* mode, const MirPixelFormat pf) 90 | { 91 | switch (pf) 92 | { 93 | case mir_pixel_format_rgb_565: 94 | mode->redBits = 5; 95 | mode->greenBits = 6; 96 | mode->blueBits = 5; 97 | break; 98 | case mir_pixel_format_rgba_5551: 99 | mode->redBits = 5; 100 | mode->greenBits = 5; 101 | mode->blueBits = 5; 102 | break; 103 | case mir_pixel_format_rgba_4444: 104 | mode->redBits = 4; 105 | mode->greenBits = 4; 106 | mode->blueBits = 4; 107 | break; 108 | case mir_pixel_format_abgr_8888: 109 | case mir_pixel_format_xbgr_8888: 110 | case mir_pixel_format_argb_8888: 111 | case mir_pixel_format_xrgb_8888: 112 | case mir_pixel_format_bgr_888: 113 | case mir_pixel_format_rgb_888: 114 | default: 115 | mode->redBits = 8; 116 | mode->greenBits = 8; 117 | mode->blueBits = 8; 118 | break; 119 | } 120 | } 121 | 122 | GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) 123 | { 124 | int i; 125 | GLFWvidmode* modes = NULL; 126 | MirDisplayConfiguration* displayConfig = 127 | mir_connection_create_display_config(_glfw.mir.connection); 128 | 129 | for (i = 0; i < displayConfig->num_outputs; i++) 130 | { 131 | const MirDisplayOutput* out = displayConfig->outputs + i; 132 | if (out->output_id != monitor->mir.output_id) 133 | continue; 134 | 135 | modes = calloc(out->num_modes, sizeof(GLFWvidmode)); 136 | 137 | for (*found = 0; *found < out->num_modes; (*found)++) 138 | { 139 | modes[*found].width = out->modes[*found].horizontal_resolution; 140 | modes[*found].height = out->modes[*found].vertical_resolution; 141 | modes[*found].refreshRate = out->modes[*found].refresh_rate; 142 | 143 | FillInRGBBitsFromPixelFormat(&modes[*found], out->output_formats[*found]); 144 | } 145 | 146 | break; 147 | } 148 | 149 | mir_display_config_destroy(displayConfig); 150 | 151 | return modes; 152 | } 153 | 154 | void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) 155 | { 156 | *mode = monitor->modes[monitor->mir.cur_mode]; 157 | } 158 | 159 | void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) 160 | { 161 | _glfwInputError(GLFW_PLATFORM_ERROR, 162 | "Mir: Unsupported function %s", __PRETTY_FUNCTION__); 163 | } 164 | 165 | void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) 166 | { 167 | _glfwInputError(GLFW_PLATFORM_ERROR, 168 | "Mir: Unsupported function %s", __PRETTY_FUNCTION__); 169 | } 170 | 171 | 172 | ////////////////////////////////////////////////////////////////////////// 173 | ////// GLFW native API ////// 174 | ////////////////////////////////////////////////////////////////////////// 175 | 176 | GLFWAPI int glfwGetMirMonitor(GLFWmonitor* handle) 177 | { 178 | _GLFWmonitor* monitor = (_GLFWmonitor*) handle; 179 | _GLFW_REQUIRE_INIT_OR_RETURN(0); 180 | return monitor->mir.output_id; 181 | } 182 | 183 | -------------------------------------------------------------------------------- /glfw/src/mir_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 Mir - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014-2015 Brandon Schaefer 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_mir_platform_h_ 28 | #define _glfw3_mir_platform_h_ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | 36 | typedef VkFlags VkMirSurfaceCreateFlagsKHR; 37 | 38 | typedef struct VkMirSurfaceCreateInfoKHR 39 | { 40 | VkStructureType sType; 41 | const void* pNext; 42 | VkMirSurfaceCreateFlagsKHR flags; 43 | MirConnection* connection; 44 | MirSurface* mirSurface; 45 | } VkMirSurfaceCreateInfoKHR; 46 | 47 | typedef VkResult (APIENTRY *PFN_vkCreateMirSurfaceKHR)(VkInstance,const VkMirSurfaceCreateInfoKHR*,const VkAllocationCallbacks*,VkSurfaceKHR*); 48 | typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceMirPresentationSupportKHR)(VkPhysicalDevice,uint32_t,MirConnection*); 49 | 50 | #include "posix_tls.h" 51 | #include "posix_time.h" 52 | #include "linux_joystick.h" 53 | #include "xkb_unicode.h" 54 | #include "egl_context.h" 55 | 56 | #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL) 57 | #define _glfw_dlclose(handle) dlclose(handle) 58 | #define _glfw_dlsym(handle, name) dlsym(handle, name) 59 | 60 | #define _GLFW_EGL_NATIVE_WINDOW ((EGLNativeWindowType) window->mir.window) 61 | #define _GLFW_EGL_NATIVE_DISPLAY ((EGLNativeDisplayType) _glfw.mir.display) 62 | 63 | #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowMir mir 64 | #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorMir mir 65 | #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryMir mir 66 | #define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorMir mir 67 | 68 | #define _GLFW_PLATFORM_CONTEXT_STATE 69 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE 70 | 71 | 72 | // Mir-specific Event Queue 73 | // 74 | typedef struct EventQueue 75 | { 76 | TAILQ_HEAD(, EventNode) head; 77 | } EventQueue; 78 | 79 | // Mir-specific per-window data 80 | // 81 | typedef struct _GLFWwindowMir 82 | { 83 | MirSurface* surface; 84 | int width; 85 | int height; 86 | MirEGLNativeWindowType window; 87 | 88 | } _GLFWwindowMir; 89 | 90 | // Mir-specific per-monitor data 91 | // 92 | typedef struct _GLFWmonitorMir 93 | { 94 | int cur_mode; 95 | int output_id; 96 | int x; 97 | int y; 98 | 99 | } _GLFWmonitorMir; 100 | 101 | // Mir-specific global data 102 | // 103 | typedef struct _GLFWlibraryMir 104 | { 105 | MirConnection* connection; 106 | MirEGLNativeDisplayType display; 107 | MirCursorConfiguration* default_conf; 108 | EventQueue* event_queue; 109 | 110 | short int publicKeys[256]; 111 | 112 | pthread_mutex_t event_mutex; 113 | pthread_cond_t event_cond; 114 | 115 | } _GLFWlibraryMir; 116 | 117 | // Mir-specific per-cursor data 118 | // TODO: Only system cursors are implemented in Mir atm. Need to wait for support. 119 | // 120 | typedef struct _GLFWcursorMir 121 | { 122 | MirCursorConfiguration* conf; 123 | MirBufferStream* custom_cursor; 124 | } _GLFWcursorMir; 125 | 126 | 127 | extern void _glfwInitEventQueueMir(EventQueue* queue); 128 | extern void _glfwDeleteEventQueueMir(EventQueue* queue); 129 | 130 | #endif // _glfw3_mir_platform_h_ 131 | -------------------------------------------------------------------------------- /glfw/src/nsgl_context.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 OS X - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2016 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_nsgl_context_h_ 28 | #define _glfw3_nsgl_context_h_ 29 | 30 | #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextNSGL nsgl 31 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryNSGL nsgl 32 | 33 | 34 | // NSGL-specific per-context data 35 | // 36 | typedef struct _GLFWcontextNSGL 37 | { 38 | id pixelFormat; 39 | id object; 40 | 41 | } _GLFWcontextNSGL; 42 | 43 | // NSGL-specific global data 44 | // 45 | typedef struct _GLFWlibraryNSGL 46 | { 47 | // dlopen handle for OpenGL.framework (for glfwGetProcAddress) 48 | CFBundleRef framework; 49 | 50 | } _GLFWlibraryNSGL; 51 | 52 | 53 | GLFWbool _glfwInitNSGL(void); 54 | void _glfwTerminateNSGL(void); 55 | GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, 56 | const _GLFWctxconfig* ctxconfig, 57 | const _GLFWfbconfig* fbconfig); 58 | void _glfwDestroyContextNSGL(_GLFWwindow* window); 59 | 60 | #endif // _glfw3_nsgl_context_h_ 61 | -------------------------------------------------------------------------------- /glfw/src/posix_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 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 | ////////////////////////////////////////////////////////////////////////// 35 | ////// GLFW internal API ////// 36 | ////////////////////////////////////////////////////////////////////////// 37 | 38 | // Initialise timer 39 | // 40 | void _glfwInitTimerPOSIX(void) 41 | { 42 | #if defined(CLOCK_MONOTONIC) 43 | struct timespec ts; 44 | 45 | if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) 46 | { 47 | _glfw.posix_time.monotonic = GLFW_TRUE; 48 | _glfw.posix_time.frequency = 1000000000; 49 | } 50 | else 51 | #endif 52 | { 53 | _glfw.posix_time.monotonic = GLFW_FALSE; 54 | _glfw.posix_time.frequency = 1000000; 55 | } 56 | } 57 | 58 | 59 | ////////////////////////////////////////////////////////////////////////// 60 | ////// GLFW platform API ////// 61 | ////////////////////////////////////////////////////////////////////////// 62 | 63 | uint64_t _glfwPlatformGetTimerValue(void) 64 | { 65 | #if defined(CLOCK_MONOTONIC) 66 | if (_glfw.posix_time.monotonic) 67 | { 68 | struct timespec ts; 69 | clock_gettime(CLOCK_MONOTONIC, &ts); 70 | return (uint64_t) ts.tv_sec * (uint64_t) 1000000000 + (uint64_t) ts.tv_nsec; 71 | } 72 | else 73 | #endif 74 | { 75 | struct timeval tv; 76 | gettimeofday(&tv, NULL); 77 | return (uint64_t) tv.tv_sec * (uint64_t) 1000000 + (uint64_t) tv.tv_usec; 78 | } 79 | } 80 | 81 | uint64_t _glfwPlatformGetTimerFrequency(void) 82 | { 83 | return _glfw.posix_time.frequency; 84 | } 85 | 86 | -------------------------------------------------------------------------------- /glfw/src/posix_time.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 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_posix_time_h_ 29 | #define _glfw3_posix_time_h_ 30 | 31 | #define _GLFW_PLATFORM_LIBRARY_TIME_STATE _GLFWtimePOSIX posix_time 32 | 33 | #include 34 | 35 | 36 | // POSIX-specific global timer data 37 | // 38 | typedef struct _GLFWtimePOSIX 39 | { 40 | GLFWbool monotonic; 41 | uint64_t frequency; 42 | 43 | } _GLFWtimePOSIX; 44 | 45 | 46 | void _glfwInitTimerPOSIX(void); 47 | 48 | #endif // _glfw3_posix_time_h_ 49 | -------------------------------------------------------------------------------- /glfw/src/posix_tls.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 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 | GLFWbool _glfwInitThreadLocalStoragePOSIX(void) 36 | { 37 | if (pthread_key_create(&_glfw.posix_tls.context, NULL) != 0) 38 | { 39 | _glfwInputError(GLFW_PLATFORM_ERROR, 40 | "POSIX: Failed to create context TLS"); 41 | return GLFW_FALSE; 42 | } 43 | 44 | _glfw.posix_tls.allocated = GLFW_TRUE; 45 | return GLFW_TRUE; 46 | } 47 | 48 | void _glfwTerminateThreadLocalStoragePOSIX(void) 49 | { 50 | if (_glfw.posix_tls.allocated) 51 | pthread_key_delete(_glfw.posix_tls.context); 52 | } 53 | 54 | 55 | ////////////////////////////////////////////////////////////////////////// 56 | ////// GLFW platform API ////// 57 | ////////////////////////////////////////////////////////////////////////// 58 | 59 | void _glfwPlatformSetCurrentContext(_GLFWwindow* context) 60 | { 61 | pthread_setspecific(_glfw.posix_tls.context, context); 62 | } 63 | 64 | _GLFWwindow* _glfwPlatformGetCurrentContext(void) 65 | { 66 | return pthread_getspecific(_glfw.posix_tls.context); 67 | } 68 | 69 | -------------------------------------------------------------------------------- /glfw/src/posix_tls.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 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_posix_tls_h_ 29 | #define _glfw3_posix_tls_h_ 30 | 31 | #include 32 | 33 | #define _GLFW_PLATFORM_LIBRARY_TLS_STATE _GLFWtlsPOSIX posix_tls 34 | 35 | 36 | // POSIX-specific global TLS data 37 | // 38 | typedef struct _GLFWtlsPOSIX 39 | { 40 | GLFWbool allocated; 41 | pthread_key_t context; 42 | 43 | } _GLFWtlsPOSIX; 44 | 45 | 46 | GLFWbool _glfwInitThreadLocalStoragePOSIX(void); 47 | void _glfwTerminateThreadLocalStoragePOSIX(void); 48 | 49 | #endif // _glfw3_posix_tls_h_ 50 | -------------------------------------------------------------------------------- /glfw/src/wgl_context.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 WGL - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 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 | 32 | #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000 33 | #define WGL_SUPPORT_OPENGL_ARB 0x2010 34 | #define WGL_DRAW_TO_WINDOW_ARB 0x2001 35 | #define WGL_PIXEL_TYPE_ARB 0x2013 36 | #define WGL_TYPE_RGBA_ARB 0x202b 37 | #define WGL_ACCELERATION_ARB 0x2003 38 | #define WGL_NO_ACCELERATION_ARB 0x2025 39 | #define WGL_RED_BITS_ARB 0x2015 40 | #define WGL_RED_SHIFT_ARB 0x2016 41 | #define WGL_GREEN_BITS_ARB 0x2017 42 | #define WGL_GREEN_SHIFT_ARB 0x2018 43 | #define WGL_BLUE_BITS_ARB 0x2019 44 | #define WGL_BLUE_SHIFT_ARB 0x201a 45 | #define WGL_ALPHA_BITS_ARB 0x201b 46 | #define WGL_ALPHA_SHIFT_ARB 0x201c 47 | #define WGL_ACCUM_BITS_ARB 0x201d 48 | #define WGL_ACCUM_RED_BITS_ARB 0x201e 49 | #define WGL_ACCUM_GREEN_BITS_ARB 0x201f 50 | #define WGL_ACCUM_BLUE_BITS_ARB 0x2020 51 | #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021 52 | #define WGL_DEPTH_BITS_ARB 0x2022 53 | #define WGL_STENCIL_BITS_ARB 0x2023 54 | #define WGL_AUX_BUFFERS_ARB 0x2024 55 | #define WGL_STEREO_ARB 0x2012 56 | #define WGL_DOUBLE_BUFFER_ARB 0x2011 57 | #define WGL_SAMPLES_ARB 0x2042 58 | #define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20a9 59 | #define WGL_CONTEXT_DEBUG_BIT_ARB 0x00000001 60 | #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 61 | #define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126 62 | #define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 63 | #define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 64 | #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 65 | #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 66 | #define WGL_CONTEXT_FLAGS_ARB 0x2094 67 | #define WGL_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004 68 | #define WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004 69 | #define WGL_LOSE_CONTEXT_ON_RESET_ARB 0x8252 70 | #define WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 71 | #define WGL_NO_RESET_NOTIFICATION_ARB 0x8261 72 | #define WGL_CONTEXT_RELEASE_BEHAVIOR_ARB 0x2097 73 | #define WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB 0 74 | #define WGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB 0x2098 75 | 76 | #define ERROR_INVALID_VERSION_ARB 0x2095 77 | #define ERROR_INVALID_PROFILE_ARB 0x2096 78 | 79 | typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC)(int); 80 | typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC)(HDC,int,int,UINT,const int*,int*); 81 | typedef const char* (WINAPI * PFNWGLGETEXTENSIONSSTRINGEXTPROC)(void); 82 | typedef const char* (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC)(HDC); 83 | typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC,HGLRC,const int*); 84 | 85 | typedef HGLRC (WINAPI * WGLCREATECONTEXT_T)(HDC); 86 | typedef BOOL (WINAPI * WGLDELETECONTEXT_T)(HGLRC); 87 | typedef PROC (WINAPI * WGLGETPROCADDRESS_T)(LPCSTR); 88 | typedef HDC (WINAPI * WGLGETCURRENTDC_T)(void); 89 | typedef BOOL (WINAPI * WGLMAKECURRENT_T)(HDC,HGLRC); 90 | typedef BOOL (WINAPI * WGLSHARELISTS_T)(HGLRC,HGLRC); 91 | 92 | // opengl32.dll function pointer typedefs 93 | #define wglCreateContext _glfw.wgl.CreateContext 94 | #define wglDeleteContext _glfw.wgl.DeleteContext 95 | #define wglGetProcAddress _glfw.wgl.GetProcAddress 96 | #define wglGetCurrentDC _glfw.wgl.GetCurrentDC 97 | #define wglMakeCurrent _glfw.wgl.MakeCurrent 98 | #define wglShareLists _glfw.wgl.ShareLists 99 | 100 | #define _GLFW_RECREATION_NOT_NEEDED 0 101 | #define _GLFW_RECREATION_REQUIRED 1 102 | #define _GLFW_RECREATION_IMPOSSIBLE 2 103 | 104 | #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextWGL wgl 105 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryWGL wgl 106 | 107 | 108 | // WGL-specific per-context data 109 | // 110 | typedef struct _GLFWcontextWGL 111 | { 112 | HDC dc; 113 | HGLRC handle; 114 | int interval; 115 | 116 | } _GLFWcontextWGL; 117 | 118 | // WGL-specific global data 119 | // 120 | typedef struct _GLFWlibraryWGL 121 | { 122 | HINSTANCE instance; 123 | WGLCREATECONTEXT_T CreateContext; 124 | WGLDELETECONTEXT_T DeleteContext; 125 | WGLGETPROCADDRESS_T GetProcAddress; 126 | WGLGETCURRENTDC_T GetCurrentDC; 127 | WGLMAKECURRENT_T MakeCurrent; 128 | WGLSHARELISTS_T ShareLists; 129 | 130 | GLFWbool extensionsLoaded; 131 | 132 | PFNWGLSWAPINTERVALEXTPROC SwapIntervalEXT; 133 | PFNWGLGETPIXELFORMATATTRIBIVARBPROC GetPixelFormatAttribivARB; 134 | PFNWGLGETEXTENSIONSSTRINGEXTPROC GetExtensionsStringEXT; 135 | PFNWGLGETEXTENSIONSSTRINGARBPROC GetExtensionsStringARB; 136 | PFNWGLCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB; 137 | GLFWbool EXT_swap_control; 138 | GLFWbool ARB_multisample; 139 | GLFWbool ARB_framebuffer_sRGB; 140 | GLFWbool EXT_framebuffer_sRGB; 141 | GLFWbool ARB_pixel_format; 142 | GLFWbool ARB_create_context; 143 | GLFWbool ARB_create_context_profile; 144 | GLFWbool EXT_create_context_es2_profile; 145 | GLFWbool ARB_create_context_robustness; 146 | GLFWbool ARB_context_flush_control; 147 | 148 | } _GLFWlibraryWGL; 149 | 150 | 151 | GLFWbool _glfwInitWGL(void); 152 | void _glfwTerminateWGL(void); 153 | GLFWbool _glfwCreateContextWGL(_GLFWwindow* window, 154 | const _GLFWctxconfig* ctxconfig, 155 | const _GLFWfbconfig* fbconfig); 156 | 157 | #endif // _glfw3_wgl_context_h_ 158 | -------------------------------------------------------------------------------- /glfw/src/win32_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2016 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_win32_joystick_h_ 28 | #define _glfw3_win32_joystick_h_ 29 | 30 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE \ 31 | _GLFWjoystickWin32 win32_js[GLFW_JOYSTICK_LAST + 1] 32 | 33 | // Joystick element (axis, button or slider) 34 | // 35 | typedef struct _GLFWjoyobjectWin32 36 | { 37 | int offset; 38 | int type; 39 | } _GLFWjoyobjectWin32; 40 | 41 | // Win32-specific per-joystick data 42 | // 43 | typedef struct _GLFWjoystickWin32 44 | { 45 | GLFWbool present; 46 | float* axes; 47 | int axisCount; 48 | unsigned char* buttons; 49 | int buttonCount; 50 | _GLFWjoyobjectWin32* objects; 51 | int objectCount; 52 | char* name; 53 | IDirectInputDevice8W* device; 54 | DWORD index; 55 | GUID guid; 56 | } _GLFWjoystickWin32; 57 | 58 | 59 | void _glfwInitJoysticksWin32(void); 60 | void _glfwTerminateJoysticksWin32(void); 61 | void _glfwDetectJoystickConnectionWin32(void); 62 | void _glfwDetectJoystickDisconnectionWin32(void); 63 | 64 | #endif // _glfw3_win32_joystick_h_ 65 | -------------------------------------------------------------------------------- /glfw/src/win32_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 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 | // Initialise timer 36 | // 37 | void _glfwInitTimerWin32(void) 38 | { 39 | uint64_t frequency; 40 | 41 | if (QueryPerformanceFrequency((LARGE_INTEGER*) &frequency)) 42 | { 43 | _glfw.win32_time.hasPC = GLFW_TRUE; 44 | _glfw.win32_time.frequency = frequency; 45 | } 46 | else 47 | { 48 | _glfw.win32_time.hasPC = GLFW_FALSE; 49 | _glfw.win32_time.frequency = 1000; 50 | } 51 | } 52 | 53 | 54 | ////////////////////////////////////////////////////////////////////////// 55 | ////// GLFW platform API ////// 56 | ////////////////////////////////////////////////////////////////////////// 57 | 58 | uint64_t _glfwPlatformGetTimerValue(void) 59 | { 60 | if (_glfw.win32_time.hasPC) 61 | { 62 | uint64_t value; 63 | QueryPerformanceCounter((LARGE_INTEGER*) &value); 64 | return value; 65 | } 66 | else 67 | return (uint64_t) _glfw_timeGetTime(); 68 | } 69 | 70 | uint64_t _glfwPlatformGetTimerFrequency(void) 71 | { 72 | return _glfw.win32_time.frequency; 73 | } 74 | 75 | -------------------------------------------------------------------------------- /glfw/src/win32_tls.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2016 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 | GLFWbool _glfwInitThreadLocalStorageWin32(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 GLFW_FALSE; 43 | } 44 | 45 | _glfw.win32_tls.allocated = GLFW_TRUE; 46 | return GLFW_TRUE; 47 | } 48 | 49 | void _glfwTerminateThreadLocalStorageWin32(void) 50 | { 51 | if (_glfw.win32_tls.allocated) 52 | TlsFree(_glfw.win32_tls.context); 53 | } 54 | 55 | 56 | ////////////////////////////////////////////////////////////////////////// 57 | ////// GLFW platform API ////// 58 | ////////////////////////////////////////////////////////////////////////// 59 | 60 | void _glfwPlatformSetCurrentContext(_GLFWwindow* context) 61 | { 62 | TlsSetValue(_glfw.win32_tls.context, context); 63 | } 64 | 65 | _GLFWwindow* _glfwPlatformGetCurrentContext(void) 66 | { 67 | return TlsGetValue(_glfw.win32_tls.context); 68 | } 69 | 70 | -------------------------------------------------------------------------------- /glfw/src/wl_monitor.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 Wayland - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 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 | #include "internal.h" 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | 35 | struct _GLFWvidmodeWayland 36 | { 37 | GLFWvidmode base; 38 | uint32_t flags; 39 | }; 40 | 41 | static void geometry(void* data, 42 | struct wl_output* output, 43 | int32_t x, 44 | int32_t y, 45 | int32_t physicalWidth, 46 | int32_t physicalHeight, 47 | int32_t subpixel, 48 | const char* make, 49 | const char* model, 50 | int32_t transform) 51 | { 52 | struct _GLFWmonitor *monitor = data; 53 | 54 | monitor->wl.x = x; 55 | monitor->wl.y = y; 56 | monitor->widthMM = physicalWidth; 57 | monitor->heightMM = physicalHeight; 58 | } 59 | 60 | static void mode(void* data, 61 | struct wl_output* output, 62 | uint32_t flags, 63 | int32_t width, 64 | int32_t height, 65 | int32_t refresh) 66 | { 67 | struct _GLFWmonitor *monitor = data; 68 | _GLFWvidmodeWayland mode = { { 0 }, }; 69 | 70 | mode.base.width = width; 71 | mode.base.height = height; 72 | mode.base.refreshRate = refresh / 1000; 73 | mode.flags = flags; 74 | 75 | if (monitor->wl.modesCount + 1 >= monitor->wl.modesSize) 76 | { 77 | int size = monitor->wl.modesSize * 2; 78 | _GLFWvidmodeWayland* modes = 79 | realloc(monitor->wl.modes, 80 | size * sizeof(_GLFWvidmodeWayland)); 81 | monitor->wl.modes = modes; 82 | monitor->wl.modesSize = size; 83 | } 84 | 85 | monitor->wl.modes[monitor->wl.modesCount++] = mode; 86 | } 87 | 88 | static void done(void* data, 89 | struct wl_output* output) 90 | { 91 | struct _GLFWmonitor *monitor = data; 92 | 93 | monitor->wl.done = GLFW_TRUE; 94 | } 95 | 96 | static void scale(void* data, 97 | struct wl_output* output, 98 | int32_t factor) 99 | { 100 | struct _GLFWmonitor *monitor = data; 101 | 102 | monitor->wl.scale = factor; 103 | } 104 | 105 | static const struct wl_output_listener output_listener = { 106 | geometry, 107 | mode, 108 | done, 109 | scale, 110 | }; 111 | 112 | 113 | ////////////////////////////////////////////////////////////////////////// 114 | ////// GLFW internal API ////// 115 | ////////////////////////////////////////////////////////////////////////// 116 | 117 | void _glfwAddOutputWayland(uint32_t name, uint32_t version) 118 | { 119 | _GLFWmonitor *monitor; 120 | struct wl_output *output; 121 | char name_str[80]; 122 | 123 | memset(name_str, 0, sizeof(name_str)); 124 | snprintf(name_str, 79, "wl_output@%u", name); 125 | 126 | if (version < 2) 127 | { 128 | _glfwInputError(GLFW_PLATFORM_ERROR, 129 | "Wayland: Unsupported output interface version"); 130 | return; 131 | } 132 | 133 | monitor = _glfwAllocMonitor(name_str, 0, 0); 134 | 135 | output = wl_registry_bind(_glfw.wl.registry, 136 | name, 137 | &wl_output_interface, 138 | 2); 139 | if (!output) 140 | { 141 | _glfwFreeMonitor(monitor); 142 | return; 143 | } 144 | 145 | monitor->wl.modes = calloc(4, sizeof(_GLFWvidmodeWayland)); 146 | monitor->wl.modesSize = 4; 147 | 148 | monitor->wl.scale = 1; 149 | 150 | monitor->wl.output = output; 151 | wl_output_add_listener(output, &output_listener, monitor); 152 | 153 | if (_glfw.wl.monitorsCount + 1 >= _glfw.wl.monitorsSize) 154 | { 155 | _GLFWmonitor** monitors = _glfw.wl.monitors; 156 | int size = _glfw.wl.monitorsSize * 2; 157 | 158 | monitors = realloc(monitors, size * sizeof(_GLFWmonitor*)); 159 | 160 | _glfw.wl.monitors = monitors; 161 | _glfw.wl.monitorsSize = size; 162 | } 163 | 164 | _glfw.wl.monitors[_glfw.wl.monitorsCount++] = monitor; 165 | } 166 | 167 | 168 | ////////////////////////////////////////////////////////////////////////// 169 | ////// GLFW platform API ////// 170 | ////////////////////////////////////////////////////////////////////////// 171 | 172 | _GLFWmonitor** _glfwPlatformGetMonitors(int* count) 173 | { 174 | _GLFWmonitor** monitors; 175 | _GLFWmonitor* monitor; 176 | int i, monitorsCount = _glfw.wl.monitorsCount; 177 | 178 | if (_glfw.wl.monitorsCount == 0) 179 | goto err; 180 | 181 | monitors = calloc(monitorsCount, sizeof(_GLFWmonitor*)); 182 | 183 | for (i = 0; i < monitorsCount; i++) 184 | { 185 | _GLFWmonitor* origMonitor = _glfw.wl.monitors[i]; 186 | monitor = calloc(1, sizeof(_GLFWmonitor)); 187 | 188 | monitor->modes = 189 | _glfwPlatformGetVideoModes(origMonitor, 190 | &origMonitor->wl.modesCount); 191 | *monitor = *_glfw.wl.monitors[i]; 192 | monitors[i] = monitor; 193 | } 194 | 195 | *count = monitorsCount; 196 | return monitors; 197 | 198 | err: 199 | *count = 0; 200 | return NULL; 201 | } 202 | 203 | GLFWbool _glfwPlatformIsSameMonitor(_GLFWmonitor* first, _GLFWmonitor* second) 204 | { 205 | return first->wl.output == second->wl.output; 206 | } 207 | 208 | void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) 209 | { 210 | if (xpos) 211 | *xpos = monitor->wl.x; 212 | if (ypos) 213 | *ypos = monitor->wl.y; 214 | } 215 | 216 | GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) 217 | { 218 | GLFWvidmode *modes; 219 | int i, modesCount = monitor->wl.modesCount; 220 | 221 | modes = calloc(modesCount, sizeof(GLFWvidmode)); 222 | 223 | for (i = 0; i < modesCount; i++) 224 | modes[i] = monitor->wl.modes[i].base; 225 | 226 | *found = modesCount; 227 | return modes; 228 | } 229 | 230 | void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) 231 | { 232 | int i; 233 | 234 | for (i = 0; i < monitor->wl.modesCount; i++) 235 | { 236 | if (monitor->wl.modes[i].flags & WL_OUTPUT_MODE_CURRENT) 237 | { 238 | *mode = monitor->wl.modes[i].base; 239 | return; 240 | } 241 | } 242 | } 243 | 244 | void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) 245 | { 246 | // TODO 247 | _glfwInputError(GLFW_PLATFORM_ERROR, 248 | "Wayland: Gamma ramp getting not supported yet"); 249 | } 250 | 251 | void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) 252 | { 253 | // TODO 254 | _glfwInputError(GLFW_PLATFORM_ERROR, 255 | "Wayland: Gamma ramp setting not supported yet"); 256 | } 257 | 258 | 259 | ////////////////////////////////////////////////////////////////////////// 260 | ////// GLFW native API ////// 261 | ////////////////////////////////////////////////////////////////////////// 262 | 263 | GLFWAPI struct wl_output* glfwGetWaylandMonitor(GLFWmonitor* handle) 264 | { 265 | _GLFWmonitor* monitor = (_GLFWmonitor*) handle; 266 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 267 | return monitor->wl.output; 268 | } 269 | 270 | -------------------------------------------------------------------------------- /glfw/src/wl_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 Wayland - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 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_wayland_platform_h_ 28 | #define _glfw3_wayland_platform_h_ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | typedef VkFlags VkWaylandSurfaceCreateFlagsKHR; 35 | 36 | typedef struct VkWaylandSurfaceCreateInfoKHR 37 | { 38 | VkStructureType sType; 39 | const void* pNext; 40 | VkWaylandSurfaceCreateFlagsKHR flags; 41 | struct wl_display* display; 42 | struct wl_surface* surface; 43 | } VkWaylandSurfaceCreateInfoKHR; 44 | 45 | typedef VkResult (APIENTRY *PFN_vkCreateWaylandSurfaceKHR)(VkInstance,const VkWaylandSurfaceCreateInfoKHR*,const VkAllocationCallbacks*,VkSurfaceKHR*); 46 | typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR)(VkPhysicalDevice,uint32_t,struct wl_display*); 47 | 48 | #include "posix_tls.h" 49 | #include "posix_time.h" 50 | #include "linux_joystick.h" 51 | #include "xkb_unicode.h" 52 | #include "egl_context.h" 53 | 54 | #include "wayland-relative-pointer-unstable-v1-client-protocol.h" 55 | #include "wayland-pointer-constraints-unstable-v1-client-protocol.h" 56 | 57 | #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL) 58 | #define _glfw_dlclose(handle) dlclose(handle) 59 | #define _glfw_dlsym(handle, name) dlsym(handle, name) 60 | 61 | #define _GLFW_EGL_NATIVE_WINDOW ((EGLNativeWindowType) window->wl.native) 62 | #define _GLFW_EGL_NATIVE_DISPLAY ((EGLNativeDisplayType) _glfw.wl.display) 63 | 64 | #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWayland wl 65 | #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWayland wl 66 | #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorWayland wl 67 | #define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorWayland wl 68 | 69 | #define _GLFW_PLATFORM_CONTEXT_STATE 70 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE 71 | 72 | 73 | // Wayland-specific video mode data 74 | // 75 | typedef struct _GLFWvidmodeWayland _GLFWvidmodeWayland; 76 | 77 | // Wayland-specific per-window data 78 | // 79 | typedef struct _GLFWwindowWayland 80 | { 81 | int width, height; 82 | GLFWbool visible; 83 | GLFWbool maximized; 84 | struct wl_surface* surface; 85 | struct wl_egl_window* native; 86 | struct wl_shell_surface* shell_surface; 87 | struct wl_callback* callback; 88 | 89 | _GLFWcursor* currentCursor; 90 | double cursorPosX, cursorPosY; 91 | 92 | char* title; 93 | 94 | // We need to track the monitors the window spans on to calculate the 95 | // optimal scaling factor. 96 | int scale; 97 | _GLFWmonitor** monitors; 98 | int monitorsCount; 99 | int monitorsSize; 100 | 101 | struct { 102 | struct zwp_relative_pointer_v1* relativePointer; 103 | struct zwp_locked_pointer_v1* lockedPointer; 104 | } pointerLock; 105 | } _GLFWwindowWayland; 106 | 107 | // Wayland-specific global data 108 | // 109 | typedef struct _GLFWlibraryWayland 110 | { 111 | struct wl_display* display; 112 | struct wl_registry* registry; 113 | struct wl_compositor* compositor; 114 | struct wl_shell* shell; 115 | struct wl_shm* shm; 116 | struct wl_seat* seat; 117 | struct wl_pointer* pointer; 118 | struct wl_keyboard* keyboard; 119 | struct zwp_relative_pointer_manager_v1* relativePointerManager; 120 | struct zwp_pointer_constraints_v1* pointerConstraints; 121 | 122 | int wl_compositor_version; 123 | 124 | struct wl_cursor_theme* cursorTheme; 125 | struct wl_surface* cursorSurface; 126 | uint32_t pointerSerial; 127 | 128 | _GLFWmonitor** monitors; 129 | int monitorsCount; 130 | int monitorsSize; 131 | 132 | short int publicKeys[256]; 133 | 134 | struct { 135 | struct xkb_context* context; 136 | struct xkb_keymap* keymap; 137 | struct xkb_state* state; 138 | xkb_mod_mask_t control_mask; 139 | xkb_mod_mask_t alt_mask; 140 | xkb_mod_mask_t shift_mask; 141 | xkb_mod_mask_t super_mask; 142 | unsigned int modifiers; 143 | } xkb; 144 | 145 | _GLFWwindow* pointerFocus; 146 | _GLFWwindow* keyboardFocus; 147 | 148 | } _GLFWlibraryWayland; 149 | 150 | // Wayland-specific per-monitor data 151 | // 152 | typedef struct _GLFWmonitorWayland 153 | { 154 | struct wl_output* output; 155 | 156 | _GLFWvidmodeWayland* modes; 157 | int modesCount; 158 | int modesSize; 159 | GLFWbool done; 160 | 161 | int x; 162 | int y; 163 | int scale; 164 | } _GLFWmonitorWayland; 165 | 166 | // Wayland-specific per-cursor data 167 | // 168 | typedef struct _GLFWcursorWayland 169 | { 170 | struct wl_cursor_image* image; 171 | struct wl_buffer* buffer; 172 | int width, height; 173 | int xhot, yhot; 174 | } _GLFWcursorWayland; 175 | 176 | 177 | void _glfwAddOutputWayland(uint32_t name, uint32_t version); 178 | 179 | #endif // _glfw3_wayland_platform_h_ 180 | -------------------------------------------------------------------------------- /glfw/src/xkb_unicode.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.2 Linux - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 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_xkb_unicode_h_ 28 | #define _glfw3_xkb_unicode_h_ 29 | 30 | 31 | long _glfwKeySym2Unicode(unsigned int keysym); 32 | 33 | #endif // _glfw3_xkb_unicode_h_ 34 | -------------------------------------------------------------------------------- /glfw/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | link_libraries(glfw) 3 | 4 | if (BUILD_SHARED_LIBS) 5 | link_libraries("${MATH_LIBRARY}") 6 | endif() 7 | 8 | if (MSVC) 9 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 10 | endif() 11 | 12 | include_directories("${GLFW_SOURCE_DIR}/deps") 13 | 14 | set(GLAD "${GLFW_SOURCE_DIR}/deps/glad/glad.h" 15 | "${GLFW_SOURCE_DIR}/deps/glad.c") 16 | set(GETOPT "${GLFW_SOURCE_DIR}/deps/getopt.h" 17 | "${GLFW_SOURCE_DIR}/deps/getopt.c") 18 | set(TINYCTHREAD "${GLFW_SOURCE_DIR}/deps/tinycthread.h" 19 | "${GLFW_SOURCE_DIR}/deps/tinycthread.c") 20 | 21 | add_executable(clipboard clipboard.c ${GETOPT} ${GLAD}) 22 | add_executable(events events.c ${GETOPT} ${GLAD}) 23 | add_executable(msaa msaa.c ${GETOPT} ${GLAD}) 24 | add_executable(gamma gamma.c ${GETOPT} ${GLAD}) 25 | add_executable(glfwinfo glfwinfo.c ${GETOPT} ${GLAD}) 26 | add_executable(iconify iconify.c ${GETOPT} ${GLAD}) 27 | add_executable(joysticks joysticks.c ${GLAD}) 28 | add_executable(monitors monitors.c ${GETOPT} ${GLAD}) 29 | add_executable(reopen reopen.c ${GLAD}) 30 | add_executable(cursor cursor.c ${GLAD}) 31 | 32 | add_executable(empty WIN32 MACOSX_BUNDLE empty.c ${TINYCTHREAD} ${GLAD}) 33 | add_executable(icon WIN32 MACOSX_BUNDLE icon.c ${GLAD}) 34 | add_executable(sharing WIN32 MACOSX_BUNDLE sharing.c ${GLAD}) 35 | add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c ${GETOPT} ${GLAD}) 36 | add_executable(threads WIN32 MACOSX_BUNDLE threads.c ${TINYCTHREAD} ${GLAD}) 37 | add_executable(timeout WIN32 MACOSX_BUNDLE timeout.c ${GLAD}) 38 | add_executable(title WIN32 MACOSX_BUNDLE title.c ${GLAD}) 39 | add_executable(windows WIN32 MACOSX_BUNDLE windows.c ${GETOPT} ${GLAD}) 40 | 41 | target_link_libraries(empty "${CMAKE_THREAD_LIBS_INIT}" "${RT_LIBRARY}") 42 | target_link_libraries(threads "${CMAKE_THREAD_LIBS_INIT}" "${RT_LIBRARY}") 43 | 44 | set(WINDOWS_BINARIES empty icon sharing tearing threads timeout title windows) 45 | set(CONSOLE_BINARIES clipboard events msaa gamma glfwinfo 46 | iconify joysticks monitors reopen cursor) 47 | 48 | if (VULKAN_FOUND) 49 | add_executable(vulkan WIN32 vulkan.c ${ICON}) 50 | target_include_directories(vulkan PRIVATE "${VULKAN_INCLUDE_DIR}") 51 | if (NOT GLFW_VULKAN_STATIC) 52 | target_link_libraries(vulkan "${VULKAN_LIBRARY}") 53 | endif() 54 | list(APPEND WINDOWS_BINARIES vulkan) 55 | endif() 56 | 57 | set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES 58 | FOLDER "GLFW3/Tests") 59 | 60 | if (MSVC) 61 | # Tell MSVC to use main instead of WinMain for Windows subsystem executables 62 | set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES 63 | LINK_FLAGS "/ENTRY:mainCRTStartup") 64 | endif() 65 | 66 | if (APPLE) 67 | set_target_properties(empty PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Empty Event") 68 | set_target_properties(sharing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Sharing") 69 | set_target_properties(tearing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Tearing") 70 | set_target_properties(threads PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Threads") 71 | set_target_properties(timeout PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Timeout") 72 | set_target_properties(title PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Title") 73 | set_target_properties(windows PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Windows") 74 | 75 | set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES 76 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${GLFW_VERSION} 77 | MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION_FULL} 78 | MACOSX_BUNDLE_INFO_PLIST "${GLFW_SOURCE_DIR}/CMake/MacOSXBundleInfo.plist.in") 79 | endif() 80 | 81 | -------------------------------------------------------------------------------- /glfw/tests/clipboard.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Clipboard test program 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This program is used to test the clipboard functionality. 27 | // 28 | //======================================================================== 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | #include "getopt.h" 37 | 38 | #if defined(__APPLE__) 39 | #define MODIFIER GLFW_MOD_SUPER 40 | #else 41 | #define MODIFIER GLFW_MOD_CONTROL 42 | #endif 43 | 44 | static void usage(void) 45 | { 46 | printf("Usage: clipboard [-h]\n"); 47 | } 48 | 49 | static void error_callback(int error, const char* description) 50 | { 51 | fprintf(stderr, "Error: %s\n", description); 52 | } 53 | 54 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 55 | { 56 | if (action != GLFW_PRESS) 57 | return; 58 | 59 | switch (key) 60 | { 61 | case GLFW_KEY_ESCAPE: 62 | glfwSetWindowShouldClose(window, GLFW_TRUE); 63 | break; 64 | 65 | case GLFW_KEY_V: 66 | if (mods == MODIFIER) 67 | { 68 | const char* string; 69 | 70 | string = glfwGetClipboardString(window); 71 | if (string) 72 | printf("Clipboard contains \"%s\"\n", string); 73 | else 74 | printf("Clipboard does not contain a string\n"); 75 | } 76 | break; 77 | 78 | case GLFW_KEY_C: 79 | if (mods == MODIFIER) 80 | { 81 | const char* string = "Hello GLFW World!"; 82 | glfwSetClipboardString(window, string); 83 | printf("Setting clipboard to \"%s\"\n", string); 84 | } 85 | break; 86 | } 87 | } 88 | 89 | static void framebuffer_size_callback(GLFWwindow* window, int width, int height) 90 | { 91 | glViewport(0, 0, width, height); 92 | } 93 | 94 | int main(int argc, char** argv) 95 | { 96 | int ch; 97 | GLFWwindow* window; 98 | 99 | while ((ch = getopt(argc, argv, "h")) != -1) 100 | { 101 | switch (ch) 102 | { 103 | case 'h': 104 | usage(); 105 | exit(EXIT_SUCCESS); 106 | 107 | default: 108 | usage(); 109 | exit(EXIT_FAILURE); 110 | } 111 | } 112 | 113 | glfwSetErrorCallback(error_callback); 114 | 115 | if (!glfwInit()) 116 | { 117 | fprintf(stderr, "Failed to initialize GLFW\n"); 118 | exit(EXIT_FAILURE); 119 | } 120 | 121 | window = glfwCreateWindow(200, 200, "Clipboard Test", NULL, NULL); 122 | if (!window) 123 | { 124 | glfwTerminate(); 125 | 126 | fprintf(stderr, "Failed to open GLFW window\n"); 127 | exit(EXIT_FAILURE); 128 | } 129 | 130 | glfwMakeContextCurrent(window); 131 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 132 | glfwSwapInterval(1); 133 | 134 | glfwSetKeyCallback(window, key_callback); 135 | glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 136 | 137 | glMatrixMode(GL_PROJECTION); 138 | glOrtho(-1.f, 1.f, -1.f, 1.f, -1.f, 1.f); 139 | glMatrixMode(GL_MODELVIEW); 140 | 141 | glClearColor(0.5f, 0.5f, 0.5f, 0); 142 | 143 | while (!glfwWindowShouldClose(window)) 144 | { 145 | glClear(GL_COLOR_BUFFER_BIT); 146 | 147 | glColor3f(0.8f, 0.2f, 0.4f); 148 | glRectf(-0.5f, -0.5f, 0.5f, 0.5f); 149 | 150 | glfwSwapBuffers(window); 151 | glfwWaitEvents(); 152 | } 153 | 154 | glfwTerminate(); 155 | exit(EXIT_SUCCESS); 156 | } 157 | 158 | -------------------------------------------------------------------------------- /glfw/tests/empty.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Empty event test 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test is intended to verify that posting of empty events works 27 | // 28 | //======================================================================== 29 | 30 | #include "tinycthread.h" 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | static volatile int running = GLFW_TRUE; 40 | 41 | static void error_callback(int error, const char* description) 42 | { 43 | fprintf(stderr, "Error: %s\n", description); 44 | } 45 | 46 | static int thread_main(void* data) 47 | { 48 | struct timespec time; 49 | 50 | while (running) 51 | { 52 | clock_gettime(CLOCK_REALTIME, &time); 53 | time.tv_sec += 1; 54 | thrd_sleep(&time, NULL); 55 | 56 | glfwPostEmptyEvent(); 57 | } 58 | 59 | return 0; 60 | } 61 | 62 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 63 | { 64 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 65 | glfwSetWindowShouldClose(window, GLFW_TRUE); 66 | } 67 | 68 | static float nrand(void) 69 | { 70 | return (float) rand() / (float) RAND_MAX; 71 | } 72 | 73 | int main(void) 74 | { 75 | int result; 76 | thrd_t thread; 77 | GLFWwindow* window; 78 | 79 | srand((unsigned int) time(NULL)); 80 | 81 | glfwSetErrorCallback(error_callback); 82 | 83 | if (!glfwInit()) 84 | exit(EXIT_FAILURE); 85 | 86 | window = glfwCreateWindow(640, 480, "Empty Event Test", NULL, NULL); 87 | if (!window) 88 | { 89 | glfwTerminate(); 90 | exit(EXIT_FAILURE); 91 | } 92 | 93 | glfwMakeContextCurrent(window); 94 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 95 | glfwSetKeyCallback(window, key_callback); 96 | 97 | if (thrd_create(&thread, thread_main, NULL) != thrd_success) 98 | { 99 | fprintf(stderr, "Failed to create secondary thread\n"); 100 | 101 | glfwTerminate(); 102 | exit(EXIT_FAILURE); 103 | } 104 | 105 | while (running) 106 | { 107 | int width, height; 108 | float r = nrand(), g = nrand(), b = nrand(); 109 | float l = (float) sqrt(r * r + g * g + b * b); 110 | 111 | glfwGetFramebufferSize(window, &width, &height); 112 | 113 | glViewport(0, 0, width, height); 114 | glClearColor(r / l, g / l, b / l, 1.f); 115 | glClear(GL_COLOR_BUFFER_BIT); 116 | glfwSwapBuffers(window); 117 | 118 | glfwWaitEvents(); 119 | 120 | if (glfwWindowShouldClose(window)) 121 | running = GLFW_FALSE; 122 | } 123 | 124 | glfwHideWindow(window); 125 | thrd_join(thread, &result); 126 | glfwDestroyWindow(window); 127 | 128 | glfwTerminate(); 129 | exit(EXIT_SUCCESS); 130 | } 131 | 132 | -------------------------------------------------------------------------------- /glfw/tests/gamma.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Gamma correction test program 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This program is used to test the gamma correction functionality for 27 | // both full screen and windowed mode windows 28 | // 29 | //======================================================================== 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | #include "getopt.h" 38 | 39 | #define STEP_SIZE 0.1f 40 | 41 | static GLfloat gamma_value = 1.0f; 42 | 43 | static void usage(void) 44 | { 45 | printf("Usage: gamma [-h] [-f]\n"); 46 | printf("Options:\n"); 47 | printf(" -f create full screen window\n"); 48 | printf(" -h show this help\n"); 49 | } 50 | 51 | static void set_gamma(GLFWwindow* window, float value) 52 | { 53 | GLFWmonitor* monitor = glfwGetWindowMonitor(window); 54 | if (!monitor) 55 | monitor = glfwGetPrimaryMonitor(); 56 | 57 | gamma_value = value; 58 | printf("Gamma: %f\n", gamma_value); 59 | glfwSetGamma(monitor, gamma_value); 60 | } 61 | 62 | static void error_callback(int error, const char* description) 63 | { 64 | fprintf(stderr, "Error: %s\n", description); 65 | } 66 | 67 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 68 | { 69 | if (action != GLFW_PRESS) 70 | return; 71 | 72 | switch (key) 73 | { 74 | case GLFW_KEY_ESCAPE: 75 | { 76 | glfwSetWindowShouldClose(window, GLFW_TRUE); 77 | break; 78 | } 79 | 80 | case GLFW_KEY_KP_ADD: 81 | case GLFW_KEY_UP: 82 | case GLFW_KEY_Q: 83 | { 84 | set_gamma(window, gamma_value + STEP_SIZE); 85 | break; 86 | } 87 | 88 | case GLFW_KEY_KP_SUBTRACT: 89 | case GLFW_KEY_DOWN: 90 | case GLFW_KEY_W: 91 | { 92 | if (gamma_value - STEP_SIZE > 0.f) 93 | set_gamma(window, gamma_value - STEP_SIZE); 94 | 95 | break; 96 | } 97 | } 98 | } 99 | 100 | static void framebuffer_size_callback(GLFWwindow* window, int width, int height) 101 | { 102 | glViewport(0, 0, width, height); 103 | } 104 | 105 | int main(int argc, char** argv) 106 | { 107 | int width, height, ch; 108 | GLFWmonitor* monitor = NULL; 109 | GLFWwindow* window; 110 | 111 | glfwSetErrorCallback(error_callback); 112 | 113 | if (!glfwInit()) 114 | exit(EXIT_FAILURE); 115 | 116 | while ((ch = getopt(argc, argv, "fh")) != -1) 117 | { 118 | switch (ch) 119 | { 120 | case 'h': 121 | usage(); 122 | exit(EXIT_SUCCESS); 123 | 124 | case 'f': 125 | monitor = glfwGetPrimaryMonitor(); 126 | break; 127 | 128 | default: 129 | usage(); 130 | exit(EXIT_FAILURE); 131 | } 132 | } 133 | 134 | if (monitor) 135 | { 136 | const GLFWvidmode* mode = glfwGetVideoMode(monitor); 137 | 138 | glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate); 139 | glfwWindowHint(GLFW_RED_BITS, mode->redBits); 140 | glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits); 141 | glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits); 142 | 143 | width = mode->width; 144 | height = mode->height; 145 | } 146 | else 147 | { 148 | width = 200; 149 | height = 200; 150 | } 151 | 152 | window = glfwCreateWindow(width, height, "Gamma Test", monitor, NULL); 153 | if (!window) 154 | { 155 | glfwTerminate(); 156 | exit(EXIT_FAILURE); 157 | } 158 | 159 | set_gamma(window, 1.f); 160 | 161 | glfwMakeContextCurrent(window); 162 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 163 | glfwSwapInterval(1); 164 | 165 | glfwSetKeyCallback(window, key_callback); 166 | glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 167 | 168 | glMatrixMode(GL_PROJECTION); 169 | glOrtho(-1.f, 1.f, -1.f, 1.f, -1.f, 1.f); 170 | glMatrixMode(GL_MODELVIEW); 171 | 172 | glClearColor(0.5f, 0.5f, 0.5f, 0); 173 | 174 | while (!glfwWindowShouldClose(window)) 175 | { 176 | glClear(GL_COLOR_BUFFER_BIT); 177 | 178 | glColor3f(0.8f, 0.2f, 0.4f); 179 | glRectf(-0.5f, -0.5f, 0.5f, 0.5f); 180 | 181 | glfwSwapBuffers(window); 182 | glfwWaitEvents(); 183 | } 184 | 185 | glfwTerminate(); 186 | exit(EXIT_SUCCESS); 187 | } 188 | 189 | -------------------------------------------------------------------------------- /glfw/tests/icon.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Window icon test program 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This program is used to test the icon feature. 27 | // 28 | //======================================================================== 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | // a simple glfw logo 38 | const char* const logo[] = 39 | { 40 | "................", 41 | "................", 42 | "...0000..0......", 43 | "...0.....0......", 44 | "...0.00..0......", 45 | "...0..0..0......", 46 | "...0000..0000...", 47 | "................", 48 | "................", 49 | "...000..0...0...", 50 | "...0....0...0...", 51 | "...000..0.0.0...", 52 | "...0....0.0.0...", 53 | "...0....00000...", 54 | "................", 55 | "................" 56 | }; 57 | 58 | const unsigned char icon_colors[5][4] = 59 | { 60 | { 0, 0, 0, 255 }, // black 61 | { 255, 0, 0, 255 }, // red 62 | { 0, 255, 0, 255 }, // green 63 | { 0, 0, 255, 255 }, // blue 64 | { 255, 255, 255, 255 } // white 65 | }; 66 | 67 | static int cur_icon_color = 0; 68 | 69 | static void set_icon(GLFWwindow* window, int icon_color) 70 | { 71 | int x, y; 72 | unsigned char pixels[16 * 16 * 4]; 73 | unsigned char* target = pixels; 74 | GLFWimage img = { 16, 16, pixels }; 75 | 76 | for (y = 0; y < img.width; y++) 77 | { 78 | for (x = 0; x < img.height; x++) 79 | { 80 | if (logo[y][x] == '0') 81 | memcpy(target, icon_colors[icon_color], 4); 82 | else 83 | memset(target, 0, 4); 84 | 85 | target += 4; 86 | } 87 | } 88 | 89 | glfwSetWindowIcon(window, 1, &img); 90 | } 91 | 92 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 93 | { 94 | if (action != GLFW_PRESS) 95 | return; 96 | 97 | switch (key) 98 | { 99 | case GLFW_KEY_ESCAPE: 100 | glfwSetWindowShouldClose(window, GLFW_TRUE); 101 | break; 102 | case GLFW_KEY_SPACE: 103 | cur_icon_color = (cur_icon_color + 1) % 5; 104 | set_icon(window, cur_icon_color); 105 | break; 106 | case GLFW_KEY_X: 107 | glfwSetWindowIcon(window, 0, NULL); 108 | break; 109 | } 110 | } 111 | 112 | int main(int argc, char** argv) 113 | { 114 | GLFWwindow* window; 115 | 116 | if (!glfwInit()) 117 | { 118 | fprintf(stderr, "Failed to initialize GLFW\n"); 119 | exit(EXIT_FAILURE); 120 | } 121 | 122 | window = glfwCreateWindow(200, 200, "Window Icon", NULL, NULL); 123 | if (!window) 124 | { 125 | glfwTerminate(); 126 | 127 | fprintf(stderr, "Failed to open GLFW window\n"); 128 | exit(EXIT_FAILURE); 129 | } 130 | 131 | glfwMakeContextCurrent(window); 132 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 133 | 134 | glfwSetKeyCallback(window, key_callback); 135 | set_icon(window, cur_icon_color); 136 | 137 | while (!glfwWindowShouldClose(window)) 138 | { 139 | glClear(GL_COLOR_BUFFER_BIT); 140 | glfwSwapBuffers(window); 141 | glfwWaitEvents(); 142 | } 143 | 144 | glfwDestroyWindow(window); 145 | glfwTerminate(); 146 | exit(EXIT_SUCCESS); 147 | } 148 | 149 | -------------------------------------------------------------------------------- /glfw/tests/joysticks.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Joystick input test 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test displays the state of every button and axis of every connected 27 | // joystick and/or gamepad 28 | // 29 | //======================================================================== 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | #ifdef _MSC_VER 39 | #define strdup(x) _strdup(x) 40 | #endif 41 | 42 | static int joysticks[GLFW_JOYSTICK_LAST + 1]; 43 | static int joystick_count = 0; 44 | 45 | static void error_callback(int error, const char* description) 46 | { 47 | fprintf(stderr, "Error: %s\n", description); 48 | } 49 | 50 | static void framebuffer_size_callback(GLFWwindow* window, int width, int height) 51 | { 52 | glViewport(0, 0, width, height); 53 | } 54 | 55 | static void draw_joystick(int index, int x, int y, int width, int height) 56 | { 57 | int i; 58 | int axis_count, button_count; 59 | const float* axes; 60 | const unsigned char* buttons; 61 | const int axis_height = 3 * height / 4; 62 | const int button_height = height / 4; 63 | 64 | axes = glfwGetJoystickAxes(joysticks[index], &axis_count); 65 | if (axis_count) 66 | { 67 | const int axis_width = width / axis_count; 68 | 69 | for (i = 0; i < axis_count; i++) 70 | { 71 | float value = axes[i] / 2.f + 0.5f; 72 | 73 | glColor3f(0.3f, 0.3f, 0.3f); 74 | glRecti(x + i * axis_width, 75 | y, 76 | x + (i + 1) * axis_width, 77 | y + axis_height); 78 | 79 | glColor3f(1.f, 1.f, 1.f); 80 | glRecti(x + i * axis_width, 81 | y + (int) (value * (axis_height - 5)), 82 | x + (i + 1) * axis_width, 83 | y + 5 + (int) (value * (axis_height - 5))); 84 | } 85 | } 86 | 87 | buttons = glfwGetJoystickButtons(joysticks[index], &button_count); 88 | if (button_count) 89 | { 90 | const int button_width = width / button_count; 91 | 92 | for (i = 0; i < button_count; i++) 93 | { 94 | if (buttons[i]) 95 | glColor3f(1.f, 1.f, 1.f); 96 | else 97 | glColor3f(0.3f, 0.3f, 0.3f); 98 | 99 | glRecti(x + i * button_width, 100 | y + axis_height, 101 | x + (i + 1) * button_width, 102 | y + axis_height + button_height); 103 | } 104 | } 105 | } 106 | 107 | static void draw_joysticks(GLFWwindow* window) 108 | { 109 | int i, width, height, offset = 0; 110 | 111 | glfwGetFramebufferSize(window, &width, &height); 112 | 113 | glMatrixMode(GL_PROJECTION); 114 | glLoadIdentity(); 115 | glOrtho(0.f, width, height, 0.f, 1.f, -1.f); 116 | glMatrixMode(GL_MODELVIEW); 117 | 118 | for (i = 0; i < joystick_count; i++) 119 | { 120 | draw_joystick(i, 121 | 0, offset * height / joystick_count, 122 | width, height / joystick_count); 123 | offset++; 124 | } 125 | } 126 | 127 | static void joystick_callback(int joy, int event) 128 | { 129 | if (event == GLFW_CONNECTED) 130 | { 131 | int axis_count, button_count; 132 | 133 | glfwGetJoystickAxes(joy, &axis_count); 134 | glfwGetJoystickButtons(joy, &button_count); 135 | 136 | printf("Found joystick %i named \'%s\' with %i axes, %i buttons\n", 137 | joy + 1, 138 | glfwGetJoystickName(joy), 139 | axis_count, 140 | button_count); 141 | 142 | joysticks[joystick_count++] = joy; 143 | } 144 | else if (event == GLFW_DISCONNECTED) 145 | { 146 | int i; 147 | 148 | for (i = 0; i < joystick_count; i++) 149 | { 150 | if (joysticks[i] == joy) 151 | break; 152 | } 153 | 154 | for (i = i + 1; i < joystick_count; i++) 155 | joysticks[i - 1] = joysticks[i]; 156 | 157 | printf("Lost joystick %i\n", joy + 1); 158 | joystick_count--; 159 | } 160 | } 161 | 162 | static void find_joysticks(void) 163 | { 164 | int joy; 165 | 166 | for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++) 167 | { 168 | if (glfwJoystickPresent(joy)) 169 | joystick_callback(joy, GLFW_CONNECTED); 170 | } 171 | } 172 | 173 | int main(void) 174 | { 175 | GLFWwindow* window; 176 | 177 | memset(joysticks, 0, sizeof(joysticks)); 178 | 179 | glfwSetErrorCallback(error_callback); 180 | 181 | if (!glfwInit()) 182 | exit(EXIT_FAILURE); 183 | 184 | find_joysticks(); 185 | glfwSetJoystickCallback(joystick_callback); 186 | 187 | window = glfwCreateWindow(640, 480, "Joystick Test", NULL, NULL); 188 | if (!window) 189 | { 190 | glfwTerminate(); 191 | exit(EXIT_FAILURE); 192 | } 193 | 194 | glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 195 | 196 | glfwMakeContextCurrent(window); 197 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 198 | glfwSwapInterval(1); 199 | 200 | while (!glfwWindowShouldClose(window)) 201 | { 202 | glClear(GL_COLOR_BUFFER_BIT); 203 | 204 | draw_joysticks(window); 205 | 206 | glfwSwapBuffers(window); 207 | glfwPollEvents(); 208 | 209 | // Workaround for an issue with msvcrt and mintty 210 | fflush(stdout); 211 | } 212 | 213 | glfwTerminate(); 214 | exit(EXIT_SUCCESS); 215 | } 216 | 217 | -------------------------------------------------------------------------------- /glfw/tests/monitors.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Monitor information tool 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test prints monitor and video mode information or verifies video 27 | // modes 28 | // 29 | //======================================================================== 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | #include "getopt.h" 39 | 40 | enum Mode 41 | { 42 | LIST_MODE, 43 | TEST_MODE 44 | }; 45 | 46 | static void usage(void) 47 | { 48 | printf("Usage: monitors [-t]\n"); 49 | printf(" monitors -h\n"); 50 | } 51 | 52 | static const char* format_mode(const GLFWvidmode* mode) 53 | { 54 | static char buffer[512]; 55 | 56 | sprintf(buffer, 57 | "%i x %i x %i (%i %i %i) %i Hz", 58 | mode->width, mode->height, 59 | mode->redBits + mode->greenBits + mode->blueBits, 60 | mode->redBits, mode->greenBits, mode->blueBits, 61 | mode->refreshRate); 62 | 63 | buffer[sizeof(buffer) - 1] = '\0'; 64 | return buffer; 65 | } 66 | 67 | static void error_callback(int error, const char* description) 68 | { 69 | fprintf(stderr, "Error: %s\n", description); 70 | } 71 | 72 | static void framebuffer_size_callback(GLFWwindow* window, int width, int height) 73 | { 74 | printf("Framebuffer resized to %ix%i\n", width, height); 75 | 76 | glViewport(0, 0, width, height); 77 | } 78 | 79 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 80 | { 81 | if (key == GLFW_KEY_ESCAPE) 82 | glfwSetWindowShouldClose(window, GLFW_TRUE); 83 | } 84 | 85 | static void list_modes(GLFWmonitor* monitor) 86 | { 87 | int count, x, y, widthMM, heightMM, i; 88 | const GLFWvidmode* mode = glfwGetVideoMode(monitor); 89 | const GLFWvidmode* modes = glfwGetVideoModes(monitor, &count); 90 | 91 | glfwGetMonitorPos(monitor, &x, &y); 92 | glfwGetMonitorPhysicalSize(monitor, &widthMM, &heightMM); 93 | 94 | printf("Name: %s (%s)\n", 95 | glfwGetMonitorName(monitor), 96 | glfwGetPrimaryMonitor() == monitor ? "primary" : "secondary"); 97 | printf("Current mode: %s\n", format_mode(mode)); 98 | printf("Virtual position: %i %i\n", x, y); 99 | 100 | printf("Physical size: %i x %i mm (%0.2f dpi)\n", 101 | widthMM, heightMM, mode->width * 25.4f / widthMM); 102 | 103 | printf("Modes:\n"); 104 | 105 | for (i = 0; i < count; i++) 106 | { 107 | printf("%3u: %s", (unsigned int) i, format_mode(modes + i)); 108 | 109 | if (memcmp(mode, modes + i, sizeof(GLFWvidmode)) == 0) 110 | printf(" (current mode)"); 111 | 112 | putchar('\n'); 113 | } 114 | } 115 | 116 | static void test_modes(GLFWmonitor* monitor) 117 | { 118 | int i, count; 119 | GLFWwindow* window; 120 | const GLFWvidmode* modes = glfwGetVideoModes(monitor, &count); 121 | 122 | for (i = 0; i < count; i++) 123 | { 124 | const GLFWvidmode* mode = modes + i; 125 | GLFWvidmode current; 126 | 127 | glfwWindowHint(GLFW_RED_BITS, mode->redBits); 128 | glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits); 129 | glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits); 130 | glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate); 131 | 132 | printf("Testing mode %u on monitor %s: %s\n", 133 | (unsigned int) i, 134 | glfwGetMonitorName(monitor), 135 | format_mode(mode)); 136 | 137 | window = glfwCreateWindow(mode->width, mode->height, 138 | "Video Mode Test", 139 | glfwGetPrimaryMonitor(), 140 | NULL); 141 | if (!window) 142 | { 143 | printf("Failed to enter mode %u: %s\n", 144 | (unsigned int) i, 145 | format_mode(mode)); 146 | continue; 147 | } 148 | 149 | glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 150 | glfwSetKeyCallback(window, key_callback); 151 | 152 | glfwMakeContextCurrent(window); 153 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 154 | glfwSwapInterval(1); 155 | 156 | glfwSetTime(0.0); 157 | 158 | while (glfwGetTime() < 5.0) 159 | { 160 | glClear(GL_COLOR_BUFFER_BIT); 161 | glfwSwapBuffers(window); 162 | glfwPollEvents(); 163 | 164 | if (glfwWindowShouldClose(window)) 165 | { 166 | printf("User terminated program\n"); 167 | 168 | glfwTerminate(); 169 | exit(EXIT_SUCCESS); 170 | } 171 | } 172 | 173 | glGetIntegerv(GL_RED_BITS, ¤t.redBits); 174 | glGetIntegerv(GL_GREEN_BITS, ¤t.greenBits); 175 | glGetIntegerv(GL_BLUE_BITS, ¤t.blueBits); 176 | 177 | glfwGetWindowSize(window, ¤t.width, ¤t.height); 178 | 179 | if (current.redBits != mode->redBits || 180 | current.greenBits != mode->greenBits || 181 | current.blueBits != mode->blueBits) 182 | { 183 | printf("*** Color bit mismatch: (%i %i %i) instead of (%i %i %i)\n", 184 | current.redBits, current.greenBits, current.blueBits, 185 | mode->redBits, mode->greenBits, mode->blueBits); 186 | } 187 | 188 | if (current.width != mode->width || current.height != mode->height) 189 | { 190 | printf("*** Size mismatch: %ix%i instead of %ix%i\n", 191 | current.width, current.height, 192 | mode->width, mode->height); 193 | } 194 | 195 | printf("Closing window\n"); 196 | 197 | glfwDestroyWindow(window); 198 | window = NULL; 199 | 200 | glfwPollEvents(); 201 | } 202 | } 203 | 204 | int main(int argc, char** argv) 205 | { 206 | int ch, i, count, mode = LIST_MODE; 207 | GLFWmonitor** monitors; 208 | 209 | while ((ch = getopt(argc, argv, "th")) != -1) 210 | { 211 | switch (ch) 212 | { 213 | case 'h': 214 | usage(); 215 | exit(EXIT_SUCCESS); 216 | case 't': 217 | mode = TEST_MODE; 218 | break; 219 | default: 220 | usage(); 221 | exit(EXIT_FAILURE); 222 | } 223 | } 224 | 225 | glfwSetErrorCallback(error_callback); 226 | 227 | if (!glfwInit()) 228 | exit(EXIT_FAILURE); 229 | 230 | monitors = glfwGetMonitors(&count); 231 | 232 | for (i = 0; i < count; i++) 233 | { 234 | if (mode == LIST_MODE) 235 | list_modes(monitors[i]); 236 | else if (mode == TEST_MODE) 237 | test_modes(monitors[i]); 238 | } 239 | 240 | glfwTerminate(); 241 | exit(EXIT_SUCCESS); 242 | } 243 | 244 | -------------------------------------------------------------------------------- /glfw/tests/msaa.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Multisample anti-aliasing test 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test renders two high contrast, slowly rotating quads, one aliased 27 | // and one (hopefully) anti-aliased, thus allowing for visual verification 28 | // of whether MSAA is indeed enabled 29 | // 30 | //======================================================================== 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | 38 | #include "getopt.h" 39 | 40 | static void error_callback(int error, const char* description) 41 | { 42 | fprintf(stderr, "Error: %s\n", description); 43 | } 44 | 45 | static void framebuffer_size_callback(GLFWwindow* window, int width, int height) 46 | { 47 | glViewport(0, 0, width, height); 48 | } 49 | 50 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 51 | { 52 | if (action != GLFW_PRESS) 53 | return; 54 | 55 | switch (key) 56 | { 57 | case GLFW_KEY_SPACE: 58 | glfwSetTime(0.0); 59 | break; 60 | } 61 | } 62 | 63 | static void usage(void) 64 | { 65 | printf("Usage: msaa [-h] [-s SAMPLES]\n"); 66 | } 67 | 68 | int main(int argc, char** argv) 69 | { 70 | int ch, samples = 4; 71 | GLFWwindow* window; 72 | 73 | while ((ch = getopt(argc, argv, "hs:")) != -1) 74 | { 75 | switch (ch) 76 | { 77 | case 'h': 78 | usage(); 79 | exit(EXIT_SUCCESS); 80 | case 's': 81 | samples = atoi(optarg); 82 | break; 83 | default: 84 | usage(); 85 | exit(EXIT_FAILURE); 86 | } 87 | } 88 | 89 | glfwSetErrorCallback(error_callback); 90 | 91 | if (!glfwInit()) 92 | exit(EXIT_FAILURE); 93 | 94 | if (samples) 95 | printf("Requesting MSAA with %i samples\n", samples); 96 | else 97 | printf("Requesting that MSAA not be available\n"); 98 | 99 | glfwWindowHint(GLFW_SAMPLES, samples); 100 | glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); 101 | 102 | window = glfwCreateWindow(800, 400, "Aliasing Detector", NULL, NULL); 103 | if (!window) 104 | { 105 | glfwTerminate(); 106 | exit(EXIT_FAILURE); 107 | } 108 | 109 | glfwSetKeyCallback(window, key_callback); 110 | glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 111 | 112 | glfwMakeContextCurrent(window); 113 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 114 | glfwSwapInterval(1); 115 | 116 | if (!GLAD_GL_ARB_multisample && !GLAD_GL_VERSION_1_3) 117 | { 118 | printf("Multisampling is not supported\n"); 119 | 120 | glfwTerminate(); 121 | exit(EXIT_FAILURE); 122 | } 123 | 124 | glfwShowWindow(window); 125 | 126 | glGetIntegerv(GL_SAMPLES, &samples); 127 | if (samples) 128 | printf("Context reports MSAA is available with %i samples\n", samples); 129 | else 130 | printf("Context reports MSAA is unavailable\n"); 131 | 132 | glMatrixMode(GL_PROJECTION); 133 | glOrtho(0.f, 1.f, 0.f, 0.5f, 0.f, 1.f); 134 | glMatrixMode(GL_MODELVIEW); 135 | 136 | while (!glfwWindowShouldClose(window)) 137 | { 138 | GLfloat time = (GLfloat) glfwGetTime(); 139 | 140 | glClear(GL_COLOR_BUFFER_BIT); 141 | 142 | glLoadIdentity(); 143 | glTranslatef(0.25f, 0.25f, 0.f); 144 | glRotatef(time, 0.f, 0.f, 1.f); 145 | 146 | glDisable(GL_MULTISAMPLE_ARB); 147 | glRectf(-0.15f, -0.15f, 0.15f, 0.15f); 148 | 149 | glLoadIdentity(); 150 | glTranslatef(0.75f, 0.25f, 0.f); 151 | glRotatef(time, 0.f, 0.f, 1.f); 152 | 153 | glEnable(GL_MULTISAMPLE_ARB); 154 | glRectf(-0.15f, -0.15f, 0.15f, 0.15f); 155 | 156 | glfwSwapBuffers(window); 157 | glfwPollEvents(); 158 | } 159 | 160 | glfwTerminate(); 161 | exit(EXIT_SUCCESS); 162 | } 163 | 164 | -------------------------------------------------------------------------------- /glfw/tests/reopen.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Window re-opener (open/close stress test) 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test came about as the result of bug #1262773 27 | // 28 | // It closes and re-opens the GLFW window every five seconds, alternating 29 | // between windowed and full screen mode 30 | // 31 | // It also times and logs opening and closing actions and attempts to separate 32 | // user initiated window closing from its own 33 | // 34 | //======================================================================== 35 | 36 | #include 37 | #include 38 | 39 | #include 40 | #include 41 | #include 42 | 43 | static void error_callback(int error, const char* description) 44 | { 45 | fprintf(stderr, "Error: %s\n", description); 46 | } 47 | 48 | static void framebuffer_size_callback(GLFWwindow* window, int width, int height) 49 | { 50 | glViewport(0, 0, width, height); 51 | } 52 | 53 | static void window_close_callback(GLFWwindow* window) 54 | { 55 | printf("Close callback triggered\n"); 56 | } 57 | 58 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 59 | { 60 | if (action != GLFW_PRESS) 61 | return; 62 | 63 | switch (key) 64 | { 65 | case GLFW_KEY_Q: 66 | case GLFW_KEY_ESCAPE: 67 | glfwSetWindowShouldClose(window, GLFW_TRUE); 68 | break; 69 | } 70 | } 71 | 72 | static GLFWwindow* open_window(int width, int height, GLFWmonitor* monitor) 73 | { 74 | double base; 75 | GLFWwindow* window; 76 | 77 | base = glfwGetTime(); 78 | 79 | window = glfwCreateWindow(width, height, "Window Re-opener", monitor, NULL); 80 | if (!window) 81 | return NULL; 82 | 83 | glfwMakeContextCurrent(window); 84 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 85 | glfwSwapInterval(1); 86 | 87 | glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 88 | glfwSetWindowCloseCallback(window, window_close_callback); 89 | glfwSetKeyCallback(window, key_callback); 90 | 91 | if (monitor) 92 | { 93 | printf("Opening full screen window on monitor %s took %0.3f seconds\n", 94 | glfwGetMonitorName(monitor), 95 | glfwGetTime() - base); 96 | } 97 | else 98 | { 99 | printf("Opening regular window took %0.3f seconds\n", 100 | glfwGetTime() - base); 101 | } 102 | 103 | return window; 104 | } 105 | 106 | static void close_window(GLFWwindow* window) 107 | { 108 | double base = glfwGetTime(); 109 | glfwDestroyWindow(window); 110 | printf("Closing window took %0.3f seconds\n", glfwGetTime() - base); 111 | } 112 | 113 | int main(int argc, char** argv) 114 | { 115 | int count = 0; 116 | GLFWwindow* window; 117 | 118 | srand((unsigned int) time(NULL)); 119 | 120 | glfwSetErrorCallback(error_callback); 121 | 122 | if (!glfwInit()) 123 | exit(EXIT_FAILURE); 124 | 125 | for (;;) 126 | { 127 | int width, height; 128 | GLFWmonitor* monitor = NULL; 129 | 130 | if (count % 2 == 0) 131 | { 132 | int monitorCount; 133 | GLFWmonitor** monitors = glfwGetMonitors(&monitorCount); 134 | monitor = monitors[rand() % monitorCount]; 135 | } 136 | 137 | if (monitor) 138 | { 139 | const GLFWvidmode* mode = glfwGetVideoMode(monitor); 140 | width = mode->width; 141 | height = mode->height; 142 | } 143 | else 144 | { 145 | width = 640; 146 | height = 480; 147 | } 148 | 149 | window = open_window(width, height, monitor); 150 | if (!window) 151 | { 152 | glfwTerminate(); 153 | exit(EXIT_FAILURE); 154 | } 155 | 156 | glMatrixMode(GL_PROJECTION); 157 | glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f); 158 | glMatrixMode(GL_MODELVIEW); 159 | 160 | glfwSetTime(0.0); 161 | 162 | while (glfwGetTime() < 5.0) 163 | { 164 | glClear(GL_COLOR_BUFFER_BIT); 165 | 166 | glPushMatrix(); 167 | glRotatef((GLfloat) glfwGetTime() * 100.f, 0.f, 0.f, 1.f); 168 | glRectf(-0.5f, -0.5f, 1.f, 1.f); 169 | glPopMatrix(); 170 | 171 | glfwSwapBuffers(window); 172 | glfwPollEvents(); 173 | 174 | if (glfwWindowShouldClose(window)) 175 | { 176 | close_window(window); 177 | printf("User closed window\n"); 178 | 179 | glfwTerminate(); 180 | exit(EXIT_SUCCESS); 181 | } 182 | } 183 | 184 | printf("Closing window\n"); 185 | close_window(window); 186 | 187 | count++; 188 | } 189 | 190 | glfwTerminate(); 191 | } 192 | 193 | -------------------------------------------------------------------------------- /glfw/tests/sharing.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Context sharing test program 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This program is used to test sharing of objects between contexts 27 | // 28 | //======================================================================== 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | #define WIDTH 400 37 | #define HEIGHT 400 38 | #define OFFSET 50 39 | 40 | static GLFWwindow* windows[2]; 41 | 42 | static void error_callback(int error, const char* description) 43 | { 44 | fprintf(stderr, "Error: %s\n", description); 45 | } 46 | 47 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 48 | { 49 | if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE) 50 | glfwSetWindowShouldClose(window, GLFW_TRUE); 51 | } 52 | 53 | static GLFWwindow* open_window(const char* title, GLFWwindow* share, int posX, int posY) 54 | { 55 | GLFWwindow* window; 56 | 57 | glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); 58 | window = glfwCreateWindow(WIDTH, HEIGHT, title, NULL, share); 59 | if (!window) 60 | return NULL; 61 | 62 | glfwMakeContextCurrent(window); 63 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 64 | glfwSwapInterval(1); 65 | glfwSetWindowPos(window, posX, posY); 66 | glfwShowWindow(window); 67 | 68 | glfwSetKeyCallback(window, key_callback); 69 | 70 | return window; 71 | } 72 | 73 | static GLuint create_texture(void) 74 | { 75 | int x, y; 76 | char pixels[256 * 256]; 77 | GLuint texture; 78 | 79 | glGenTextures(1, &texture); 80 | glBindTexture(GL_TEXTURE_2D, texture); 81 | 82 | for (y = 0; y < 256; y++) 83 | { 84 | for (x = 0; x < 256; x++) 85 | pixels[y * 256 + x] = rand() % 256; 86 | } 87 | 88 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 256, 256, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels); 89 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 90 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 91 | 92 | return texture; 93 | } 94 | 95 | static void draw_quad(GLuint texture) 96 | { 97 | int width, height; 98 | glfwGetFramebufferSize(glfwGetCurrentContext(), &width, &height); 99 | 100 | glViewport(0, 0, width, height); 101 | 102 | glMatrixMode(GL_PROJECTION); 103 | glLoadIdentity(); 104 | glOrtho(0.f, 1.f, 0.f, 1.f, 0.f, 1.f); 105 | 106 | glEnable(GL_TEXTURE_2D); 107 | glBindTexture(GL_TEXTURE_2D, texture); 108 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 109 | 110 | glBegin(GL_QUADS); 111 | 112 | glTexCoord2f(0.f, 0.f); 113 | glVertex2f(0.f, 0.f); 114 | 115 | glTexCoord2f(1.f, 0.f); 116 | glVertex2f(1.f, 0.f); 117 | 118 | glTexCoord2f(1.f, 1.f); 119 | glVertex2f(1.f, 1.f); 120 | 121 | glTexCoord2f(0.f, 1.f); 122 | glVertex2f(0.f, 1.f); 123 | 124 | glEnd(); 125 | } 126 | 127 | int main(int argc, char** argv) 128 | { 129 | int x, y, width; 130 | GLuint texture; 131 | 132 | glfwSetErrorCallback(error_callback); 133 | 134 | if (!glfwInit()) 135 | exit(EXIT_FAILURE); 136 | 137 | windows[0] = open_window("First", NULL, OFFSET, OFFSET); 138 | if (!windows[0]) 139 | { 140 | glfwTerminate(); 141 | exit(EXIT_FAILURE); 142 | } 143 | 144 | // This is the one and only time we create a texture 145 | // It is created inside the first context, created above 146 | // It will then be shared with the second context, created below 147 | texture = create_texture(); 148 | 149 | glfwGetWindowPos(windows[0], &x, &y); 150 | glfwGetWindowSize(windows[0], &width, NULL); 151 | 152 | // Put the second window to the right of the first one 153 | windows[1] = open_window("Second", windows[0], x + width + OFFSET, y); 154 | if (!windows[1]) 155 | { 156 | glfwTerminate(); 157 | exit(EXIT_FAILURE); 158 | } 159 | 160 | // Set drawing color for both contexts 161 | glfwMakeContextCurrent(windows[0]); 162 | glColor3f(0.6f, 0.f, 0.6f); 163 | glfwMakeContextCurrent(windows[1]); 164 | glColor3f(0.6f, 0.6f, 0.f); 165 | 166 | glfwMakeContextCurrent(windows[0]); 167 | 168 | while (!glfwWindowShouldClose(windows[0]) && 169 | !glfwWindowShouldClose(windows[1])) 170 | { 171 | glfwMakeContextCurrent(windows[0]); 172 | draw_quad(texture); 173 | 174 | glfwMakeContextCurrent(windows[1]); 175 | draw_quad(texture); 176 | 177 | glfwSwapBuffers(windows[0]); 178 | glfwSwapBuffers(windows[1]); 179 | 180 | glfwWaitEvents(); 181 | } 182 | 183 | glfwTerminate(); 184 | exit(EXIT_SUCCESS); 185 | } 186 | 187 | -------------------------------------------------------------------------------- /glfw/tests/tearing.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Vsync enabling test 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test renders a high contrast, horizontally moving bar, allowing for 27 | // visual verification of whether the set swap interval is indeed obeyed 28 | // 29 | //======================================================================== 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | #include "getopt.h" 39 | 40 | static int swap_tear; 41 | static int swap_interval; 42 | static double frame_rate; 43 | 44 | static void usage(void) 45 | { 46 | printf("Usage: tearing [-h] [-f]\n"); 47 | printf("Options:\n"); 48 | printf(" -f create full screen window\n"); 49 | printf(" -h show this help\n"); 50 | } 51 | 52 | static void update_window_title(GLFWwindow* window) 53 | { 54 | char title[256]; 55 | 56 | sprintf(title, "Tearing detector (interval %i%s, %0.1f Hz)", 57 | swap_interval, 58 | (swap_tear && swap_interval < 0) ? " (swap tear)" : "", 59 | frame_rate); 60 | 61 | glfwSetWindowTitle(window, title); 62 | } 63 | 64 | static void set_swap_interval(GLFWwindow* window, int interval) 65 | { 66 | swap_interval = interval; 67 | glfwSwapInterval(swap_interval); 68 | update_window_title(window); 69 | } 70 | 71 | static void error_callback(int error, const char* description) 72 | { 73 | fprintf(stderr, "Error: %s\n", description); 74 | } 75 | 76 | static void framebuffer_size_callback(GLFWwindow* window, int width, int height) 77 | { 78 | glViewport(0, 0, width, height); 79 | } 80 | 81 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 82 | { 83 | if (action != GLFW_PRESS) 84 | return; 85 | 86 | switch (key) 87 | { 88 | case GLFW_KEY_UP: 89 | { 90 | if (swap_interval + 1 > swap_interval) 91 | set_swap_interval(window, swap_interval + 1); 92 | break; 93 | } 94 | 95 | case GLFW_KEY_DOWN: 96 | { 97 | if (swap_tear) 98 | { 99 | if (swap_interval - 1 < swap_interval) 100 | set_swap_interval(window, swap_interval - 1); 101 | } 102 | else 103 | { 104 | if (swap_interval - 1 >= 0) 105 | set_swap_interval(window, swap_interval - 1); 106 | } 107 | break; 108 | } 109 | 110 | case GLFW_KEY_ESCAPE: 111 | glfwSetWindowShouldClose(window, 1); 112 | break; 113 | } 114 | } 115 | 116 | int main(int argc, char** argv) 117 | { 118 | int ch, width, height; 119 | float position; 120 | unsigned long frame_count = 0; 121 | double last_time, current_time; 122 | int fullscreen = GLFW_FALSE; 123 | GLFWmonitor* monitor = NULL; 124 | GLFWwindow* window; 125 | 126 | while ((ch = getopt(argc, argv, "fh")) != -1) 127 | { 128 | switch (ch) 129 | { 130 | case 'h': 131 | usage(); 132 | exit(EXIT_SUCCESS); 133 | 134 | case 'f': 135 | fullscreen = GLFW_TRUE; 136 | break; 137 | } 138 | } 139 | 140 | glfwSetErrorCallback(error_callback); 141 | 142 | if (!glfwInit()) 143 | exit(EXIT_FAILURE); 144 | 145 | if (fullscreen) 146 | { 147 | const GLFWvidmode* mode; 148 | 149 | monitor = glfwGetPrimaryMonitor(); 150 | mode = glfwGetVideoMode(monitor); 151 | 152 | glfwWindowHint(GLFW_RED_BITS, mode->redBits); 153 | glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits); 154 | glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits); 155 | glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate); 156 | 157 | width = mode->width; 158 | height = mode->height; 159 | } 160 | else 161 | { 162 | width = 640; 163 | height = 480; 164 | } 165 | 166 | window = glfwCreateWindow(width, height, "", monitor, NULL); 167 | if (!window) 168 | { 169 | glfwTerminate(); 170 | exit(EXIT_FAILURE); 171 | } 172 | 173 | glfwMakeContextCurrent(window); 174 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 175 | set_swap_interval(window, 0); 176 | 177 | last_time = glfwGetTime(); 178 | frame_rate = 0.0; 179 | swap_tear = (glfwExtensionSupported("WGL_EXT_swap_control_tear") || 180 | glfwExtensionSupported("GLX_EXT_swap_control_tear")); 181 | 182 | glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 183 | glfwSetKeyCallback(window, key_callback); 184 | 185 | glMatrixMode(GL_PROJECTION); 186 | glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f); 187 | glMatrixMode(GL_MODELVIEW); 188 | 189 | while (!glfwWindowShouldClose(window)) 190 | { 191 | glClear(GL_COLOR_BUFFER_BIT); 192 | 193 | position = cosf((float) glfwGetTime() * 4.f) * 0.75f; 194 | glRectf(position - 0.25f, -1.f, position + 0.25f, 1.f); 195 | 196 | glfwSwapBuffers(window); 197 | glfwPollEvents(); 198 | 199 | frame_count++; 200 | 201 | current_time = glfwGetTime(); 202 | if (current_time - last_time > 1.0) 203 | { 204 | frame_rate = frame_count / (current_time - last_time); 205 | frame_count = 0; 206 | last_time = current_time; 207 | update_window_title(window); 208 | } 209 | } 210 | 211 | glfwTerminate(); 212 | exit(EXIT_SUCCESS); 213 | } 214 | 215 | -------------------------------------------------------------------------------- /glfw/tests/threads.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Multi-threading test 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test is intended to verify whether the OpenGL context part of 27 | // the GLFW API is able to be used from multiple threads 28 | // 29 | //======================================================================== 30 | 31 | #include "tinycthread.h" 32 | 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | typedef struct 41 | { 42 | GLFWwindow* window; 43 | const char* title; 44 | float r, g, b; 45 | thrd_t id; 46 | } Thread; 47 | 48 | static volatile int running = GLFW_TRUE; 49 | 50 | static void error_callback(int error, const char* description) 51 | { 52 | fprintf(stderr, "Error: %s\n", description); 53 | } 54 | 55 | static int thread_main(void* data) 56 | { 57 | const Thread* thread = data; 58 | 59 | glfwMakeContextCurrent(thread->window); 60 | glfwSwapInterval(1); 61 | 62 | while (running) 63 | { 64 | const float v = (float) fabs(sin(glfwGetTime() * 2.f)); 65 | glClearColor(thread->r * v, thread->g * v, thread->b * v, 0.f); 66 | 67 | glClear(GL_COLOR_BUFFER_BIT); 68 | glfwSwapBuffers(thread->window); 69 | } 70 | 71 | glfwMakeContextCurrent(NULL); 72 | return 0; 73 | } 74 | 75 | int main(void) 76 | { 77 | int i, result; 78 | Thread threads[] = 79 | { 80 | { NULL, "Red", 1.f, 0.f, 0.f, 0 }, 81 | { NULL, "Green", 0.f, 1.f, 0.f, 0 }, 82 | { NULL, "Blue", 0.f, 0.f, 1.f, 0 } 83 | }; 84 | const int count = sizeof(threads) / sizeof(Thread); 85 | 86 | glfwSetErrorCallback(error_callback); 87 | 88 | if (!glfwInit()) 89 | exit(EXIT_FAILURE); 90 | 91 | glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); 92 | 93 | for (i = 0; i < count; i++) 94 | { 95 | threads[i].window = glfwCreateWindow(200, 200, 96 | threads[i].title, 97 | NULL, NULL); 98 | if (!threads[i].window) 99 | { 100 | glfwTerminate(); 101 | exit(EXIT_FAILURE); 102 | } 103 | 104 | glfwSetWindowPos(threads[i].window, 200 + 250 * i, 200); 105 | glfwShowWindow(threads[i].window); 106 | } 107 | 108 | glfwMakeContextCurrent(threads[0].window); 109 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 110 | glfwMakeContextCurrent(NULL); 111 | 112 | for (i = 0; i < count; i++) 113 | { 114 | if (thrd_create(&threads[i].id, thread_main, threads + i) != 115 | thrd_success) 116 | { 117 | fprintf(stderr, "Failed to create secondary thread\n"); 118 | 119 | glfwTerminate(); 120 | exit(EXIT_FAILURE); 121 | } 122 | } 123 | 124 | while (running) 125 | { 126 | glfwWaitEvents(); 127 | 128 | for (i = 0; i < count; i++) 129 | { 130 | if (glfwWindowShouldClose(threads[i].window)) 131 | running = GLFW_FALSE; 132 | } 133 | } 134 | 135 | for (i = 0; i < count; i++) 136 | glfwHideWindow(threads[i].window); 137 | 138 | for (i = 0; i < count; i++) 139 | thrd_join(threads[i].id, &result); 140 | 141 | exit(EXIT_SUCCESS); 142 | } 143 | 144 | -------------------------------------------------------------------------------- /glfw/tests/timeout.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Event wait timeout test 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test is intended to verify that waiting for events with timeout works 27 | // 28 | //======================================================================== 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | static void error_callback(int error, const char* description) 39 | { 40 | fprintf(stderr, "Error: %s\n", description); 41 | } 42 | 43 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 44 | { 45 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) 46 | glfwSetWindowShouldClose(window, GLFW_TRUE); 47 | } 48 | 49 | static float nrand(void) 50 | { 51 | return (float) rand() / (float) RAND_MAX; 52 | } 53 | 54 | int main(void) 55 | { 56 | GLFWwindow* window; 57 | 58 | srand((unsigned int) time(NULL)); 59 | 60 | glfwSetErrorCallback(error_callback); 61 | 62 | if (!glfwInit()) 63 | exit(EXIT_FAILURE); 64 | 65 | window = glfwCreateWindow(640, 480, "Event Wait Timeout Test", NULL, NULL); 66 | if (!window) 67 | { 68 | glfwTerminate(); 69 | exit(EXIT_FAILURE); 70 | } 71 | 72 | glfwMakeContextCurrent(window); 73 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 74 | glfwSetKeyCallback(window, key_callback); 75 | 76 | while (!glfwWindowShouldClose(window)) 77 | { 78 | int width, height; 79 | float r = nrand(), g = nrand(), b = nrand(); 80 | float l = (float) sqrt(r * r + g * g + b * b); 81 | 82 | glfwGetFramebufferSize(window, &width, &height); 83 | 84 | glViewport(0, 0, width, height); 85 | glClearColor(r / l, g / l, b / l, 1.f); 86 | glClear(GL_COLOR_BUFFER_BIT); 87 | glfwSwapBuffers(window); 88 | 89 | glfwWaitEventsTimeout(1.0); 90 | } 91 | 92 | glfwDestroyWindow(window); 93 | 94 | glfwTerminate(); 95 | exit(EXIT_SUCCESS); 96 | } 97 | 98 | -------------------------------------------------------------------------------- /glfw/tests/title.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // UTF-8 window title test 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test sets a UTF-8 window title 27 | // 28 | //======================================================================== 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | static void error_callback(int error, const char* description) 37 | { 38 | fprintf(stderr, "Error: %s\n", description); 39 | } 40 | 41 | static void framebuffer_size_callback(GLFWwindow* window, int width, int height) 42 | { 43 | glViewport(0, 0, width, height); 44 | } 45 | 46 | int main(void) 47 | { 48 | GLFWwindow* window; 49 | 50 | glfwSetErrorCallback(error_callback); 51 | 52 | if (!glfwInit()) 53 | exit(EXIT_FAILURE); 54 | 55 | window = glfwCreateWindow(400, 400, "English 日本語 русский язык 官話", NULL, NULL); 56 | if (!window) 57 | { 58 | glfwTerminate(); 59 | exit(EXIT_FAILURE); 60 | } 61 | 62 | glfwMakeContextCurrent(window); 63 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 64 | glfwSwapInterval(1); 65 | 66 | glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); 67 | 68 | while (!glfwWindowShouldClose(window)) 69 | { 70 | glClear(GL_COLOR_BUFFER_BIT); 71 | glfwSwapBuffers(window); 72 | glfwWaitEvents(); 73 | } 74 | 75 | glfwTerminate(); 76 | exit(EXIT_SUCCESS); 77 | } 78 | 79 | -------------------------------------------------------------------------------- /glfw/tests/windows.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // Simple multi-window test 3 | // Copyright (c) Camilla Berglund 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // 9 | // Permission is granted to anyone to use this software for any purpose, 10 | // including commercial applications, and to alter it and redistribute it 11 | // freely, subject to the following restrictions: 12 | // 13 | // 1. The origin of this software must not be misrepresented; you must not 14 | // claim that you wrote the original software. If you use this software 15 | // in a product, an acknowledgment in the product documentation would 16 | // be appreciated but is not required. 17 | // 18 | // 2. Altered source versions must be plainly marked as such, and must not 19 | // be misrepresented as being the original software. 20 | // 21 | // 3. This notice may not be removed or altered from any source 22 | // distribution. 23 | // 24 | //======================================================================== 25 | // 26 | // This test creates four windows and clears each in a different color 27 | // 28 | //======================================================================== 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | #include "getopt.h" 37 | 38 | static const char* titles[] = 39 | { 40 | "Red", 41 | "Green", 42 | "Blue", 43 | "Yellow" 44 | }; 45 | 46 | static const struct 47 | { 48 | float r, g, b; 49 | } colors[] = 50 | { 51 | { 0.95f, 0.32f, 0.11f }, 52 | { 0.50f, 0.80f, 0.16f }, 53 | { 0.f, 0.68f, 0.94f }, 54 | { 0.98f, 0.74f, 0.04f } 55 | }; 56 | 57 | static void usage(void) 58 | { 59 | printf("Usage: windows [-h] [-b]\n"); 60 | printf("Options:\n"); 61 | printf(" -b create decorated windows\n"); 62 | printf(" -h show this help\n"); 63 | } 64 | 65 | static void error_callback(int error, const char* description) 66 | { 67 | fprintf(stderr, "Error: %s\n", description); 68 | } 69 | 70 | static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) 71 | { 72 | if (action != GLFW_PRESS) 73 | return; 74 | 75 | switch (key) 76 | { 77 | case GLFW_KEY_SPACE: 78 | { 79 | int xpos, ypos; 80 | glfwGetWindowPos(window, &xpos, &ypos); 81 | glfwSetWindowPos(window, xpos, ypos); 82 | break; 83 | } 84 | 85 | case GLFW_KEY_ESCAPE: 86 | glfwSetWindowShouldClose(window, GLFW_TRUE); 87 | break; 88 | } 89 | } 90 | 91 | int main(int argc, char** argv) 92 | { 93 | int i, ch; 94 | int decorated = GLFW_FALSE; 95 | int running = GLFW_TRUE; 96 | GLFWwindow* windows[4]; 97 | 98 | while ((ch = getopt(argc, argv, "bh")) != -1) 99 | { 100 | switch (ch) 101 | { 102 | case 'b': 103 | decorated = GLFW_TRUE; 104 | break; 105 | case 'h': 106 | usage(); 107 | exit(EXIT_SUCCESS); 108 | default: 109 | usage(); 110 | exit(EXIT_FAILURE); 111 | } 112 | } 113 | 114 | glfwSetErrorCallback(error_callback); 115 | 116 | if (!glfwInit()) 117 | exit(EXIT_FAILURE); 118 | 119 | glfwWindowHint(GLFW_DECORATED, decorated); 120 | glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); 121 | 122 | for (i = 0; i < 4; i++) 123 | { 124 | int left, top, right, bottom; 125 | 126 | windows[i] = glfwCreateWindow(200, 200, titles[i], NULL, NULL); 127 | if (!windows[i]) 128 | { 129 | glfwTerminate(); 130 | exit(EXIT_FAILURE); 131 | } 132 | 133 | glfwSetKeyCallback(windows[i], key_callback); 134 | 135 | glfwMakeContextCurrent(windows[i]); 136 | gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); 137 | glClearColor(colors[i].r, colors[i].g, colors[i].b, 1.f); 138 | 139 | glfwGetWindowFrameSize(windows[i], &left, &top, &right, &bottom); 140 | glfwSetWindowPos(windows[i], 141 | 100 + (i & 1) * (200 + left + right), 142 | 100 + (i >> 1) * (200 + top + bottom)); 143 | } 144 | 145 | for (i = 0; i < 4; i++) 146 | glfwShowWindow(windows[i]); 147 | 148 | while (running) 149 | { 150 | for (i = 0; i < 4; i++) 151 | { 152 | glfwMakeContextCurrent(windows[i]); 153 | glClear(GL_COLOR_BUFFER_BIT); 154 | glfwSwapBuffers(windows[i]); 155 | 156 | if (glfwWindowShouldClose(windows[i])) 157 | running = GLFW_FALSE; 158 | } 159 | 160 | glfwWaitEvents(); 161 | } 162 | 163 | glfwTerminate(); 164 | exit(EXIT_SUCCESS); 165 | } 166 | 167 | -------------------------------------------------------------------------------- /gltutorial.sublime-project: -------------------------------------------------------------------------------- 1 | { 2 | "folders": 3 | [ 4 | { 5 | "path": "." 6 | } 7 | ], 8 | "build_systems": 9 | [ 10 | { 11 | "name": "gltutorial", 12 | "cmd": ["(mkdir build || true) && cd build && cmake .. && make"], 13 | "working_dir": "$project_path", 14 | "selector": "source.c++", 15 | "shell": true, 16 | "variants": [ 17 | { 18 | "name": "Clean", 19 | "working_dir": "$project_path", 20 | "cmd": ["rm -r build"] 21 | }, 22 | { 23 | "name": "run", 24 | "working_dir": "$project_path/build/bin", 25 | "cmd": "./GLTutorial" 26 | }, 27 | { 28 | "name": "teapot.obj", 29 | "working_dir": "$project_path/build/bin", 30 | "cmd": "./GLTutorial ../../obj/utah-teapot.obj" 31 | }, 32 | { 33 | "name": "circle.obj", 34 | "working_dir": "$project_path/build/bin", 35 | "cmd": "./GLTutorial ../../obj/circle.obj" 36 | } 37 | ] 38 | } 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /obj/circle.obj: -------------------------------------------------------------------------------- 1 | # Blender v2.79 (sub 0) OBJ File: '' 2 | # www.blender.org 3 | o Circle 4 | v -0.000000 0.250000 0.000000 5 | v -0.095671 0.230970 0.000000 6 | v -0.176777 0.176777 0.000000 7 | v -0.230970 0.095671 0.000000 8 | v -0.250000 -0.000000 0.000000 9 | v -0.230970 -0.095671 0.000000 10 | v -0.176777 -0.176777 0.000000 11 | v -0.095671 -0.230970 0.000000 12 | v -0.000000 -0.250000 0.000000 13 | v 0.095671 -0.230970 0.000000 14 | v 0.176777 -0.176777 0.000000 15 | v 0.230970 -0.095671 0.000000 16 | v 0.250000 0.000000 0.000000 17 | v 0.230970 0.095671 0.000000 18 | v 0.176777 0.176777 0.000000 19 | v 0.095671 0.230970 0.000000 20 | v -0.000000 0.000000 0.000000 21 | s off 22 | f 11 17 10 23 | f 4 17 3 24 | f 12 17 11 25 | f 5 17 4 26 | f 13 17 12 27 | f 6 17 5 28 | f 14 17 13 29 | f 7 17 6 30 | f 15 17 14 31 | f 8 17 7 32 | f 16 17 15 33 | f 9 17 8 34 | f 2 17 1 35 | f 1 17 16 36 | f 10 17 9 37 | f 3 17 2 38 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB Sources "*.cpp") 2 | 3 | # Sources # 4 | 5 | set(MY_HEADER_FILES 6 | ${MY_HEADER_FILES} 7 | GraphicsManager.hpp 8 | Color.hpp 9 | Mesh.hpp 10 | ) 11 | 12 | set(MY_SOURCE_FILES 13 | ${MY_SOURCE_FILES} 14 | main.cpp 15 | GraphicsManager.cpp 16 | Mesh.cpp 17 | ) 18 | 19 | add_executable(GLTutorial 20 | ${MY_HEADER_FILES} 21 | ${MY_SOURCE_FILES} 22 | ) 23 | 24 | target_link_libraries(GLTutorial glfw) 25 | target_link_libraries(GLTutorial ${OPENGL_gl_LIBRARY} glfw glm) -------------------------------------------------------------------------------- /src/Color.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | class Color { 8 | public: 9 | float r = 0; 10 | float g = 0; 11 | float b = 0; 12 | float a = 0; 13 | 14 | Color(float r, float g, float b, float a) : r(r), g(g), b(b), a(a) {} 15 | Color(float r, float g, float b) : r(r), g(g), b(b), a(1.0f) {} 16 | Color(uint32_t hex) { 17 | uint32_t a = (hex >> 24) & 0xff; 18 | uint32_t r = (hex >> 16) & 0xff; 19 | uint32_t g = (hex >> 8) & 0xff; 20 | uint32_t b = hex & 0xff; 21 | 22 | a = (float)a / 255.0f; 23 | r = (float)r / 255.0f; 24 | g = (float)g / 255.0f; 25 | b = (float)b / 255.0f; 26 | } 27 | 28 | void bindGL() { 29 | glColor4f(r, g, b, a); 30 | } 31 | 32 | Color operator*(Color& o) { 33 | return Color(r * o.r, g * o.g, b * o.b, a * o.a); 34 | } 35 | 36 | }; 37 | -------------------------------------------------------------------------------- /src/GraphicsManager.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsManager.hpp" 2 | 3 | GraphicsManager::GraphicsManager( 4 | std::string title, 5 | std::function render_fn) : title(title), render_fn(render_fn) { 6 | 7 | } 8 | 9 | bool GraphicsManager::execute() { 10 | if(!glfwInit()) 11 | return false; 12 | 13 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, gl_major_version); 14 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, gl_minor_version); 15 | 16 | window = glfwCreateWindow(640, 480, title.c_str(), NULL, NULL); 17 | 18 | if (!window) 19 | { 20 | glfwTerminate(); 21 | return false; 22 | } 23 | 24 | glfwMakeContextCurrent(window); 25 | 26 | while (!glfwWindowShouldClose(window)) 27 | { 28 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 29 | glClearColor(clear_color.r, clear_color.g, clear_color.b, clear_color.a); 30 | glLoadIdentity(); 31 | 32 | render_fn(glfwGetTime(), this); 33 | 34 | glFlush(); 35 | 36 | glfwSwapBuffers(window); 37 | glfwPollEvents(); 38 | } 39 | 40 | glfwTerminate(); 41 | return true; 42 | } -------------------------------------------------------------------------------- /src/GraphicsManager.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "Color.hpp" 11 | 12 | class GraphicsManager { 13 | 14 | public: 15 | GraphicsManager(std::string title, std::function render_fn); 16 | bool execute(); 17 | 18 | void set_gl_version(int major, int minor) { 19 | gl_major_version = major; 20 | gl_minor_version = minor; 21 | } 22 | float aspect() { return ((float)width()) / ((float)height()); } 23 | int width() { return 640; } 24 | int height() { return 480; } 25 | void set_clear_color(Color c) { clear_color = c; } 26 | 27 | private: 28 | std::string title; 29 | std::function render_fn; 30 | 31 | GLFWwindow *window; 32 | int gl_major_version = 2; 33 | int gl_minor_version = 1; 34 | 35 | Color clear_color = Color(0.2f, 0.2f, 0.3f, 1.0f); 36 | }; -------------------------------------------------------------------------------- /src/Mesh.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | #include "Mesh.hpp" 8 | 9 | Mesh::Mesh(std::vector verts, std::vector tris) : verts(verts), tris(tris) {} 10 | 11 | /** Mesh::Mesh(string local_path) 12 | * Loads a mesh from a file in .obj file format. Only basic obj 13 | * constructs are supported -- do not export with UVs, normals, 14 | * or materials/material groups. 15 | * 16 | * local_path: path to the obj (local to executable) 17 | */ 18 | Mesh::Mesh(std::string local_path) { 19 | std::ifstream infile(local_path); 20 | 21 | std::string line; 22 | while (std::getline(infile, line)) 23 | { 24 | if(line.find("v ") == 0) { 25 | line = line.substr(2, std::string::npos); 26 | std::istringstream iss(line); 27 | double x, y, z; 28 | if(iss >> x >> y >> z) { 29 | glm::vec3 v(x, y, z); 30 | verts.push_back(v); 31 | } 32 | } else if(line.find("f ") == 0) { 33 | line = line.substr(2, std::string::npos); 34 | std::istringstream iss(line); 35 | int v1, v2, v3; 36 | // only support triangles 37 | if(iss >> v1 >> v2 >> v3) { 38 | tris.push_back(v1); 39 | tris.push_back(v2); 40 | tris.push_back(v3); 41 | } 42 | } 43 | } 44 | 45 | infile.close(); 46 | } 47 | 48 | void Mesh::draw() { 49 | glBegin(GL_TRIANGLES); 50 | auto i = tris.begin(); 51 | while(i != tris.end()) { 52 | int i1 = *i; ++i; 53 | int i2 = *i; ++i; 54 | int i3 = *i; ++i; 55 | glm::vec3 v1 = verts[i1 - 1]; 56 | glm::vec3 v2 = verts[i2 - 1]; 57 | glm::vec3 v3 = verts[i3 - 1]; 58 | 59 | glm::vec3 n = glm::cross(v3 - v1, v2 - v1); 60 | 61 | glNormal3f(n.x, n.y, n.z); 62 | glVertex3f(v1.x, v1.y, v1.z); 63 | glNormal3f(n.x, n.y, n.z); 64 | glVertex3f(v2.x, v2.y, v2.z); 65 | glNormal3f(n.x, n.y, n.z); 66 | glVertex3f(v3.x, v3.y, v3.z); 67 | 68 | } 69 | glEnd(); 70 | } -------------------------------------------------------------------------------- /src/Mesh.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include "Color.hpp" 9 | 10 | class Mesh { 11 | public: 12 | Mesh(std::string local_path); 13 | Mesh(std::vector verts, std::vector tris); 14 | 15 | void draw(); 16 | private: 17 | std::vector verts; 18 | std::vector tris; 19 | }; 20 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "GraphicsManager.hpp" 14 | #include "Mesh.hpp" 15 | 16 | void render(double current_time, GraphicsManager *gm) { 17 | /** Drawing Code Goes Here! **/ 18 | 19 | } 20 | 21 | int main(int argc, char **argv) { 22 | std::string title = "OpenGL Tutorial"; 23 | std::function pass = &render; 24 | 25 | GraphicsManager *gm = new GraphicsManager(title, pass); 26 | 27 | gm->set_gl_version(2, 1); // Set OpenGL profile to 2.1 28 | gm->execute(); 29 | 30 | return 0; 31 | } --------------------------------------------------------------------------------