├── .gitignore ├── .gitmodules ├── .travis.yml ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── examples └── sdl_demo.rs ├── imgui.ini └── src ├── build.rs ├── imgui.rs ├── lib.rs └── renderer.rs /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled files 2 | *.a 3 | *.o 4 | *.so 5 | *.rlib 6 | *.dll 7 | 8 | # Logs 9 | *.log 10 | 11 | # Executables 12 | *.exe 13 | 14 | # Generated by Cargo 15 | /target/ 16 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "src/cimgui"] 2 | path = src/cimgui 3 | url = https://github.com/Extrawurst/cimgui.git 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | sudo: required 3 | rust: 4 | - nightly 5 | install: 6 | - sudo add-apt-repository ppa:team-xbmc/ppa -y 7 | - sudo apt-get update -q 8 | - sudo apt-get install libsdl2-dev 9 | before_install: 10 | - git submodule update --init --recursive 11 | env: 12 | global: 13 | - LD_LIBRARY_PATH: "/usr/local/lib" 14 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | [root] 2 | name = "imgui-rs" 3 | version = "1.47.0" 4 | dependencies = [ 5 | "gcc 0.3.21 (registry+https://github.com/rust-lang/crates.io-index)", 6 | "gl 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", 7 | "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", 8 | "sdl2 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", 9 | ] 10 | 11 | [[package]] 12 | name = "advapi32-sys" 13 | version = "0.1.2" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | dependencies = [ 16 | "winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", 17 | "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 18 | ] 19 | 20 | [[package]] 21 | name = "bitflags" 22 | version = "0.3.3" 23 | source = "registry+https://github.com/rust-lang/crates.io-index" 24 | 25 | [[package]] 26 | name = "gcc" 27 | version = "0.3.21" 28 | source = "registry+https://github.com/rust-lang/crates.io-index" 29 | dependencies = [ 30 | "advapi32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 31 | "winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", 32 | ] 33 | 34 | [[package]] 35 | name = "gl" 36 | version = "0.5.2" 37 | source = "registry+https://github.com/rust-lang/crates.io-index" 38 | dependencies = [ 39 | "gl_generator 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 40 | "khronos_api 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 41 | ] 42 | 43 | [[package]] 44 | name = "gl_generator" 45 | version = "0.4.2" 46 | source = "registry+https://github.com/rust-lang/crates.io-index" 47 | dependencies = [ 48 | "khronos_api 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 49 | "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", 50 | "xml-rs 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 51 | ] 52 | 53 | [[package]] 54 | name = "khronos_api" 55 | version = "1.0.0" 56 | source = "registry+https://github.com/rust-lang/crates.io-index" 57 | 58 | [[package]] 59 | name = "libc" 60 | version = "0.2.4" 61 | source = "registry+https://github.com/rust-lang/crates.io-index" 62 | 63 | [[package]] 64 | name = "log" 65 | version = "0.3.5" 66 | source = "registry+https://github.com/rust-lang/crates.io-index" 67 | dependencies = [ 68 | "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", 69 | ] 70 | 71 | [[package]] 72 | name = "num" 73 | version = "0.1.29" 74 | source = "registry+https://github.com/rust-lang/crates.io-index" 75 | dependencies = [ 76 | "rand 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", 77 | "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", 78 | ] 79 | 80 | [[package]] 81 | name = "rand" 82 | version = "0.3.12" 83 | source = "registry+https://github.com/rust-lang/crates.io-index" 84 | dependencies = [ 85 | "advapi32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 86 | "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", 87 | "winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", 88 | ] 89 | 90 | [[package]] 91 | name = "rustc-serialize" 92 | version = "0.3.16" 93 | source = "registry+https://github.com/rust-lang/crates.io-index" 94 | 95 | [[package]] 96 | name = "sdl2" 97 | version = "0.12.1" 98 | source = "registry+https://github.com/rust-lang/crates.io-index" 99 | dependencies = [ 100 | "bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 101 | "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", 102 | "num 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", 103 | "rand 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", 104 | "sdl2-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 105 | ] 106 | 107 | [[package]] 108 | name = "sdl2-sys" 109 | version = "0.7.0" 110 | source = "registry+https://github.com/rust-lang/crates.io-index" 111 | dependencies = [ 112 | "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", 113 | "num 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", 114 | ] 115 | 116 | [[package]] 117 | name = "winapi" 118 | version = "0.2.5" 119 | source = "registry+https://github.com/rust-lang/crates.io-index" 120 | 121 | [[package]] 122 | name = "winapi-build" 123 | version = "0.1.1" 124 | source = "registry+https://github.com/rust-lang/crates.io-index" 125 | 126 | [[package]] 127 | name = "xml-rs" 128 | version = "0.2.2" 129 | source = "registry+https://github.com/rust-lang/crates.io-index" 130 | dependencies = [ 131 | "bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 132 | ] 133 | 134 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | 2 | [package] 3 | name = "imgui-rs" 4 | version = "1.47.0" 5 | authors = ["Rod Furlan, Lucidscape "] 6 | build = "src/build.rs" 7 | license = "MIT" 8 | repository = "https://github.com/lucidscape/imgui-rs" 9 | description = """ 10 | IMGUI-RS provides Rust bindings for IMGUI, a bloat-free intermediate mode GUI library for C/C++. 11 | 12 | IMGUI outputs vertex buffers that you can render in your 3D-pipeline enabled application. It is fast, portable, renderer agnostic and self-contained. 13 | 14 | IMGUI does away with state synchronization by requiring the application to explicitly pass all state required in real-time. The user interface only retains the minimal amount of state required to facilitate the functionality required by each type of widget supported by the system. 15 | """ 16 | 17 | [lib] 18 | name = "imgui_rs" 19 | path = "src/lib.rs" 20 | 21 | [dependencies] 22 | libc = "0.2.2" 23 | gl = "0.5.2" 24 | 25 | [dev-dependencies] 26 | sdl2 = "0.12" 27 | 28 | [build-dependencies] 29 | gcc = "0.3.20" 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | IMGUI-RS 2 | ======== 3 | 4 | IMGUI-RS provides Rust bindings for IMGUI, a bloat-free intermediate mode GUI library for C/C++. 5 | 6 | IMGUI outputs vertex buffers that you can render in your 3D-pipeline enabled application. It is fast, portable, renderer agnostic and self-contained. 7 | 8 | IMGUI does away with state synchronization by requiring the application to explicitly pass all state required in real-time. The user interface only retains the minimal amount of state required to facilitate the functionality required by each type of widget supported by the system. 9 | 10 | ```toml 11 | [dependencies] 12 | imgui-rs = { git = "https://github.com/lucidscape/imgui-rs.git" } 13 | ``` 14 | 15 | Gallery 16 | ------- 17 | 18 | ![screenshot 1](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v143/examples_04.png) 19 | ![screenshot 2](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v143/test_window_01.png) 20 | ![screenshot 3](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v143/test_window_02.png) 21 | ![screenshot 4](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v143/test_window_03.png) 22 | ![screenshot 5](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v140/test_window_05_menus.png) 23 | ![screenshot 6](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v143/skinning_sample_02.png) 24 | ![screenshot 7](https://cloud.githubusercontent.com/assets/8225057/7903336/96f0fb7c-07d0-11e5-95d6-41c6a1595e5a.png) 25 | -------------------------------------------------------------------------------- /examples/sdl_demo.rs: -------------------------------------------------------------------------------- 1 | extern crate libc; 2 | extern crate gl; 3 | extern crate sdl2; 4 | extern crate imgui_rs; 5 | 6 | use std::os; 7 | use std::ffi::CString; 8 | use sdl2::pixels::Color; 9 | use sdl2::event::Event; 10 | use sdl2::mouse::Mouse; 11 | use sdl2::keyboard::Keycode; 12 | use imgui_rs::imgui::*; 13 | use imgui_rs::renderer::Renderer; 14 | 15 | fn cstr(input:&str) -> *const i8 { 16 | CString::new(input.as_bytes()).unwrap().as_ptr() as *const i8 17 | } 18 | 19 | pub fn main() { 20 | let mut state_mouse = [0u8, 0u8, 0u8]; 21 | let mut state_wheel = 0.0; 22 | 23 | // Initialize SDL video 24 | let sdl_context = sdl2::init().unwrap(); 25 | let video_subsystem = sdl_context.video().unwrap(); 26 | 27 | // Initialize SDL window 28 | let window = video_subsystem.window("imgui-rs demo", 1280, 720) 29 | .position_centered() 30 | .opengl() 31 | .build() 32 | .unwrap(); 33 | 34 | // Load OGL function pointers 35 | gl::load_with(|name| video_subsystem.gl_get_proc_address(name) as *const os::raw::c_void); 36 | 37 | // Initialize SDL renderer 38 | let mut renderer = window.renderer().build().unwrap(); 39 | renderer.set_draw_color(Color::RGB(0, 0, 100)); 40 | renderer.clear(); 41 | renderer.present(); 42 | 43 | // Initialize imgui renderer 44 | let mut ui = Renderer::new(); 45 | 46 | // Set keyboard mapping, ImGui will use those indices to peek into the io.KeyDown[] array. 47 | unsafe { 48 | (*ui.io).KeyMap[ImGuiKey_Tab as usize] = 0; 49 | (*ui.io).KeyMap[ImGuiKey_LeftArrow as usize] = 1; 50 | (*ui.io).KeyMap[ImGuiKey_RightArrow as usize] = 2; 51 | (*ui.io).KeyMap[ImGuiKey_UpArrow as usize] = 3; 52 | (*ui.io).KeyMap[ImGuiKey_DownArrow as usize] = 4; 53 | (*ui.io).KeyMap[ImGuiKey_PageUp as usize] = 5; 54 | (*ui.io).KeyMap[ImGuiKey_PageDown as usize] = 6; 55 | (*ui.io).KeyMap[ImGuiKey_Home as usize] = 7; 56 | (*ui.io).KeyMap[ImGuiKey_End as usize] = 8; 57 | (*ui.io).KeyMap[ImGuiKey_Delete as usize] = 9; 58 | (*ui.io).KeyMap[ImGuiKey_Backspace as usize] = 10; 59 | (*ui.io).KeyMap[ImGuiKey_Enter as usize] = 11; 60 | (*ui.io).KeyMap[ImGuiKey_Escape as usize] = 12; 61 | (*ui.io).KeyMap[ImGuiKey_A as usize] = 13; 62 | (*ui.io).KeyMap[ImGuiKey_C as usize] = 14; 63 | (*ui.io).KeyMap[ImGuiKey_V as usize] = 15; 64 | (*ui.io).KeyMap[ImGuiKey_X as usize] = 16; 65 | (*ui.io).KeyMap[ImGuiKey_Y as usize] = 17; 66 | (*ui.io).KeyMap[ImGuiKey_Z as usize] = 18; 67 | } 68 | 69 | // Enter main loop 70 | let mut event_pump = sdl_context.event_pump().unwrap(); 71 | 'running: loop { 72 | // Handle incoming events 73 | for event in event_pump.poll_iter() { 74 | match event { 75 | Event::Quit {..} | Event::KeyDown { keycode: Some(Keycode::Escape), .. } => { 76 | break 'running 77 | } 78 | 79 | Event::MouseWheel { y, .. } => { 80 | if y > 0 { 81 | state_wheel = 1.0; 82 | } else if y < 0 { 83 | state_wheel = -1.0; 84 | }; 85 | } 86 | 87 | Event::MouseButtonDown { mouse_btn, .. } => { 88 | match mouse_btn { 89 | Mouse::Left => state_mouse[0] = 1, 90 | Mouse::Middle => state_mouse[1] = 1, 91 | Mouse::Right => state_mouse[2] = 1, 92 | _ => () 93 | } 94 | } 95 | 96 | Event::TextInput { text, .. } => { 97 | unsafe { 98 | let text = cstr(&text); 99 | ImGuiIO_AddInputCharactersUTF8(text); 100 | } 101 | } 102 | 103 | Event::KeyDown { keycode: Some(keycode), keymod, .. } => { 104 | unsafe { 105 | let k = keycode as i32 & !(1<<30); 106 | (*ui.io).KeysDown[k as usize] = 1; 107 | (*ui.io).KeyShift = if keymod.bits() & (0x0001 | 0x0002) > 0 { 1 } else { 0 }; 108 | (*ui.io).KeyCtrl = if keymod.bits() & (0x0040 | 0x0080) > 0 { 1 } else { 0 }; 109 | (*ui.io).KeyAlt = if keymod.bits() & (0x0100 | 0x0200) > 0 { 1 } else { 0 }; 110 | } 111 | } 112 | 113 | Event::KeyUp { keycode: Some(keycode), keymod, .. } => { 114 | unsafe { 115 | let k = keycode as i32 & !(1<<30); 116 | (*ui.io).KeysDown[k as usize] = 0; 117 | (*ui.io).KeyShift = if keymod.bits() & (0x0001 | 0x0002) > 0 { 1 } else { 0 }; 118 | (*ui.io).KeyCtrl = if keymod.bits() & (0x0040 | 0x0080) > 0 { 1 } else { 0 }; 119 | (*ui.io).KeyAlt = if keymod.bits() & (0x0100 | 0x0200) > 0 { 1 } else { 0 }; 120 | } 121 | } 122 | 123 | _ => () 124 | } 125 | } 126 | 127 | unsafe { 128 | // Clear the frame buffer 129 | renderer.set_draw_color(Color::RGB(0, 0, 100)); 130 | renderer.clear(); 131 | 132 | // Pass mouse state to ImGui 133 | (*ui.io).MouseDown[0] = state_mouse[0]; 134 | (*ui.io).MouseDown[1] = state_mouse[1]; 135 | (*ui.io).MouseDown[2] = state_mouse[2]; 136 | (*ui.io).MouseWheel = state_wheel; 137 | state_mouse[0] = 0; 138 | state_mouse[1] = 0; 139 | state_mouse[2] = 0; 140 | state_wheel = 0.0; 141 | 142 | // Update ImGui 143 | let (w, h) = renderer.window().expect("window").size(); 144 | let (_, x, y) = sdl_context.mouse().mouse_state(); 145 | ui.begin_frame(w as f32, h as f32, x as f32, y as f32, 1.0 / 60.0); 146 | 147 | // Assemble a test window containing several test widgets 148 | igShowTestWindow(&mut 1); 149 | 150 | // Render IMGUI frame 151 | ui.end_frame(); 152 | 153 | // Swap buffers 154 | renderer.present(); 155 | } 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /imgui.ini: -------------------------------------------------------------------------------- 1 | [Debug] 2 | Pos=60,60 3 | Size=400,400 4 | Collapsed=0 5 | 6 | [ImGui Demo] 7 | Pos=103,12 8 | Size=550,680 9 | Collapsed=0 10 | 11 | -------------------------------------------------------------------------------- /src/build.rs: -------------------------------------------------------------------------------- 1 | extern crate gcc; 2 | 3 | fn main() { 4 | gcc::Config::new() 5 | .cpp(true) 6 | .include("src/cimgui/imgui/") 7 | .file("src/cimgui/imgui/imgui.cpp") 8 | .file("src/cimgui/imgui/imgui_draw.cpp") 9 | .file("src/cimgui/imgui/imgui_demo.cpp") 10 | .compile("libimgui.a"); 11 | 12 | gcc::Config::new() 13 | .file("src/cimgui/cimgui/cimgui.cpp") 14 | .file("src/cimgui/cimgui/fontAtlas.cpp") 15 | .file("src/cimgui/cimgui/drawList.cpp") 16 | .compile("libcimgui.a"); 17 | } 18 | -------------------------------------------------------------------------------- /src/imgui.rs: -------------------------------------------------------------------------------- 1 | #![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)] 2 | use libc::{c_void, c_char, c_int, c_uint, c_ushort, c_float, c_uchar, c_long, size_t}; 3 | use std::mem; 4 | 5 | pub type ptrdiff_t = c_long; 6 | pub type ImU32 = c_uint; 7 | pub type ImWchar = c_ushort; 8 | pub type ImTextureID = *mut c_void; 9 | pub type ImGuiID = ImU32; 10 | pub type ImGuiCol = c_int; 11 | pub type ImGuiStyleVar = c_int; 12 | pub type ImGuiKey = c_int; 13 | pub type ImGuiAlign = c_int; 14 | pub type ImGuiColorEditMode = c_int; 15 | pub type ImGuiMouseCursor = c_int; 16 | pub type ImGuiWindowFlags = c_int; 17 | pub type ImGuiSetCond = c_int; 18 | pub type ImGuiInputTextFlags = c_int; 19 | pub type ImGuiSelectableFlags = c_int; 20 | pub type ImGuiTextEditCallback = Option c_int>; 21 | 22 | pub type Enum_ImGuiWindowFlags_ = c_uint; 23 | pub const ImGuiWindowFlags_NoTitleBar: c_uint = 1; 24 | pub const ImGuiWindowFlags_NoResize: c_uint = 2; 25 | pub const ImGuiWindowFlags_NoMove: c_uint = 4; 26 | pub const ImGuiWindowFlags_NoScrollbar: c_uint = 8; 27 | pub const ImGuiWindowFlags_NoScrollWithMouse: c_uint = 16; 28 | pub const ImGuiWindowFlags_NoCollapse: c_uint = 32; 29 | pub const ImGuiWindowFlags_AlwaysAutoResize: c_uint = 64; 30 | pub const ImGuiWindowFlags_ShowBorders: c_uint = 128; 31 | pub const ImGuiWindowFlags_NoSavedSettings: c_uint = 256; 32 | pub const ImGuiWindowFlags_NoInputs: c_uint = 512; 33 | pub const ImGuiWindowFlags_MenuBar: c_uint = 1024; 34 | pub const ImGuiWindowFlags_HorizontalScrollbar: c_uint = 2048; 35 | pub const ImGuiWindowFlags_NoFocusOnAppearing: c_uint = 4096; 36 | pub const ImGuiWindowFlags_NoBringToFrontOnFocus: c_uint = 8192; 37 | pub const ImGuiWindowFlags_ChildWindow: c_uint = 1048576; 38 | pub const ImGuiWindowFlags_ChildWindowAutoFitX: c_uint = 2097152; 39 | pub const ImGuiWindowFlags_ChildWindowAutoFitY: c_uint = 4194304; 40 | pub const ImGuiWindowFlags_ComboBox: c_uint = 8388608; 41 | pub const ImGuiWindowFlags_Tooltip: c_uint = 16777216; 42 | pub const ImGuiWindowFlags_Popup: c_uint = 33554432; 43 | pub const ImGuiWindowFlags_Modal: c_uint = 67108864; 44 | pub const ImGuiWindowFlags_ChildMenu: c_uint = 134217728; 45 | 46 | pub type Enum_ImGuiInputTextFlags_ = c_uint; 47 | pub const ImGuiInputTextFlags_CharsDecimal: c_uint = 1; 48 | pub const ImGuiInputTextFlags_CharsHexadecimal: c_uint = 2; 49 | pub const ImGuiInputTextFlags_CharsUppercase: c_uint = 4; 50 | pub const ImGuiInputTextFlags_CharsNoBlank: c_uint = 8; 51 | pub const ImGuiInputTextFlags_AutoSelectAll: c_uint = 16; 52 | pub const ImGuiInputTextFlags_EnterReturnsTrue: c_uint = 32; 53 | pub const ImGuiInputTextFlags_CallbackCompletion: c_uint = 64; 54 | pub const ImGuiInputTextFlags_CallbackHistory: c_uint = 128; 55 | pub const ImGuiInputTextFlags_CallbackAlways: c_uint = 256; 56 | pub const ImGuiInputTextFlags_CallbackCharFilter: c_uint = 512; 57 | pub const ImGuiInputTextFlags_AllowTabInput: c_uint = 1024; 58 | pub const ImGuiInputTextFlags_CtrlEnterForNewLine: c_uint = 2048; 59 | pub const ImGuiInputTextFlags_NoHorizontalScroll: c_uint = 4096; 60 | pub const ImGuiInputTextFlags_AlwaysInsertMode: c_uint = 8192; 61 | pub const ImGuiInputTextFlags_ReadOnly: c_uint = 16384; 62 | pub const ImGuiInputTextFlags_Password: c_uint = 32768; 63 | pub const ImGuiInputTextFlags_Multiline: c_uint = 1048576; 64 | 65 | pub type Enum_ImGuiSelectableFlags_ = c_uint; 66 | pub const ImGuiSelectableFlags_DontClosePopups: c_uint = 1; 67 | pub const ImGuiSelectableFlags_SpanAllColumns: c_uint = 2; 68 | 69 | pub type Enum_ImGuiKey_ = c_uint; 70 | pub const ImGuiKey_Tab: c_uint = 0; 71 | pub const ImGuiKey_LeftArrow: c_uint = 1; 72 | pub const ImGuiKey_RightArrow: c_uint = 2; 73 | pub const ImGuiKey_UpArrow: c_uint = 3; 74 | pub const ImGuiKey_DownArrow: c_uint = 4; 75 | pub const ImGuiKey_PageUp: c_uint = 5; 76 | pub const ImGuiKey_PageDown: c_uint = 6; 77 | pub const ImGuiKey_Home: c_uint = 7; 78 | pub const ImGuiKey_End: c_uint = 8; 79 | pub const ImGuiKey_Delete: c_uint = 9; 80 | pub const ImGuiKey_Backspace: c_uint = 10; 81 | pub const ImGuiKey_Enter: c_uint = 11; 82 | pub const ImGuiKey_Escape: c_uint = 12; 83 | pub const ImGuiKey_A: c_uint = 13; 84 | pub const ImGuiKey_C: c_uint = 14; 85 | pub const ImGuiKey_V: c_uint = 15; 86 | pub const ImGuiKey_X: c_uint = 16; 87 | pub const ImGuiKey_Y: c_uint = 17; 88 | pub const ImGuiKey_Z: c_uint = 18; 89 | pub const ImGuiKey_COUNT: c_uint = 19; 90 | 91 | pub type Enum_ImGuiCol_ = c_uint; 92 | pub const ImGuiCol_Text: c_uint = 0; 93 | pub const ImGuiCol_TextDisabled: c_uint = 1; 94 | pub const ImGuiCol_WindowBg: c_uint = 2; 95 | pub const ImGuiCol_ChildWindowBg: c_uint = 3; 96 | pub const ImGuiCol_Border: c_uint = 4; 97 | pub const ImGuiCol_BorderShadow: c_uint = 5; 98 | pub const ImGuiCol_FrameBg: c_uint = 6; 99 | pub const ImGuiCol_FrameBgHovered: c_uint = 7; 100 | pub const ImGuiCol_FrameBgActive: c_uint = 8; 101 | pub const ImGuiCol_TitleBg: c_uint = 9; 102 | pub const ImGuiCol_TitleBgCollapsed: c_uint = 10; 103 | pub const ImGuiCol_TitleBgActive: c_uint = 11; 104 | pub const ImGuiCol_MenuBarBg: c_uint = 12; 105 | pub const ImGuiCol_ScrollbarBg: c_uint = 13; 106 | pub const ImGuiCol_ScrollbarGrab: c_uint = 14; 107 | pub const ImGuiCol_ScrollbarGrabHovered: c_uint = 15; 108 | pub const ImGuiCol_ScrollbarGrabActive: c_uint = 16; 109 | pub const ImGuiCol_ComboBg: c_uint = 17; 110 | pub const ImGuiCol_CheckMark: c_uint = 18; 111 | pub const ImGuiCol_SliderGrab: c_uint = 19; 112 | pub const ImGuiCol_SliderGrabActive: c_uint = 20; 113 | pub const ImGuiCol_Button: c_uint = 21; 114 | pub const ImGuiCol_ButtonHovered: c_uint = 22; 115 | pub const ImGuiCol_ButtonActive: c_uint = 23; 116 | pub const ImGuiCol_Header: c_uint = 24; 117 | pub const ImGuiCol_HeaderHovered: c_uint = 25; 118 | pub const ImGuiCol_HeaderActive: c_uint = 26; 119 | pub const ImGuiCol_Column: c_uint = 27; 120 | pub const ImGuiCol_ColumnHovered: c_uint = 28; 121 | pub const ImGuiCol_ColumnActive: c_uint = 29; 122 | pub const ImGuiCol_ResizeGrip: c_uint = 30; 123 | pub const ImGuiCol_ResizeGripHovered: c_uint = 31; 124 | pub const ImGuiCol_ResizeGripActive: c_uint = 32; 125 | pub const ImGuiCol_CloseButton: c_uint = 33; 126 | pub const ImGuiCol_CloseButtonHovered: c_uint = 34; 127 | pub const ImGuiCol_CloseButtonActive: c_uint = 35; 128 | pub const ImGuiCol_PlotLines: c_uint = 36; 129 | pub const ImGuiCol_PlotLinesHovered: c_uint = 37; 130 | pub const ImGuiCol_PlotHistogram: c_uint = 38; 131 | pub const ImGuiCol_PlotHistogramHovered: c_uint = 39; 132 | pub const ImGuiCol_TextSelectedBg: c_uint = 40; 133 | pub const ImGuiCol_TooltipBg: c_uint = 41; 134 | pub const ImGuiCol_ModalWindowDarkening: c_uint = 42; 135 | pub const ImGuiCol_COUNT: c_uint = 43; 136 | 137 | pub type Enum_ImGuiStyleVar_ = c_uint; 138 | pub const ImGuiStyleVar_Alpha: c_uint = 0; 139 | pub const ImGuiStyleVar_WindowPadding: c_uint = 1; 140 | pub const ImGuiStyleVar_WindowRounding: c_uint = 2; 141 | pub const ImGuiStyleVar_WindowMinSize: c_uint = 3; 142 | pub const ImGuiStyleVar_ChildWindowRounding: c_uint = 4; 143 | pub const ImGuiStyleVar_FramePadding: c_uint = 5; 144 | pub const ImGuiStyleVar_FrameRounding: c_uint = 6; 145 | pub const ImGuiStyleVar_ItemSpacing: c_uint = 7; 146 | pub const ImGuiStyleVar_ItemInnerSpacing: c_uint = 8; 147 | pub const ImGuiStyleVar_IndentSpacing: c_uint = 9; 148 | pub const ImGuiStyleVar_GrabMinSize: c_uint = 10; 149 | 150 | pub type Enum_ImGuiAlign_ = c_uint; 151 | pub const ImGuiAlign_Left: c_uint = 1; 152 | pub const ImGuiAlign_Center: c_uint = 2; 153 | pub const ImGuiAlign_Right: c_uint = 4; 154 | pub const ImGuiAlign_Top: c_uint = 8; 155 | pub const ImGuiAlign_VCenter: c_uint = 16; 156 | pub const ImGuiAlign_Default: c_uint = 9; 157 | 158 | pub type Enum_ImGuiColorEditMode_ = c_int; 159 | pub const ImGuiColorEditMode_UserSelect: c_int = -2; 160 | pub const ImGuiColorEditMode_UserSelectShowButton: c_int = -1; 161 | pub const ImGuiColorEditMode_RGB: c_int = 0; 162 | pub const ImGuiColorEditMode_HSV: c_int = 1; 163 | pub const ImGuiColorEditMode_HEX: c_int = 2; 164 | 165 | pub type Enum_ImGuiMouseCursor_ = c_uint; 166 | pub const ImGuiMouseCursor_Arrow: c_uint = 0; 167 | pub const ImGuiMouseCursor_TextInput: c_uint = 1; 168 | pub const ImGuiMouseCursor_Move: c_uint = 2; 169 | pub const ImGuiMouseCursor_ResizeNS: c_uint = 3; 170 | pub const ImGuiMouseCursor_ResizeEW: c_uint = 4; 171 | pub const ImGuiMouseCursor_ResizeNESW: c_uint = 5; 172 | pub const ImGuiMouseCursor_ResizeNWSE: c_uint = 6; 173 | pub const ImGuiMouseCursor_Count_: c_uint = 7; 174 | 175 | pub type Enum_ImGuiSetCond_ = c_uint; 176 | pub const ImGuiSetCond_Always: c_uint = 1; 177 | pub const ImGuiSetCond_Once: c_uint = 2; 178 | pub const ImGuiSetCond_FirstUseEver: c_uint = 4; 179 | pub const ImGuiSetCond_Appearing: c_uint = 8; 180 | 181 | #[repr(C)] 182 | #[derive(Copy)] 183 | pub struct ImVector { 184 | pub Size: c_int, 185 | pub Capacity: c_int, 186 | pub Data: *mut T, 187 | } 188 | impl Clone for ImVector { 189 | fn clone(&self) -> Self { 190 | panic!("TODO") 191 | } 192 | } 193 | impl Default for ImVector { 194 | fn default() -> Self { 195 | unsafe { mem::zeroed() } 196 | } 197 | } 198 | 199 | #[repr(C)] 200 | #[derive(Copy)] 201 | pub struct ImVec2 { 202 | pub x: c_float, 203 | pub y: c_float, 204 | } 205 | impl Clone for ImVec2 { 206 | fn clone(&self) -> Self { 207 | *self 208 | } 209 | } 210 | impl Default for ImVec2 { 211 | fn default() -> Self { 212 | unsafe { mem::zeroed() } 213 | } 214 | } 215 | 216 | #[repr(C)] 217 | #[derive(Copy)] 218 | pub struct ImVec4 { 219 | pub x: c_float, 220 | pub y: c_float, 221 | pub z: c_float, 222 | pub w: c_float, 223 | } 224 | impl Clone for ImVec4 { 225 | fn clone(&self) -> Self { 226 | *self 227 | } 228 | } 229 | impl Default for ImVec4 { 230 | fn default() -> Self { 231 | unsafe { mem::zeroed() } 232 | } 233 | } 234 | 235 | #[repr(C)] 236 | #[derive(Copy)] 237 | pub struct ImGuiStyle { 238 | pub Alpha: c_float, 239 | pub WindowPadding: ImVec2, 240 | pub WindowMinSize: ImVec2, 241 | pub WindowRounding: c_float, 242 | pub WindowTitleAlign: ImGuiAlign, 243 | pub ChildWindowRounding: c_float, 244 | pub FramePadding: ImVec2, 245 | pub FrameRounding: c_float, 246 | pub ItemSpacing: ImVec2, 247 | pub ItemInnerSpacing: ImVec2, 248 | pub TouchExtraPadding: ImVec2, 249 | pub WindowFillAlphaDefault: c_float, 250 | pub IndentSpacing: c_float, 251 | pub ColumnsMinSpacing: c_float, 252 | pub ScrollbarSize: c_float, 253 | pub ScrollbarRounding: c_float, 254 | pub GrabMinSize: c_float, 255 | pub GrabRounding: c_float, 256 | pub DisplayWindowPadding: ImVec2, 257 | pub DisplaySafeAreaPadding: ImVec2, 258 | pub AntiAliasedLines: u8, 259 | pub AntiAliasedShapes: u8, 260 | pub CurveTessellationTol: c_float, 261 | pub Colors: [ImVec4; 43usize], 262 | } 263 | impl Clone for ImGuiStyle { 264 | fn clone(&self) -> Self { 265 | *self 266 | } 267 | } 268 | impl Default for ImGuiStyle { 269 | fn default() -> Self { 270 | unsafe { mem::zeroed() } 271 | } 272 | } 273 | 274 | #[repr(C)] 275 | #[derive(Copy)] 276 | pub struct ImGuiIO { 277 | pub DisplaySize: ImVec2, 278 | pub DeltaTime: c_float, 279 | pub IniSavingRate: c_float, 280 | pub IniFilename: *const c_char, 281 | pub LogFilename: *const c_char, 282 | pub MouseDoubleClickTime: c_float, 283 | pub MouseDoubleClickMaxDist: c_float, 284 | pub MouseDragThreshold: c_float, 285 | pub KeyMap: [c_int; 19usize], 286 | pub KeyRepeatDelay: c_float, 287 | pub KeyRepeatRate: c_float, 288 | pub UserData: *mut c_void, 289 | pub Fonts: *mut ImFontAtlas, 290 | pub FontGlobalScale: c_float, 291 | pub FontAllowUserScaling: u8, 292 | pub DisplayFramebufferScale: ImVec2, 293 | pub DisplayVisibleMin: ImVec2, 294 | pub DisplayVisibleMax: ImVec2, 295 | pub RenderDrawListsFn: Option ()>, 296 | pub GetClipboardTextFn: Option *const c_char>, 297 | pub SetClipboardTextFn: Option ()>, 298 | pub MemAllocFn: Option *mut c_void>, 299 | pub MemFreeFn: Option ()>, 300 | pub ImeSetInputScreenPosFn: Option ()>, 301 | pub ImeWindowHandle: *mut c_void, 302 | pub MousePos: ImVec2, 303 | pub MouseDown: [u8; 5usize], 304 | pub MouseWheel: c_float, 305 | pub MouseDrawCursor: u8, 306 | pub KeyCtrl: u8, 307 | pub KeyShift: u8, 308 | pub KeyAlt: u8, 309 | pub KeysDown: [u8; 512usize], 310 | pub InputCharacters: [ImWchar; 17usize], 311 | pub WantCaptureMouse: u8, 312 | pub WantCaptureKeyboard: u8, 313 | pub WantTextInput: u8, 314 | pub Framerate: c_float, 315 | pub MetricsAllocs: c_int, 316 | pub MetricsRenderVertices: c_int, 317 | pub MetricsRenderIndices: c_int, 318 | pub MetricsActiveWindows: c_int, 319 | pub MousePosPrev: ImVec2, 320 | pub MouseDelta: ImVec2, 321 | pub MouseClicked: [u8; 5usize], 322 | pub MouseClickedPos: [ImVec2; 5usize], 323 | pub MouseClickedTime: [c_float; 5usize], 324 | pub MouseDoubleClicked: [u8; 5usize], 325 | pub MouseReleased: [u8; 5usize], 326 | pub MouseDownOwned: [u8; 5usize], 327 | pub MouseDownDuration: [c_float; 5usize], 328 | pub MouseDownDurationPrev: [c_float; 5usize], 329 | pub MouseDragMaxDistanceSqr: [c_float; 5usize], 330 | pub KeysDownDuration: [c_float; 512usize], 331 | pub KeysDownDurationPrev: [c_float; 512usize], 332 | } 333 | impl Clone for ImGuiIO { 334 | fn clone(&self) -> Self { 335 | *self 336 | } 337 | } 338 | impl Default for ImGuiIO { 339 | fn default() -> Self { 340 | unsafe { mem::zeroed() } 341 | } 342 | } 343 | 344 | #[repr(C)] 345 | #[derive(Copy)] 346 | pub struct ImGuiOnceUponAFrame { 347 | pub RefFrame: c_int, 348 | } 349 | impl Clone for ImGuiOnceUponAFrame { 350 | fn clone(&self) -> Self { 351 | *self 352 | } 353 | } 354 | impl Default for ImGuiOnceUponAFrame { 355 | fn default() -> Self { 356 | unsafe { mem::zeroed() } 357 | } 358 | } 359 | 360 | #[repr(C)] 361 | #[derive(Copy)] 362 | pub struct ImGuiTextFilter { 363 | pub InputBuf: [c_char; 256usize], 364 | pub Filters: ImVector, 365 | pub CountGrep: c_int, 366 | } 367 | impl Clone for ImGuiTextFilter { 368 | fn clone(&self) -> Self { 369 | *self 370 | } 371 | } 372 | impl Default for ImGuiTextFilter { 373 | fn default() -> Self { 374 | unsafe { mem::zeroed() } 375 | } 376 | } 377 | 378 | #[repr(C)] 379 | #[derive(Copy)] 380 | pub struct Struct_TextRange { 381 | pub b: *const c_char, 382 | pub e: *const c_char, 383 | } 384 | impl Clone for Struct_TextRange { 385 | fn clone(&self) -> Self { 386 | *self 387 | } 388 | } 389 | impl Default for Struct_TextRange { 390 | fn default() -> Self { 391 | unsafe { mem::zeroed() } 392 | } 393 | } 394 | 395 | #[repr(C)] 396 | #[derive(Copy)] 397 | pub struct ImGuiTextBuffer { 398 | pub Buf: ImVector, 399 | } 400 | impl Clone for ImGuiTextBuffer { 401 | fn clone(&self) -> Self { 402 | *self 403 | } 404 | } 405 | impl Default for ImGuiTextBuffer { 406 | fn default() -> Self { 407 | unsafe { mem::zeroed() } 408 | } 409 | } 410 | 411 | #[repr(C)] 412 | #[derive(Copy)] 413 | pub struct ImGuiStorage { 414 | pub Data: ImVector, 415 | } 416 | impl Clone for ImGuiStorage { 417 | fn clone(&self) -> Self { 418 | *self 419 | } 420 | } 421 | impl Default for ImGuiStorage { 422 | fn default() -> Self { 423 | unsafe { mem::zeroed() } 424 | } 425 | } 426 | 427 | #[repr(C)] 428 | #[derive(Copy)] 429 | pub struct Struct_Pair { 430 | pub key: ImGuiID, 431 | pub _bindgen_data_1_: [u64; 1usize], 432 | } 433 | impl Struct_Pair { 434 | pub unsafe fn val_i(&mut self) -> *mut c_int { 435 | let raw: *mut u8 = mem::transmute(&self._bindgen_data_1_); 436 | mem::transmute(raw.offset(0)) 437 | } 438 | pub unsafe fn val_f(&mut self) -> *mut c_float { 439 | let raw: *mut u8 = mem::transmute(&self._bindgen_data_1_); 440 | mem::transmute(raw.offset(0)) 441 | } 442 | pub unsafe fn val_p(&mut self) -> *mut *mut c_void { 443 | let raw: *mut u8 = mem::transmute(&self._bindgen_data_1_); 444 | mem::transmute(raw.offset(0)) 445 | } 446 | } 447 | impl Clone for Struct_Pair { 448 | fn clone(&self) -> Self { 449 | *self 450 | } 451 | } 452 | impl Default for Struct_Pair { 453 | fn default() -> Self { 454 | unsafe { mem::zeroed() } 455 | } 456 | } 457 | 458 | #[repr(C)] 459 | #[derive(Copy)] 460 | pub struct ImGuiTextEditCallbackData { 461 | pub EventFlag: ImGuiInputTextFlags, 462 | pub Flags: ImGuiInputTextFlags, 463 | pub UserData: *mut c_void, 464 | pub ReadOnly: u8, 465 | pub EventChar: ImWchar, 466 | pub EventKey: ImGuiKey, 467 | pub Buf: *mut c_char, 468 | pub BufSize: c_int, 469 | pub BufDirty: u8, 470 | pub CursorPos: c_int, 471 | pub SelectionStart: c_int, 472 | pub SelectionEnd: c_int, 473 | } 474 | impl Clone for ImGuiTextEditCallbackData { 475 | fn clone(&self) -> Self { 476 | *self 477 | } 478 | } 479 | impl Default for ImGuiTextEditCallbackData { 480 | fn default() -> Self { 481 | unsafe { mem::zeroed() } 482 | } 483 | } 484 | 485 | #[repr(C)] 486 | #[derive(Copy)] 487 | pub struct ImColor { 488 | pub Value: ImVec4, 489 | } 490 | impl Clone for ImColor { 491 | fn clone(&self) -> Self { 492 | *self 493 | } 494 | } 495 | impl Default for ImColor { 496 | fn default() -> Self { 497 | unsafe { mem::zeroed() } 498 | } 499 | } 500 | 501 | #[repr(C)] 502 | #[derive(Copy)] 503 | pub struct ImGuiListClipper { 504 | pub ItemsHeight: c_float, 505 | pub ItemsCount: c_int, 506 | pub DisplayStart: c_int, 507 | pub DisplayEnd: c_int, 508 | } 509 | impl Clone for ImGuiListClipper { 510 | fn clone(&self) -> Self { 511 | *self 512 | } 513 | } 514 | impl Default for ImGuiListClipper { 515 | fn default() -> Self { 516 | unsafe { mem::zeroed() } 517 | } 518 | } 519 | 520 | pub type ImDrawCallback = Option ()>; 521 | 522 | #[repr(C)] 523 | #[derive(Copy)] 524 | pub struct ImDrawCmd { 525 | pub ElemCount: c_uint, 526 | pub ClipRect: ImVec4, 527 | pub TextureId: ImTextureID, 528 | pub UserCallback: ImDrawCallback, 529 | pub UserCallbackData: *mut c_void, 530 | } 531 | impl Clone for ImDrawCmd { 532 | fn clone(&self) -> Self { 533 | *self 534 | } 535 | } 536 | impl Default for ImDrawCmd { 537 | fn default() -> Self { 538 | unsafe { mem::zeroed() } 539 | } 540 | } 541 | 542 | pub type ImDrawIdx = c_ushort; 543 | 544 | #[repr(C)] 545 | #[derive(Copy)] 546 | pub struct ImDrawVert { 547 | pub pos: ImVec2, 548 | pub uv: ImVec2, 549 | pub col: ImU32, 550 | } 551 | impl Clone for ImDrawVert { 552 | fn clone(&self) -> Self { 553 | *self 554 | } 555 | } 556 | impl Default for ImDrawVert { 557 | fn default() -> Self { 558 | unsafe { mem::zeroed() } 559 | } 560 | } 561 | 562 | #[repr(C)] 563 | #[derive(Copy)] 564 | pub struct ImDrawChannel { 565 | pub CmdBuffer: ImVector, 566 | pub IdxBuffer: ImVector, 567 | } 568 | impl Clone for ImDrawChannel { 569 | fn clone(&self) -> Self { 570 | *self 571 | } 572 | } 573 | impl Default for ImDrawChannel { 574 | fn default() -> Self { 575 | unsafe { mem::zeroed() } 576 | } 577 | } 578 | 579 | #[repr(C)] 580 | #[derive(Copy)] 581 | pub struct ImDrawList { 582 | pub CmdBuffer: ImVector, 583 | pub IdxBuffer: ImVector, 584 | pub VtxBuffer: ImVector, 585 | pub _OwnerName: *const c_char, 586 | pub _VtxCurrentIdx: c_uint, 587 | pub _VtxWritePtr: *mut ImDrawVert, 588 | pub _IdxWritePtr: *mut ImDrawIdx, 589 | pub _ClipRectStack: ImVector, 590 | pub _TextureIdStack: ImVector, 591 | pub _Path: ImVector, 592 | pub _ChannelsCurrent: c_int, 593 | pub _ChannelsCount: c_int, 594 | pub _Channels: ImVector, 595 | } 596 | impl Clone for ImDrawList { 597 | fn clone(&self) -> Self { 598 | *self 599 | } 600 | } 601 | impl Default for ImDrawList { 602 | fn default() -> Self { 603 | unsafe { mem::zeroed() } 604 | } 605 | } 606 | 607 | #[repr(C)] 608 | #[derive(Copy)] 609 | pub struct ImDrawData { 610 | pub Valid: u8, 611 | pub CmdLists: *mut *mut ImDrawList, 612 | pub CmdListsCount: c_int, 613 | pub TotalVtxCount: c_int, 614 | pub TotalIdxCount: c_int, 615 | } 616 | impl Clone for ImDrawData { 617 | fn clone(&self) -> Self { 618 | *self 619 | } 620 | } 621 | impl Default for ImDrawData { 622 | fn default() -> Self { 623 | unsafe { mem::zeroed() } 624 | } 625 | } 626 | 627 | #[repr(C)] 628 | #[derive(Copy)] 629 | pub struct ImFontConfig { 630 | pub FontData: *mut c_void, 631 | pub FontDataSize: c_int, 632 | pub FontDataOwnedByAtlas: u8, 633 | pub FontNo: c_int, 634 | pub SizePixels: c_float, 635 | pub OversampleH: c_int, 636 | pub OversampleV: c_int, 637 | pub PixelSnapH: u8, 638 | pub GlyphExtraSpacing: ImVec2, 639 | pub GlyphRanges: *const ImWchar, 640 | pub MergeMode: u8, 641 | pub MergeGlyphCenterV: u8, 642 | pub Name: [c_char; 32usize], 643 | pub DstFont: *mut ImFont, 644 | } 645 | impl Clone for ImFontConfig { 646 | fn clone(&self) -> Self { 647 | *self 648 | } 649 | } 650 | impl Default for ImFontConfig { 651 | fn default() -> Self { 652 | unsafe { mem::zeroed() } 653 | } 654 | } 655 | 656 | #[repr(C)] 657 | #[derive(Copy)] 658 | pub struct ImFontAtlas { 659 | pub TexID: *mut c_void, 660 | pub TexPixelsAlpha8: *mut c_uchar, 661 | pub TexPixelsRGBA32: *mut c_uint, 662 | pub TexWidth: c_int, 663 | pub TexHeight: c_int, 664 | pub TexDesiredWidth: c_int, 665 | pub TexUvWhitePixel: ImVec2, 666 | pub Fonts: ImVector<*const ImFont>, 667 | pub ConfigData: ImVector, 668 | } 669 | impl Clone for ImFontAtlas { 670 | fn clone(&self) -> Self { 671 | *self 672 | } 673 | } 674 | impl Default for ImFontAtlas { 675 | fn default() -> Self { 676 | unsafe { mem::zeroed() } 677 | } 678 | } 679 | 680 | #[repr(C)] 681 | #[derive(Copy)] 682 | pub struct ImFont { 683 | pub FontSize: c_float, 684 | pub Scale: c_float, 685 | pub DisplayOffset: ImVec2, 686 | pub FallbackChar: ImWchar, 687 | pub ConfigData: *mut ImFontConfig, 688 | pub ConfigDataCount: c_int, 689 | pub Ascent: c_float, 690 | pub Descent: c_float, 691 | pub ContainerAtlas: *mut ImFontAtlas, 692 | pub Glyphs: ImVector, 693 | pub FallbackGlyph: *const Struct_Glyph, 694 | pub FallbackXAdvance: c_float, 695 | pub IndexXAdvance: ImVector, 696 | pub IndexLookup: ImVector, 697 | } 698 | impl Clone for ImFont { 699 | fn clone(&self) -> Self { 700 | *self 701 | } 702 | } 703 | impl Default for ImFont { 704 | fn default() -> Self { 705 | unsafe { mem::zeroed() } 706 | } 707 | } 708 | 709 | #[repr(C)] 710 | #[derive(Copy)] 711 | pub struct Struct_Glyph { 712 | pub Codepoint: ImWchar, 713 | pub XAdvance: c_float, 714 | pub X0: c_float, 715 | pub Y0: c_float, 716 | pub X1: c_float, 717 | pub Y1: c_float, 718 | pub U0: c_float, 719 | pub V0: c_float, 720 | pub U1: c_float, 721 | pub V1: c_float, 722 | } 723 | impl Clone for Struct_Glyph { 724 | fn clone(&self) -> Self { 725 | *self 726 | } 727 | } 728 | impl Default for Struct_Glyph { 729 | fn default() -> Self { 730 | unsafe { mem::zeroed() } 731 | } 732 | } 733 | 734 | #[link(name = "imgui")] 735 | extern "C" { 736 | pub fn igGetIO() -> *mut ImGuiIO; 737 | pub fn igGetStyle() -> *mut ImGuiStyle; 738 | pub fn igGetDrawData() -> *mut ImDrawData; 739 | pub fn igNewFrame() -> (); 740 | pub fn igRender() -> (); 741 | pub fn igShutdown() -> (); 742 | pub fn igShowUserGuide() -> (); 743 | pub fn igShowStyleEditor(_ref: *mut ImGuiStyle) -> (); 744 | pub fn igShowTestWindow(opened: *mut u8) -> (); 745 | pub fn igShowMetricsWindow(opened: *mut u8) -> (); 746 | pub fn igBegin(name: *const c_char, p_opened: *mut u8, flags: ImGuiWindowFlags) -> u8; 747 | pub fn igBegin2(name: *const c_char, p_opened: *mut u8, size_on_first_use: ImVec2, bg_alpha: c_float, flags: ImGuiWindowFlags) -> u8; 748 | pub fn igEnd() -> (); 749 | pub fn igBeginChild(str_id: *const c_char, size: ImVec2, border: u8, extra_flags: ImGuiWindowFlags) -> u8; 750 | pub fn igBeginChildEx(id: ImGuiID, size: ImVec2, border: u8, extra_flags: ImGuiWindowFlags) -> u8; 751 | pub fn igEndChild() -> (); 752 | pub fn igGetContentRegionMax(out: *mut ImVec2) -> (); 753 | pub fn igGetContentRegionAvail(out: *mut ImVec2) -> (); 754 | pub fn igGetContentRegionAvailWidth() -> c_float; 755 | pub fn igGetWindowContentRegionMin(out: *mut ImVec2) -> (); 756 | pub fn igGetWindowContentRegionMax(out: *mut ImVec2) -> (); 757 | pub fn igGetWindowContentRegionWidth() -> c_float; 758 | pub fn igGetWindowDrawList() -> *mut ImDrawList; 759 | pub fn igGetWindowFont() -> *mut ImFont; 760 | pub fn igGetWindowFontSize() -> c_float; 761 | pub fn igSetWindowFontScale(scale: c_float) -> (); 762 | pub fn igGetWindowPos(out: *mut ImVec2) -> (); 763 | pub fn igGetWindowSize(out: *mut ImVec2) -> (); 764 | pub fn igGetWindowWidth() -> c_float; 765 | pub fn igGetWindowHeight() -> c_float; 766 | pub fn igIsWindowCollapsed() -> u8; 767 | pub fn igSetNextWindowPos(pos: ImVec2, cond: ImGuiSetCond) -> (); 768 | pub fn igSetNextWindowPosCenter(cond: ImGuiSetCond) -> (); 769 | pub fn igSetNextWindowSize(size: ImVec2, cond: ImGuiSetCond) -> (); 770 | pub fn igSetNextWindowContentSize(size: ImVec2) -> (); 771 | pub fn igSetNextWindowContentWidth(width: c_float) -> (); 772 | pub fn igSetNextWindowCollapsed(collapsed: u8, cond: ImGuiSetCond) -> (); 773 | pub fn igSetNextWindowFocus() -> (); 774 | pub fn igSetWindowPos(pos: ImVec2, cond: ImGuiSetCond) -> (); 775 | pub fn igSetWindowSize(size: ImVec2, cond: ImGuiSetCond) -> (); 776 | pub fn igSetWindowCollapsed(collapsed: u8, cond: ImGuiSetCond) -> (); 777 | pub fn igSetWindowFocus() -> (); 778 | pub fn igSetWindowPosByName(name: *const c_char, pos: ImVec2, cond: ImGuiSetCond) -> (); 779 | pub fn igSetWindowSize2(name: *const c_char, size: ImVec2, cond: ImGuiSetCond) -> (); 780 | pub fn igSetWindowCollapsed2(name: *const c_char, collapsed: u8, cond: ImGuiSetCond) -> (); 781 | pub fn igSetWindowFocus2(name: *const c_char) -> (); 782 | pub fn igGetScrollX() -> c_float; 783 | pub fn igGetScrollY() -> c_float; 784 | pub fn igGetScrollMaxX() -> c_float; 785 | pub fn igGetScrollMaxY() -> c_float; 786 | pub fn igSetScrollX(scroll_x: c_float) -> (); 787 | pub fn igSetScrollY(scroll_y: c_float) -> (); 788 | pub fn igSetScrollHere(center_y_ratio: c_float) -> (); 789 | pub fn igSetScrollFromPosY(pos_y: c_float, center_y_ratio: c_float) -> (); 790 | pub fn igSetKeyboardFocusHere(offset: c_int) -> (); 791 | pub fn igSetStateStorage(tree: *mut ImGuiStorage) -> (); 792 | pub fn igGetStateStorage() -> *mut ImGuiStorage; 793 | pub fn igPushFont(font: *mut ImFont) -> (); 794 | pub fn igPopFont() -> (); 795 | pub fn igPushStyleColor(idx: ImGuiCol, col: ImVec4) -> (); 796 | pub fn igPopStyleColor(count: c_int) -> (); 797 | pub fn igPushStyleVar(idx: ImGuiStyleVar, val: c_float) -> (); 798 | pub fn igPushStyleVarVec(idx: ImGuiStyleVar, val: ImVec2) -> (); 799 | pub fn igPopStyleVar(count: c_int) -> (); 800 | pub fn igGetColorU32(idx: ImGuiCol, alpha_mul: c_float) -> ImU32; 801 | pub fn igGetColorU32Vec(col: *const ImVec4) -> ImU32; 802 | pub fn igPushItemWidth(item_width: c_float) -> (); 803 | pub fn igPopItemWidth() -> (); 804 | pub fn igCalcItemWidth() -> c_float; 805 | pub fn igPushTextWrapPos(wrap_pos_x: c_float) -> (); 806 | pub fn igPopTextWrapPos() -> (); 807 | pub fn igPushAllowKeyboardFocus(v: u8) -> (); 808 | pub fn igPopAllowKeyboardFocus() -> (); 809 | pub fn igPushButtonRepeat(repeat: u8) -> (); 810 | pub fn igPopButtonRepeat() -> (); 811 | pub fn igBeginGroup() -> (); 812 | pub fn igEndGroup() -> (); 813 | pub fn igSeparator() -> (); 814 | pub fn igSameLine(local_pos_x: c_float, spacing_w: c_float) -> (); 815 | pub fn igSpacing() -> (); 816 | pub fn igDummy(size: *const ImVec2) -> (); 817 | pub fn igIndent() -> (); 818 | pub fn igUnindent() -> (); 819 | pub fn igColumns(count: c_int, id: *const c_char, border: u8) -> (); 820 | pub fn igNextColumn() -> (); 821 | pub fn igGetColumnIndex() -> c_int; 822 | pub fn igGetColumnOffset(column_index: c_int) -> c_float; 823 | pub fn igSetColumnOffset(column_index: c_int, offset_x: c_float) -> (); 824 | pub fn igGetColumnWidth(column_index: c_int) -> c_float; 825 | pub fn igGetColumnsCount() -> c_int; 826 | pub fn igGetCursorPos(pOut: *mut ImVec2) -> (); 827 | pub fn igGetCursorPosX() -> c_float; 828 | pub fn igGetCursorPosY() -> c_float; 829 | pub fn igSetCursorPos(local_pos: ImVec2) -> (); 830 | pub fn igSetCursorPosX(x: c_float) -> (); 831 | pub fn igSetCursorPosY(y: c_float) -> (); 832 | pub fn igGetCursorStartPos(pOut: *mut ImVec2) -> (); 833 | pub fn igGetCursorScreenPos(pOut: *mut ImVec2) -> (); 834 | pub fn igSetCursorScreenPos(pos: ImVec2) -> (); 835 | pub fn igAlignFirstTextHeightToWidgets() -> (); 836 | pub fn igGetTextLineHeight() -> c_float; 837 | pub fn igGetTextLineHeightWithSpacing() -> c_float; 838 | pub fn igGetItemsLineHeightWithSpacing() -> c_float; 839 | pub fn igPushIdStr(str_id: *const c_char) -> (); 840 | pub fn igPushIdStrRange(str_begin: *const c_char, str_end: *const c_char) -> (); 841 | pub fn igPushIdPtr(ptr_id: *const c_void) -> (); 842 | pub fn igPushIdInt(int_id: c_int) -> (); 843 | pub fn igPopId() -> (); 844 | pub fn igGetIdStr(str_id: *const c_char) -> ImGuiID; 845 | pub fn igGetIdStrRange(str_begin: *const c_char, str_end: *const c_char) -> ImGuiID; 846 | pub fn igGetIdPtr(ptr_id: *const c_void) -> ImGuiID; 847 | pub fn igText(fmt: *const c_char, ...) -> (); 848 | pub fn igTextColored(col: ImVec4, fmt: *const c_char, ...) -> (); 849 | pub fn igTextDisabled(fmt: *const c_char, ...) -> (); 850 | pub fn igTextWrapped(fmt: *const c_char, ...) -> (); 851 | pub fn igTextUnformatted(text: *const c_char, text_end: *const c_char) -> (); 852 | pub fn igLabelText(label: *const c_char, fmt: *const c_char, ...) -> (); 853 | pub fn igBullet() -> (); 854 | pub fn igBulletText(fmt: *const c_char, ...) -> (); 855 | pub fn igButton(label: *const c_char, size: ImVec2) -> u8; 856 | pub fn igSmallButton(label: *const c_char) -> u8; 857 | pub fn igInvisibleButton(str_id: *const c_char, size: ImVec2) -> u8; 858 | pub fn igImage(user_texture_id: ImTextureID, size: ImVec2, uv0: ImVec2, uv1: ImVec2, tint_col: ImVec4, border_col: ImVec4) -> (); 859 | pub fn igImageButton(user_texture_id: ImTextureID, size: ImVec2, uv0: ImVec2, uv1: ImVec2, frame_padding: c_int, bg_col: ImVec4, tint_col: ImVec4) -> u8; 860 | pub fn igCollapsingHeader(label: *const c_char, str_id: *const c_char, display_frame: u8, default_open: u8) -> u8; 861 | pub fn igCheckbox(label: *const c_char, v: *mut u8) -> u8; 862 | pub fn igCheckboxFlags(label: *const c_char, flags: *mut c_uint, flags_value: c_uint) -> u8; 863 | pub fn igRadioButtonBool(label: *const c_char, active: u8) -> u8; 864 | pub fn igRadioButton(label: *const c_char, v: *mut c_int, v_button: c_int) -> u8; 865 | pub fn igCombo(label: *const c_char, current_item: *mut c_int, items: *mut *const c_char, items_count: c_int, height_in_items: c_int) -> u8; 866 | pub fn igCombo2(label: *const c_char, current_item: *mut c_int, items_separated_by_zeros: *const c_char, height_in_items: c_int) -> u8; 867 | pub fn igCombo3(label: *const c_char, current_item: *mut c_int, items_getter: Option u8>, data: *mut c_void, items_count: c_int, height_in_items: c_int) -> u8; 868 | pub fn igColorButton(col: ImVec4, small_height: u8, outline_border: u8) -> u8; 869 | pub fn igColorEdit3(label: *const c_char, col: *mut c_float) -> u8; 870 | pub fn igColorEdit4(label: *const c_char, col: *mut c_float, show_alpha: u8) -> u8; 871 | pub fn igColorEditMode(mode: ImGuiColorEditMode) -> (); 872 | pub fn igPlotLines(label: *const c_char, values: *const c_float, values_count: c_int, values_offset: c_int, overlay_text: *const c_char, scale_min: c_float, scale_max: c_float, graph_size: ImVec2, stride: c_int) -> (); 873 | pub fn igPlotLines2(label: *const c_char, values_getter: Option c_float>, data: *mut c_void, values_count: c_int, values_offset: c_int, overlay_text: *const c_char, scale_min: c_float, scale_max: c_float, graph_size: ImVec2) -> (); 874 | pub fn igPlotHistogram(label: *const c_char, values: *const c_float, values_count: c_int, values_offset: c_int, overlay_text: *const c_char, scale_min: c_float, scale_max: c_float, graph_size: ImVec2, stride: c_int) -> (); 875 | pub fn igPlotHistogram2(label: *const c_char, values_getter: Option c_float>, data: *mut c_void, values_count: c_int, values_offset: c_int, overlay_text: *const c_char, scale_min: c_float, scale_max: c_float, graph_size: ImVec2) -> (); 876 | pub fn igProgressBar(fraction: c_float, size_arg: *const ImVec2, overlay: *const c_char) -> (); 877 | pub fn igSliderFloat(label: *const c_char, v: *mut c_float, v_min: c_float, v_max: c_float, display_format: *const c_char, power: c_float) -> u8; 878 | pub fn igSliderFloat2(label: *const c_char, v: *mut c_float, v_min: c_float, v_max: c_float, display_format: *const c_char, power: c_float) -> u8; 879 | pub fn igSliderFloat3(label: *const c_char, v: *mut c_float, v_min: c_float, v_max: c_float, display_format: *const c_char, power: c_float) -> u8; 880 | pub fn igSliderFloat4(label: *const c_char, v: *mut c_float, v_min: c_float, v_max: c_float, display_format: *const c_char, power: c_float) -> u8; 881 | pub fn igSliderAngle(label: *const c_char, v_rad: *mut c_float, v_degrees_min: c_float, v_degrees_max: c_float) -> u8; 882 | pub fn igSliderInt(label: *const c_char, v: *mut c_int, v_min: c_int, v_max: c_int, display_format: *const c_char) -> u8; 883 | pub fn igSliderInt2(label: *const c_char, v: *mut c_int, v_min: c_int, v_max: c_int, display_format: *const c_char) -> u8; 884 | pub fn igSliderInt3(label: *const c_char, v: *mut c_int, v_min: c_int, v_max: c_int, display_format: *const c_char) -> u8; 885 | pub fn igSliderInt4(label: *const c_char, v: *mut c_int, v_min: c_int, v_max: c_int, display_format: *const c_char) -> u8; 886 | pub fn igVSliderFloat(label: *const c_char, size: ImVec2, v: *mut c_float, v_min: c_float, v_max: c_float, display_format: *const c_char, power: c_float) -> u8; 887 | pub fn igVSliderInt(label: *const c_char, size: ImVec2, v: *mut c_int, v_min: c_int, v_max: c_int, display_format: *const c_char) -> u8; 888 | pub fn igDragFloat(label: *const c_char, v: *mut c_float, v_speed: c_float, v_min: c_float, v_max: c_float, display_format: *const c_char, power: c_float) -> u8; 889 | pub fn igDragFloat2(label: *const c_char, v: *mut c_float, v_speed: c_float, v_min: c_float, v_max: c_float, display_format: *const c_char, power: c_float) -> u8; 890 | pub fn igDragFloat3(label: *const c_char, v: *mut c_float, v_speed: c_float, v_min: c_float, v_max: c_float, display_format: *const c_char, power: c_float) -> u8; 891 | pub fn igDragFloat4(label: *const c_char, v: *mut c_float, v_speed: c_float, v_min: c_float, v_max: c_float, display_format: *const c_char, power: c_float) -> u8; 892 | pub fn igDragFloatRange2(label: *const c_char, v_current_min: *mut c_float, v_current_max: *mut c_float, v_speed: c_float, v_min: c_float, v_max: c_float, display_format: *const c_char, display_format_max: *const c_char, power: c_float) -> u8; 893 | pub fn igDragInt(label: *const c_char, v: *mut c_int, v_speed: c_float, v_min: c_int, v_max: c_int, display_format: *const c_char) -> u8; 894 | pub fn igDragInt2(label: *const c_char, v: *mut c_int, v_speed: c_float, v_min: c_int, v_max: c_int, display_format: *const c_char) -> u8; 895 | pub fn igDragInt3(label: *const c_char, v: *mut c_int, v_speed: c_float, v_min: c_int, v_max: c_int, display_format: *const c_char) -> u8; 896 | pub fn igDragInt4(label: *const c_char, v: *mut c_int, v_speed: c_float, v_min: c_int, v_max: c_int, display_format: *const c_char) -> u8; 897 | pub fn igDragIntRange2(label: *const c_char, v_current_min: *mut c_int, v_current_max: *mut c_int, v_speed: c_float, v_min: c_int, v_max: c_int, display_format: *const c_char, display_format_max: *const c_char) -> u8; 898 | pub fn igInputText(label: *const c_char, buf: *mut c_char, buf_size: size_t, flags: ImGuiInputTextFlags, callback: ImGuiTextEditCallback, user_data: *mut c_void) -> u8; 899 | pub fn igInputTextMultiline(label: *const c_char, buf: *mut c_char, buf_size: size_t, size: ImVec2, flags: ImGuiInputTextFlags, callback: ImGuiTextEditCallback, user_data: *mut c_void) -> u8; 900 | pub fn igInputFloat(label: *const c_char, v: *mut c_float, step: c_float, step_fast: c_float, decimal_precision: c_int, extra_flags: ImGuiInputTextFlags) -> u8; 901 | pub fn igInputFloat2(label: *const c_char, v: *mut c_float, decimal_precision: c_int, extra_flags: ImGuiInputTextFlags) -> u8; 902 | pub fn igInputFloat3(label: *const c_char, v: *mut c_float, decimal_precision: c_int, extra_flags: ImGuiInputTextFlags) -> u8; 903 | pub fn igInputFloat4(label: *const c_char, v: *mut c_float, decimal_precision: c_int, extra_flags: ImGuiInputTextFlags) -> u8; 904 | pub fn igInputInt(label: *const c_char, v: *mut c_int, step: c_int, step_fast: c_int, extra_flags: ImGuiInputTextFlags) -> u8; 905 | pub fn igInputInt2(label: *const c_char, v: *mut c_int, extra_flags: ImGuiInputTextFlags) -> u8; 906 | pub fn igInputInt3(label: *const c_char, v: *mut c_int, extra_flags: ImGuiInputTextFlags) -> u8; 907 | pub fn igInputInt4(label: *const c_char, v: *mut c_int, extra_flags: ImGuiInputTextFlags) -> u8; 908 | pub fn igTreeNode(str_label_id: *const c_char) -> u8; 909 | pub fn igTreeNodeStr(str_id: *const c_char, fmt: *const c_char, ...) -> u8; 910 | pub fn igTreeNodePtr(ptr_id: *const c_void, fmt: *const c_char, ...) -> u8; 911 | pub fn igTreePushStr(str_id: *const c_char) -> (); 912 | pub fn igTreePushPtr(ptr_id: *const c_void) -> (); 913 | pub fn igTreePop() -> (); 914 | pub fn igSetNextTreeNodeOpened(opened: u8, cond: ImGuiSetCond) -> (); 915 | pub fn igSelectable(label: *const c_char, selected: u8, flags: ImGuiSelectableFlags, size: ImVec2) -> u8; 916 | pub fn igSelectableEx(label: *const c_char, p_selected: *mut u8, flags: ImGuiSelectableFlags, size: ImVec2) -> u8; 917 | pub fn igListBox(label: *const c_char, current_item: *mut c_int, items: *mut *const c_char, items_count: c_int, height_in_items: c_int) -> u8; 918 | pub fn igListBox2(label: *const c_char, current_item: *mut c_int, items_getter: Option u8>, data: *mut c_void, items_count: c_int, height_in_items: c_int) -> u8; 919 | pub fn igListBoxHeader(label: *const c_char, size: ImVec2) -> u8; 920 | pub fn igListBoxHeader2(label: *const c_char, items_count: c_int, height_in_items: c_int) -> u8; 921 | pub fn igListBoxFooter() -> (); 922 | pub fn igValueBool(prefix: *const c_char, b: u8) -> (); 923 | pub fn igValueInt(prefix: *const c_char, v: c_int) -> (); 924 | pub fn igValueUInt(prefix: *const c_char, v: c_uint) -> (); 925 | pub fn igValueFloat(prefix: *const c_char, v: c_float, float_format: *const c_char) -> (); 926 | pub fn igValueColor(prefix: *const c_char, v: ImVec4) -> (); 927 | pub fn igValueColor2(prefix: *const c_char, v: c_uint) -> (); 928 | pub fn igSetTooltip(fmt: *const c_char, ...) -> (); 929 | pub fn igBeginTooltip() -> (); 930 | pub fn igEndTooltip() -> (); 931 | pub fn igBeginMainMenuBar() -> u8; 932 | pub fn igEndMainMenuBar() -> (); 933 | pub fn igBeginMenuBar() -> u8; 934 | pub fn igEndMenuBar() -> (); 935 | pub fn igBeginMenu(label: *const c_char, enabled: u8) -> u8; 936 | pub fn igEndMenu() -> (); 937 | pub fn igMenuItem(label: *const c_char, shortcut: *const c_char, selected: u8, enabled: u8) -> u8; 938 | pub fn igMenuItemPtr(label: *const c_char, shortcut: *const c_char, p_selected: *mut u8, enabled: u8) -> u8; 939 | pub fn igOpenPopup(str_id: *const c_char) -> (); 940 | pub fn igBeginPopup(str_id: *const c_char) -> u8; 941 | pub fn igBeginPopupModal(name: *const c_char, p_opened: *mut u8, extra_flags: ImGuiWindowFlags) -> u8; 942 | pub fn igBeginPopupContextItem(str_id: *const c_char, mouse_button: c_int) -> u8; 943 | pub fn igBeginPopupContextWindow(also_over_items: u8, str_id: *const c_char, mouse_button: c_int) -> u8; 944 | pub fn igBeginPopupContextVoid(str_id: *const c_char, mouse_button: c_int) -> u8; 945 | pub fn igEndPopup() -> (); 946 | pub fn igCloseCurrentPopup() -> (); 947 | pub fn igLogToTTY(max_depth: c_int) -> (); 948 | pub fn igLogToFile(max_depth: c_int, filename: *const c_char) -> (); 949 | pub fn igLogToClipboard(max_depth: c_int) -> (); 950 | pub fn igLogFinish() -> (); 951 | pub fn igLogButtons() -> (); 952 | pub fn igLogText(fmt: *const c_char, ...) -> (); 953 | pub fn igIsItemHovered() -> u8; 954 | pub fn igIsItemHoveredRect() -> u8; 955 | pub fn igIsItemActive() -> u8; 956 | pub fn igIsItemVisible() -> u8; 957 | pub fn igIsAnyItemHovered() -> u8; 958 | pub fn igIsAnyItemActive() -> u8; 959 | pub fn igGetItemRectMin(pOut: *mut ImVec2) -> (); 960 | pub fn igGetItemRectMax(pOut: *mut ImVec2) -> (); 961 | pub fn igGetItemRectSize(pOut: *mut ImVec2) -> (); 962 | pub fn igIsWindowHovered() -> u8; 963 | pub fn igIsWindowFocused() -> u8; 964 | pub fn igIsRootWindowFocused() -> u8; 965 | pub fn igIsRootWindowOrAnyChildFocused() -> u8; 966 | pub fn igIsRectVisible(item_size: ImVec2) -> u8; 967 | pub fn igIsPosHoveringAnyWindow(pos: ImVec2) -> u8; 968 | pub fn igGetTime() -> c_float; 969 | pub fn igGetFrameCount() -> c_int; 970 | pub fn igGetStyleColName(idx: ImGuiCol) -> *const c_char; 971 | pub fn igCalcItemRectClosestPoint(pOut: *mut ImVec2, pos: ImVec2, on_edge: u8, outward: c_float) -> (); 972 | pub fn igCalcTextSize(pOut: *mut ImVec2, text: *const c_char, text_end: *const c_char, hide_text_after_double_hash: u8, wrap_width: c_float) -> (); 973 | pub fn igCalcListClipping(items_count: c_int, items_height: c_float, out_items_display_start: *mut c_int, out_items_display_end: *mut c_int) -> (); 974 | pub fn igBeginChildFrame(id: ImGuiID, size: ImVec2, extra_flags: ImGuiWindowFlags) -> u8; 975 | pub fn igEndChildFrame() -> (); 976 | pub fn igColorConvertU32ToFloat4(pOut: *mut ImVec4, _in: ImU32) -> (); 977 | pub fn igColorConvertFloat4ToU32(_in: ImVec4) -> ImU32; 978 | pub fn igColorConvertRGBtoHSV(r: c_float, g: c_float, b: c_float, out_h: *mut c_float, out_s: *mut c_float, out_v: *mut c_float) -> (); 979 | pub fn igColorConvertHSVtoRGB(h: c_float, s: c_float, v: c_float, out_r: *mut c_float, out_g: *mut c_float, out_b: *mut c_float) -> (); 980 | pub fn igGetKeyIndex(key: ImGuiKey) -> c_int; 981 | pub fn igIsKeyDown(key_index: c_int) -> u8; 982 | pub fn igIsKeyPressed(key_index: c_int, repeat: u8) -> u8; 983 | pub fn igIsKeyReleased(key_index: c_int) -> u8; 984 | pub fn igIsMouseDown(button: c_int) -> u8; 985 | pub fn igIsMouseClicked(button: c_int, repeat: u8) -> u8; 986 | pub fn igIsMouseDoubleClicked(button: c_int) -> u8; 987 | pub fn igIsMouseReleased(button: c_int) -> u8; 988 | pub fn igIsMouseHoveringWindow() -> u8; 989 | pub fn igIsMouseHoveringAnyWindow() -> u8; 990 | pub fn igIsMouseHoveringRect(pos_min: ImVec2, pos_max: ImVec2, clip: u8) -> u8; 991 | pub fn igIsMouseDragging(button: c_int, lock_threshold: c_float) -> u8; 992 | pub fn igGetMousePos(pOut: *mut ImVec2) -> (); 993 | pub fn igGetMousePosOnOpeningCurrentPopup(pOut: *mut ImVec2) -> (); 994 | pub fn igGetMouseDragDelta(pOut: *mut ImVec2, button: c_int, lock_threshold: c_float) -> (); 995 | pub fn igResetMouseDragDelta(button: c_int) -> (); 996 | pub fn igGetMouseCursor() -> ImGuiMouseCursor; 997 | pub fn igSetMouseCursor(_type: ImGuiMouseCursor) -> (); 998 | pub fn igCaptureKeyboardFromApp() -> (); 999 | pub fn igCaptureMouseFromApp() -> (); 1000 | pub fn igMemAlloc(sz: size_t) -> *mut c_void; 1001 | pub fn igMemFree(ptr: *mut c_void) -> (); 1002 | pub fn igGetClipboardText() -> *const c_char; 1003 | pub fn igSetClipboardText(text: *const c_char) -> (); 1004 | pub fn igGetVersion() -> *const c_char; 1005 | pub fn igGetInternalState() -> *mut c_void; 1006 | pub fn igGetInternalStateSize() -> size_t; 1007 | pub fn igSetInternalState(state: *mut c_void, construct: u8) -> (); 1008 | pub fn ImFontAtlas_GetTexDataAsRGBA32(atlas: *mut ImFontAtlas, out_pixels: *mut *mut c_uchar, out_width: *mut c_int, out_height: *mut c_int, out_bytes_per_pixel: *mut c_int) -> (); 1009 | pub fn ImFontAtlas_GetTexDataAsAlpha8(atlas: *mut ImFontAtlas, out_pixels: *mut *mut c_uchar, out_width: *mut c_int, out_height: *mut c_int, out_bytes_per_pixel: *mut c_int) -> (); 1010 | pub fn ImFontAtlas_SetTexID(atlas: *mut ImFontAtlas, tex: *mut c_void) -> (); 1011 | pub fn ImFontAtlas_AddFont(atlas: *mut ImFontAtlas, font_cfg: *const ImFontConfig) -> *mut ImFont; 1012 | pub fn ImFontAtlas_AddFontDefault(atlas: *mut ImFontAtlas, font_cfg: *const ImFontConfig) -> *mut ImFont; 1013 | pub fn ImFontAtlas_AddFontFromFileTTF(atlas: *mut ImFontAtlas, filename: *const c_char, size_pixels: c_float, font_cfg: *const ImFontConfig, glyph_ranges: *const ImWchar) -> *mut ImFont; 1014 | pub fn ImFontAtlas_AddFontFromMemoryTTF(atlas: *mut ImFontAtlas, ttf_data: *mut c_void, ttf_size: c_int, size_pixels: c_float, font_cfg: *const ImFontConfig, glyph_ranges: *const ImWchar) -> *mut ImFont; 1015 | pub fn ImFontAtlas_AddFontFromMemoryCompressedTTF(atlas: *mut ImFontAtlas, compressed_ttf_data: *const c_void, compressed_ttf_size: c_int, size_pixels: c_float, font_cfg: *const ImFontConfig, glyph_ranges: *const ImWchar) -> *mut ImFont; 1016 | pub fn ImFontAtlas_AddFontFromMemoryCompressedBase85TTF(atlas: *mut ImFontAtlas, compressed_ttf_data_base85: *const c_char, size_pixels: c_float, font_cfg: *const ImFontConfig, glyph_ranges: *const ImWchar) -> *mut ImFont; 1017 | pub fn ImFontAtlas_ClearTexData(atlas: *mut ImFontAtlas) -> (); 1018 | pub fn ImFontAtlas_Clear(atlas: *mut ImFontAtlas) -> (); 1019 | pub fn ImGuiIO_AddInputCharacter(c: c_ushort) -> (); 1020 | pub fn ImGuiIO_AddInputCharactersUTF8(utf8_chars: *const c_char) -> (); 1021 | pub fn ImGuiIO_ClearInputCharacters() -> (); 1022 | pub fn ImDrawData_DeIndexAllBuffers(drawData: *mut ImDrawData) -> (); 1023 | pub fn ImDrawList_GetVertexBufferSize(list: *mut ImDrawList) -> c_int; 1024 | pub fn ImDrawList_GetVertexPtr(list: *mut ImDrawList, n: c_int) -> *mut ImDrawVert; 1025 | pub fn ImDrawList_GetIndexBufferSize(list: *mut ImDrawList) -> c_int; 1026 | pub fn ImDrawList_GetIndexPtr(list: *mut ImDrawList, n: c_int) -> *mut ImDrawIdx; 1027 | pub fn ImDrawList_GetCmdSize(list: *mut ImDrawList) -> c_int; 1028 | pub fn ImDrawList_GetCmdPtr(list: *mut ImDrawList, n: c_int) -> *mut ImDrawCmd; 1029 | pub fn ImDrawList_Clear(list: *mut ImDrawList) -> (); 1030 | pub fn ImDrawList_ClearFreeMemory(list: *mut ImDrawList) -> (); 1031 | pub fn ImDrawList_PushClipRect(list: *mut ImDrawList, clip_rect: ImVec4) -> (); 1032 | pub fn ImDrawList_PushClipRectFullScreen(list: *mut ImDrawList) -> (); 1033 | pub fn ImDrawList_PopClipRect(list: *mut ImDrawList) -> (); 1034 | pub fn ImDrawList_PushTextureID(list: *mut ImDrawList, texture_id: ImTextureID) -> (); 1035 | pub fn ImDrawList_PopTextureID(list: *mut ImDrawList) -> (); 1036 | pub fn ImDrawList_AddLine(list: *mut ImDrawList, a: ImVec2, b: ImVec2, col: ImU32, thickness: c_float) -> (); 1037 | pub fn ImDrawList_AddRect(list: *mut ImDrawList, a: ImVec2, b: ImVec2, col: ImU32, rounding: c_float, rounding_corners: c_int) -> (); 1038 | pub fn ImDrawList_AddRectFilled(list: *mut ImDrawList, a: ImVec2, b: ImVec2, col: ImU32, rounding: c_float, rounding_corners: c_int) -> (); 1039 | pub fn ImDrawList_AddRectFilledMultiColor(list: *mut ImDrawList, a: ImVec2, b: ImVec2, col_upr_left: ImU32, col_upr_right: ImU32, col_bot_right: ImU32, col_bot_left: ImU32) -> (); 1040 | pub fn ImDrawList_AddTriangleFilled(list: *mut ImDrawList, a: ImVec2, b: ImVec2, c: ImVec2, col: ImU32) -> (); 1041 | pub fn ImDrawList_AddCircle(list: *mut ImDrawList, centre: ImVec2, radius: c_float, col: ImU32, num_segments: c_int) -> (); 1042 | pub fn ImDrawList_AddCircleFilled(list: *mut ImDrawList, centre: ImVec2, radius: c_float, col: ImU32, num_segments: c_int) -> (); 1043 | pub fn ImDrawList_AddText(list: *mut ImDrawList, pos: ImVec2, col: ImU32, text_begin: *const c_char, text_end: *const c_char) -> (); 1044 | pub fn ImDrawList_AddTextExt(list: *mut ImDrawList, font: *const ImFont, font_size: c_float, pos: ImVec2, col: ImU32, text_begin: *const c_char, text_end: *const c_char, wrap_width: c_float, cpu_fine_clip_rect: *const ImVec4) -> (); 1045 | pub fn ImDrawList_AddImage(list: *mut ImDrawList, user_texture_id: ImTextureID, a: ImVec2, b: ImVec2, uv0: ImVec2, uv1: ImVec2, col: ImU32) -> (); 1046 | pub fn ImDrawList_AddPolyline(list: *mut ImDrawList, points: *const ImVec2, num_points: c_int, col: ImU32, closed: u8, thickness: c_float, anti_aliased: u8) -> (); 1047 | pub fn ImDrawList_AddConvexPolyFilled(list: *mut ImDrawList, points: *const ImVec2, num_points: c_int, col: ImU32, anti_aliased: u8) -> (); 1048 | pub fn ImDrawList_AddBezierCurve(list: *mut ImDrawList, pos0: ImVec2, cp0: ImVec2, cp1: ImVec2, pos1: ImVec2, col: ImU32, thickness: c_float, num_segments: c_int) -> (); 1049 | pub fn ImDrawList_PathClear(list: *mut ImDrawList) -> (); 1050 | pub fn ImDrawList_PathLineTo(list: *mut ImDrawList, pos: ImVec2) -> (); 1051 | pub fn ImDrawList_PathLineToMergeDuplicate(list: *mut ImDrawList, pos: ImVec2) -> (); 1052 | pub fn ImDrawList_PathFill(list: *mut ImDrawList, col: ImU32) -> (); 1053 | pub fn ImDrawList_PathStroke(list: *mut ImDrawList, col: ImU32, closed: u8, thickness: c_float) -> (); 1054 | pub fn ImDrawList_PathArcTo(list: *mut ImDrawList, centre: ImVec2, radius: c_float, a_min: c_float, a_max: c_float, num_segments: c_int) -> (); 1055 | pub fn ImDrawList_PathArcToFast(list: *mut ImDrawList, centre: ImVec2, radius: c_float, a_min_of_12: c_int, a_max_of_12: c_int) -> (); 1056 | pub fn ImDrawList_PathBezierCurveTo(list: *mut ImDrawList, p1: ImVec2, p2: ImVec2, p3: ImVec2, num_segments: c_int) -> (); 1057 | pub fn ImDrawList_PathRect(list: *mut ImDrawList, rect_min: ImVec2, rect_max: ImVec2, rounding: c_float, rounding_corners: c_int) -> (); 1058 | pub fn ImDrawList_ChannelsSplit(list: *mut ImDrawList, channels_count: c_int) -> (); 1059 | pub fn ImDrawList_ChannelsMerge(list: *mut ImDrawList) -> (); 1060 | pub fn ImDrawList_ChannelsSetCurrent(list: *mut ImDrawList, channel_index: c_int) -> (); 1061 | pub fn ImDrawList_AddCallback(list: *mut ImDrawList, callback: ImDrawCallback, callback_data: *mut c_void) -> (); 1062 | pub fn ImDrawList_AddDrawCmd(list: *mut ImDrawList) -> (); 1063 | pub fn ImDrawList_PrimReserve(list: *mut ImDrawList, idx_count: c_int, vtx_count: c_int) -> (); 1064 | pub fn ImDrawList_PrimRect(list: *mut ImDrawList, a: ImVec2, b: ImVec2, col: ImU32) -> (); 1065 | pub fn ImDrawList_PrimRectUV(list: *mut ImDrawList, a: ImVec2, b: ImVec2, uv_a: ImVec2, uv_b: ImVec2, col: ImU32) -> (); 1066 | pub fn ImDrawList_PrimVtx(list: *mut ImDrawList, pos: ImVec2, uv: ImVec2, col: ImU32) -> (); 1067 | pub fn ImDrawList_PrimWriteVtx(list: *mut ImDrawList, pos: ImVec2, uv: ImVec2, col: ImU32) -> (); 1068 | pub fn ImDrawList_PrimWriteIdx(list: *mut ImDrawList, idx: ImDrawIdx) -> (); 1069 | pub fn ImDrawList_UpdateClipRect(list: *mut ImDrawList) -> (); 1070 | pub fn ImDrawList_UpdateTextureID(list: *mut ImDrawList) -> (); 1071 | } 1072 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | extern crate libc; 2 | extern crate gl; 3 | 4 | pub mod imgui; 5 | pub mod renderer; 6 | -------------------------------------------------------------------------------- /src/renderer.rs: -------------------------------------------------------------------------------- 1 | use std::ptr; 2 | use std::os::raw; 3 | use std::mem::{size_of, transmute}; 4 | use std::ffi::CString; 5 | use libc::{c_void, c_int, c_uchar}; 6 | use gl; 7 | use imgui::*; 8 | 9 | static VERTEX_SHADER: &'static str = " 10 | #version 330 11 | uniform mat4 ProjMtx; 12 | in vec2 Position; 13 | in vec2 UV; 14 | in vec4 Color; 15 | out vec2 Frag_UV; 16 | out vec4 Frag_Color; 17 | void main() 18 | { 19 | Frag_UV = UV; 20 | Frag_Color = Color; 21 | gl_Position = ProjMtx * vec4(Position.xy, 0, 1); 22 | } 23 | "; 24 | 25 | static FRAGMENT_SHADER: &'static str = " 26 | #version 330 27 | uniform sampler2D Texture; 28 | in vec2 Frag_UV; 29 | in vec4 Frag_Color; 30 | out vec4 Out_Color; 31 | void main() 32 | { 33 | Out_Color = Frag_Color * texture(Texture, Frag_UV.st); 34 | } 35 | "; 36 | 37 | #[derive(Debug)] 38 | pub struct Renderer { 39 | pub io:*mut ImGuiIO, 40 | program_handle: u32, 41 | vertex_shader_handle: u32, 42 | fragment_shader_handle: u32, 43 | vao_handle: u32, 44 | vbo_handle: u32, 45 | elements_handle: u32, 46 | font_texture_handle: u32, 47 | idx_tex: u32, 48 | idx_projection: u32, 49 | idx_position: u32, 50 | idx_uv: u32, 51 | idx_color: u32 52 | } 53 | 54 | fn cstr(input:&str) -> *const i8 { 55 | CString::new(input.as_bytes()).unwrap().as_ptr() as *const i8 56 | } 57 | 58 | impl Renderer { 59 | pub fn new() -> Renderer { 60 | unsafe { 61 | // Backup GL state 62 | let (mut last_texture, mut last_array_buffer, mut last_vertex_array) = (0, 0, 0); 63 | gl::GetIntegerv(gl::TEXTURE_BINDING_2D, &mut last_texture); 64 | gl::GetIntegerv(gl::ARRAY_BUFFER_BINDING, &mut last_array_buffer); 65 | gl::GetIntegerv(gl::VERTEX_ARRAY_BINDING, &mut last_vertex_array); 66 | 67 | // Compile and link shaders 68 | let program_handle = gl::CreateProgram(); 69 | let vertex_shader_handle = gl::CreateShader(gl::VERTEX_SHADER); 70 | let fragment_shader_handle = gl::CreateShader(gl::FRAGMENT_SHADER); 71 | gl::ShaderSource(vertex_shader_handle, 1, &cstr(VERTEX_SHADER), ptr::null()); 72 | gl::ShaderSource(fragment_shader_handle, 1, &cstr(FRAGMENT_SHADER), ptr::null()); 73 | gl::CompileShader(vertex_shader_handle); 74 | gl::CompileShader(fragment_shader_handle); 75 | gl::AttachShader(program_handle, vertex_shader_handle); 76 | gl::AttachShader(program_handle, fragment_shader_handle); 77 | gl::LinkProgram(program_handle); 78 | let idx_tex = gl::GetUniformLocation(program_handle, cstr("Texture")); 79 | let idx_projection = gl::GetUniformLocation(program_handle, cstr("ProjMtx")); 80 | let idx_position = gl::GetAttribLocation(program_handle, cstr("Position")); 81 | let idx_uv = gl::GetAttribLocation(program_handle, cstr("UV")); 82 | let idx_color = gl::GetAttribLocation(program_handle, cstr("Color")); 83 | 84 | // Initialize draw element buffer 85 | let mut elements_handle = 0; 86 | gl::GenBuffers(1, &mut elements_handle); 87 | 88 | // Initialize VBO 89 | let mut vbo_handle = 0; 90 | gl::GenBuffers(1, &mut vbo_handle); 91 | gl::BindBuffer(gl::ARRAY_BUFFER, vbo_handle); 92 | 93 | // Initialize vertex attributes 94 | let mut vao_handle = 0; 95 | let stride = size_of::() as i32; 96 | let v2size = size_of::(); 97 | gl::GenVertexArrays(1, &mut vao_handle); 98 | gl::BindVertexArray(vao_handle); 99 | gl::EnableVertexAttribArray(idx_position as u32); 100 | gl::EnableVertexAttribArray(idx_uv as u32); 101 | gl::EnableVertexAttribArray(idx_color as u32); 102 | gl::VertexAttribPointer(idx_position as u32, 2, gl::FLOAT, gl::FALSE, stride, 0 as *const raw::c_void); 103 | gl::VertexAttribPointer(idx_uv as u32, 2, gl::FLOAT, gl::FALSE, stride, v2size as *const raw::c_void); 104 | gl::VertexAttribPointer(idx_color as u32, 4, gl::UNSIGNED_BYTE, gl::TRUE, stride, (v2size as isize * 2) as *const raw::c_void); 105 | 106 | // Build font texture atlas 107 | let mut io = igGetIO(); 108 | let mut pixels: *mut c_uchar = ptr::null_mut(); 109 | let mut width: c_int = 0; 110 | let mut height: c_int = 0; 111 | let mut bytes_per_pixel: c_int = 0; 112 | ImFontAtlas_GetTexDataAsRGBA32((*io).Fonts, &mut pixels, &mut width, &mut height, &mut bytes_per_pixel); 113 | 114 | // Upload font texture 115 | let mut font_texture_handle = 0; 116 | gl::GenTextures(1, &mut font_texture_handle); 117 | gl::BindTexture(gl::TEXTURE_2D, font_texture_handle); 118 | gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::LINEAR as i32); 119 | gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::LINEAR as i32); 120 | gl::TexImage2D(gl::TEXTURE_2D, 0, gl::RGBA as i32, width, height, 0, gl::RGBA, gl::UNSIGNED_BYTE, pixels as *const raw::c_void); 121 | ImFontAtlas_SetTexID((*io).Fonts, font_texture_handle as *mut c_void); 122 | 123 | // Restore modified GL state 124 | gl::BindTexture(gl::TEXTURE_2D, last_texture as u32); 125 | gl::BindBuffer(gl::ARRAY_BUFFER, last_array_buffer as u32); 126 | gl::BindVertexArray(last_vertex_array as u32); 127 | 128 | // Disable automatic rendering, instead call ImGui::GetDrawData() to acquire draw lists 129 | (*io).RenderDrawListsFn = None; 130 | 131 | Renderer { 132 | io: io, 133 | program_handle: program_handle, 134 | vertex_shader_handle: vertex_shader_handle, 135 | fragment_shader_handle: fragment_shader_handle, 136 | vao_handle: vao_handle, 137 | vbo_handle: vbo_handle, 138 | elements_handle: elements_handle, 139 | font_texture_handle: font_texture_handle, 140 | idx_tex: idx_tex as u32, 141 | idx_projection: idx_projection as u32, 142 | idx_position: idx_position as u32, 143 | idx_uv: idx_uv as u32, 144 | idx_color: idx_color as u32 145 | } 146 | } 147 | } 148 | 149 | pub fn begin_frame(&mut self, w:f32, h:f32, mouse_x:f32, mouse_y:f32, dt:f32) { 150 | unsafe { 151 | (*self.io).DeltaTime = dt; 152 | (*self.io).DisplaySize = ImVec2 { x: w, y: h }; 153 | (*self.io).DisplayFramebufferScale = ImVec2 { x: 1.0, y: 1.0 }; 154 | (*self.io).MousePos = ImVec2 { x: mouse_x, y: mouse_y }; 155 | igNewFrame(); 156 | } 157 | } 158 | 159 | pub fn end_frame(&mut self) { 160 | unsafe { 161 | // Backup GL state 162 | let mut last_program = 0; 163 | let mut last_texture = 0; 164 | let mut last_array_buffer = 0; 165 | let mut last_element_array_buffer = 0; 166 | let mut last_vertex_array = 0; 167 | let mut last_blend_src = 0; 168 | let mut last_blend_dst = 0; 169 | let mut last_blend_equation_rgb = 0; 170 | let mut last_blend_equation_alpha = 0; 171 | let mut last_viewport = [0i32, 0i32, 0i32, 0i32]; 172 | let last_enable_blend = gl::IsEnabled(gl::BLEND); 173 | let last_enable_cull_face = gl::IsEnabled(gl::CULL_FACE); 174 | let last_enable_depth_test = gl::IsEnabled(gl::DEPTH_TEST); 175 | let last_enable_scissor_test = gl::IsEnabled(gl::SCISSOR_TEST); 176 | gl::GetIntegerv(gl::CURRENT_PROGRAM, &mut last_program); 177 | gl::GetIntegerv(gl::TEXTURE_BINDING_2D, &mut last_texture); 178 | gl::GetIntegerv(gl::ARRAY_BUFFER_BINDING, &mut last_array_buffer); 179 | gl::GetIntegerv(gl::ELEMENT_ARRAY_BUFFER_BINDING, &mut last_element_array_buffer); 180 | gl::GetIntegerv(gl::VERTEX_ARRAY_BINDING, &mut last_vertex_array); 181 | gl::GetIntegerv(gl::BLEND_SRC, &mut last_blend_src); 182 | gl::GetIntegerv(gl::BLEND_DST, &mut last_blend_dst); 183 | gl::GetIntegerv(gl::BLEND_EQUATION_RGB, &mut last_blend_equation_rgb); 184 | gl::GetIntegerv(gl::BLEND_EQUATION_ALPHA, &mut last_blend_equation_alpha); 185 | gl::GetIntegerv(gl::VIEWPORT, transmute(&mut last_viewport)); 186 | 187 | // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled 188 | gl::Enable(gl::BLEND); 189 | gl::BlendEquation(gl::FUNC_ADD); 190 | gl::BlendFunc(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA); 191 | gl::Disable(gl::CULL_FACE); 192 | gl::Disable(gl::DEPTH_TEST); 193 | gl::Enable(gl::SCISSOR_TEST); 194 | gl::ActiveTexture(gl::TEXTURE0); 195 | 196 | // Setup orthographic projection matrix 197 | let (w, h) = ((*self.io).DisplaySize.x, (*self.io).DisplaySize.y); 198 | gl::Viewport(0, 0, w as i32, h as i32); 199 | let ortho_projection = [ 200 | 2.0/w, 0.0, 0.0, 0.0, 201 | 0.0, 2.0/-h, 0.0, 0.0, 202 | 0.0, 0.0, -1.0, 0.0, 203 | -1.0, 1.0, 0.0, 1.0, 204 | ]; 205 | gl::UseProgram(self.program_handle); 206 | gl::Uniform1i(self.idx_tex as i32, 0); 207 | gl::UniformMatrix4fv(self.idx_projection as i32, 1, gl::FALSE, &ortho_projection[0]); 208 | gl::BindVertexArray(self.vao_handle); 209 | 210 | // Generate render commands 211 | igRender(); 212 | 213 | // Execute render commands 214 | let draw_data = igGetDrawData(); 215 | for i in 0..(*draw_data).CmdListsCount { 216 | let cmd_list = (*draw_data).CmdLists.offset(i as isize); 217 | gl::BindBuffer(gl::ARRAY_BUFFER, self.vbo_handle); 218 | gl::BufferData(gl::ARRAY_BUFFER, 219 | ImDrawList_GetVertexBufferSize(*cmd_list) as isize * size_of::() as isize, 220 | ImDrawList_GetVertexPtr(*cmd_list, 0) as *const raw::c_void, 221 | gl::STREAM_DRAW 222 | ); 223 | gl::BindBuffer(gl::ELEMENT_ARRAY_BUFFER, self.elements_handle); 224 | gl::BufferData(gl::ELEMENT_ARRAY_BUFFER, 225 | ImDrawList_GetIndexBufferSize(*cmd_list) as isize * size_of::() as isize, 226 | ImDrawList_GetIndexPtr(*cmd_list, 0) as *const raw::c_void, 227 | gl::STREAM_DRAW 228 | ); 229 | 230 | // Handle commands 231 | let mut ptr: *const u16 = ptr::null_mut(); 232 | for j in 0..ImDrawList_GetCmdSize(*cmd_list) { 233 | let cmd = ImDrawList_GetCmdPtr(*cmd_list, j); 234 | let elements = (*cmd).ElemCount as i32; 235 | 236 | // Handle user-defined callback 237 | match (*cmd).UserCallback { 238 | Some(callback) => callback(*cmd_list, cmd), 239 | None => { 240 | gl::BindTexture(gl::TEXTURE_2D, (*cmd).TextureId as u32); 241 | gl::Scissor((*cmd).ClipRect.x as i32, (h - (*cmd).ClipRect.w) as i32, ((*cmd).ClipRect.z - (*cmd).ClipRect.x) as i32, ((*cmd).ClipRect.w - (*cmd).ClipRect.y) as i32); 242 | gl::DrawElements(gl::TRIANGLES, elements, gl::UNSIGNED_SHORT, ptr as *const _); 243 | } 244 | } 245 | ptr = ptr.offset(elements as isize) 246 | } 247 | } 248 | 249 | // Restore modified GL state 250 | gl::UseProgram(last_program as u32); 251 | gl::BindTexture(gl::TEXTURE_2D, last_texture as u32); 252 | gl::BindBuffer(gl::ARRAY_BUFFER, last_array_buffer as u32); 253 | gl::BindBuffer(gl::ELEMENT_ARRAY_BUFFER, last_element_array_buffer as u32); 254 | gl::BindVertexArray(last_vertex_array as u32); 255 | gl::BlendEquationSeparate(last_blend_equation_rgb as u32, last_blend_equation_alpha as u32); 256 | gl::BlendFunc(last_blend_src as u32, last_blend_dst as u32); 257 | if last_enable_blend == 1 { gl::Enable(gl::BLEND); } else { gl::Disable(gl::BLEND) }; 258 | if last_enable_cull_face == 1 { gl::Enable(gl::CULL_FACE); } else { gl::Disable(gl::CULL_FACE) }; 259 | if last_enable_depth_test == 1 { gl::Enable(gl::DEPTH_TEST); } else { gl::Disable(gl::DEPTH_TEST) }; 260 | if last_enable_scissor_test == 1 { gl::Enable(gl::SCISSOR_TEST); } else { gl::Disable(gl::SCISSOR_TEST) }; 261 | gl::Viewport(last_viewport[0], last_viewport[1], last_viewport[2], last_viewport[3]); 262 | 263 | } 264 | } 265 | } 266 | --------------------------------------------------------------------------------