├── LICENSE ├── README.md └── my_example ├── my_ball.sln └── suspension_ball ├── ImGui ├── font.h ├── imconfig.h ├── imgui.cpp ├── imgui.h ├── imgui_demo.cpp ├── imgui_draw.cpp ├── imgui_impl_glfw.cpp ├── imgui_impl_glfw.h ├── imgui_impl_opengl3.cpp ├── imgui_impl_opengl3.h ├── imgui_impl_opengl3_loader.h ├── imgui_internal.h ├── imgui_tables.cpp ├── imgui_widgets.cpp ├── imstb_rectpack.h ├── imstb_textedit.h ├── imstb_truetype.h └── stb_image.h ├── draw.h ├── global.h ├── icon.h ├── knobs ├── imgui-knobs.cpp └── imgui-knobs.h ├── libs └── glfw │ ├── COPYING.txt │ ├── include │ └── GLFW │ │ ├── glfw3.h │ │ └── glfw3native.h │ └── lib-vc2010-64 │ └── glfw3.lib ├── log ├── log.cpp ├── log.h └── log_animation.h ├── main.cpp ├── suspension_ball.vcxproj ├── suspension_ball.vcxproj.filters ├── suspension_ball.vcxproj.user ├── theme ├── Gradient.h └── themes.h └── widget.h /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ImGui_FloatBall 2 | An example of a floating ball for Android and PC 3 | 4 | # License 5 | [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) 6 | -------------------------------------------------------------------------------- /my_example/my_ball.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.2.32630.192 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "suspension_ball", "suspension_ball\suspension_ball.vcxproj", "{6D9EF402-7EF2-44B4-B2EC-E482FE4C7935}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {6D9EF402-7EF2-44B4-B2EC-E482FE4C7935}.Debug|x64.ActiveCfg = Debug|x64 17 | {6D9EF402-7EF2-44B4-B2EC-E482FE4C7935}.Debug|x64.Build.0 = Debug|x64 18 | {6D9EF402-7EF2-44B4-B2EC-E482FE4C7935}.Debug|x86.ActiveCfg = Debug|Win32 19 | {6D9EF402-7EF2-44B4-B2EC-E482FE4C7935}.Debug|x86.Build.0 = Debug|Win32 20 | {6D9EF402-7EF2-44B4-B2EC-E482FE4C7935}.Release|x64.ActiveCfg = Release|x64 21 | {6D9EF402-7EF2-44B4-B2EC-E482FE4C7935}.Release|x64.Build.0 = Release|x64 22 | {6D9EF402-7EF2-44B4-B2EC-E482FE4C7935}.Release|x86.ActiveCfg = Release|Win32 23 | {6D9EF402-7EF2-44B4-B2EC-E482FE4C7935}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {52F954B1-8032-4485-BBD4-E3B7549CB945} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /my_example/suspension_ball/ImGui/font.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalvqw/ImGui_FloatBall/e2e7726965dee0d3721743b35bc8fe7d17eaf7b0/my_example/suspension_ball/ImGui/font.h -------------------------------------------------------------------------------- /my_example/suspension_ball/ImGui/imconfig.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // COMPILE-TIME OPTIONS FOR DEAR IMGUI 3 | // Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure. 4 | // You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions. 5 | //----------------------------------------------------------------------------- 6 | // A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it) 7 | // B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template. 8 | //----------------------------------------------------------------------------- 9 | // You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp 10 | // files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures. 11 | // Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts. 12 | // Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using. 13 | //----------------------------------------------------------------------------- 14 | 15 | #pragma once 16 | 17 | //---- Define assertion handler. Defaults to calling assert(). 18 | // If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement. 19 | //#define IM_ASSERT(_EXPR) MyAssert(_EXPR) 20 | //#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts 21 | 22 | //---- Define attributes of all API symbols declarations, e.g. for DLL under Windows 23 | // Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility. 24 | // DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions() 25 | // for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details. 26 | //#define IMGUI_API __declspec( dllexport ) 27 | //#define IMGUI_API __declspec( dllimport ) 28 | 29 | //---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names. 30 | //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS 31 | //#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions. 32 | 33 | //---- Disable all of Dear ImGui or don't implement standard windows/tools. 34 | // It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp. 35 | //#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty. 36 | //#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. 37 | //#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowStackToolWindow() will be empty (this was called IMGUI_DISABLE_METRICS_WINDOW before 1.88). 38 | 39 | //---- Don't implement some functions to reduce linkage requirements. 40 | //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a) 41 | //#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW) 42 | //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a) 43 | //#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime). 44 | //#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default). 45 | //#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf) 46 | //#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself. 47 | //#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies) 48 | //#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function. 49 | //#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions(). 50 | //#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available 51 | 52 | //---- Include imgui_user.h at the end of imgui.h as a convenience 53 | //#define IMGUI_INCLUDE_IMGUI_USER_H 54 | 55 | //---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another) 56 | //#define IMGUI_USE_BGRA_PACKED_COLOR 57 | 58 | //---- Use 32-bit for ImWchar (default is 16-bit) to support unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...) 59 | //#define IMGUI_USE_WCHAR32 60 | 61 | //---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version 62 | // By default the embedded implementations are declared static and not available outside of Dear ImGui sources files. 63 | //#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h" 64 | //#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h" 65 | //#define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if enabled 66 | //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION 67 | //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION 68 | 69 | //---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined) 70 | // Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by stb_sprintf.h. 71 | //#define IMGUI_USE_STB_SPRINTF 72 | 73 | //---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui) 74 | // Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided). 75 | // On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'. 76 | //#define IMGUI_ENABLE_FREETYPE 77 | 78 | //---- Use stb_truetype to build and rasterize the font atlas (default) 79 | // The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend. 80 | //#define IMGUI_ENABLE_STB_TRUETYPE 81 | 82 | //---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4. 83 | // This will be inlined as part of ImVec2 and ImVec4 class declarations. 84 | /* 85 | #define IM_VEC2_CLASS_EXTRA \ 86 | constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \ 87 | operator MyVec2() const { return MyVec2(x,y); } 88 | 89 | #define IM_VEC4_CLASS_EXTRA \ 90 | constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \ 91 | operator MyVec4() const { return MyVec4(x,y,z,w); } 92 | */ 93 | 94 | //---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices. 95 | // Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices). 96 | // Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer. 97 | // Read about ImGuiBackendFlags_RendererHasVtxOffset for details. 98 | //#define ImDrawIdx unsigned int 99 | 100 | //---- Override ImDrawCallback signature (will need to modify renderer backends accordingly) 101 | //struct ImDrawList; 102 | //struct ImDrawCmd; 103 | //typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data); 104 | //#define ImDrawCallback MyImDrawCallback 105 | 106 | //---- Debug Tools: Macro to break in Debugger 107 | // (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.) 108 | //#define IM_DEBUG_BREAK IM_ASSERT(0) 109 | //#define IM_DEBUG_BREAK __debugbreak() 110 | 111 | //---- Debug Tools: Have the Item Picker break in the ItemAdd() function instead of ItemHoverable(), 112 | // (which comes earlier in the code, will catch a few extra items, allow picking items other than Hovered one.) 113 | // This adds a small runtime cost which is why it is not enabled by default. 114 | //#define IMGUI_DEBUG_TOOL_ITEM_PICKER_EX 115 | 116 | //---- Debug Tools: Enable slower asserts 117 | //#define IMGUI_DEBUG_PARANOID 118 | 119 | //---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files. 120 | /* 121 | namespace ImGui 122 | { 123 | void MyFunction(const char* name, const MyMatrix44& v); 124 | } 125 | */ 126 | -------------------------------------------------------------------------------- /my_example/suspension_ball/ImGui/imgui_impl_glfw.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Backend for GLFW 2 | // This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan, WebGPU..) 3 | // (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) 4 | // (Requires: GLFW 3.1+. Prefer GLFW 3.3+ for full feature support.) 5 | 6 | // Implemented features: 7 | // [X] Platform: Clipboard support. 8 | // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] 9 | // [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 10 | // [x] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+). 11 | // [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. 12 | 13 | // Issues: 14 | // [ ] Platform: Multi-viewport support: ParentViewportID not honored, and so io.ConfigViewportsNoDefaultParent has no effect (minor). 15 | 16 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 17 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 18 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 19 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 20 | 21 | #pragma once 22 | #include "imgui.h" // IMGUI_IMPL_API 23 | 24 | struct GLFWwindow; 25 | struct GLFWmonitor; 26 | 27 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks); 28 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks); 29 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool install_callbacks); 30 | IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown(); 31 | IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame(); 32 | 33 | // GLFW callbacks (installer) 34 | // - When calling Init with 'install_callbacks=true': ImGui_ImplGlfw_InstallCallbacks() is called. GLFW callbacks will be installed for you. They will chain-call user's previously installed callbacks, if any. 35 | // - When calling Init with 'install_callbacks=false': GLFW callbacks won't be installed. You will need to call individual function yourself from your own GLFW callbacks. 36 | IMGUI_IMPL_API void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window); 37 | IMGUI_IMPL_API void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window); 38 | 39 | // GLFW callbacks (individual callbacks to call if you didn't install callbacks) 40 | IMGUI_IMPL_API void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused); // Since 1.84 41 | IMGUI_IMPL_API void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered); // Since 1.84 42 | IMGUI_IMPL_API void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y); // Since 1.87 43 | IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods); 44 | IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset); 45 | IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); 46 | IMGUI_IMPL_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c); 47 | IMGUI_IMPL_API void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor* monitor, int event); 48 | -------------------------------------------------------------------------------- /my_example/suspension_ball/ImGui/imgui_impl_opengl3.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for modern OpenGL with shaders / programmatic pipeline 2 | // - Desktop GL: 2.x 3.x 4.x 3 | // - Embedded GL: ES 2.0 (WebGL 1.0), ES 3.0 (WebGL 2.0) 4 | // This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..) 5 | 6 | // Implemented features: 7 | // [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID! 8 | // [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. 9 | // [x] Renderer: Large meshes support (64k+ vertices) with 16-bit indices (Desktop OpenGL only). 10 | 11 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 12 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 13 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 14 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 15 | 16 | // About GLSL version: 17 | // The 'glsl_version' initialization parameter should be nullptr (default) or a "#version XXX" string. 18 | // On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es" 19 | // Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp. 20 | 21 | #pragma once 22 | #include "imgui.h" // IMGUI_IMPL_API 23 | 24 | // Backend API 25 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = nullptr); 26 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown(); 27 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame(); 28 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data); 29 | 30 | // (Optional) Called by Init/NewFrame/Shutdown 31 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture(); 32 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyFontsTexture(); 33 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects(); 34 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects(); 35 | 36 | // Specific OpenGL ES versions 37 | //#define IMGUI_IMPL_OPENGL_ES2 // Auto-detected on Emscripten 38 | //#define IMGUI_IMPL_OPENGL_ES3 // Auto-detected on iOS/Android 39 | 40 | // You can explicitly select GLES2 or GLES3 API by using one of the '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line. 41 | #if !defined(IMGUI_IMPL_OPENGL_ES2) \ 42 | && !defined(IMGUI_IMPL_OPENGL_ES3) 43 | 44 | // Try to detect GLES on matching platforms 45 | #if defined(__APPLE__) 46 | #include 47 | #endif 48 | #if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__)) 49 | #define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es" 50 | #elif defined(__EMSCRIPTEN__) || defined(__amigaos4__) 51 | #define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100" 52 | #else 53 | // Otherwise imgui_impl_opengl3_loader.h will be used. 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /my_example/suspension_ball/ImGui/imgui_impl_opengl3_loader.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // About imgui_impl_opengl3_loader.h: 3 | // 4 | // We embed our own OpenGL loader to not require user to provide their own or to have to use ours, 5 | // which proved to be endless problems for users. 6 | // Our loader is custom-generated, based on gl3w but automatically filtered to only include 7 | // enums/functions that we use in our imgui_impl_opengl3.cpp source file in order to be small. 8 | // 9 | // YOU SHOULD NOT NEED TO INCLUDE/USE THIS DIRECTLY. THIS IS USED BY imgui_impl_opengl3.cpp ONLY. 10 | // THE REST OF YOUR APP SHOULD USE A DIFFERENT GL LOADER: ANY GL LOADER OF YOUR CHOICE. 11 | // 12 | // IF YOU GET BUILD ERRORS IN THIS FILE (commonly macro redefinitions or function redefinitions): 13 | // IT LIKELY MEANS THAT YOU ARE BUILDING 'imgui_impl_opengl3.cpp' OR INCUDING 'imgui_impl_opengl3_loader.h' 14 | // IN THE SAME COMPILATION UNIT AS ONE OF YOUR FILE WHICH IS USING A THIRD-PARTY OPENGL LOADER. 15 | // (e.g. COULD HAPPEN IF YOU ARE DOING A UNITY/JUMBO BUILD, OR INCLUDING .CPP FILES FROM OTHERS) 16 | // YOU SHOULD NOT BUILD BOTH IN THE SAME COMPILATION UNIT. 17 | // BUT IF YOU REALLY WANT TO, you can '#define IMGUI_IMPL_OPENGL_LOADER_CUSTOM' and imgui_impl_opengl3.cpp 18 | // WILL NOT BE USING OUR LOADER, AND INSTEAD EXPECT ANOTHER/YOUR LOADER TO BE AVAILABLE IN THE COMPILATION UNIT. 19 | // 20 | // Regenerate with: 21 | // python gl3w_gen.py --output ../imgui/backends/imgui_impl_opengl3_loader.h --ref ../imgui/backends/imgui_impl_opengl3.cpp ./extra_symbols.txt 22 | // 23 | // More info: 24 | // https://github.com/dearimgui/gl3w_stripped 25 | // https://github.com/ocornut/imgui/issues/4445 26 | //----------------------------------------------------------------------------- 27 | 28 | /* 29 | * This file was generated with gl3w_gen.py, part of imgl3w 30 | * (hosted at https://github.com/dearimgui/gl3w_stripped) 31 | * 32 | * This is free and unencumbered software released into the public domain. 33 | * 34 | * Anyone is free to copy, modify, publish, use, compile, sell, or 35 | * distribute this software, either in source code form or as a compiled 36 | * binary, for any purpose, commercial or non-commercial, and by any 37 | * means. 38 | * 39 | * In jurisdictions that recognize copyright laws, the author or authors 40 | * of this software dedicate any and all copyright interest in the 41 | * software to the public domain. We make this dedication for the benefit 42 | * of the public at large and to the detriment of our heirs and 43 | * successors. We intend this dedication to be an overt act of 44 | * relinquishment in perpetuity of all present and future rights to this 45 | * software under copyright law. 46 | * 47 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 48 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 49 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 50 | * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 51 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 52 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 53 | * OTHER DEALINGS IN THE SOFTWARE. 54 | */ 55 | 56 | #ifndef __gl3w_h_ 57 | #define __gl3w_h_ 58 | 59 | // Adapted from KHR/khrplatform.h to avoid including entire file. 60 | #ifndef __khrplatform_h_ 61 | typedef float khronos_float_t; 62 | typedef signed char khronos_int8_t; 63 | typedef unsigned char khronos_uint8_t; 64 | typedef signed short int khronos_int16_t; 65 | typedef unsigned short int khronos_uint16_t; 66 | #ifdef _WIN64 67 | typedef signed long long int khronos_intptr_t; 68 | typedef signed long long int khronos_ssize_t; 69 | #else 70 | typedef signed long int khronos_intptr_t; 71 | typedef signed long int khronos_ssize_t; 72 | #endif 73 | 74 | #if defined(_MSC_VER) && !defined(__clang__) 75 | typedef signed __int64 khronos_int64_t; 76 | typedef unsigned __int64 khronos_uint64_t; 77 | #elif (defined(__clang__) || defined(__GNUC__)) && (__cplusplus < 201100) 78 | #include 79 | typedef int64_t khronos_int64_t; 80 | typedef uint64_t khronos_uint64_t; 81 | #else 82 | typedef signed long long khronos_int64_t; 83 | typedef unsigned long long khronos_uint64_t; 84 | #endif 85 | #endif // __khrplatform_h_ 86 | 87 | #ifndef __gl_glcorearb_h_ 88 | #define __gl_glcorearb_h_ 1 89 | #ifdef __cplusplus 90 | extern "C" { 91 | #endif 92 | /* 93 | ** Copyright 2013-2020 The Khronos Group Inc. 94 | ** SPDX-License-Identifier: MIT 95 | ** 96 | ** This header is generated from the Khronos OpenGL / OpenGL ES XML 97 | ** API Registry. The current version of the Registry, generator scripts 98 | ** used to make the header, and the header can be found at 99 | ** https://github.com/KhronosGroup/OpenGL-Registry 100 | */ 101 | #if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) 102 | #ifndef WIN32_LEAN_AND_MEAN 103 | #define WIN32_LEAN_AND_MEAN 1 104 | #endif 105 | #include 106 | #endif 107 | #ifndef APIENTRY 108 | #define APIENTRY 109 | #endif 110 | #ifndef APIENTRYP 111 | #define APIENTRYP APIENTRY * 112 | #endif 113 | #ifndef GLAPI 114 | #define GLAPI extern 115 | #endif 116 | /* glcorearb.h is for use with OpenGL core profile implementations. 117 | ** It should should be placed in the same directory as gl.h and 118 | ** included as . 119 | ** 120 | ** glcorearb.h includes only APIs in the latest OpenGL core profile 121 | ** implementation together with APIs in newer ARB extensions which 122 | ** can be supported by the core profile. It does not, and never will 123 | ** include functionality removed from the core profile, such as 124 | ** fixed-function vertex and fragment processing. 125 | ** 126 | ** Do not #include both and either of or 127 | ** in the same source file. 128 | */ 129 | /* Generated C header for: 130 | * API: gl 131 | * Profile: core 132 | * Versions considered: .* 133 | * Versions emitted: .* 134 | * Default extensions included: glcore 135 | * Additional extensions included: _nomatch_^ 136 | * Extensions removed: _nomatch_^ 137 | */ 138 | #ifndef GL_VERSION_1_0 139 | typedef void GLvoid; 140 | typedef unsigned int GLenum; 141 | 142 | typedef khronos_float_t GLfloat; 143 | typedef int GLint; 144 | typedef int GLsizei; 145 | typedef unsigned int GLbitfield; 146 | typedef double GLdouble; 147 | typedef unsigned int GLuint; 148 | typedef unsigned char GLboolean; 149 | typedef khronos_uint8_t GLubyte; 150 | #define GL_COLOR_BUFFER_BIT 0x00004000 151 | #define GL_FALSE 0 152 | #define GL_TRUE 1 153 | #define GL_TRIANGLES 0x0004 154 | #define GL_ONE 1 155 | #define GL_SRC_ALPHA 0x0302 156 | #define GL_ONE_MINUS_SRC_ALPHA 0x0303 157 | #define GL_FRONT_AND_BACK 0x0408 158 | #define GL_POLYGON_MODE 0x0B40 159 | #define GL_CULL_FACE 0x0B44 160 | #define GL_DEPTH_TEST 0x0B71 161 | #define GL_STENCIL_TEST 0x0B90 162 | #define GL_VIEWPORT 0x0BA2 163 | #define GL_BLEND 0x0BE2 164 | #define GL_SCISSOR_BOX 0x0C10 165 | #define GL_SCISSOR_TEST 0x0C11 166 | #define GL_UNPACK_ROW_LENGTH 0x0CF2 167 | #define GL_PACK_ALIGNMENT 0x0D05 168 | #define GL_TEXTURE_2D 0x0DE1 169 | #define GL_UNSIGNED_BYTE 0x1401 170 | #define GL_UNSIGNED_SHORT 0x1403 171 | #define GL_UNSIGNED_INT 0x1405 172 | #define GL_FLOAT 0x1406 173 | #define GL_RGBA 0x1908 174 | #define GL_FILL 0x1B02 175 | #define GL_VENDOR 0x1F00 176 | #define GL_RENDERER 0x1F01 177 | #define GL_VERSION 0x1F02 178 | #define GL_EXTENSIONS 0x1F03 179 | #define GL_LINEAR 0x2601 180 | #define GL_TEXTURE_MAG_FILTER 0x2800 181 | #define GL_TEXTURE_MIN_FILTER 0x2801 182 | typedef void (APIENTRYP PFNGLPOLYGONMODEPROC) (GLenum face, GLenum mode); 183 | typedef void (APIENTRYP PFNGLSCISSORPROC) (GLint x, GLint y, GLsizei width, GLsizei height); 184 | typedef void (APIENTRYP PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param); 185 | typedef void (APIENTRYP PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels); 186 | typedef void (APIENTRYP PFNGLCLEARPROC) (GLbitfield mask); 187 | typedef void (APIENTRYP PFNGLCLEARCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); 188 | typedef void (APIENTRYP PFNGLDISABLEPROC) (GLenum cap); 189 | typedef void (APIENTRYP PFNGLENABLEPROC) (GLenum cap); 190 | typedef void (APIENTRYP PFNGLFLUSHPROC) (void); 191 | typedef void (APIENTRYP PFNGLPIXELSTOREIPROC) (GLenum pname, GLint param); 192 | typedef void (APIENTRYP PFNGLREADPIXELSPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels); 193 | typedef GLenum (APIENTRYP PFNGLGETERRORPROC) (void); 194 | typedef void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *data); 195 | typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGPROC) (GLenum name); 196 | typedef GLboolean (APIENTRYP PFNGLISENABLEDPROC) (GLenum cap); 197 | typedef void (APIENTRYP PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height); 198 | #ifdef GL_GLEXT_PROTOTYPES 199 | GLAPI void APIENTRY glPolygonMode (GLenum face, GLenum mode); 200 | GLAPI void APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height); 201 | GLAPI void APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param); 202 | GLAPI void APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels); 203 | GLAPI void APIENTRY glClear (GLbitfield mask); 204 | GLAPI void APIENTRY glClearColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); 205 | GLAPI void APIENTRY glDisable (GLenum cap); 206 | GLAPI void APIENTRY glEnable (GLenum cap); 207 | GLAPI void APIENTRY glFlush (void); 208 | GLAPI void APIENTRY glPixelStorei (GLenum pname, GLint param); 209 | GLAPI void APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels); 210 | GLAPI GLenum APIENTRY glGetError (void); 211 | GLAPI void APIENTRY glGetIntegerv (GLenum pname, GLint *data); 212 | GLAPI const GLubyte *APIENTRY glGetString (GLenum name); 213 | GLAPI GLboolean APIENTRY glIsEnabled (GLenum cap); 214 | GLAPI void APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height); 215 | #endif 216 | #endif /* GL_VERSION_1_0 */ 217 | #ifndef GL_VERSION_1_1 218 | typedef khronos_float_t GLclampf; 219 | typedef double GLclampd; 220 | #define GL_TEXTURE_BINDING_2D 0x8069 221 | typedef void (APIENTRYP PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices); 222 | typedef void (APIENTRYP PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture); 223 | typedef void (APIENTRYP PFNGLDELETETEXTURESPROC) (GLsizei n, const GLuint *textures); 224 | typedef void (APIENTRYP PFNGLGENTEXTURESPROC) (GLsizei n, GLuint *textures); 225 | #ifdef GL_GLEXT_PROTOTYPES 226 | GLAPI void APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const void *indices); 227 | GLAPI void APIENTRY glBindTexture (GLenum target, GLuint texture); 228 | GLAPI void APIENTRY glDeleteTextures (GLsizei n, const GLuint *textures); 229 | GLAPI void APIENTRY glGenTextures (GLsizei n, GLuint *textures); 230 | #endif 231 | #endif /* GL_VERSION_1_1 */ 232 | #ifndef GL_VERSION_1_3 233 | #define GL_TEXTURE0 0x84C0 234 | #define GL_ACTIVE_TEXTURE 0x84E0 235 | typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); 236 | #ifdef GL_GLEXT_PROTOTYPES 237 | GLAPI void APIENTRY glActiveTexture (GLenum texture); 238 | #endif 239 | #endif /* GL_VERSION_1_3 */ 240 | #ifndef GL_VERSION_1_4 241 | #define GL_BLEND_DST_RGB 0x80C8 242 | #define GL_BLEND_SRC_RGB 0x80C9 243 | #define GL_BLEND_DST_ALPHA 0x80CA 244 | #define GL_BLEND_SRC_ALPHA 0x80CB 245 | #define GL_FUNC_ADD 0x8006 246 | typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); 247 | typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode); 248 | #ifdef GL_GLEXT_PROTOTYPES 249 | GLAPI void APIENTRY glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); 250 | GLAPI void APIENTRY glBlendEquation (GLenum mode); 251 | #endif 252 | #endif /* GL_VERSION_1_4 */ 253 | #ifndef GL_VERSION_1_5 254 | typedef khronos_ssize_t GLsizeiptr; 255 | typedef khronos_intptr_t GLintptr; 256 | #define GL_ARRAY_BUFFER 0x8892 257 | #define GL_ELEMENT_ARRAY_BUFFER 0x8893 258 | #define GL_ARRAY_BUFFER_BINDING 0x8894 259 | #define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 260 | #define GL_STREAM_DRAW 0x88E0 261 | typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer); 262 | typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers); 263 | typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers); 264 | typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const void *data, GLenum usage); 265 | typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const void *data); 266 | #ifdef GL_GLEXT_PROTOTYPES 267 | GLAPI void APIENTRY glBindBuffer (GLenum target, GLuint buffer); 268 | GLAPI void APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers); 269 | GLAPI void APIENTRY glGenBuffers (GLsizei n, GLuint *buffers); 270 | GLAPI void APIENTRY glBufferData (GLenum target, GLsizeiptr size, const void *data, GLenum usage); 271 | GLAPI void APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const void *data); 272 | #endif 273 | #endif /* GL_VERSION_1_5 */ 274 | #ifndef GL_VERSION_2_0 275 | typedef char GLchar; 276 | typedef khronos_int16_t GLshort; 277 | typedef khronos_int8_t GLbyte; 278 | typedef khronos_uint16_t GLushort; 279 | #define GL_BLEND_EQUATION_RGB 0x8009 280 | #define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 281 | #define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 282 | #define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 283 | #define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 284 | #define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 285 | #define GL_BLEND_EQUATION_ALPHA 0x883D 286 | #define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A 287 | #define GL_FRAGMENT_SHADER 0x8B30 288 | #define GL_VERTEX_SHADER 0x8B31 289 | #define GL_COMPILE_STATUS 0x8B81 290 | #define GL_LINK_STATUS 0x8B82 291 | #define GL_INFO_LOG_LENGTH 0x8B84 292 | #define GL_CURRENT_PROGRAM 0x8B8D 293 | #define GL_UPPER_LEFT 0x8CA2 294 | typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha); 295 | typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader); 296 | typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader); 297 | typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void); 298 | typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type); 299 | typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program); 300 | typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader); 301 | typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader); 302 | typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index); 303 | typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index); 304 | typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name); 305 | typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params); 306 | typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); 307 | typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params); 308 | typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); 309 | typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name); 310 | typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params); 311 | typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, void **pointer); 312 | typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program); 313 | typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length); 314 | typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program); 315 | typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0); 316 | typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); 317 | typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer); 318 | #ifdef GL_GLEXT_PROTOTYPES 319 | GLAPI void APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha); 320 | GLAPI void APIENTRY glAttachShader (GLuint program, GLuint shader); 321 | GLAPI void APIENTRY glCompileShader (GLuint shader); 322 | GLAPI GLuint APIENTRY glCreateProgram (void); 323 | GLAPI GLuint APIENTRY glCreateShader (GLenum type); 324 | GLAPI void APIENTRY glDeleteProgram (GLuint program); 325 | GLAPI void APIENTRY glDeleteShader (GLuint shader); 326 | GLAPI void APIENTRY glDetachShader (GLuint program, GLuint shader); 327 | GLAPI void APIENTRY glDisableVertexAttribArray (GLuint index); 328 | GLAPI void APIENTRY glEnableVertexAttribArray (GLuint index); 329 | GLAPI GLint APIENTRY glGetAttribLocation (GLuint program, const GLchar *name); 330 | GLAPI void APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint *params); 331 | GLAPI void APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); 332 | GLAPI void APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint *params); 333 | GLAPI void APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); 334 | GLAPI GLint APIENTRY glGetUniformLocation (GLuint program, const GLchar *name); 335 | GLAPI void APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint *params); 336 | GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, void **pointer); 337 | GLAPI void APIENTRY glLinkProgram (GLuint program); 338 | GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length); 339 | GLAPI void APIENTRY glUseProgram (GLuint program); 340 | GLAPI void APIENTRY glUniform1i (GLint location, GLint v0); 341 | GLAPI void APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); 342 | GLAPI void APIENTRY glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer); 343 | #endif 344 | #endif /* GL_VERSION_2_0 */ 345 | #ifndef GL_VERSION_3_0 346 | typedef khronos_uint16_t GLhalf; 347 | #define GL_MAJOR_VERSION 0x821B 348 | #define GL_MINOR_VERSION 0x821C 349 | #define GL_NUM_EXTENSIONS 0x821D 350 | #define GL_FRAMEBUFFER_SRGB 0x8DB9 351 | #define GL_VERTEX_ARRAY_BINDING 0x85B5 352 | typedef void (APIENTRYP PFNGLGETBOOLEANI_VPROC) (GLenum target, GLuint index, GLboolean *data); 353 | typedef void (APIENTRYP PFNGLGETINTEGERI_VPROC) (GLenum target, GLuint index, GLint *data); 354 | typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint index); 355 | typedef void (APIENTRYP PFNGLBINDVERTEXARRAYPROC) (GLuint array); 356 | typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint *arrays); 357 | typedef void (APIENTRYP PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays); 358 | #ifdef GL_GLEXT_PROTOTYPES 359 | GLAPI const GLubyte *APIENTRY glGetStringi (GLenum name, GLuint index); 360 | GLAPI void APIENTRY glBindVertexArray (GLuint array); 361 | GLAPI void APIENTRY glDeleteVertexArrays (GLsizei n, const GLuint *arrays); 362 | GLAPI void APIENTRY glGenVertexArrays (GLsizei n, GLuint *arrays); 363 | #endif 364 | #endif /* GL_VERSION_3_0 */ 365 | #ifndef GL_VERSION_3_1 366 | #define GL_VERSION_3_1 1 367 | #define GL_PRIMITIVE_RESTART 0x8F9D 368 | #endif /* GL_VERSION_3_1 */ 369 | #ifndef GL_VERSION_3_2 370 | #define GL_VERSION_3_2 1 371 | typedef struct __GLsync *GLsync; 372 | typedef khronos_uint64_t GLuint64; 373 | typedef khronos_int64_t GLint64; 374 | typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex); 375 | typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data); 376 | #ifdef GL_GLEXT_PROTOTYPES 377 | GLAPI void APIENTRY glDrawElementsBaseVertex (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex); 378 | #endif 379 | #endif /* GL_VERSION_3_2 */ 380 | #ifndef GL_VERSION_3_3 381 | #define GL_VERSION_3_3 1 382 | #define GL_SAMPLER_BINDING 0x8919 383 | typedef void (APIENTRYP PFNGLBINDSAMPLERPROC) (GLuint unit, GLuint sampler); 384 | #ifdef GL_GLEXT_PROTOTYPES 385 | GLAPI void APIENTRY glBindSampler (GLuint unit, GLuint sampler); 386 | #endif 387 | #endif /* GL_VERSION_3_3 */ 388 | #ifndef GL_VERSION_4_1 389 | typedef void (APIENTRYP PFNGLGETFLOATI_VPROC) (GLenum target, GLuint index, GLfloat *data); 390 | typedef void (APIENTRYP PFNGLGETDOUBLEI_VPROC) (GLenum target, GLuint index, GLdouble *data); 391 | #endif /* GL_VERSION_4_1 */ 392 | #ifndef GL_VERSION_4_3 393 | typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam); 394 | #endif /* GL_VERSION_4_3 */ 395 | #ifndef GL_VERSION_4_5 396 | #define GL_CLIP_ORIGIN 0x935C 397 | typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKI_VPROC) (GLuint xfb, GLenum pname, GLuint index, GLint *param); 398 | typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKI64_VPROC) (GLuint xfb, GLenum pname, GLuint index, GLint64 *param); 399 | #endif /* GL_VERSION_4_5 */ 400 | #ifndef GL_ARB_bindless_texture 401 | typedef khronos_uint64_t GLuint64EXT; 402 | #endif /* GL_ARB_bindless_texture */ 403 | #ifndef GL_ARB_cl_event 404 | struct _cl_context; 405 | struct _cl_event; 406 | #endif /* GL_ARB_cl_event */ 407 | #ifndef GL_ARB_clip_control 408 | #define GL_ARB_clip_control 1 409 | #endif /* GL_ARB_clip_control */ 410 | #ifndef GL_ARB_debug_output 411 | typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam); 412 | #endif /* GL_ARB_debug_output */ 413 | #ifndef GL_EXT_EGL_image_storage 414 | typedef void *GLeglImageOES; 415 | #endif /* GL_EXT_EGL_image_storage */ 416 | #ifndef GL_EXT_direct_state_access 417 | typedef void (APIENTRYP PFNGLGETFLOATI_VEXTPROC) (GLenum pname, GLuint index, GLfloat *params); 418 | typedef void (APIENTRYP PFNGLGETDOUBLEI_VEXTPROC) (GLenum pname, GLuint index, GLdouble *params); 419 | typedef void (APIENTRYP PFNGLGETPOINTERI_VEXTPROC) (GLenum pname, GLuint index, void **params); 420 | typedef void (APIENTRYP PFNGLGETVERTEXARRAYINTEGERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, GLint *param); 421 | typedef void (APIENTRYP PFNGLGETVERTEXARRAYPOINTERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, void **param); 422 | #endif /* GL_EXT_direct_state_access */ 423 | #ifndef GL_NV_draw_vulkan_image 424 | typedef void (APIENTRY *GLVULKANPROCNV)(void); 425 | #endif /* GL_NV_draw_vulkan_image */ 426 | #ifndef GL_NV_gpu_shader5 427 | typedef khronos_int64_t GLint64EXT; 428 | #endif /* GL_NV_gpu_shader5 */ 429 | #ifndef GL_NV_vertex_buffer_unified_memory 430 | typedef void (APIENTRYP PFNGLGETINTEGERUI64I_VNVPROC) (GLenum value, GLuint index, GLuint64EXT *result); 431 | #endif /* GL_NV_vertex_buffer_unified_memory */ 432 | #ifdef __cplusplus 433 | } 434 | #endif 435 | #endif 436 | 437 | #ifndef GL3W_API 438 | #define GL3W_API 439 | #endif 440 | 441 | #ifndef __gl_h_ 442 | #define __gl_h_ 443 | #endif 444 | 445 | #ifdef __cplusplus 446 | extern "C" { 447 | #endif 448 | 449 | #define GL3W_OK 0 450 | #define GL3W_ERROR_INIT -1 451 | #define GL3W_ERROR_LIBRARY_OPEN -2 452 | #define GL3W_ERROR_OPENGL_VERSION -3 453 | 454 | typedef void (*GL3WglProc)(void); 455 | typedef GL3WglProc (*GL3WGetProcAddressProc)(const char *proc); 456 | 457 | /* gl3w api */ 458 | GL3W_API int imgl3wInit(void); 459 | GL3W_API int imgl3wInit2(GL3WGetProcAddressProc proc); 460 | GL3W_API int imgl3wIsSupported(int major, int minor); 461 | GL3W_API GL3WglProc imgl3wGetProcAddress(const char *proc); 462 | 463 | /* gl3w internal state */ 464 | union GL3WProcs { 465 | GL3WglProc ptr[58]; 466 | struct { 467 | PFNGLACTIVETEXTUREPROC ActiveTexture; 468 | PFNGLATTACHSHADERPROC AttachShader; 469 | PFNGLBINDBUFFERPROC BindBuffer; 470 | PFNGLBINDSAMPLERPROC BindSampler; 471 | PFNGLBINDTEXTUREPROC BindTexture; 472 | PFNGLBINDVERTEXARRAYPROC BindVertexArray; 473 | PFNGLBLENDEQUATIONPROC BlendEquation; 474 | PFNGLBLENDEQUATIONSEPARATEPROC BlendEquationSeparate; 475 | PFNGLBLENDFUNCSEPARATEPROC BlendFuncSeparate; 476 | PFNGLBUFFERDATAPROC BufferData; 477 | PFNGLBUFFERSUBDATAPROC BufferSubData; 478 | PFNGLCLEARPROC Clear; 479 | PFNGLCLEARCOLORPROC ClearColor; 480 | PFNGLCOMPILESHADERPROC CompileShader; 481 | PFNGLCREATEPROGRAMPROC CreateProgram; 482 | PFNGLCREATESHADERPROC CreateShader; 483 | PFNGLDELETEBUFFERSPROC DeleteBuffers; 484 | PFNGLDELETEPROGRAMPROC DeleteProgram; 485 | PFNGLDELETESHADERPROC DeleteShader; 486 | PFNGLDELETETEXTURESPROC DeleteTextures; 487 | PFNGLDELETEVERTEXARRAYSPROC DeleteVertexArrays; 488 | PFNGLDETACHSHADERPROC DetachShader; 489 | PFNGLDISABLEPROC Disable; 490 | PFNGLDISABLEVERTEXATTRIBARRAYPROC DisableVertexAttribArray; 491 | PFNGLDRAWELEMENTSPROC DrawElements; 492 | PFNGLDRAWELEMENTSBASEVERTEXPROC DrawElementsBaseVertex; 493 | PFNGLENABLEPROC Enable; 494 | PFNGLENABLEVERTEXATTRIBARRAYPROC EnableVertexAttribArray; 495 | PFNGLFLUSHPROC Flush; 496 | PFNGLGENBUFFERSPROC GenBuffers; 497 | PFNGLGENTEXTURESPROC GenTextures; 498 | PFNGLGENVERTEXARRAYSPROC GenVertexArrays; 499 | PFNGLGETATTRIBLOCATIONPROC GetAttribLocation; 500 | PFNGLGETERRORPROC GetError; 501 | PFNGLGETINTEGERVPROC GetIntegerv; 502 | PFNGLGETPROGRAMINFOLOGPROC GetProgramInfoLog; 503 | PFNGLGETPROGRAMIVPROC GetProgramiv; 504 | PFNGLGETSHADERINFOLOGPROC GetShaderInfoLog; 505 | PFNGLGETSHADERIVPROC GetShaderiv; 506 | PFNGLGETSTRINGPROC GetString; 507 | PFNGLGETSTRINGIPROC GetStringi; 508 | PFNGLGETUNIFORMLOCATIONPROC GetUniformLocation; 509 | PFNGLGETVERTEXATTRIBPOINTERVPROC GetVertexAttribPointerv; 510 | PFNGLGETVERTEXATTRIBIVPROC GetVertexAttribiv; 511 | PFNGLISENABLEDPROC IsEnabled; 512 | PFNGLLINKPROGRAMPROC LinkProgram; 513 | PFNGLPIXELSTOREIPROC PixelStorei; 514 | PFNGLPOLYGONMODEPROC PolygonMode; 515 | PFNGLREADPIXELSPROC ReadPixels; 516 | PFNGLSCISSORPROC Scissor; 517 | PFNGLSHADERSOURCEPROC ShaderSource; 518 | PFNGLTEXIMAGE2DPROC TexImage2D; 519 | PFNGLTEXPARAMETERIPROC TexParameteri; 520 | PFNGLUNIFORM1IPROC Uniform1i; 521 | PFNGLUNIFORMMATRIX4FVPROC UniformMatrix4fv; 522 | PFNGLUSEPROGRAMPROC UseProgram; 523 | PFNGLVERTEXATTRIBPOINTERPROC VertexAttribPointer; 524 | PFNGLVIEWPORTPROC Viewport; 525 | } gl; 526 | }; 527 | 528 | GL3W_API extern union GL3WProcs imgl3wProcs; 529 | 530 | /* OpenGL functions */ 531 | #define glActiveTexture imgl3wProcs.gl.ActiveTexture 532 | #define glAttachShader imgl3wProcs.gl.AttachShader 533 | #define glBindBuffer imgl3wProcs.gl.BindBuffer 534 | #define glBindSampler imgl3wProcs.gl.BindSampler 535 | #define glBindTexture imgl3wProcs.gl.BindTexture 536 | #define glBindVertexArray imgl3wProcs.gl.BindVertexArray 537 | #define glBlendEquation imgl3wProcs.gl.BlendEquation 538 | #define glBlendEquationSeparate imgl3wProcs.gl.BlendEquationSeparate 539 | #define glBlendFuncSeparate imgl3wProcs.gl.BlendFuncSeparate 540 | #define glBufferData imgl3wProcs.gl.BufferData 541 | #define glBufferSubData imgl3wProcs.gl.BufferSubData 542 | #define glClear imgl3wProcs.gl.Clear 543 | #define glClearColor imgl3wProcs.gl.ClearColor 544 | #define glCompileShader imgl3wProcs.gl.CompileShader 545 | #define glCreateProgram imgl3wProcs.gl.CreateProgram 546 | #define glCreateShader imgl3wProcs.gl.CreateShader 547 | #define glDeleteBuffers imgl3wProcs.gl.DeleteBuffers 548 | #define glDeleteProgram imgl3wProcs.gl.DeleteProgram 549 | #define glDeleteShader imgl3wProcs.gl.DeleteShader 550 | #define glDeleteTextures imgl3wProcs.gl.DeleteTextures 551 | #define glDeleteVertexArrays imgl3wProcs.gl.DeleteVertexArrays 552 | #define glDetachShader imgl3wProcs.gl.DetachShader 553 | #define glDisable imgl3wProcs.gl.Disable 554 | #define glDisableVertexAttribArray imgl3wProcs.gl.DisableVertexAttribArray 555 | #define glDrawElements imgl3wProcs.gl.DrawElements 556 | #define glDrawElementsBaseVertex imgl3wProcs.gl.DrawElementsBaseVertex 557 | #define glEnable imgl3wProcs.gl.Enable 558 | #define glEnableVertexAttribArray imgl3wProcs.gl.EnableVertexAttribArray 559 | #define glFlush imgl3wProcs.gl.Flush 560 | #define glGenBuffers imgl3wProcs.gl.GenBuffers 561 | #define glGenTextures imgl3wProcs.gl.GenTextures 562 | #define glGenVertexArrays imgl3wProcs.gl.GenVertexArrays 563 | #define glGetAttribLocation imgl3wProcs.gl.GetAttribLocation 564 | #define glGetError imgl3wProcs.gl.GetError 565 | #define glGetIntegerv imgl3wProcs.gl.GetIntegerv 566 | #define glGetProgramInfoLog imgl3wProcs.gl.GetProgramInfoLog 567 | #define glGetProgramiv imgl3wProcs.gl.GetProgramiv 568 | #define glGetShaderInfoLog imgl3wProcs.gl.GetShaderInfoLog 569 | #define glGetShaderiv imgl3wProcs.gl.GetShaderiv 570 | #define glGetString imgl3wProcs.gl.GetString 571 | #define glGetStringi imgl3wProcs.gl.GetStringi 572 | #define glGetUniformLocation imgl3wProcs.gl.GetUniformLocation 573 | #define glGetVertexAttribPointerv imgl3wProcs.gl.GetVertexAttribPointerv 574 | #define glGetVertexAttribiv imgl3wProcs.gl.GetVertexAttribiv 575 | #define glIsEnabled imgl3wProcs.gl.IsEnabled 576 | #define glLinkProgram imgl3wProcs.gl.LinkProgram 577 | #define glPixelStorei imgl3wProcs.gl.PixelStorei 578 | #define glPolygonMode imgl3wProcs.gl.PolygonMode 579 | #define glReadPixels imgl3wProcs.gl.ReadPixels 580 | #define glScissor imgl3wProcs.gl.Scissor 581 | #define glShaderSource imgl3wProcs.gl.ShaderSource 582 | #define glTexImage2D imgl3wProcs.gl.TexImage2D 583 | #define glTexParameteri imgl3wProcs.gl.TexParameteri 584 | #define glUniform1i imgl3wProcs.gl.Uniform1i 585 | #define glUniformMatrix4fv imgl3wProcs.gl.UniformMatrix4fv 586 | #define glUseProgram imgl3wProcs.gl.UseProgram 587 | #define glVertexAttribPointer imgl3wProcs.gl.VertexAttribPointer 588 | #define glViewport imgl3wProcs.gl.Viewport 589 | 590 | #ifdef __cplusplus 591 | } 592 | #endif 593 | 594 | #endif 595 | 596 | #ifdef IMGL3W_IMPL 597 | #ifdef __cplusplus 598 | extern "C" { 599 | #endif 600 | 601 | #include 602 | 603 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 604 | 605 | #if defined(_WIN32) 606 | #ifndef WIN32_LEAN_AND_MEAN 607 | #define WIN32_LEAN_AND_MEAN 1 608 | #endif 609 | #include 610 | 611 | static HMODULE libgl; 612 | typedef PROC(__stdcall* GL3WglGetProcAddr)(LPCSTR); 613 | static GL3WglGetProcAddr wgl_get_proc_address; 614 | 615 | static int open_libgl(void) 616 | { 617 | libgl = LoadLibraryA("opengl32.dll"); 618 | if (!libgl) 619 | return GL3W_ERROR_LIBRARY_OPEN; 620 | wgl_get_proc_address = (GL3WglGetProcAddr)GetProcAddress(libgl, "wglGetProcAddress"); 621 | return GL3W_OK; 622 | } 623 | 624 | static void close_libgl(void) { FreeLibrary(libgl); } 625 | static GL3WglProc get_proc(const char *proc) 626 | { 627 | GL3WglProc res; 628 | res = (GL3WglProc)wgl_get_proc_address(proc); 629 | if (!res) 630 | res = (GL3WglProc)GetProcAddress(libgl, proc); 631 | return res; 632 | } 633 | #elif defined(__APPLE__) 634 | #include 635 | 636 | static void *libgl; 637 | static int open_libgl(void) 638 | { 639 | libgl = dlopen("/System/Library/Frameworks/OpenGL.framework/OpenGL", RTLD_LAZY | RTLD_LOCAL); 640 | if (!libgl) 641 | return GL3W_ERROR_LIBRARY_OPEN; 642 | return GL3W_OK; 643 | } 644 | 645 | static void close_libgl(void) { dlclose(libgl); } 646 | 647 | static GL3WglProc get_proc(const char *proc) 648 | { 649 | GL3WglProc res; 650 | *(void **)(&res) = dlsym(libgl, proc); 651 | return res; 652 | } 653 | #else 654 | #include 655 | 656 | static void *libgl; 657 | static GL3WglProc (*glx_get_proc_address)(const GLubyte *); 658 | 659 | static int open_libgl(void) 660 | { 661 | libgl = dlopen("libGL.so.1", RTLD_LAZY | RTLD_LOCAL); 662 | if (!libgl) 663 | return GL3W_ERROR_LIBRARY_OPEN; 664 | *(void **)(&glx_get_proc_address) = dlsym(libgl, "glXGetProcAddressARB"); 665 | return GL3W_OK; 666 | } 667 | 668 | static void close_libgl(void) { dlclose(libgl); } 669 | 670 | static GL3WglProc get_proc(const char *proc) 671 | { 672 | GL3WglProc res; 673 | res = glx_get_proc_address((const GLubyte *)proc); 674 | if (!res) 675 | *(void **)(&res) = dlsym(libgl, proc); 676 | return res; 677 | } 678 | #endif 679 | 680 | static struct { int major, minor; } version; 681 | 682 | static int parse_version(void) 683 | { 684 | if (!glGetIntegerv) 685 | return GL3W_ERROR_INIT; 686 | glGetIntegerv(GL_MAJOR_VERSION, &version.major); 687 | glGetIntegerv(GL_MINOR_VERSION, &version.minor); 688 | if (version.major < 3) 689 | return GL3W_ERROR_OPENGL_VERSION; 690 | return GL3W_OK; 691 | } 692 | 693 | static void load_procs(GL3WGetProcAddressProc proc); 694 | 695 | int imgl3wInit(void) 696 | { 697 | int res = open_libgl(); 698 | if (res) 699 | return res; 700 | atexit(close_libgl); 701 | return imgl3wInit2(get_proc); 702 | } 703 | 704 | int imgl3wInit2(GL3WGetProcAddressProc proc) 705 | { 706 | load_procs(proc); 707 | return parse_version(); 708 | } 709 | 710 | int imgl3wIsSupported(int major, int minor) 711 | { 712 | if (major < 3) 713 | return 0; 714 | if (version.major == major) 715 | return version.minor >= minor; 716 | return version.major >= major; 717 | } 718 | 719 | GL3WglProc imgl3wGetProcAddress(const char *proc) { return get_proc(proc); } 720 | 721 | static const char *proc_names[] = { 722 | "glActiveTexture", 723 | "glAttachShader", 724 | "glBindBuffer", 725 | "glBindSampler", 726 | "glBindTexture", 727 | "glBindVertexArray", 728 | "glBlendEquation", 729 | "glBlendEquationSeparate", 730 | "glBlendFuncSeparate", 731 | "glBufferData", 732 | "glBufferSubData", 733 | "glClear", 734 | "glClearColor", 735 | "glCompileShader", 736 | "glCreateProgram", 737 | "glCreateShader", 738 | "glDeleteBuffers", 739 | "glDeleteProgram", 740 | "glDeleteShader", 741 | "glDeleteTextures", 742 | "glDeleteVertexArrays", 743 | "glDetachShader", 744 | "glDisable", 745 | "glDisableVertexAttribArray", 746 | "glDrawElements", 747 | "glDrawElementsBaseVertex", 748 | "glEnable", 749 | "glEnableVertexAttribArray", 750 | "glFlush", 751 | "glGenBuffers", 752 | "glGenTextures", 753 | "glGenVertexArrays", 754 | "glGetAttribLocation", 755 | "glGetError", 756 | "glGetIntegerv", 757 | "glGetProgramInfoLog", 758 | "glGetProgramiv", 759 | "glGetShaderInfoLog", 760 | "glGetShaderiv", 761 | "glGetString", 762 | "glGetStringi", 763 | "glGetUniformLocation", 764 | "glGetVertexAttribPointerv", 765 | "glGetVertexAttribiv", 766 | "glIsEnabled", 767 | "glLinkProgram", 768 | "glPixelStorei", 769 | "glPolygonMode", 770 | "glReadPixels", 771 | "glScissor", 772 | "glShaderSource", 773 | "glTexImage2D", 774 | "glTexParameteri", 775 | "glUniform1i", 776 | "glUniformMatrix4fv", 777 | "glUseProgram", 778 | "glVertexAttribPointer", 779 | "glViewport", 780 | }; 781 | 782 | GL3W_API union GL3WProcs imgl3wProcs; 783 | 784 | static void load_procs(GL3WGetProcAddressProc proc) 785 | { 786 | size_t i; 787 | for (i = 0; i < ARRAY_SIZE(proc_names); i++) 788 | imgl3wProcs.ptr[i] = proc(proc_names[i]); 789 | } 790 | 791 | #ifdef __cplusplus 792 | } 793 | #endif 794 | #endif 795 | -------------------------------------------------------------------------------- /my_example/suspension_ball/ImGui/imstb_rectpack.h: -------------------------------------------------------------------------------- 1 | // [DEAR IMGUI] 2 | // This is a slightly modified version of stb_rect_pack.h 1.01. 3 | // Grep for [DEAR IMGUI] to find the changes. 4 | // 5 | // stb_rect_pack.h - v1.01 - public domain - rectangle packing 6 | // Sean Barrett 2014 7 | // 8 | // Useful for e.g. packing rectangular textures into an atlas. 9 | // Does not do rotation. 10 | // 11 | // Before #including, 12 | // 13 | // #define STB_RECT_PACK_IMPLEMENTATION 14 | // 15 | // in the file that you want to have the implementation. 16 | // 17 | // Not necessarily the awesomest packing method, but better than 18 | // the totally naive one in stb_truetype (which is primarily what 19 | // this is meant to replace). 20 | // 21 | // Has only had a few tests run, may have issues. 22 | // 23 | // More docs to come. 24 | // 25 | // No memory allocations; uses qsort() and assert() from stdlib. 26 | // Can override those by defining STBRP_SORT and STBRP_ASSERT. 27 | // 28 | // This library currently uses the Skyline Bottom-Left algorithm. 29 | // 30 | // Please note: better rectangle packers are welcome! Please 31 | // implement them to the same API, but with a different init 32 | // function. 33 | // 34 | // Credits 35 | // 36 | // Library 37 | // Sean Barrett 38 | // Minor features 39 | // Martins Mozeiko 40 | // github:IntellectualKitty 41 | // 42 | // Bugfixes / warning fixes 43 | // Jeremy Jaussaud 44 | // Fabian Giesen 45 | // 46 | // Version history: 47 | // 48 | // 1.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section 49 | // 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles 50 | // 0.99 (2019-02-07) warning fixes 51 | // 0.11 (2017-03-03) return packing success/fail result 52 | // 0.10 (2016-10-25) remove cast-away-const to avoid warnings 53 | // 0.09 (2016-08-27) fix compiler warnings 54 | // 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0) 55 | // 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0) 56 | // 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort 57 | // 0.05: added STBRP_ASSERT to allow replacing assert 58 | // 0.04: fixed minor bug in STBRP_LARGE_RECTS support 59 | // 0.01: initial release 60 | // 61 | // LICENSE 62 | // 63 | // See end of file for license information. 64 | 65 | ////////////////////////////////////////////////////////////////////////////// 66 | // 67 | // INCLUDE SECTION 68 | // 69 | 70 | #ifndef STB_INCLUDE_STB_RECT_PACK_H 71 | #define STB_INCLUDE_STB_RECT_PACK_H 72 | 73 | #define STB_RECT_PACK_VERSION 1 74 | 75 | #ifdef STBRP_STATIC 76 | #define STBRP_DEF static 77 | #else 78 | #define STBRP_DEF extern 79 | #endif 80 | 81 | #ifdef __cplusplus 82 | extern "C" { 83 | #endif 84 | 85 | typedef struct stbrp_context stbrp_context; 86 | typedef struct stbrp_node stbrp_node; 87 | typedef struct stbrp_rect stbrp_rect; 88 | 89 | typedef int stbrp_coord; 90 | 91 | #define STBRP__MAXVAL 0x7fffffff 92 | // Mostly for internal use, but this is the maximum supported coordinate value. 93 | 94 | STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects); 95 | // Assign packed locations to rectangles. The rectangles are of type 96 | // 'stbrp_rect' defined below, stored in the array 'rects', and there 97 | // are 'num_rects' many of them. 98 | // 99 | // Rectangles which are successfully packed have the 'was_packed' flag 100 | // set to a non-zero value and 'x' and 'y' store the minimum location 101 | // on each axis (i.e. bottom-left in cartesian coordinates, top-left 102 | // if you imagine y increasing downwards). Rectangles which do not fit 103 | // have the 'was_packed' flag set to 0. 104 | // 105 | // You should not try to access the 'rects' array from another thread 106 | // while this function is running, as the function temporarily reorders 107 | // the array while it executes. 108 | // 109 | // To pack into another rectangle, you need to call stbrp_init_target 110 | // again. To continue packing into the same rectangle, you can call 111 | // this function again. Calling this multiple times with multiple rect 112 | // arrays will probably produce worse packing results than calling it 113 | // a single time with the full rectangle array, but the option is 114 | // available. 115 | // 116 | // The function returns 1 if all of the rectangles were successfully 117 | // packed and 0 otherwise. 118 | 119 | struct stbrp_rect 120 | { 121 | // reserved for your use: 122 | int id; 123 | 124 | // input: 125 | stbrp_coord w, h; 126 | 127 | // output: 128 | stbrp_coord x, y; 129 | int was_packed; // non-zero if valid packing 130 | 131 | }; // 16 bytes, nominally 132 | 133 | 134 | STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes); 135 | // Initialize a rectangle packer to: 136 | // pack a rectangle that is 'width' by 'height' in dimensions 137 | // using temporary storage provided by the array 'nodes', which is 'num_nodes' long 138 | // 139 | // You must call this function every time you start packing into a new target. 140 | // 141 | // There is no "shutdown" function. The 'nodes' memory must stay valid for 142 | // the following stbrp_pack_rects() call (or calls), but can be freed after 143 | // the call (or calls) finish. 144 | // 145 | // Note: to guarantee best results, either: 146 | // 1. make sure 'num_nodes' >= 'width' 147 | // or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1' 148 | // 149 | // If you don't do either of the above things, widths will be quantized to multiples 150 | // of small integers to guarantee the algorithm doesn't run out of temporary storage. 151 | // 152 | // If you do #2, then the non-quantized algorithm will be used, but the algorithm 153 | // may run out of temporary storage and be unable to pack some rectangles. 154 | 155 | STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem); 156 | // Optionally call this function after init but before doing any packing to 157 | // change the handling of the out-of-temp-memory scenario, described above. 158 | // If you call init again, this will be reset to the default (false). 159 | 160 | 161 | STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic); 162 | // Optionally select which packing heuristic the library should use. Different 163 | // heuristics will produce better/worse results for different data sets. 164 | // If you call init again, this will be reset to the default. 165 | 166 | enum 167 | { 168 | STBRP_HEURISTIC_Skyline_default=0, 169 | STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default, 170 | STBRP_HEURISTIC_Skyline_BF_sortHeight 171 | }; 172 | 173 | 174 | ////////////////////////////////////////////////////////////////////////////// 175 | // 176 | // the details of the following structures don't matter to you, but they must 177 | // be visible so you can handle the memory allocations for them 178 | 179 | struct stbrp_node 180 | { 181 | stbrp_coord x,y; 182 | stbrp_node *next; 183 | }; 184 | 185 | struct stbrp_context 186 | { 187 | int width; 188 | int height; 189 | int align; 190 | int init_mode; 191 | int heuristic; 192 | int num_nodes; 193 | stbrp_node *active_head; 194 | stbrp_node *free_head; 195 | stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2' 196 | }; 197 | 198 | #ifdef __cplusplus 199 | } 200 | #endif 201 | 202 | #endif 203 | 204 | ////////////////////////////////////////////////////////////////////////////// 205 | // 206 | // IMPLEMENTATION SECTION 207 | // 208 | 209 | #ifdef STB_RECT_PACK_IMPLEMENTATION 210 | #ifndef STBRP_SORT 211 | #include 212 | #define STBRP_SORT qsort 213 | #endif 214 | 215 | #ifndef STBRP_ASSERT 216 | #include 217 | #define STBRP_ASSERT assert 218 | #endif 219 | 220 | #ifdef _MSC_VER 221 | #define STBRP__NOTUSED(v) (void)(v) 222 | #define STBRP__CDECL __cdecl 223 | #else 224 | #define STBRP__NOTUSED(v) (void)sizeof(v) 225 | #define STBRP__CDECL 226 | #endif 227 | 228 | enum 229 | { 230 | STBRP__INIT_skyline = 1 231 | }; 232 | 233 | STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic) 234 | { 235 | switch (context->init_mode) { 236 | case STBRP__INIT_skyline: 237 | STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight); 238 | context->heuristic = heuristic; 239 | break; 240 | default: 241 | STBRP_ASSERT(0); 242 | } 243 | } 244 | 245 | STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem) 246 | { 247 | if (allow_out_of_mem) 248 | // if it's ok to run out of memory, then don't bother aligning them; 249 | // this gives better packing, but may fail due to OOM (even though 250 | // the rectangles easily fit). @TODO a smarter approach would be to only 251 | // quantize once we've hit OOM, then we could get rid of this parameter. 252 | context->align = 1; 253 | else { 254 | // if it's not ok to run out of memory, then quantize the widths 255 | // so that num_nodes is always enough nodes. 256 | // 257 | // I.e. num_nodes * align >= width 258 | // align >= width / num_nodes 259 | // align = ceil(width/num_nodes) 260 | 261 | context->align = (context->width + context->num_nodes-1) / context->num_nodes; 262 | } 263 | } 264 | 265 | STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes) 266 | { 267 | int i; 268 | 269 | for (i=0; i < num_nodes-1; ++i) 270 | nodes[i].next = &nodes[i+1]; 271 | nodes[i].next = NULL; 272 | context->init_mode = STBRP__INIT_skyline; 273 | context->heuristic = STBRP_HEURISTIC_Skyline_default; 274 | context->free_head = &nodes[0]; 275 | context->active_head = &context->extra[0]; 276 | context->width = width; 277 | context->height = height; 278 | context->num_nodes = num_nodes; 279 | stbrp_setup_allow_out_of_mem(context, 0); 280 | 281 | // node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly) 282 | context->extra[0].x = 0; 283 | context->extra[0].y = 0; 284 | context->extra[0].next = &context->extra[1]; 285 | context->extra[1].x = (stbrp_coord) width; 286 | context->extra[1].y = (1<<30); 287 | context->extra[1].next = NULL; 288 | } 289 | 290 | // find minimum y position if it starts at x1 291 | static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste) 292 | { 293 | stbrp_node *node = first; 294 | int x1 = x0 + width; 295 | int min_y, visited_width, waste_area; 296 | 297 | STBRP__NOTUSED(c); 298 | 299 | STBRP_ASSERT(first->x <= x0); 300 | 301 | #if 0 302 | // skip in case we're past the node 303 | while (node->next->x <= x0) 304 | ++node; 305 | #else 306 | STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency 307 | #endif 308 | 309 | STBRP_ASSERT(node->x <= x0); 310 | 311 | min_y = 0; 312 | waste_area = 0; 313 | visited_width = 0; 314 | while (node->x < x1) { 315 | if (node->y > min_y) { 316 | // raise min_y higher. 317 | // we've accounted for all waste up to min_y, 318 | // but we'll now add more waste for everything we've visted 319 | waste_area += visited_width * (node->y - min_y); 320 | min_y = node->y; 321 | // the first time through, visited_width might be reduced 322 | if (node->x < x0) 323 | visited_width += node->next->x - x0; 324 | else 325 | visited_width += node->next->x - node->x; 326 | } else { 327 | // add waste area 328 | int under_width = node->next->x - node->x; 329 | if (under_width + visited_width > width) 330 | under_width = width - visited_width; 331 | waste_area += under_width * (min_y - node->y); 332 | visited_width += under_width; 333 | } 334 | node = node->next; 335 | } 336 | 337 | *pwaste = waste_area; 338 | return min_y; 339 | } 340 | 341 | typedef struct 342 | { 343 | int x,y; 344 | stbrp_node **prev_link; 345 | } stbrp__findresult; 346 | 347 | static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height) 348 | { 349 | int best_waste = (1<<30), best_x, best_y = (1 << 30); 350 | stbrp__findresult fr; 351 | stbrp_node **prev, *node, *tail, **best = NULL; 352 | 353 | // align to multiple of c->align 354 | width = (width + c->align - 1); 355 | width -= width % c->align; 356 | STBRP_ASSERT(width % c->align == 0); 357 | 358 | // if it can't possibly fit, bail immediately 359 | if (width > c->width || height > c->height) { 360 | fr.prev_link = NULL; 361 | fr.x = fr.y = 0; 362 | return fr; 363 | } 364 | 365 | node = c->active_head; 366 | prev = &c->active_head; 367 | while (node->x + width <= c->width) { 368 | int y,waste; 369 | y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste); 370 | if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL 371 | // bottom left 372 | if (y < best_y) { 373 | best_y = y; 374 | best = prev; 375 | } 376 | } else { 377 | // best-fit 378 | if (y + height <= c->height) { 379 | // can only use it if it first vertically 380 | if (y < best_y || (y == best_y && waste < best_waste)) { 381 | best_y = y; 382 | best_waste = waste; 383 | best = prev; 384 | } 385 | } 386 | } 387 | prev = &node->next; 388 | node = node->next; 389 | } 390 | 391 | best_x = (best == NULL) ? 0 : (*best)->x; 392 | 393 | // if doing best-fit (BF), we also have to try aligning right edge to each node position 394 | // 395 | // e.g, if fitting 396 | // 397 | // ____________________ 398 | // |____________________| 399 | // 400 | // into 401 | // 402 | // | | 403 | // | ____________| 404 | // |____________| 405 | // 406 | // then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned 407 | // 408 | // This makes BF take about 2x the time 409 | 410 | if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) { 411 | tail = c->active_head; 412 | node = c->active_head; 413 | prev = &c->active_head; 414 | // find first node that's admissible 415 | while (tail->x < width) 416 | tail = tail->next; 417 | while (tail) { 418 | int xpos = tail->x - width; 419 | int y,waste; 420 | STBRP_ASSERT(xpos >= 0); 421 | // find the left position that matches this 422 | while (node->next->x <= xpos) { 423 | prev = &node->next; 424 | node = node->next; 425 | } 426 | STBRP_ASSERT(node->next->x > xpos && node->x <= xpos); 427 | y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste); 428 | if (y + height <= c->height) { 429 | if (y <= best_y) { 430 | if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) { 431 | best_x = xpos; 432 | //STBRP_ASSERT(y <= best_y); [DEAR IMGUI] 433 | best_y = y; 434 | best_waste = waste; 435 | best = prev; 436 | } 437 | } 438 | } 439 | tail = tail->next; 440 | } 441 | } 442 | 443 | fr.prev_link = best; 444 | fr.x = best_x; 445 | fr.y = best_y; 446 | return fr; 447 | } 448 | 449 | static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height) 450 | { 451 | // find best position according to heuristic 452 | stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height); 453 | stbrp_node *node, *cur; 454 | 455 | // bail if: 456 | // 1. it failed 457 | // 2. the best node doesn't fit (we don't always check this) 458 | // 3. we're out of memory 459 | if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) { 460 | res.prev_link = NULL; 461 | return res; 462 | } 463 | 464 | // on success, create new node 465 | node = context->free_head; 466 | node->x = (stbrp_coord) res.x; 467 | node->y = (stbrp_coord) (res.y + height); 468 | 469 | context->free_head = node->next; 470 | 471 | // insert the new node into the right starting point, and 472 | // let 'cur' point to the remaining nodes needing to be 473 | // stiched back in 474 | 475 | cur = *res.prev_link; 476 | if (cur->x < res.x) { 477 | // preserve the existing one, so start testing with the next one 478 | stbrp_node *next = cur->next; 479 | cur->next = node; 480 | cur = next; 481 | } else { 482 | *res.prev_link = node; 483 | } 484 | 485 | // from here, traverse cur and free the nodes, until we get to one 486 | // that shouldn't be freed 487 | while (cur->next && cur->next->x <= res.x + width) { 488 | stbrp_node *next = cur->next; 489 | // move the current node to the free list 490 | cur->next = context->free_head; 491 | context->free_head = cur; 492 | cur = next; 493 | } 494 | 495 | // stitch the list back in 496 | node->next = cur; 497 | 498 | if (cur->x < res.x + width) 499 | cur->x = (stbrp_coord) (res.x + width); 500 | 501 | #ifdef _DEBUG 502 | cur = context->active_head; 503 | while (cur->x < context->width) { 504 | STBRP_ASSERT(cur->x < cur->next->x); 505 | cur = cur->next; 506 | } 507 | STBRP_ASSERT(cur->next == NULL); 508 | 509 | { 510 | int count=0; 511 | cur = context->active_head; 512 | while (cur) { 513 | cur = cur->next; 514 | ++count; 515 | } 516 | cur = context->free_head; 517 | while (cur) { 518 | cur = cur->next; 519 | ++count; 520 | } 521 | STBRP_ASSERT(count == context->num_nodes+2); 522 | } 523 | #endif 524 | 525 | return res; 526 | } 527 | 528 | static int STBRP__CDECL rect_height_compare(const void *a, const void *b) 529 | { 530 | const stbrp_rect *p = (const stbrp_rect *) a; 531 | const stbrp_rect *q = (const stbrp_rect *) b; 532 | if (p->h > q->h) 533 | return -1; 534 | if (p->h < q->h) 535 | return 1; 536 | return (p->w > q->w) ? -1 : (p->w < q->w); 537 | } 538 | 539 | static int STBRP__CDECL rect_original_order(const void *a, const void *b) 540 | { 541 | const stbrp_rect *p = (const stbrp_rect *) a; 542 | const stbrp_rect *q = (const stbrp_rect *) b; 543 | return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed); 544 | } 545 | 546 | STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects) 547 | { 548 | int i, all_rects_packed = 1; 549 | 550 | // we use the 'was_packed' field internally to allow sorting/unsorting 551 | for (i=0; i < num_rects; ++i) { 552 | rects[i].was_packed = i; 553 | } 554 | 555 | // sort according to heuristic 556 | STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare); 557 | 558 | for (i=0; i < num_rects; ++i) { 559 | if (rects[i].w == 0 || rects[i].h == 0) { 560 | rects[i].x = rects[i].y = 0; // empty rect needs no space 561 | } else { 562 | stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h); 563 | if (fr.prev_link) { 564 | rects[i].x = (stbrp_coord) fr.x; 565 | rects[i].y = (stbrp_coord) fr.y; 566 | } else { 567 | rects[i].x = rects[i].y = STBRP__MAXVAL; 568 | } 569 | } 570 | } 571 | 572 | // unsort 573 | STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order); 574 | 575 | // set was_packed flags and all_rects_packed status 576 | for (i=0; i < num_rects; ++i) { 577 | rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL); 578 | if (!rects[i].was_packed) 579 | all_rects_packed = 0; 580 | } 581 | 582 | // return the all_rects_packed status 583 | return all_rects_packed; 584 | } 585 | #endif 586 | 587 | /* 588 | ------------------------------------------------------------------------------ 589 | This software is available under 2 licenses -- choose whichever you prefer. 590 | ------------------------------------------------------------------------------ 591 | ALTERNATIVE A - MIT License 592 | Copyright (c) 2017 Sean Barrett 593 | Permission is hereby granted, free of charge, to any person obtaining a copy of 594 | this software and associated documentation files (the "Software"), to deal in 595 | the Software without restriction, including without limitation the rights to 596 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 597 | of the Software, and to permit persons to whom the Software is furnished to do 598 | so, subject to the following conditions: 599 | The above copyright notice and this permission notice shall be included in all 600 | copies or substantial portions of the Software. 601 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 602 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 603 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 604 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 605 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 606 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 607 | SOFTWARE. 608 | ------------------------------------------------------------------------------ 609 | ALTERNATIVE B - Public Domain (www.unlicense.org) 610 | This is free and unencumbered software released into the public domain. 611 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute this 612 | software, either in source code form or as a compiled binary, for any purpose, 613 | commercial or non-commercial, and by any means. 614 | In jurisdictions that recognize copyright laws, the author or authors of this 615 | software dedicate any and all copyright interest in the software to the public 616 | domain. We make this dedication for the benefit of the public at large and to 617 | the detriment of our heirs and successors. We intend this dedication to be an 618 | overt act of relinquishment in perpetuity of all present and future rights to 619 | this software under copyright law. 620 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 621 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 622 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 623 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 624 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 625 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 626 | ------------------------------------------------------------------------------ 627 | */ 628 | -------------------------------------------------------------------------------- /my_example/suspension_ball/draw.h: -------------------------------------------------------------------------------- 1 | #ifndef DRAW_H 2 | #define DRAW_H 3 | 4 | #define STB_IMAGE_IMPLEMENTATION 5 | #include "ImGui/stb_image.h" 6 | #include "ImGui/imgui.h" 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #ifndef GL_CLAMP_TO_EDGE 13 | #define GL_CLAMP_TO_EDGE 0x812F 14 | #endif 15 | 16 | void PlotVar(const char* label, float value, float scale_min = FLT_MAX, float scale_max = FLT_MAX, size_t buffer_size = 120); 17 | 18 | // Simple helper function to load an image into a OpenGL texture with common settings 19 | bool LoadTextureFromFile(const char* filename, GLuint* out_texture, int* out_width, int* out_height) 20 | { 21 | // Load from file 22 | int image_width = 0; 23 | int image_height = 0; 24 | unsigned char* image_data = stbi_load(filename, &image_width, &image_height, NULL, 4); 25 | if (image_data == NULL) 26 | return false; 27 | 28 | // Create a OpenGL texture identifier 29 | GLuint image_texture; 30 | glGenTextures(1, &image_texture); 31 | glBindTexture(GL_TEXTURE_2D, image_texture); 32 | 33 | // Setup filtering parameters for display 34 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 35 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 36 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // This is required on WebGL for non power-of-two textures 37 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // Same 38 | 39 | // Upload pixels into texture 40 | #if defined(GL_UNPACK_ROW_LENGTH) && !defined(__EMSCRIPTEN__) 41 | glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); 42 | #endif 43 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image_width, image_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data); 44 | stbi_image_free(image_data); 45 | 46 | *out_texture = image_texture; 47 | *out_width = image_width; 48 | *out_height = image_height; 49 | 50 | return true; 51 | } 52 | 53 | struct PlotVarData 54 | { 55 | ImGuiID ID; 56 | std::vector Data; 57 | int DataInsertIdx; 58 | int LastFrame; 59 | 60 | PlotVarData() : ID(0), DataInsertIdx(0), LastFrame(-1) {} 61 | }; 62 | 63 | typedef std::map PlotVarsMap; 64 | static PlotVarsMap g_PlotVarsMap; 65 | 66 | // Plot value over time 67 | // Call with 'value == FLT_MAX' to draw without adding new value to the buffer 68 | void PlotVar(const char* label, float value, float scale_min, float scale_max, size_t buffer_size) 69 | { 70 | assert(label); 71 | if (buffer_size == 0) 72 | buffer_size = 120; 73 | 74 | ImGui::PushID(label); 75 | ImGuiID id = ImGui::GetID(""); 76 | 77 | // Lookup O(log N) 78 | PlotVarData& pvd = g_PlotVarsMap[id]; 79 | 80 | // Setup 81 | if (pvd.Data.capacity() != buffer_size) 82 | { 83 | pvd.Data.resize(buffer_size); 84 | memset(&pvd.Data[0], 0, sizeof(float) * buffer_size); 85 | pvd.DataInsertIdx = 0; 86 | pvd.LastFrame = -1; 87 | } 88 | 89 | // Insert (avoid unnecessary modulo operator) 90 | if (pvd.DataInsertIdx == buffer_size) 91 | pvd.DataInsertIdx = 0; 92 | int display_idx = pvd.DataInsertIdx; 93 | if (value != FLT_MAX) 94 | pvd.Data[pvd.DataInsertIdx++] = value; 95 | 96 | // Draw 97 | int current_frame = ImGui::GetFrameCount(); 98 | if (pvd.LastFrame != current_frame) 99 | { 100 | ImGui::PlotLines("##plot", &pvd.Data[0], buffer_size, pvd.DataInsertIdx, NULL, scale_min, scale_max, ImVec2(0, 40)); 101 | ImGui::SameLine(); 102 | ImGui::Text("%s\n%-3.4f", label, pvd.Data[display_idx]); // Display last value in buffer 103 | pvd.LastFrame = current_frame; 104 | } 105 | 106 | ImGui::PopID(); 107 | } 108 | 109 | void PlotVarFlushOldEntries() 110 | { 111 | int current_frame = ImGui::GetFrameCount(); 112 | for (PlotVarsMap::iterator it = g_PlotVarsMap.begin(); it != g_PlotVarsMap.end(); ) 113 | { 114 | PlotVarData& pvd = it->second; 115 | if (pvd.LastFrame < current_frame - max(400, (int)pvd.Data.size())) 116 | it = g_PlotVarsMap.erase(it); 117 | else 118 | ++it; 119 | } 120 | } 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /my_example/suspension_ball/global.h: -------------------------------------------------------------------------------- 1 | #ifndef GLOBAL_H 2 | #define GLOBAL_H 3 | 4 | #include "ImGui/imgui.h" 5 | #include "ImGui/imgui_impl_glfw.h" 6 | #include "ImGui/imgui_impl_opengl3.h" 7 | #include "ImGui/imgui_internal.h" 8 | #include "ImGui/imstb_truetype.h" 9 | #include "ImGui/imstb_textedit.h" 10 | #include "ImGui/font.h" 11 | //#include "Image/test.hpp" 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #pragma comment(lib, "legacy_stdio_definitions") 18 | #pragma warning( disable : 4996 ) 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /my_example/suspension_ball/icon.h: -------------------------------------------------------------------------------- 1 | #ifndef _ICON_H_ 2 | #define _ICON_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include "ImGui/imgui.h" 8 | #include "ImGui/imgui_internal.h" 9 | using namespace std; 10 | 11 | namespace ImSpinner 12 | { 13 | #define DECLPROP(name,type,def) struct name { type value = def; operator type() { return value; } }; 14 | enum SpinnerTypeT { 15 | e_st_rainbow = 0, 16 | e_st_angle, 17 | e_st_dots, 18 | e_st_ang, 19 | 20 | e_st_count 21 | }; 22 | 23 | using float_ptr = float *; 24 | 25 | DECLPROP (SpinnerType, SpinnerTypeT, e_st_rainbow) 26 | DECLPROP (Radius, float, 16.f) 27 | DECLPROP (Speed, float, 1.f) 28 | DECLPROP (Thickness, float, 1.f) 29 | DECLPROP (Color, ImColor, 0xffffffff) 30 | DECLPROP (BgColor, ImColor, 0xffffffff) 31 | DECLPROP (Angle, float, IM_PI) 32 | DECLPROP (FloatPtr, float_ptr, nullptr) 33 | DECLPROP (Dots, int, 0) 34 | DECLPROP (MiddleDots, int, 0) 35 | DECLPROP (MinThickness, float, 0.f) 36 | #undef DECLPROP 37 | 38 | namespace detail { 39 | bool SpinnerBegin(const char *label, float radius, ImVec2 &pos, ImVec2 &size, ImVec2 ¢re) { 40 | ImGuiWindow *window = ImGui::GetCurrentWindow(); 41 | if (window->SkipItems) 42 | return false; 43 | 44 | ImGuiContext &g = *GImGui; 45 | const ImGuiStyle &style = g.Style; 46 | const ImGuiID id = window->GetID(label); 47 | 48 | pos = window->DC.CursorPos; 49 | size = ImVec2((radius) * 2, (radius + style.FramePadding.y) * 2); 50 | 51 | const ImRect bb(pos, ImVec2(pos.x + size.x, pos.y + size.y)); 52 | ImGui::ItemSize(bb, style.FramePadding.y); 53 | 54 | centre = bb.GetCenter(); 55 | if (!ImGui::ItemAdd(bb, id)) 56 | return false; 57 | 58 | return true; 59 | } 60 | 61 | #define IMPLRPOP(basetype,type) basetype m_##type; \ 62 | void set##type(const basetype& v) { m_##type = v;} \ 63 | void set(type h) { m_##type = h.value;} \ 64 | template \ 65 | void set(const type& h, const Args&... args) { set##type(h.value); this->template set(args...); } 66 | struct SpinnerConfig { 67 | SpinnerConfig() {} 68 | 69 | template void set() {} 70 | 71 | template 72 | SpinnerConfig(const Args&... args) { this->template set(args...); } 73 | 74 | IMPLRPOP(SpinnerTypeT, SpinnerType) 75 | IMPLRPOP(float, Radius) 76 | IMPLRPOP(float, Speed) 77 | IMPLRPOP(float, Thickness) 78 | IMPLRPOP(ImColor, Color) 79 | IMPLRPOP(ImColor, BgColor) 80 | IMPLRPOP(float, Angle) 81 | IMPLRPOP(float_ptr, FloatPtr) 82 | IMPLRPOP(int, Dots) 83 | IMPLRPOP(int, MiddleDots) 84 | IMPLRPOP(float, MinThickness) 85 | }; 86 | #undef IMPLRPOP 87 | } 88 | 89 | #define SPINNER_HEADER(pos, size, centre) ImVec2 pos, size, centre; if (!detail::SpinnerBegin(label, radius, pos, size, centre)) { return; }; ImGuiWindow *window = ImGui::GetCurrentWindow(); 90 | 91 | void SpinnerAngTriple(const char *label, float radius1, float radius2, float radius3, float thickness, const ImColor &c1 = 0xffffffff, const ImColor &c2 = 0xffffff80, const ImColor &c3 = 0xffffffff, float speed = 2.8f, float angle = IM_PI) 92 | { 93 | float radius = ImMax(ImMax(radius1, radius2), radius3); 94 | SPINNER_HEADER(pos, size, centre); 95 | 96 | // Render 97 | float start1 = (float)ImGui::GetTime() * speed; 98 | const size_t num_segments = window->DrawList->_CalcCircleAutoSegmentCount(radius) * 2; 99 | const float angle_offset = angle / num_segments; 100 | window->DrawList->PathClear(); 101 | for (size_t i = 0; i < num_segments; ++i) 102 | { 103 | const float a = start1 + (i * angle_offset); 104 | window->DrawList->PathLineTo(ImVec2(centre.x + ImCos(a) * radius1, centre.y + ImSin(a) * radius1)); 105 | } 106 | window->DrawList->PathStroke(c1, false, thickness); 107 | 108 | float start2 = (float)ImGui::GetTime() * 1.2f * speed; 109 | window->DrawList->PathClear(); 110 | for (size_t i = 0; i < num_segments; ++i) 111 | { 112 | const float a = start2 + (i * angle_offset); 113 | window->DrawList->PathLineTo(ImVec2(centre.x + ImCos(-a) * radius2, centre.y + ImSin(-a) * radius2)); 114 | } 115 | window->DrawList->PathStroke(c2, false, thickness); 116 | 117 | float start3 = (float)ImGui::GetTime() * 0.9f * speed; 118 | window->DrawList->PathClear(); 119 | for (size_t i = 0; i < num_segments; ++i) 120 | { 121 | const float a = start3 + (i * angle_offset); 122 | window->DrawList->PathLineTo(ImVec2(centre.x + ImCos(a) * radius3, centre.y + ImSin(a) * radius3)); 123 | } 124 | window->DrawList->PathStroke(c3, false, thickness); 125 | } 126 | 127 | void SpinnerIngYang(const char *label, float radius, float thickness, bool reverse, float yang_detlta_r, const ImColor &colorI = 0xffffffff, const ImColor &colorY = 0xffffffff, float speed = 2.8f, float angle = IM_PI * 0.7f) 128 | { 129 | SPINNER_HEADER(pos, size, centre); 130 | 131 | // Render 132 | const size_t num_segments = window->DrawList->_CalcCircleAutoSegmentCount(radius); 133 | float startI = (float)ImGui::GetTime() * speed; 134 | float startY = (float)ImGui::GetTime() * (speed + (yang_detlta_r > 0.f ? ImClamp(yang_detlta_r * 0.5f, 0.5f, 2.f) : 0.f)); 135 | 136 | const float angle_offset = angle / num_segments; 137 | const float th = thickness / num_segments; 138 | for (size_t i = 0; i < num_segments; ++i) 139 | { 140 | const float a = startI + (i * angle_offset); 141 | const float a1 = startI + ((i + 1) * angle_offset); 142 | window->DrawList->AddLine(ImVec2(centre.x + ImCos(a) * radius, centre.y + ImSin(a) * radius), 143 | ImVec2(centre.x + ImCos(a1) * radius, centre.y + ImSin(a1) * radius), 144 | colorI, 145 | th * i); 146 | } 147 | const float ai_end = startI + (num_segments * angle_offset); 148 | ImVec2 circle_i_center{centre.x + ImCos(ai_end) * radius, centre.y + ImSin(ai_end) * radius}; 149 | window->DrawList->AddCircleFilled(circle_i_center, thickness / 2.f, colorI, (int)num_segments); 150 | const float rv = reverse ? -1.f : 1.f; 151 | const float yang_radius = (radius - yang_detlta_r); 152 | for (size_t i = 0; i < num_segments; ++i) 153 | { 154 | const float a = startY + IM_PI + (i * angle_offset); 155 | const float a1 = startY + IM_PI + ((i+1) * angle_offset); 156 | window->DrawList->AddLine(ImVec2(centre.x + ImCos(a * rv) * yang_radius, centre.y + ImSin(a * rv) * yang_radius), 157 | ImVec2(centre.x + ImCos(a1 * rv) * yang_radius, centre.y + ImSin(a1 * rv) * yang_radius), 158 | colorY, 159 | th * i); 160 | } 161 | const float ay_end = startY + IM_PI + (num_segments * angle_offset); 162 | ImVec2 circle_y_center{centre.x + ImCos(ay_end * rv) * yang_radius, centre.y + ImSin(ay_end * rv) * yang_radius}; 163 | window->DrawList->AddCircleFilled(circle_y_center, thickness / 2.f, colorY, (int)num_segments); 164 | } 165 | 166 | } 167 | 168 | #endif -------------------------------------------------------------------------------- /my_example/suspension_ball/knobs/imgui-knobs.cpp: -------------------------------------------------------------------------------- 1 | #include "imgui-knobs.h" 2 | 3 | #include 4 | #include 5 | #include "../ImGui/imgui.h" 6 | #include "../ImGui/imgui_internal.h" 7 | 8 | #define IMGUIKNOBS_PI 3.14159265358979323846 9 | 10 | namespace ImGuiKnobs { 11 | namespace detail { 12 | void draw_arc1(ImVec2 center, float radius, float start_angle, float end_angle, float thickness, ImColor color, int num_segments) { 13 | ImVec2 start = { 14 | center[0] + cosf(start_angle) * radius, 15 | center[1] + sinf(start_angle) * radius, 16 | }; 17 | 18 | ImVec2 end = { 19 | center[0] + cosf(end_angle) * radius, 20 | center[1] + sinf(end_angle) * radius, 21 | }; 22 | 23 | // Calculate bezier arc points 24 | auto ax = start[0] - center[0]; 25 | auto ay = start[1] - center[1]; 26 | auto bx = end[0] - center[0]; 27 | auto by = end[1] - center[1]; 28 | auto q1 = ax * ax + ay * ay; 29 | auto q2 = q1 + ax * bx + ay * by; 30 | auto k2 = (4.0f / 3.0f) * (sqrtf((2.0f * q1 * q2)) - q2) / (ax * by - ay * bx); 31 | auto arc1 = ImVec2{center[0] + ax - k2 * ay, center[1] + ay + k2 * ax}; 32 | auto arc2 = ImVec2{center[0] + bx + k2 * by, center[1] + by - k2 * bx}; 33 | 34 | auto *draw_list = ImGui::GetWindowDrawList(); 35 | 36 | draw_list->AddBezierCurve(start, arc1, arc2, end, color, thickness, num_segments); 37 | } 38 | 39 | void draw_arc(ImVec2 center, float radius, float start_angle, float end_angle, float thickness, ImColor color, int num_segments, int bezier_count) { 40 | // Overlap and angle of ends of bezier curves needs work, only looks good when not transperant 41 | auto overlap = thickness * radius * 0.00001f * IMGUIKNOBS_PI; 42 | auto delta = end_angle - start_angle; 43 | auto bez_step = 1.0f / bezier_count; 44 | auto mid_angle = start_angle + overlap; 45 | 46 | for (auto i = 0; i < bezier_count - 1; i++) { 47 | auto mid_angle2 = delta * bez_step + mid_angle; 48 | draw_arc1(center, radius, mid_angle - overlap, mid_angle2 + overlap, thickness, color, num_segments); 49 | mid_angle = mid_angle2; 50 | } 51 | 52 | draw_arc1(center, radius, mid_angle - overlap, end_angle, thickness, color, num_segments); 53 | } 54 | 55 | template 56 | struct knob { 57 | float radius; 58 | bool value_changed; 59 | ImVec2 center; 60 | bool is_active; 61 | bool is_hovered; 62 | float angle_min; 63 | float angle_max; 64 | float t; 65 | float angle; 66 | float angle_cos; 67 | float angle_sin; 68 | 69 | knob(const char *_label, ImGuiDataType data_type, DataType *p_value, DataType v_min, DataType v_max, float speed, float _radius, const char *format, ImGuiKnobFlags flags) { 70 | radius = _radius; 71 | t = ((float) *p_value - v_min) / (v_max - v_min); 72 | auto screen_pos = ImGui::GetCursorScreenPos(); 73 | 74 | // Handle dragging 75 | ImGui::InvisibleButton(_label, {radius * 2.0f, radius * 2.0f}); 76 | auto gid = ImGui::GetID(_label); 77 | ImGuiSliderFlags drag_flags = 0; 78 | if (!(flags & ImGuiKnobFlags_DragHorizontal)) { 79 | drag_flags |= ImGuiSliderFlags_Vertical; 80 | } 81 | value_changed = ImGui::DragBehavior(gid, data_type, p_value, speed, &v_min, &v_max, format, drag_flags); 82 | 83 | angle_min = IMGUIKNOBS_PI * 0.75; 84 | angle_max = IMGUIKNOBS_PI * 2.25; 85 | center = {screen_pos[0] + radius, screen_pos[1] + radius}; 86 | is_active = ImGui::IsItemActive(); 87 | is_hovered = ImGui::IsItemHovered(); 88 | angle = angle_min + (angle_max - angle_min) * t; 89 | angle_cos = cosf(angle); 90 | angle_sin = sinf(angle); 91 | } 92 | 93 | void draw_dot(float size, float radius, float angle, color_set color, bool filled, int segments) { 94 | auto dot_size = size * this->radius; 95 | auto dot_radius = radius * this->radius; 96 | 97 | ImGui::GetWindowDrawList()->AddCircleFilled( 98 | {center[0] + cosf(angle) * dot_radius, center[1] + sinf(angle) * dot_radius}, 99 | dot_size, 100 | is_active ? color.active : (is_hovered ? color.hovered : color.base), 101 | segments); 102 | } 103 | 104 | void draw_tick(float start, float end, float width, float angle, color_set color) { 105 | auto tick_start = start * radius; 106 | auto tick_end = end * radius; 107 | auto angle_cos = cosf(angle); 108 | auto angle_sin = sinf(angle); 109 | 110 | ImGui::GetWindowDrawList()->AddLine( 111 | {center[0] + angle_cos * tick_end, center[1] + angle_sin * tick_end}, 112 | {center[0] + angle_cos * tick_start, center[1] + angle_sin * tick_start}, 113 | is_active ? color.active : (is_hovered ? color.hovered : color.base), 114 | width * radius); 115 | } 116 | 117 | void draw_circle(float size, color_set color, bool filled, int segments) { 118 | auto circle_radius = size * radius; 119 | 120 | ImGui::GetWindowDrawList()->AddCircleFilled( 121 | center, 122 | circle_radius, 123 | is_active ? color.active : (is_hovered ? color.hovered : color.base)); 124 | } 125 | 126 | void draw_arc(float radius, float size, float start_angle, float end_angle, color_set color, int segments, int bezier_count) { 127 | auto track_radius = radius * this->radius; 128 | auto track_size = size * this->radius * 0.5f + 0.0001f; 129 | 130 | detail::draw_arc( 131 | center, 132 | track_radius, 133 | start_angle, 134 | end_angle, 135 | track_size, 136 | is_active ? color.active : (is_hovered ? color.hovered : color.base), 137 | segments, 138 | bezier_count); 139 | } 140 | }; 141 | 142 | template 143 | knob knob_with_drag(const char *label, ImGuiDataType data_type, DataType *p_value, DataType v_min, DataType v_max, float _speed, const char *format, float size, ImGuiKnobFlags flags) { 144 | auto speed = _speed == 0 ? (v_max - v_min) / 250.f : _speed; 145 | ImGui::PushID(label); 146 | auto width = size == 0 ? ImGui::GetTextLineHeight() * 4.0f : size * ImGui::GetIO().FontGlobalScale; 147 | ImGui::PushItemWidth(width); 148 | 149 | ImGui::BeginGroup(); 150 | 151 | // There's an issue with `SameLine` and Groups, see https://github.com/ocornut/imgui/issues/4190. 152 | // This is probably not the best solution, but seems to work for now 153 | ImGui::GetCurrentWindow()->DC.CurrLineTextBaseOffset = 0; 154 | 155 | // Draw title 156 | if (!(flags & ImGuiKnobFlags_NoTitle)) { 157 | auto title_size = ImGui::CalcTextSize(label, NULL, false, width); 158 | 159 | // Center title 160 | ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (width - title_size[0]) * 0.5f); 161 | 162 | ImGui::Text("%s", label); 163 | } 164 | 165 | // Draw knob 166 | knob k(label, data_type, p_value, v_min, v_max, speed, width * 0.5f, format, flags); 167 | 168 | // Draw tooltip 169 | if (flags & ImGuiKnobFlags_ValueTooltip && (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) || ImGui::IsItemActive())) { 170 | ImGui::BeginTooltip(); 171 | ImGui::Text(format, *p_value); 172 | ImGui::EndTooltip(); 173 | } 174 | 175 | // Draw input 176 | if (!(flags & ImGuiKnobFlags_NoInput)) { 177 | ImGuiSliderFlags drag_flags = 0; 178 | if (!(flags & ImGuiKnobFlags_DragHorizontal)) { 179 | drag_flags |= ImGuiSliderFlags_Vertical; 180 | } 181 | auto changed = ImGui::DragScalar("###knob_drag", data_type, p_value, speed, &v_min, &v_max, format, drag_flags); 182 | if (changed) { 183 | k.value_changed = true; 184 | } 185 | } 186 | 187 | ImGui::EndGroup(); 188 | ImGui::PopItemWidth(); 189 | ImGui::PopID(); 190 | 191 | return k; 192 | } 193 | 194 | color_set GetPrimaryColorSet() { 195 | auto *colors = ImGui::GetStyle().Colors; 196 | 197 | return {colors[ImGuiCol_ButtonActive], colors[ImGuiCol_ButtonHovered], colors[ImGuiCol_ButtonHovered]}; 198 | } 199 | 200 | color_set GetSecondaryColorSet() { 201 | auto *colors = ImGui::GetStyle().Colors; 202 | auto active = ImVec4( 203 | colors[ImGuiCol_ButtonActive].x * 0.5f, 204 | colors[ImGuiCol_ButtonActive].y * 0.5f, 205 | colors[ImGuiCol_ButtonActive].z * 0.5f, 206 | colors[ImGuiCol_ButtonActive].w); 207 | 208 | auto hovered = ImVec4( 209 | colors[ImGuiCol_ButtonHovered].x * 0.5f, 210 | colors[ImGuiCol_ButtonHovered].y * 0.5f, 211 | colors[ImGuiCol_ButtonHovered].z * 0.5f, 212 | colors[ImGuiCol_ButtonHovered].w); 213 | 214 | return {active, hovered, hovered}; 215 | } 216 | 217 | color_set GetTrackColorSet() { 218 | auto *colors = ImGui::GetStyle().Colors; 219 | 220 | return {colors[ImGuiCol_FrameBg], colors[ImGuiCol_FrameBg], colors[ImGuiCol_FrameBg]}; 221 | } 222 | }// namespace detail 223 | 224 | 225 | template 226 | bool BaseKnob(const char *label, ImGuiDataType data_type, DataType *p_value, DataType v_min, DataType v_max, float speed, const char *format, ImGuiKnobVariant variant, float size, ImGuiKnobFlags flags, int steps = 10) { 227 | auto knob = detail::knob_with_drag(label, data_type, p_value, v_min, v_max, speed, format, size, flags); 228 | 229 | switch (variant) { 230 | case ImGuiKnobVariant_Tick: { 231 | knob.draw_circle(0.85, detail::GetSecondaryColorSet(), true, 32); 232 | knob.draw_tick(0.5, 0.85, 0.08, knob.angle, detail::GetPrimaryColorSet()); 233 | break; 234 | } 235 | case ImGuiKnobVariant_Dot: { 236 | knob.draw_circle(0.85, detail::GetSecondaryColorSet(), true, 32); 237 | knob.draw_dot(0.12, 0.6, knob.angle, detail::GetPrimaryColorSet(), true, 12); 238 | break; 239 | } 240 | 241 | case ImGuiKnobVariant_Wiper: { 242 | knob.draw_circle(0.7, detail::GetSecondaryColorSet(), true, 32); 243 | knob.draw_arc(0.8, 0.41, knob.angle_min, knob.angle_max, detail::GetTrackColorSet(), 16, 2); 244 | 245 | if (knob.t > 0.01) { 246 | knob.draw_arc(0.8, 0.43, knob.angle_min, knob.angle, detail::GetPrimaryColorSet(), 16, 2); 247 | } 248 | break; 249 | } 250 | case ImGuiKnobVariant_WiperOnly: { 251 | knob.draw_arc(0.8, 0.41, knob.angle_min, knob.angle_max, detail::GetTrackColorSet(), 32, 2); 252 | 253 | if (knob.t > 0.01) { 254 | knob.draw_arc(0.8, 0.43, knob.angle_min, knob.angle, detail::GetPrimaryColorSet(), 16, 2); 255 | } 256 | break; 257 | } 258 | case ImGuiKnobVariant_WiperDot: { 259 | knob.draw_circle(0.6, detail::GetSecondaryColorSet(), true, 32); 260 | knob.draw_arc(0.85, 0.41, knob.angle_min, knob.angle_max, detail::GetTrackColorSet(), 16, 2); 261 | knob.draw_dot(0.1, 0.85, knob.angle, detail::GetPrimaryColorSet(), true, 12); 262 | break; 263 | } 264 | case ImGuiKnobVariant_Stepped: { 265 | for (auto n = 0.f; n < steps; n++) { 266 | auto a = n / (steps - 1); 267 | auto angle = knob.angle_min + (knob.angle_max - knob.angle_min) * a; 268 | knob.draw_tick(0.7, 0.9, 0.04, angle, detail::GetPrimaryColorSet()); 269 | } 270 | 271 | knob.draw_circle(0.6, detail::GetSecondaryColorSet(), true, 32); 272 | knob.draw_dot(0.12, 0.4, knob.angle, detail::GetPrimaryColorSet(), true, 12); 273 | break; 274 | } 275 | case ImGuiKnobVariant_Space: { 276 | knob.draw_circle(0.3 - knob.t * 0.1, detail::GetSecondaryColorSet(), true, 16); 277 | 278 | if (knob.t > 0.01) { 279 | knob.draw_arc(0.4, 0.15, knob.angle_min - 1.0, knob.angle - 1.0, detail::GetPrimaryColorSet(), 16, 2); 280 | knob.draw_arc(0.6, 0.15, knob.angle_min + 1.0, knob.angle + 1.0, detail::GetPrimaryColorSet(), 16, 2); 281 | knob.draw_arc(0.8, 0.15, knob.angle_min + 3.0, knob.angle + 3.0, detail::GetPrimaryColorSet(), 16, 2); 282 | } 283 | break; 284 | } 285 | } 286 | 287 | return knob.value_changed; 288 | } 289 | 290 | bool Knob(const char *label, float *p_value, float v_min, float v_max, float speed, const char *format, ImGuiKnobVariant variant, float size, ImGuiKnobFlags flags, int steps) { 291 | const char *_format = format == NULL ? "%.3f" : format; 292 | return BaseKnob(label, ImGuiDataType_Float, p_value, v_min, v_max, speed, _format, variant, size, flags, steps); 293 | } 294 | 295 | bool KnobInt(const char *label, int *p_value, int v_min, int v_max, float speed, const char *format, ImGuiKnobVariant variant, float size, ImGuiKnobFlags flags, int steps) { 296 | const char *_format = format == NULL ? "%i" : format; 297 | return BaseKnob(label, ImGuiDataType_S32, p_value, v_min, v_max, speed, _format, variant, size, flags, steps); 298 | } 299 | 300 | }// namespace ImGuiKnobs 301 | -------------------------------------------------------------------------------- /my_example/suspension_ball/knobs/imgui-knobs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "../ImGui/imgui.h" 5 | 6 | typedef int ImGuiKnobFlags; 7 | 8 | enum ImGuiKnobFlags_ { 9 | ImGuiKnobFlags_NoTitle = 1 << 0, 10 | ImGuiKnobFlags_NoInput = 1 << 1, 11 | ImGuiKnobFlags_ValueTooltip = 1 << 2, 12 | ImGuiKnobFlags_DragHorizontal = 1 << 3, 13 | }; 14 | 15 | typedef int ImGuiKnobVariant; 16 | 17 | enum ImGuiKnobVariant_ { 18 | ImGuiKnobVariant_Tick = 1 << 0, 19 | ImGuiKnobVariant_Dot = 1 << 1, 20 | ImGuiKnobVariant_Wiper = 1 << 2, 21 | ImGuiKnobVariant_WiperOnly = 1 << 3, 22 | ImGuiKnobVariant_WiperDot = 1 << 4, 23 | ImGuiKnobVariant_Stepped = 1 << 5, 24 | ImGuiKnobVariant_Space = 1 << 6, 25 | }; 26 | 27 | namespace ImGuiKnobs { 28 | 29 | struct color_set { 30 | ImColor base; 31 | ImColor hovered; 32 | ImColor active; 33 | 34 | color_set(ImColor base, ImColor hovered, ImColor active) : base(base), hovered(hovered), active(active) {} 35 | 36 | color_set(ImColor color) { 37 | base = color; 38 | hovered = color; 39 | active = color; 40 | } 41 | }; 42 | 43 | bool Knob(const char *label, float *p_value, float v_min, float v_max, float speed = 0, const char *format = NULL, ImGuiKnobVariant variant = ImGuiKnobVariant_Tick, float size = 0, ImGuiKnobFlags flags = 0, int steps = 10); 44 | bool KnobInt(const char *label, int *p_value, int v_min, int v_max, float speed = 0, const char *format = NULL, ImGuiKnobVariant variant = ImGuiKnobVariant_Tick, float size = 0, ImGuiKnobFlags flags = 0, int steps = 10); 45 | }// namespace ImGuiKnobs 46 | -------------------------------------------------------------------------------- /my_example/suspension_ball/libs/glfw/COPYING.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002-2006 Marcus Geelnard 2 | Copyright (c) 2006-2010 Camilla Berglund 3 | 4 | This software is provided 'as-is', without any express or implied 5 | warranty. In no event will the authors be held liable for any damages 6 | arising from the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it 10 | freely, subject to the following restrictions: 11 | 12 | 1. The origin of this software must not be misrepresented; you must not 13 | claim that you wrote the original software. If you use this software 14 | in a product, an acknowledgment in the product documentation would 15 | be appreciated but is not required. 16 | 17 | 2. Altered source versions must be plainly marked as such, and must not 18 | be misrepresented as being the original software. 19 | 20 | 3. This notice may not be removed or altered from any source 21 | distribution. 22 | 23 | -------------------------------------------------------------------------------- /my_example/suspension_ball/libs/glfw/include/GLFW/glfw3native.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * GLFW 3.2 - www.glfw.org 3 | * A library for OpenGL, window and input 4 | *------------------------------------------------------------------------ 5 | * Copyright (c) 2002-2006 Marcus Geelnard 6 | * Copyright (c) 2006-2010 Camilla Berglund 7 | * 8 | * This software is provided 'as-is', without any express or implied 9 | * warranty. In no event will the authors be held liable for any damages 10 | * arising from the use of this software. 11 | * 12 | * Permission is granted to anyone to use this software for any purpose, 13 | * including commercial applications, and to alter it and redistribute it 14 | * freely, subject to the following restrictions: 15 | * 16 | * 1. The origin of this software must not be misrepresented; you must not 17 | * claim that you wrote the original software. If you use this software 18 | * in a product, an acknowledgment in the product documentation would 19 | * be appreciated but is not required. 20 | * 21 | * 2. Altered source versions must be plainly marked as such, and must not 22 | * be misrepresented as being the original software. 23 | * 24 | * 3. This notice may not be removed or altered from any source 25 | * distribution. 26 | * 27 | *************************************************************************/ 28 | 29 | #ifndef _glfw3_native_h_ 30 | #define _glfw3_native_h_ 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | 37 | /************************************************************************* 38 | * Doxygen documentation 39 | *************************************************************************/ 40 | 41 | /*! @file glfw3native.h 42 | * @brief The header of the native access functions. 43 | * 44 | * This is the header file of the native access functions. See @ref native for 45 | * more information. 46 | */ 47 | /*! @defgroup native Native access 48 | * 49 | * **By using the native access functions you assert that you know what you're 50 | * doing and how to fix problems caused by using them. If you don't, you 51 | * shouldn't be using them.** 52 | * 53 | * Before the inclusion of @ref glfw3native.h, you may define exactly one 54 | * window system API macro and zero or more context creation API macros. 55 | * 56 | * The chosen backends must match those the library was compiled for. Failure 57 | * to do this will cause a link-time error. 58 | * 59 | * The available window API macros are: 60 | * * `GLFW_EXPOSE_NATIVE_WIN32` 61 | * * `GLFW_EXPOSE_NATIVE_COCOA` 62 | * * `GLFW_EXPOSE_NATIVE_X11` 63 | * * `GLFW_EXPOSE_NATIVE_WAYLAND` 64 | * * `GLFW_EXPOSE_NATIVE_MIR` 65 | * 66 | * The available context API macros are: 67 | * * `GLFW_EXPOSE_NATIVE_WGL` 68 | * * `GLFW_EXPOSE_NATIVE_NSGL` 69 | * * `GLFW_EXPOSE_NATIVE_GLX` 70 | * * `GLFW_EXPOSE_NATIVE_EGL` 71 | * 72 | * These macros select which of the native access functions that are declared 73 | * and which platform-specific headers to include. It is then up your (by 74 | * definition platform-specific) code to handle which of these should be 75 | * defined. 76 | */ 77 | 78 | 79 | /************************************************************************* 80 | * System headers and types 81 | *************************************************************************/ 82 | 83 | #if defined(GLFW_EXPOSE_NATIVE_WIN32) 84 | // This is a workaround for the fact that glfw3.h needs to export APIENTRY (for 85 | // example to allow applications to correctly declare a GL_ARB_debug_output 86 | // callback) but windows.h assumes no one will define APIENTRY before it does 87 | #undef APIENTRY 88 | #include 89 | #elif defined(GLFW_EXPOSE_NATIVE_COCOA) 90 | #include 91 | #if defined(__OBJC__) 92 | #import 93 | #else 94 | typedef void* id; 95 | #endif 96 | #elif defined(GLFW_EXPOSE_NATIVE_X11) 97 | #include 98 | #include 99 | #elif defined(GLFW_EXPOSE_NATIVE_WAYLAND) 100 | #include 101 | #elif defined(GLFW_EXPOSE_NATIVE_MIR) 102 | #include 103 | #endif 104 | 105 | #if defined(GLFW_EXPOSE_NATIVE_WGL) 106 | /* WGL is declared by windows.h */ 107 | #endif 108 | #if defined(GLFW_EXPOSE_NATIVE_NSGL) 109 | /* NSGL is declared by Cocoa.h */ 110 | #endif 111 | #if defined(GLFW_EXPOSE_NATIVE_GLX) 112 | #include 113 | #endif 114 | #if defined(GLFW_EXPOSE_NATIVE_EGL) 115 | #include 116 | #endif 117 | 118 | 119 | /************************************************************************* 120 | * Functions 121 | *************************************************************************/ 122 | 123 | #if defined(GLFW_EXPOSE_NATIVE_WIN32) 124 | /*! @brief Returns the adapter device name of the specified monitor. 125 | * 126 | * @return The UTF-8 encoded adapter device name (for example `\\.\DISPLAY1`) 127 | * of the specified monitor, or `NULL` if an [error](@ref error_handling) 128 | * occurred. 129 | * 130 | * @thread_safety This function may be called from any thread. Access is not 131 | * synchronized. 132 | * 133 | * @since Added in version 3.1. 134 | * 135 | * @ingroup native 136 | */ 137 | GLFWAPI const char* glfwGetWin32Adapter(GLFWmonitor* monitor); 138 | 139 | /*! @brief Returns the display device name of the specified monitor. 140 | * 141 | * @return The UTF-8 encoded display device name (for example 142 | * `\\.\DISPLAY1\Monitor0`) of the specified monitor, or `NULL` if an 143 | * [error](@ref error_handling) occurred. 144 | * 145 | * @thread_safety This function may be called from any thread. Access is not 146 | * synchronized. 147 | * 148 | * @since Added in version 3.1. 149 | * 150 | * @ingroup native 151 | */ 152 | GLFWAPI const char* glfwGetWin32Monitor(GLFWmonitor* monitor); 153 | 154 | /*! @brief Returns the `HWND` of the specified window. 155 | * 156 | * @return The `HWND` of the specified window, or `NULL` if an 157 | * [error](@ref error_handling) occurred. 158 | * 159 | * @thread_safety This function may be called from any thread. Access is not 160 | * synchronized. 161 | * 162 | * @since Added in version 3.0. 163 | * 164 | * @ingroup native 165 | */ 166 | GLFWAPI HWND glfwGetWin32Window(GLFWwindow* window); 167 | #endif 168 | 169 | #if defined(GLFW_EXPOSE_NATIVE_WGL) 170 | /*! @brief Returns the `HGLRC` of the specified window. 171 | * 172 | * @return The `HGLRC` of the specified window, or `NULL` if an 173 | * [error](@ref error_handling) occurred. 174 | * 175 | * @thread_safety This function may be called from any thread. Access is not 176 | * synchronized. 177 | * 178 | * @since Added in version 3.0. 179 | * 180 | * @ingroup native 181 | */ 182 | GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* window); 183 | #endif 184 | 185 | #if defined(GLFW_EXPOSE_NATIVE_COCOA) 186 | /*! @brief Returns the `CGDirectDisplayID` of the specified monitor. 187 | * 188 | * @return The `CGDirectDisplayID` of the specified monitor, or 189 | * `kCGNullDirectDisplay` if an [error](@ref error_handling) occurred. 190 | * 191 | * @thread_safety This function may be called from any thread. Access is not 192 | * synchronized. 193 | * 194 | * @since Added in version 3.1. 195 | * 196 | * @ingroup native 197 | */ 198 | GLFWAPI CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* monitor); 199 | 200 | /*! @brief Returns the `NSWindow` of the specified window. 201 | * 202 | * @return The `NSWindow` of the specified window, or `nil` if an 203 | * [error](@ref error_handling) occurred. 204 | * 205 | * @thread_safety This function may be called from any thread. Access is not 206 | * synchronized. 207 | * 208 | * @since Added in version 3.0. 209 | * 210 | * @ingroup native 211 | */ 212 | GLFWAPI id glfwGetCocoaWindow(GLFWwindow* window); 213 | #endif 214 | 215 | #if defined(GLFW_EXPOSE_NATIVE_NSGL) 216 | /*! @brief Returns the `NSOpenGLContext` of the specified window. 217 | * 218 | * @return The `NSOpenGLContext` of the specified window, or `nil` if an 219 | * [error](@ref error_handling) occurred. 220 | * 221 | * @thread_safety This function may be called from any thread. Access is not 222 | * synchronized. 223 | * 224 | * @since Added in version 3.0. 225 | * 226 | * @ingroup native 227 | */ 228 | GLFWAPI id glfwGetNSGLContext(GLFWwindow* window); 229 | #endif 230 | 231 | #if defined(GLFW_EXPOSE_NATIVE_X11) 232 | /*! @brief Returns the `Display` used by GLFW. 233 | * 234 | * @return The `Display` used by GLFW, or `NULL` if an 235 | * [error](@ref error_handling) occurred. 236 | * 237 | * @thread_safety This function may be called from any thread. Access is not 238 | * synchronized. 239 | * 240 | * @since Added in version 3.0. 241 | * 242 | * @ingroup native 243 | */ 244 | GLFWAPI Display* glfwGetX11Display(void); 245 | 246 | /*! @brief Returns the `RRCrtc` of the specified monitor. 247 | * 248 | * @return The `RRCrtc` of the specified monitor, or `None` if an 249 | * [error](@ref error_handling) occurred. 250 | * 251 | * @thread_safety This function may be called from any thread. Access is not 252 | * synchronized. 253 | * 254 | * @since Added in version 3.1. 255 | * 256 | * @ingroup native 257 | */ 258 | GLFWAPI RRCrtc glfwGetX11Adapter(GLFWmonitor* monitor); 259 | 260 | /*! @brief Returns the `RROutput` of the specified monitor. 261 | * 262 | * @return The `RROutput` of the specified monitor, or `None` if an 263 | * [error](@ref error_handling) occurred. 264 | * 265 | * @thread_safety This function may be called from any thread. Access is not 266 | * synchronized. 267 | * 268 | * @since Added in version 3.1. 269 | * 270 | * @ingroup native 271 | */ 272 | GLFWAPI RROutput glfwGetX11Monitor(GLFWmonitor* monitor); 273 | 274 | /*! @brief Returns the `Window` of the specified window. 275 | * 276 | * @return The `Window` of the specified window, or `None` if an 277 | * [error](@ref error_handling) occurred. 278 | * 279 | * @thread_safety This function may be called from any thread. Access is not 280 | * synchronized. 281 | * 282 | * @since Added in version 3.0. 283 | * 284 | * @ingroup native 285 | */ 286 | GLFWAPI Window glfwGetX11Window(GLFWwindow* window); 287 | #endif 288 | 289 | #if defined(GLFW_EXPOSE_NATIVE_GLX) 290 | /*! @brief Returns the `GLXContext` of the specified window. 291 | * 292 | * @return The `GLXContext` of the specified window, or `NULL` if an 293 | * [error](@ref error_handling) occurred. 294 | * 295 | * @thread_safety This function may be called from any thread. Access is not 296 | * synchronized. 297 | * 298 | * @since Added in version 3.0. 299 | * 300 | * @ingroup native 301 | */ 302 | GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* window); 303 | 304 | /*! @brief Returns the `GLXWindow` of the specified window. 305 | * 306 | * @return The `GLXWindow` of the specified window, or `None` if an 307 | * [error](@ref error_handling) occurred. 308 | * 309 | * @thread_safety This function may be called from any thread. Access is not 310 | * synchronized. 311 | * 312 | * @since Added in version 3.2. 313 | * 314 | * @ingroup native 315 | */ 316 | GLFWAPI GLXWindow glfwGetGLXWindow(GLFWwindow* window); 317 | #endif 318 | 319 | #if defined(GLFW_EXPOSE_NATIVE_WAYLAND) 320 | /*! @brief Returns the `struct wl_display*` used by GLFW. 321 | * 322 | * @return The `struct wl_display*` used by GLFW, or `NULL` if an 323 | * [error](@ref error_handling) occurred. 324 | * 325 | * @thread_safety This function may be called from any thread. Access is not 326 | * synchronized. 327 | * 328 | * @since Added in version 3.2. 329 | * 330 | * @ingroup native 331 | */ 332 | GLFWAPI struct wl_display* glfwGetWaylandDisplay(void); 333 | 334 | /*! @brief Returns the `struct wl_output*` of the specified monitor. 335 | * 336 | * @return The `struct wl_output*` of the specified monitor, or `NULL` if an 337 | * [error](@ref error_handling) occurred. 338 | * 339 | * @thread_safety This function may be called from any thread. Access is not 340 | * synchronized. 341 | * 342 | * @since Added in version 3.2. 343 | * 344 | * @ingroup native 345 | */ 346 | GLFWAPI struct wl_output* glfwGetWaylandMonitor(GLFWmonitor* monitor); 347 | 348 | /*! @brief Returns the main `struct wl_surface*` of the specified window. 349 | * 350 | * @return The main `struct wl_surface*` of the specified window, or `NULL` if 351 | * an [error](@ref error_handling) occurred. 352 | * 353 | * @thread_safety This function may be called from any thread. Access is not 354 | * synchronized. 355 | * 356 | * @since Added in version 3.2. 357 | * 358 | * @ingroup native 359 | */ 360 | GLFWAPI struct wl_surface* glfwGetWaylandWindow(GLFWwindow* window); 361 | #endif 362 | 363 | #if defined(GLFW_EXPOSE_NATIVE_MIR) 364 | /*! @brief Returns the `MirConnection*` used by GLFW. 365 | * 366 | * @return The `MirConnection*` used by GLFW, or `NULL` if an 367 | * [error](@ref error_handling) occurred. 368 | * 369 | * @thread_safety This function may be called from any thread. Access is not 370 | * synchronized. 371 | * 372 | * @since Added in version 3.2. 373 | * 374 | * @ingroup native 375 | */ 376 | GLFWAPI MirConnection* glfwGetMirDisplay(void); 377 | 378 | /*! @brief Returns the Mir output ID of the specified monitor. 379 | * 380 | * @return The Mir output ID of the specified monitor, or zero if an 381 | * [error](@ref error_handling) occurred. 382 | * 383 | * @thread_safety This function may be called from any thread. Access is not 384 | * synchronized. 385 | * 386 | * @since Added in version 3.2. 387 | * 388 | * @ingroup native 389 | */ 390 | GLFWAPI int glfwGetMirMonitor(GLFWmonitor* monitor); 391 | 392 | /*! @brief Returns the `MirSurface*` of the specified window. 393 | * 394 | * @return The `MirSurface*` of the specified window, or `NULL` if an 395 | * [error](@ref error_handling) occurred. 396 | * 397 | * @thread_safety This function may be called from any thread. Access is not 398 | * synchronized. 399 | * 400 | * @since Added in version 3.2. 401 | * 402 | * @ingroup native 403 | */ 404 | GLFWAPI MirSurface* glfwGetMirWindow(GLFWwindow* window); 405 | #endif 406 | 407 | #if defined(GLFW_EXPOSE_NATIVE_EGL) 408 | /*! @brief Returns the `EGLDisplay` used by GLFW. 409 | * 410 | * @return The `EGLDisplay` used by GLFW, or `EGL_NO_DISPLAY` if an 411 | * [error](@ref error_handling) occurred. 412 | * 413 | * @thread_safety This function may be called from any thread. Access is not 414 | * synchronized. 415 | * 416 | * @since Added in version 3.0. 417 | * 418 | * @ingroup native 419 | */ 420 | GLFWAPI EGLDisplay glfwGetEGLDisplay(void); 421 | 422 | /*! @brief Returns the `EGLContext` of the specified window. 423 | * 424 | * @return The `EGLContext` of the specified window, or `EGL_NO_CONTEXT` if an 425 | * [error](@ref error_handling) occurred. 426 | * 427 | * @thread_safety This function may be called from any thread. Access is not 428 | * synchronized. 429 | * 430 | * @since Added in version 3.0. 431 | * 432 | * @ingroup native 433 | */ 434 | GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* window); 435 | 436 | /*! @brief Returns the `EGLSurface` of the specified window. 437 | * 438 | * @return The `EGLSurface` of the specified window, or `EGL_NO_SURFACE` if an 439 | * [error](@ref error_handling) occurred. 440 | * 441 | * @thread_safety This function may be called from any thread. Access is not 442 | * synchronized. 443 | * 444 | * @since Added in version 3.0. 445 | * 446 | * @ingroup native 447 | */ 448 | GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* window); 449 | #endif 450 | 451 | #ifdef __cplusplus 452 | } 453 | #endif 454 | 455 | #endif /* _glfw3_native_h_ */ 456 | 457 | -------------------------------------------------------------------------------- /my_example/suspension_ball/libs/glfw/lib-vc2010-64/glfw3.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalvqw/ImGui_FloatBall/e2e7726965dee0d3721743b35bc8fe7d17eaf7b0/my_example/suspension_ball/libs/glfw/lib-vc2010-64/glfw3.lib -------------------------------------------------------------------------------- /my_example/suspension_ball/log/log.cpp: -------------------------------------------------------------------------------- 1 | #include "log.h" 2 | #include "../imgui/imgui.h" 3 | #pragma warning (disable : 4244) 4 | 5 | struct tab_anim 6 | { 7 | float label_anim; 8 | float hovered_anim; 9 | float active_anim; 10 | }; 11 | 12 | bool login::selected(const char* label, bool tab) 13 | { 14 | ImGuiWindow* window = ImGui::GetCurrentWindow(); 15 | if (window->SkipItems) 16 | return false; 17 | 18 | ImGuiContext& g = *GImGui; 19 | const ImGuiStyle& style = g.Style; 20 | const ImGuiID id = window->GetID(label); 21 | const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true); 22 | ImVec2 pos = window->DC.CursorPos; 23 | 24 | const ImRect rect(pos, ImVec2(pos.x + label_size.x, pos.y + label_size.y)); 25 | ImGui::ItemSize(ImVec4(rect.Min.x, rect.Min.y, rect.Max.x, rect.Max.y), style.FramePadding.y); 26 | if (!ImGui::ItemAdd(rect, id)) 27 | return false; 28 | 29 | bool hovered, held; 30 | bool pressed = ImGui::ButtonBehavior(rect, id, &hovered, &held, NULL); 31 | 32 | static std::map anim; 33 | auto it_anim = anim.find(id); 34 | if (it_anim == anim.end()) 35 | { 36 | anim.insert({ id, {0.6f, 0.f, 0.f} }); 37 | it_anim = anim.find(id); 38 | } 39 | 40 | it_anim->second.label_anim = ImLerp(it_anim->second.label_anim, tab ? 0.0f : 0.6f, 0.05f * (1.0f - ImGui::GetIO().DeltaTime)); 41 | it_anim->second.hovered_anim = ImLerp(it_anim->second.hovered_anim, hovered ? 0.2f : 0.0f, 0.03f * (1.0f - ImGui::GetIO().DeltaTime)); 42 | it_anim->second.active_anim = ImLerp(it_anim->second.active_anim, tab ? 1.0f : 0.0f, 0.08f * (1.0f - ImGui::GetIO().DeltaTime)); 43 | 44 | window->DrawList->AddText(ImVec2((rect.Min.x + rect.Max.x) / 2.f - (label_size.x / 2.f), (rect.Min.y + rect.Max.y) / 2.f - (label_size.y / 2.f)), ImColor(1.0f, 1.0f, 1.0f, it_anim->second.label_anim + it_anim->second.hovered_anim), label); 45 | window->DrawList->AddText(ImVec2((rect.Min.x + rect.Max.x) / 2.f - (label_size.x / 2.f), (rect.Min.y + rect.Max.y) / 2.f - (label_size.y / 2.f)), ImColor(accent_colour[0], accent_colour[1], accent_colour[2], it_anim->second.active_anim), label); 46 | 47 | return pressed; 48 | } 49 | -------------------------------------------------------------------------------- /my_example/suspension_ball/log/log.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "../imgui/imgui.h" 10 | #include "../imgui/imgui_internal.h" 11 | 12 | extern float accent_colour[4]; 13 | 14 | namespace login { 15 | bool selected(const char* label, bool tab = false); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /my_example/suspension_ball/log/log_animation.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../imgui/imgui_internal.h" 4 | 5 | namespace ImGui { 6 | 7 | bool BufferingBar(const char* label, float value, const ImVec2& size_arg, const ImU32& bg_col, const ImU32& fg_col) { 8 | ImGuiWindow* window = GetCurrentWindow(); 9 | if (window->SkipItems) 10 | return false; 11 | 12 | ImGuiContext& g = *GImGui; 13 | const ImGuiStyle& style = g.Style; 14 | const ImGuiID id = window->GetID(label); 15 | 16 | ImVec2 pos = window->DC.CursorPos; 17 | ImVec2 size = size_arg; 18 | size.x -= style.FramePadding.x * 2; 19 | 20 | const ImRect bb(pos, ImVec2(pos.x + size.x, pos.y + size.y)); 21 | ItemSize(bb, style.FramePadding.y); 22 | if (!ItemAdd(bb, id)) 23 | return false; 24 | 25 | // Render 26 | const float circleStart = size.x * 0.7f; 27 | const float circleEnd = size.x; 28 | const float circleWidth = circleEnd - circleStart; 29 | 30 | window->DrawList->AddRectFilled(bb.Min, ImVec2(pos.x + circleStart, bb.Max.y), bg_col); 31 | window->DrawList->AddRectFilled(bb.Min, ImVec2(pos.x + circleStart * value, bb.Max.y), fg_col); 32 | 33 | const float t = g.Time; 34 | const float r = size.y / 2; 35 | const float speed = 1.5f; 36 | 37 | const float a = speed * 0; 38 | const float b = speed * 0.333f; 39 | const float c = speed * 0.666f; 40 | 41 | const float o1 = (circleWidth + r) * (t + a - speed * (int)((t + a) / speed)) / speed; 42 | const float o2 = (circleWidth + r) * (t + b - speed * (int)((t + b) / speed)) / speed; 43 | const float o3 = (circleWidth + r) * (t + c - speed * (int)((t + c) / speed)) / speed; 44 | 45 | window->DrawList->AddCircleFilled(ImVec2(pos.x + circleEnd - o1, bb.Min.y + r), r, bg_col); 46 | window->DrawList->AddCircleFilled(ImVec2(pos.x + circleEnd - o2, bb.Min.y + r), r, bg_col); 47 | window->DrawList->AddCircleFilled(ImVec2(pos.x + circleEnd - o3, bb.Min.y + r), r, bg_col); 48 | } 49 | 50 | bool Spinner(const char* label, float radius, int thickness, const ImU32& color) { 51 | ImGuiWindow* window = GetCurrentWindow(); 52 | if (window->SkipItems) 53 | return false; 54 | 55 | ImGuiContext& g = *GImGui; 56 | const ImGuiStyle& style = g.Style; 57 | const ImGuiID id = window->GetID(label); 58 | 59 | ImVec2 pos = window->DC.CursorPos; 60 | ImVec2 size((radius) * 2, (radius + style.FramePadding.y) * 2); 61 | 62 | const ImRect bb(pos, ImVec2(pos.x + size.x, pos.y + size.y)); 63 | ItemSize(bb, style.FramePadding.y); 64 | if (!ItemAdd(bb, id)) 65 | return false; 66 | 67 | // Render 68 | window->DrawList->PathClear(); 69 | 70 | int num_segments = 30; 71 | int start = abs((int)(ImSin(g.Time * 1.8f) * (num_segments - 5))); 72 | 73 | const float a_min = IM_PI * 2.0f * ((float)start) / (float)num_segments; 74 | const float a_max = IM_PI * 2.0f * ((float)num_segments - 3) / (float)num_segments; 75 | 76 | const ImVec2 centre = ImVec2(pos.x + radius, pos.y + radius + style.FramePadding.y); 77 | 78 | for (int i = 0; i < num_segments; ++i) { 79 | const float a = a_min + ((float)i / (float)num_segments) * (a_max - a_min); 80 | window->DrawList->PathLineTo(ImVec2(centre.x + ImCos(a + g.Time * 8) * radius, 81 | centre.y + ImSin(a + g.Time * 8) * radius)); 82 | } 83 | 84 | window->DrawList->PathStroke(color, false, thickness); 85 | } 86 | 87 | } -------------------------------------------------------------------------------- /my_example/suspension_ball/main.cpp: -------------------------------------------------------------------------------- 1 | #include "global.h" 2 | #include "draw.h" 3 | #include "knobs/imgui-knobs.h" 4 | #include "theme/themes.h" 5 | #include "log/log.h" 6 | #include "log/log_animation.h" 7 | #include "icon.h" 8 | #include "widget.h" 9 | #include 10 | #include 11 | 12 | ImFont* tab_title; 13 | ImFont* icon; 14 | 15 | static int tab = 0; 16 | 17 | static float content_animation = 0.0f; 18 | static float dpi_scale = 1.0f; 19 | 20 | static char username[64]; 21 | static char password[64]; 22 | 23 | float accent_colour[4] = { 173 / 255.f, 57 / 255.f, 57 / 255.f, 1.f }; 24 | 25 | 26 | static void glfw_error_callback(int error, const char* description) 27 | { 28 | fprintf(stderr, "Glfw Error %d: %s\n", error, description); 29 | } 30 | 31 | void shut(const char* text, bool* close, float x) 32 | { 33 | ImGui::SetCursorPos({ x - 170.0f,10.0f }); 34 | if (ImGui::SmallButton(text)) 35 | *close = true; 36 | } 37 | 38 | int main() 39 | { 40 | // Setup window 41 | glfwSetErrorCallback(glfw_error_callback); 42 | if (!glfwInit()) 43 | return 1; 44 | 45 | const char* glsl_version = "#version 130"; 46 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 47 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); 48 | 49 | // Create window with graphics context 50 | GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+OpenGL3 example", NULL, NULL); 51 | if (window == NULL) 52 | return 1; 53 | glfwMakeContextCurrent(window); 54 | glfwSwapInterval(1); // Enable vsync 55 | 56 | // Setup Dear ImGui context 57 | IMGUI_CHECKVERSION(); 58 | ImGui::CreateContext(); 59 | 60 | ImGui::StyleColorsClassic(); 61 | 62 | ImGuiIO& io = ImGui::GetIO(); (void)io; 63 | ImFont* font = io.Fonts->AddFontFromMemoryTTF((void*)ZKBlackfont_data, ZKBlackfont_size, 25.0f, nullptr, io.Fonts->GetGlyphRangesChineseFull()); 64 | 65 | ImGui_ImplGlfw_InitForOpenGL(window, true); 66 | ImGui_ImplOpenGL3_Init(glsl_version); 67 | 68 | static bool isBall = true; 69 | static bool isMenu = false; 70 | static bool open = false; 71 | static bool close = false; 72 | static bool mem = true; 73 | static bool button = true; 74 | static bool bar = true; 75 | 76 | static float count = 0; 77 | static float winx = 120; 78 | static float winy = 60; 79 | static float memory_x = 600; 80 | static float memory_y = 300; 81 | 82 | static ImVec2 Pos = { 0, 0 }; 83 | static ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); 84 | //ImGuiWindow* G_window = nullptr; 85 | static float velocity = 1.f; 86 | while (!glfwWindowShouldClose(window)) 87 | { 88 | glfwPollEvents(); 89 | 90 | ImGui_ImplOpenGL3_NewFrame(); 91 | ImGui_ImplGlfw_NewFrame(); 92 | ImGui::NewFrame(); 93 | 94 | ImGuiStyle& Style = ImGui::GetStyle(); 95 | auto Color = Style.Colors; 96 | 97 | time_t t = time(0); 98 | char tmp[32] = { NULL }; 99 | static int Tab = 0; 100 | const char* text = "-"; 101 | static double s0 = 0.1; 102 | enum Tab 103 | { 104 | Esp, 105 | Widget, 106 | Setting, 107 | }; 108 | 109 | static int Theme = 0; 110 | enum Theme 111 | { 112 | black, 113 | colorful, 114 | gray, 115 | red 116 | }; 117 | 118 | switch (Theme) 119 | { 120 | case Theme::black: 121 | ImCandy::Theme_Blender(&Style); 122 | break; 123 | case Theme::colorful: 124 | ImCandy::Theme_Cyberpunk(&Style); 125 | break; 126 | case Theme::gray: 127 | ImCandy::Theme_Nord(&Style); 128 | break; 129 | case Theme::red: 130 | ImCandy::Theme_Red(&Style); 131 | break; 132 | } 133 | 134 | if (tab == 0) { 135 | ImGui::SetNextWindowSize(ImVec2(800 * dpi_scale, 400 * dpi_scale)); 136 | ImGui::Begin("loader", nullptr, ImGuiWindowFlags_NoDecoration); 137 | { 138 | auto draw = ImGui::GetWindowDrawList(); 139 | ImVec2 pos = ImGui::GetWindowPos(); 140 | ImVec2 size = ImGui::GetWindowSize(); 141 | 142 | draw->AddText(icon, 14.0f, ImVec2(pos.x + 9, pos.y + 4), ImColor(accent_colour[0], accent_colour[1], accent_colour[2]), u8"至简"); 143 | 144 | draw->AddLine(ImVec2(pos.x, pos.y + 23), ImVec2(pos.x + size.x, pos.y + 23), ImColor(46, 46, 46)); // upper line 145 | draw->AddRectFilledMultiColor(ImVec2(pos.x, pos.y + 24), ImVec2(pos.x + size.x, pos.y + 30), ImColor(0, 0, 0), ImColor(0, 0, 0), ImColor(0, 0, 0, 0), ImColor(0, 0, 0, 0)); // upper 'glow' 146 | 147 | content_animation = ImLerp(content_animation, content_animation < 1.0f ? 1.0f : 0.0f, 0.07f * (1.0f - ImGui::GetIO().DeltaTime)); 148 | 149 | draw->AddText(tab_title, 17.0f, ImVec2(pos.x + size.x / 2 - ImGui::CalcTextSize("Bilibili唯我至简").x / 2, pos.y + 45 * content_animation), ImColor(0.8f, 0.8f, 0.8f, content_animation), u8"Bilibili唯我至简"); 150 | 151 | ImGui::SetCursorPos(ImVec2(200 * dpi_scale, 85 * content_animation)); 152 | 153 | ImGui::BeginChild("log_window", ImVec2(size.x / 2, size.y - 140)); 154 | { 155 | ImGui::InputText(u8"用户名", username, sizeof(username)); 156 | ImGui::InputText(u8"密码", password, sizeof(password), ImGuiInputTextFlags_Password); 157 | ImGui::Spacing(); 158 | ImGui::Spacing(); 159 | 160 | if (ImGui::Button(u8"登录", ImVec2(162 * dpi_scale, 25 * dpi_scale))) 161 | { 162 | Pos = ImGui::GetWindowPos(); 163 | tab = 1; 164 | } 165 | } 166 | ImGui::EndChild(); 167 | } 168 | ImGui::End(); 169 | } 170 | if (tab == 1) 171 | { 172 | ImGui::SetNextWindowBgAlpha(0.0f); 173 | ImGui::SetWindowPos("Progress", Pos, 1); 174 | ImGui::Begin("Progress", &bar, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoScrollWithMouse); 175 | ImGui::SetWindowSize({ 400, 80 }); 176 | 177 | const ImU32 col = ImGui::GetColorU32(ImVec4(0.83f, 0.13f, 0.07f, 1.0f)); 178 | const ImU32 bg = ImGui::GetColorU32(ImGuiCol_Button); 179 | 180 | ImSpinner::SpinnerAngTriple("SpinnerAngTriple", 16, 13, 10, 1.3f, ImColor(255, 255, 255), ImColor(255, 0, 0), ImColor(255, 255, 255), 5 * velocity, 1.5f * IM_PI); 181 | ImGui::BufferingBar("buffer_bar", count / 200.0f, ImVec2(400, 6), bg, col); 182 | ImGui::End(); 183 | ++count; 184 | if (count == 200) 185 | tab = 2; 186 | } 187 | 188 | if (tab == 2) { 189 | if (isBall) 190 | { 191 | ImGui::SetNextWindowBgAlpha(0.0f); 192 | ImGui::Begin("Ball", &isBall, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize); 193 | ImGui::SetWindowSize({ 60, 60 }); 194 | ImSpinner::SpinnerIngYang("my_ball", 16, 5, true, 3.f, ImColor(255, 255, 255), ImColor(255, 0, 0), 4 * velocity, IM_PI * 0.8f); 195 | if (ImGui::IsClickandDrag()) { 196 | isMenu = true; 197 | isBall = false; 198 | open = false; 199 | Pos = ImGui::GetWindowPos(); 200 | ImGui::SetWindowPos("Menu", Pos, 1); 201 | } 202 | ImGui::End(); 203 | } 204 | 205 | if (isMenu) 206 | { 207 | 208 | ImGui::Begin("Menu", &isMenu, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoScrollWithMouse); 209 | ImGui::SetWindowSize({ winx, winy }); 210 | Pos = ImGui::GetWindowPos(); 211 | ImGui::SetWindowPos("Ball", Pos, 1); 212 | 213 | ImSpinner::SpinnerIngYang("my_ball", 16, 5, true, 3.f, ImColor(255, 255, 255), ImColor(255, 0, 0), 4 * velocity, IM_PI * 0.8f); 214 | ImGui::SameLine(); 215 | ImGui::Text(u8"至简"); 216 | 217 | ImGui::PushStyleColor(ImGuiCol_Button, Tab == Tab::Esp ? Color[ImGuiCol_Button] : ImVec4(0.0f, 0.0f, 0.0f, 0.0f)); 218 | if (ImGui::Button(u8"测试", { 100.0f,40.0f })) 219 | { 220 | Tab = Tab::Esp; 221 | } 222 | ImGui::PopStyleColor(); 223 | 224 | ImGui::PushStyleColor(ImGuiCol_Button, Tab == Tab::Widget ? Color[ImGuiCol_Button] : ImVec4(0.0f, 0.0f, 0.0f, 0.0f)); 225 | if (ImGui::Button(u8"小组件", { 100.0f,40.0f })) 226 | { 227 | Tab = Tab::Widget; 228 | } 229 | ImGui::PopStyleColor(); 230 | 231 | ImGui::PushStyleColor(ImGuiCol_Button, Tab == Tab::Setting ? Color[ImGuiCol_Button] : ImVec4(0.0f, 0.0f, 0.0f, 0.0f)); 232 | if (ImGui::Button(u8"设置", { 100.0f,40.0f })) 233 | { 234 | Tab = Tab::Setting; 235 | } 236 | ImGui::PopStyleColor(); 237 | 238 | ImGui::SetCursorPos({ 120.0f,10.0f }); 239 | ImGui::NextColumn(); 240 | ImGui::BeginChild("Child", { winx - 130.0f,winy - 20.0f }, true); 241 | switch (Tab) 242 | { 243 | case Tab::Esp: 244 | shut(text, &close, winx); 245 | 246 | ImGui::PushStyleColor(ImGuiCol_Button, ImCandy::Rainbow(s0)); 247 | if (ImGui::Button("FBI WARNNING ! ! !")) 248 | ShellExecute(nullptr, "open", "https:///github.com/dalvqw/Imgui_FloatBall", nullptr, nullptr, SW_SHOWNORMAL); 249 | ImGui::PopStyleColor(); 250 | 251 | PlotVar("Framerate", ImGui::GetIO().Framerate); 252 | ImGui::Text(u8"Frames (%.1fFPS)", ImGui::GetIO().Framerate); 253 | strftime(tmp, sizeof(tmp), "%Y-%m-%d %H:%M", localtime(&t)); 254 | ImGui::TextColored(Color[ImGuiCol_Text], "%s", tmp); 255 | break; 256 | case Tab::Widget: 257 | shut(text, &close, winx); 258 | ToggleButton("button", &button, Color[ImGuiCol_ButtonHovered], Color[ImGuiCol_Button]); 259 | 260 | ImGuiKnobs::Knob(u8"Bilibili", &winx, 600.0f, 1200.0f, 2.0f, "%.1ff", ImGuiKnobVariant_Space); 261 | ImGui::SameLine(); 262 | ImGuiKnobs::Knob(u8"唯我至简", &winy, 300.0f, 600.0f, 2.0f, "%.1ff", ImGuiKnobVariant_WiperDot); 263 | if (mem) 264 | { 265 | memory_x = winx; 266 | memory_y = winy; 267 | } 268 | break; 269 | case Tab::Setting: 270 | shut(text, &close, winx); 271 | 272 | ImGui::Text(u8"主题"); 273 | ImGui::SameLine(); 274 | ImGui::SetCursorPos({ 74.0f,35.0f }); 275 | ImGui::SetNextItemWidth(85.0f); 276 | ImGui::Combo(u8" ", &Theme, u8"黑色\0炫彩\0灰色\0红白"); 277 | 278 | break; 279 | } 280 | ImGui::EndChild(); 281 | 282 | if (!open) 283 | { 284 | winx += 60; 285 | winy += 30; 286 | if (winx >= memory_x) 287 | { 288 | open = true; 289 | mem = true; 290 | } 291 | } 292 | 293 | if (close) 294 | { 295 | mem = false; 296 | winx -= 60; 297 | winy -= 30; 298 | if (winx <= 120) 299 | { 300 | close = false; 301 | isBall = true; 302 | isMenu = false; 303 | } 304 | } 305 | 306 | ImGui::End(); 307 | } 308 | } 309 | // Rendering 310 | ImGui::Render(); 311 | int display_w, display_h; 312 | glfwGetFramebufferSize(window, &display_w, &display_h); 313 | glViewport(0, 0, display_w, display_h); 314 | glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w); 315 | glClear(GL_COLOR_BUFFER_BIT); 316 | ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); 317 | 318 | glfwSwapBuffers(window); 319 | } 320 | 321 | 322 | // Cleanup 323 | ImGui::PopFont(); 324 | ImGui_ImplOpenGL3_Shutdown(); 325 | ImGui_ImplGlfw_Shutdown(); 326 | ImGui::DestroyContext(); 327 | 328 | glfwDestroyWindow(window); 329 | glfwTerminate(); 330 | return 0; 331 | } 332 | -------------------------------------------------------------------------------- /my_example/suspension_ball/suspension_ball.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {6d9ef402-7ef2-44b4-b2ec-e482fe4c7935} 25 | suspensionball 26 | 10.0 27 | my_ball 28 | 29 | 30 | 31 | Application 32 | true 33 | v143 34 | Unicode 35 | 36 | 37 | Application 38 | false 39 | v143 40 | true 41 | Unicode 42 | 43 | 44 | Application 45 | true 46 | v143 47 | Unicode 48 | 49 | 50 | Application 51 | false 52 | v143 53 | true 54 | Unicode 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | Level3 77 | true 78 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 79 | true 80 | 81 | 82 | Console 83 | true 84 | 85 | 86 | 87 | 88 | Level3 89 | true 90 | true 91 | true 92 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 93 | true 94 | 95 | 96 | Console 97 | true 98 | true 99 | true 100 | 101 | 102 | 103 | 104 | Level3 105 | true 106 | 107 | 108 | true 109 | .\libs\glfw\include;%(AdditionalIncludeDirectories);.\.. 110 | 4244 111 | stdcpp14 112 | 113 | 114 | Console 115 | true 116 | .\libs\glfw\lib-vc2010-64;%(AdditionalLibraryDirectories) 117 | opengl32.lib;glfw3.lib;%(AdditionalDependencies) 118 | 119 | 120 | 121 | 122 | Level3 123 | true 124 | true 125 | true 126 | 127 | 128 | true 129 | .\libs\glfw\include;%(AdditionalIncludeDirectories);.\.. 130 | 4244 131 | stdcpp14 132 | 133 | 134 | Console 135 | true 136 | true 137 | true 138 | .\libs\glfw\lib-vc2010-64;%(AdditionalLibraryDirectories) 139 | opengl32.lib;glfw3.lib;%(AdditionalDependencies) 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | -------------------------------------------------------------------------------- /my_example/suspension_ball/suspension_ball.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {70d9dd9d-25cf-446c-9a1c-2e21c4138303} 14 | 15 | 16 | {ff8fddc0-0d03-4d06-8414-b4da77a53baa} 17 | 18 | 19 | {69f45b7b-156f-46e9-b907-38abb7585108} 20 | 21 | 22 | {866200c1-91e8-4814-b0bf-a8b614efa07c} 23 | 24 | 25 | 26 | 27 | 源文件 28 | 29 | 30 | ImGui 31 | 32 | 33 | ImGui 34 | 35 | 36 | ImGui 37 | 38 | 39 | ImGui 40 | 41 | 42 | ImGui 43 | 44 | 45 | ImGui 46 | 47 | 48 | knobs 49 | 50 | 51 | log 52 | 53 | 54 | 55 | 56 | ImGui 57 | 58 | 59 | ImGui 60 | 61 | 62 | ImGui 63 | 64 | 65 | ImGui 66 | 67 | 68 | ImGui 69 | 70 | 71 | ImGui 72 | 73 | 74 | ImGui 75 | 76 | 77 | ImGui 78 | 79 | 80 | ImGui 81 | 82 | 83 | 头文件 84 | 85 | 86 | 头文件 87 | 88 | 89 | knobs 90 | 91 | 92 | ImGui 93 | 94 | 95 | 头文件 96 | 97 | 98 | 头文件 99 | 100 | 101 | 头文件 102 | 103 | 104 | theme 105 | 106 | 107 | theme 108 | 109 | 110 | log 111 | 112 | 113 | log 114 | 115 | 116 | -------------------------------------------------------------------------------- /my_example/suspension_ball/suspension_ball.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /my_example/suspension_ball/theme/Gradient.h: -------------------------------------------------------------------------------- 1 | #ifndef Gradient_H 2 | #define Gradient_H 3 | 4 | #define _USE_MATH_DEFINES 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #define GRADIENT_KEY_DEFAULT_PRECISION double 16 | #define GRADIENT_COLOR_PRECISION_TYPE double 17 | #define GRADIENT_VALARRAY_FORMAT_OPEN "(" 18 | #define GRADIENT_VALARRAY_FORMAT_CLOSE ")" 19 | #define GRADIENT_VALARRAY_FORMAT_SEPARATOR ", " 20 | #define M_PI 3.14159265358979323846f 21 | 22 | namespace gradient { 23 | 24 | template 25 | T linear_interpolation(T x) { 26 | return x; 27 | } 28 | 29 | template 30 | T cosine_interpolation(T x) { 31 | return T(1) - (cos(x * T(M_PI)) + T(1)) / T(2); 32 | } 33 | } 34 | 35 | namespace gradient { 36 | using default_precision = GRADIENT_KEY_DEFAULT_PRECISION; 37 | template using Interpolation = std::function; 38 | 39 | template 40 | class GradientBase { 41 | public: 42 | explicit GradientBase(const Interpolation& interpolation) 43 | : interpolationMethod(interpolation) {} 44 | GradientBase() 45 | : interpolationMethod(linear_interpolation) {} 46 | virtual ~GradientBase() = default; 47 | 48 | Interpolation& interpolation() { return this->interpolationMethod; } 49 | const Interpolation& interpolation() const { return this->interpolationMethod; } 50 | void setInterpolation(const Interpolation& interp) { this->interpolationMethod = interp; } 51 | 52 | T interpolate(const T& lowerBound, const T& upperBound, precision r) const { 53 | assert(interpolationMethod); 54 | r = interpolationMethod(r); 55 | return upperBound * r + lowerBound * (precision(1) - r); 56 | } 57 | 58 | private: 59 | Interpolation interpolationMethod; 60 | }; 61 | 62 | template 63 | class LinearGradient : public GradientBase { 64 | public: 65 | using GradientBase::GradientBase; 66 | ~LinearGradient() override = default; 67 | T& operator[](precision keyPoint); 68 | const T& operator[](precision keyPoint) const; 69 | T operator()(precision point) const; 70 | 71 | private: 72 | std::map keyPoints; 73 | }; 74 | } 75 | 76 | namespace gradient { 77 | 78 | namespace operators { 79 | 80 | template 81 | std::ostream& operator<<(std::ostream& ostream, const T& valarray) { 82 | ostream << GRADIENT_VALARRAY_FORMAT_OPEN; 83 | bool firstValue = true; 84 | std::for_each(begin(valarray), end(valarray), [&firstValue, &ostream](const value_type& element) { 85 | if (!firstValue) { 86 | ostream << GRADIENT_VALARRAY_FORMAT_SEPARATOR; 87 | } 88 | else { 89 | firstValue = false; 90 | } 91 | ostream << element; 92 | }); 93 | ostream << GRADIENT_VALARRAY_FORMAT_CLOSE; 94 | return ostream; 95 | } 96 | } 97 | } 98 | 99 | namespace gradient { 100 | 101 | template 102 | T& LinearGradient::operator[](precision keyPoint) { 103 | return this->keyPoints[keyPoint]; 104 | } 105 | 106 | template 107 | const T& LinearGradient::operator[](precision keyPoint) const { 108 | return this->keyPoints.at(keyPoint); 109 | } 110 | 111 | template 112 | T LinearGradient::operator()(precision point) const { 113 | 114 | assert(!this->keyPoints.empty()); 115 | T returnValue; 116 | 117 | const auto upper_bound_it = this->keyPoints.upper_bound(point); 118 | 119 | 120 | if (upper_bound_it == this->keyPoints.end()) { 121 | returnValue = this->keyPoints.rbegin()->second; 122 | } 123 | else { 124 | if (upper_bound_it == this->keyPoints.begin()) { 125 | returnValue = this->keyPoints.begin()->second; 126 | } 127 | else { 128 | const auto lower_bound_it = prev(upper_bound_it); 129 | 130 | const T& min = lower_bound_it->second; 131 | const T& max = upper_bound_it->second; 132 | const precision min_point = lower_bound_it->first; 133 | const precision max_point = upper_bound_it->first; 134 | const precision ratio = (point - min_point) / (max_point - min_point); 135 | returnValue = this->interpolate(min, max, ratio); 136 | } 137 | } 138 | 139 | return returnValue; 140 | } 141 | } 142 | 143 | namespace gradient { 144 | 145 | using Color = std::valarray; 146 | using LinearColorGradient = LinearGradient; 147 | 148 | template class LinearGradient; 149 | template void GradientBase::setInterpolation(const Interpolation& interpolation); 150 | } 151 | 152 | #endif -------------------------------------------------------------------------------- /my_example/suspension_ball/theme/themes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "../imgui/imgui.h" 6 | #include "gradient.h" 7 | 8 | #ifdef IMCANDYCONSTS 9 | 10 | const ImVec4 IV4_WHITE{ 1.000,1.000,1.000,1.000 };//#ffffff 11 | const ImVec4 IV4_BLACK{ 0.000,0.000,0.000,1.000 };//#000000 12 | const ImVec4 IV4_CRIMSON{ 0.827,0.063,0.153,1.000 };//#D31027 13 | const ImVec4 IV4_SKYBLUE{ 0.125,0.741,1.000,1.000 };//#20BDFF 14 | const ImVec4 IV4_AZURE{ 0.000,0.447,1.000,1.000 };//#0072ff 15 | const ImVec4 IV4_HOTPINK{ 1.000,0.000,0.600,1.000 };//#FF0099 16 | const ImVec4 IV4_CHARTREUSE{ 0.678,0.820,0.000,1.000 };//#ADD100 17 | const ImVec4 IV4_EMERALD{ 0.220,0.937,0.490,1.000 };//#38ef7d 18 | const ImVec4 IV4_BUBBLEGUM{ 0.988,0.404,0.980,1.000 };//#fc67fa 19 | const ImVec4 IV4_TWITCH{ 0.569,0.275,1.000,1.000 };//#9146FF 20 | const ImVec4 IV4_DISCORD{ 0.345,0.396,0.949,1.000 };//#5865F2 21 | const ImVec4 IV4_TWITTER{ 0.114,0.631,0.949,1.000 };//#1DA1F2 22 | const ImVec4 IV4_SPOTIFY{ 0.114,0.725,0.329,1.000 };//#1DB954 23 | const ImVec4 IV4_GOOGLEBLUE{ 0.259,0.522,0.957,1.000 };//#4285F4 24 | const ImVec4 IV4_MANGO{ 1.000,0.784,0.216,1.000 };//#FFC837 25 | const ImVec4 IV4_VIOLET{ 0.584,0.000,1.000,1.000 };//#9500ff 26 | const ImVec4 IV4_COSMICLATTE{ 1.000,0.973,0.906,1.000 };//#fff8e7 27 | const ImVec4 IV4_TEAL{ 0.314,0.788,0.765,1.000 };//#50C9C3 28 | const ImVec4 IV4_DRACULA{ 0.157,0.165,0.212,1.000 };//#282a36 29 | const ImVec4 IV4_2077YELLOW{ 0.992,0.961,0.000,1.000 };//#fdf500 30 | const ImVec4 IV4_CPNBLUE{ 0.000,0.878,1.000,1.0000 };//#00e0ff 31 | const ImVec4 IV4_CPNVIOLET{ 0.612,0.000,1.000,1.000 };//#9c00ff 32 | const ImVec4 IV4_CPNPURPLE{ 0.365,0.000,1.000,1.000 };//#5d00ff 33 | const ImVec4 IV4_CPNDEEP{ 0.000,0.039,0.122,1.000 };//#000a1f 34 | #endif 35 | 36 | namespace ImCandy 37 | { 38 | 39 | ImVec4 Rainbow(double& static_ratio, double step = 0.01) 40 | { 41 | step *= 6; 42 | 43 | gradient::LinearColorGradient gradient; 44 | gradient[0.0] = { 255,0,0 }; 45 | gradient[1.0] = { 255,255,0 }; 46 | gradient[2.0] = { 0,255,0 }; 47 | gradient[3.0] = { 0,255,255 }; 48 | gradient[4.0] = { 0,0,255 }; 49 | gradient[5.0] = { 255,0,255 }; 50 | gradient[6.0] = { 255,0,0 }; 51 | 52 | double r, g, b = 0; 53 | 54 | auto color = gradient(static_ratio); 55 | r = color[0]; 56 | g = color[1]; 57 | b = color[2]; 58 | 59 | static_ratio += step; 60 | if (static_ratio >= 6.0) 61 | static_ratio = 0.0; 62 | 63 | return ImVec4(r / 255.0, g / 255.0, b / 255.0, 1.0); 64 | } 65 | 66 | ImVec4 RainbowP(double step = 0.01) 67 | { 68 | static double static_ratio = 0.0; 69 | 70 | int normalized = int(static_ratio * 256 * 6); 71 | 72 | int region = normalized / 256; 73 | 74 | int x = normalized % 256; 75 | 76 | int r = 0, g = 0, b = 0; 77 | switch (region) 78 | { 79 | case 0: r = 255; g = 0; b = 0; g += x; break; 80 | case 1: r = 255; g = 255; b = 0; r -= x; break; 81 | case 2: r = 0; g = 255; b = 0; b += x; break; 82 | case 3: r = 0; g = 255; b = 255; g -= x; break; 83 | case 4: r = 0; g = 0; b = 255; r += x; break; 84 | case 5: r = 255; g = 0; b = 255; b -= x; break; 85 | } 86 | 87 | static_ratio += step; 88 | if (static_ratio >= 1.0) 89 | static_ratio = 0.0; 90 | 91 | return ImVec4(r / 255.0, g / 255.0, b / 255.0, 1.0); 92 | } 93 | 94 | ImVec4 Gradient2(ImVec4 col1, ImVec4 col2, double& static_ratio, double step = 0.01) 95 | { 96 | std::valarray col1a(3); 97 | col1a[0] = col1.x * 255.0; 98 | col1a[1] = col1.y * 255.0; 99 | col1a[2] = col1.z * 255.0; 100 | std::valarray col2a(3); 101 | col2a[0] = col2.x * 255.0; 102 | col2a[1] = col2.y * 255.0; 103 | col2a[2] = col2.z * 255.0; 104 | 105 | gradient::LinearColorGradient gradient; 106 | gradient[0.0] = col1a; 107 | gradient[1.0] = col2a; 108 | gradient[2.0] = col1a; 109 | 110 | double r, g, b = 0; 111 | 112 | auto color = gradient(static_ratio); 113 | r = color[0]; 114 | g = color[1]; 115 | b = color[2]; 116 | 117 | static_ratio += step; 118 | if (static_ratio >= 2.0) 119 | static_ratio = 0.0; 120 | 121 | return ImVec4(r / 255.0, g / 255.0, b / 255.0, 1.0); 122 | } 123 | 124 | ImVec4 Gradient3(ImVec4 col1, ImVec4 col2, ImVec4 col3, double& static_ratio, double step = 0.01) 125 | { 126 | std::valarray col1a(3); 127 | col1a[0] = col1.x * 255.0; 128 | col1a[1] = col1.y * 255.0; 129 | col1a[2] = col1.z * 255.0; 130 | std::valarray col2a(3); 131 | col2a[0] = col2.x * 255.0; 132 | col2a[1] = col2.y * 255.0; 133 | col2a[2] = col2.z * 255.0; 134 | std::valarray col3a(3); 135 | col3a[0] = col3.x * 255.0; 136 | col3a[1] = col3.y * 255.0; 137 | col3a[2] = col3.z * 255.0; 138 | 139 | 140 | gradient::LinearColorGradient gradient; 141 | gradient[0.0] = col1a; 142 | gradient[1.0] = col2a; 143 | gradient[2.0] = col3a; 144 | gradient[3.0] = col1a; 145 | 146 | double r, g, b = 0; 147 | 148 | auto color = gradient(static_ratio); 149 | r = color[0]; 150 | g = color[1]; 151 | b = color[2]; 152 | 153 | static_ratio += step; 154 | if (static_ratio >= 3.0) 155 | static_ratio = 0.0; 156 | 157 | return ImVec4(r / 255.0, g / 255.0, b / 255.0, 1.0); 158 | } 159 | 160 | /*--------------------------------------------------------------------------------------------------------- 161 | THEMES */ 162 | 163 | void Theme_Blender(ImGuiStyle* style) 164 | { 165 | ImVec4* colors = style->Colors; 166 | colors[ImGuiCol_Text] = ImVec4(0.84f, 0.84f, 0.84f, 1.00f); 167 | colors[ImGuiCol_WindowBg] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f); 168 | colors[ImGuiCol_ChildBg] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f); 169 | colors[ImGuiCol_PopupBg] = ImVec4(0.09f, 0.09f, 0.09f, 1.00f); 170 | colors[ImGuiCol_FrameBg] = ImVec4(0.33f, 0.33f, 0.33f, 1.00f); 171 | colors[ImGuiCol_FrameBgHovered] = ImVec4(0.47f, 0.47f, 0.47f, 1.00f); 172 | colors[ImGuiCol_FrameBgActive] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f); 173 | colors[ImGuiCol_TitleBg] = ImVec4(0.11f, 0.11f, 0.11f, 1.00f); 174 | colors[ImGuiCol_TitleBgActive] = ImVec4(0.28f, 0.45f, 0.70f, 1.00f); 175 | colors[ImGuiCol_MenuBarBg] = ImVec4(0.11f, 0.11f, 0.11f, 1.00f); 176 | colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.33f, 0.33f, 0.33f, 1.00f); 177 | colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.33f, 0.33f, 0.33f, 1.00f); 178 | colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.35f, 0.35f, 0.35f, 1.00f); 179 | colors[ImGuiCol_CheckMark] = ImVec4(0.28f, 0.45f, 0.70f, 1.00f); 180 | colors[ImGuiCol_SliderGrab] = ImVec4(0.28f, 0.45f, 0.70f, 1.00f); 181 | colors[ImGuiCol_SliderGrabActive] = ImVec4(0.28f, 0.45f, 0.70f, 1.00f); 182 | colors[ImGuiCol_Button] = ImVec4(0.33f, 0.33f, 0.33f, 1.00f); 183 | colors[ImGuiCol_ButtonHovered] = ImVec4(0.40f, 0.40f, 0.40f, 1.00f); 184 | colors[ImGuiCol_ButtonActive] = ImVec4(0.28f, 0.45f, 0.70f, 1.00f); 185 | colors[ImGuiCol_Header] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); 186 | colors[ImGuiCol_HeaderHovered] = ImVec4(0.28f, 0.45f, 0.70f, 1.00f); 187 | colors[ImGuiCol_HeaderActive] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); 188 | colors[ImGuiCol_Separator] = ImVec4(0.18f, 0.18f, 0.18f, 1.00f); 189 | colors[ImGuiCol_SeparatorHovered] = ImVec4(0.28f, 0.45f, 0.70f, 1.00f); 190 | colors[ImGuiCol_SeparatorActive] = ImVec4(0.28f, 0.45f, 0.70f, 1.00f); 191 | colors[ImGuiCol_ResizeGrip] = ImVec4(0.54f, 0.54f, 0.54f, 1.00f); 192 | colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.28f, 0.45f, 0.70f, 1.00f); 193 | colors[ImGuiCol_ResizeGripActive] = ImVec4(0.19f, 0.39f, 0.69f, 1.00f); 194 | colors[ImGuiCol_Tab] = ImVec4(0.11f, 0.11f, 0.11f, 1.00f); 195 | colors[ImGuiCol_TabHovered] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f); 196 | colors[ImGuiCol_TabActive] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f); 197 | colors[ImGuiCol_PlotHistogram] = ImVec4(0.28f, 0.45f, 0.70f, 1.00f); 198 | colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.20f, 0.39f, 0.69f, 1.00f); 199 | colors[ImGuiCol_TextSelectedBg] = ImVec4(0.28f, 0.45f, 0.70f, 1.00f); 200 | colors[ImGuiCol_NavHighlight] = ImVec4(0.28f, 0.45f, 0.70f, 1.00f); 201 | style->WindowPadding = ImVec2(12.00f, 8.00f); 202 | style->ItemSpacing = ImVec2(7.00f, 3.00f); 203 | style->GrabMinSize = 20.00f; 204 | style->WindowRounding = 8.00f; 205 | style->FrameBorderSize = 0.00f; 206 | style->FrameRounding = 4.00f; 207 | style->GrabRounding = 12.00f; 208 | } 209 | 210 | void Theme_Cyberpunk(ImGuiStyle* style) 211 | { 212 | ImVec4* colors = style->Colors; 213 | colors[ImGuiCol_Text] = ImVec4(0.00f, 0.82f, 1.00f, 1.00f); 214 | colors[ImGuiCol_TextDisabled] = ImVec4(0.00f, 0.36f, 0.63f, 1.00f); 215 | colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.04f, 0.12f, 1.00f); 216 | colors[ImGuiCol_ChildBg] = ImVec4(0.03f, 0.04f, 0.22f, 1.00f); 217 | colors[ImGuiCol_PopupBg] = ImVec4(0.12f, 0.06f, 0.27f, 1.00f); 218 | colors[ImGuiCol_FrameBg] = ImVec4(0.00f, 0.75f, 1.00f, 0.20f); 219 | colors[ImGuiCol_FrameBgHovered] = ImVec4(0.34f, 0.00f, 1.00f, 1.00f); 220 | colors[ImGuiCol_FrameBgActive] = ImVec4(0.08f, 0.00f, 1.00f, 1.00f); 221 | colors[ImGuiCol_TitleBg] = ImVec4(0.00f, 0.81f, 0.95f, 1.00f); 222 | colors[ImGuiCol_TitleBgActive] = ImVec4(0.61f, 0.00f, 1.00f, 1.00f); 223 | colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.25f, 0.00f, 0.54f, 0.81f); 224 | colors[ImGuiCol_MenuBarBg] = ImVec4(0.61f, 0.00f, 1.00f, 1.00f); 225 | colors[ImGuiCol_ScrollbarBg] = ImVec4(0.00f, 0.88f, 1.00f, 1.00f); 226 | colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.61f, 0.00f, 1.00f, 1.00f); 227 | colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.01f, 0.00f, 1.00f, 1.00f); 228 | colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.95f, 0.19f, 0.67f, 1.00f); 229 | colors[ImGuiCol_CheckMark] = ImVec4(0.95f, 0.19f, 0.92f, 1.00f); 230 | colors[ImGuiCol_SliderGrab] = ImVec4(0.00f, 1.00f, 0.95f, 1.00f); 231 | colors[ImGuiCol_SliderGrabActive] = ImVec4(0.81f, 0.00f, 1.00f, 1.00f); 232 | colors[ImGuiCol_Button] = ImVec4(0.00f, 0.98f, 1.00f, 0.52f); 233 | colors[ImGuiCol_ButtonHovered] = ImVec4(0.94f, 0.00f, 1.00f, 0.80f); 234 | colors[ImGuiCol_ButtonActive] = ImVec4(0.01f, 0.00f, 1.00f, 1.00f); 235 | colors[ImGuiCol_Header] = ImVec4(0.00f, 0.95f, 1.00f, 0.40f); 236 | colors[ImGuiCol_HeaderHovered] = ImVec4(0.94f, 0.00f, 1.00f, 0.80f); 237 | colors[ImGuiCol_HeaderActive] = ImVec4(0.01f, 0.00f, 1.00f, 1.00f); 238 | colors[ImGuiCol_Separator] = ImVec4(0.74f, 0.00f, 1.00f, 0.50f); 239 | colors[ImGuiCol_SeparatorHovered] = ImVec4(0.34f, 0.00f, 1.00f, 0.78f); 240 | colors[ImGuiCol_SeparatorActive] = ImVec4(0.00f, 1.00f, 0.85f, 1.00f); 241 | colors[ImGuiCol_ResizeGrip] = ImVec4(0.61f, 0.00f, 1.00f, 1.00f); 242 | colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.89f, 0.26f, 0.98f, 0.67f); 243 | colors[ImGuiCol_ResizeGripActive] = ImVec4(0.00f, 0.88f, 1.00f, 0.95f); 244 | colors[ImGuiCol_Tab] = ImVec4(0.36f, 0.00f, 1.00f, 1.00f); 245 | colors[ImGuiCol_TabHovered] = ImVec4(0.00f, 0.92f, 1.00f, 0.80f); 246 | colors[ImGuiCol_TabActive] = ImVec4(0.62f, 0.00f, 0.80f, 1.00f); 247 | colors[ImGuiCol_PlotHistogram] = ImVec4(0.00f, 1.00f, 0.88f, 1.00f); 248 | style->FrameBorderSize = 0.00f; 249 | style->WindowRounding = 0.00f; 250 | style->FrameRounding = 0.00f; 251 | style->ScrollbarRounding = 0.00f; 252 | style->GrabRounding = 0.00f; 253 | } 254 | 255 | void Theme_Nord(ImGuiStyle* style) 256 | { 257 | ImVec4* colors = style->Colors; 258 | colors[ImGuiCol_Text] = ImVec4(0.85f, 0.87f, 0.91f, 0.88f); 259 | colors[ImGuiCol_TextDisabled] = ImVec4(0.49f, 0.50f, 0.53f, 1.00f); 260 | colors[ImGuiCol_WindowBg] = ImVec4(0.18f, 0.20f, 0.25f, 1.00f); 261 | colors[ImGuiCol_ChildBg] = ImVec4(0.16f, 0.17f, 0.20f, 1.00f); 262 | colors[ImGuiCol_PopupBg] = ImVec4(0.23f, 0.26f, 0.32f, 1.00f); 263 | colors[ImGuiCol_FrameBg] = ImVec4(0.23f, 0.26f, 0.32f, 1.00f); 264 | colors[ImGuiCol_FrameBgHovered] = ImVec4(0.56f, 0.74f, 0.73f, 1.00f); 265 | colors[ImGuiCol_FrameBgActive] = ImVec4(0.53f, 0.75f, 0.82f, 1.00f); 266 | colors[ImGuiCol_TitleBg] = ImVec4(0.16f, 0.16f, 0.20f, 1.00f); 267 | colors[ImGuiCol_TitleBgActive] = ImVec4(0.16f, 0.16f, 0.20f, 1.00f); 268 | colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.16f, 0.16f, 0.20f, 1.00f); 269 | colors[ImGuiCol_MenuBarBg] = ImVec4(0.16f, 0.16f, 0.20f, 1.00f); 270 | colors[ImGuiCol_ScrollbarBg] = ImVec4(0.18f, 0.20f, 0.25f, 1.00f); 271 | colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.23f, 0.26f, 0.32f, 0.60f); 272 | colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.23f, 0.26f, 0.32f, 1.00f); 273 | colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.23f, 0.26f, 0.32f, 1.00f); 274 | colors[ImGuiCol_CheckMark] = ImVec4(0.37f, 0.51f, 0.67f, 1.00f); 275 | colors[ImGuiCol_SliderGrab] = ImVec4(0.51f, 0.63f, 0.76f, 1.00f); 276 | colors[ImGuiCol_SliderGrabActive] = ImVec4(0.37f, 0.51f, 0.67f, 1.00f); 277 | colors[ImGuiCol_Button] = ImVec4(0.18f, 0.20f, 0.25f, 1.00f); 278 | colors[ImGuiCol_ButtonHovered] = ImVec4(0.51f, 0.63f, 0.76f, 1.00f); 279 | colors[ImGuiCol_ButtonActive] = ImVec4(0.37f, 0.51f, 0.67f, 1.00f); 280 | colors[ImGuiCol_Header] = ImVec4(0.51f, 0.63f, 0.76f, 1.00f); 281 | colors[ImGuiCol_HeaderHovered] = ImVec4(0.53f, 0.75f, 0.82f, 1.00f); 282 | colors[ImGuiCol_HeaderActive] = ImVec4(0.37f, 0.51f, 0.67f, 1.00f); 283 | colors[ImGuiCol_SeparatorHovered] = ImVec4(0.56f, 0.74f, 0.73f, 1.00f); 284 | colors[ImGuiCol_SeparatorActive] = ImVec4(0.53f, 0.75f, 0.82f, 1.00f); 285 | colors[ImGuiCol_ResizeGrip] = ImVec4(0.53f, 0.75f, 0.82f, 0.86f); 286 | colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.61f, 0.74f, 0.87f, 1.00f); 287 | colors[ImGuiCol_ResizeGripActive] = ImVec4(0.37f, 0.51f, 0.67f, 1.00f); 288 | colors[ImGuiCol_Tab] = ImVec4(0.18f, 0.20f, 0.25f, 1.00f); 289 | colors[ImGuiCol_TabHovered] = ImVec4(0.22f, 0.24f, 0.31f, 1.00f); 290 | colors[ImGuiCol_TabActive] = ImVec4(0.23f, 0.26f, 0.32f, 1.00f); 291 | colors[ImGuiCol_TabUnfocused] = ImVec4(0.13f, 0.15f, 0.18f, 1.00f); 292 | colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.17f, 0.19f, 0.23f, 1.00f); 293 | colors[ImGuiCol_PlotHistogram] = ImVec4(0.56f, 0.74f, 0.73f, 1.00f); 294 | colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.53f, 0.75f, 0.82f, 1.00f); 295 | colors[ImGuiCol_TextSelectedBg] = ImVec4(0.37f, 0.51f, 0.67f, 1.00f); 296 | colors[ImGuiCol_NavHighlight] = ImVec4(0.53f, 0.75f, 0.82f, 0.86f); 297 | style->WindowBorderSize = 1.00f; 298 | style->ChildBorderSize = 1.00f; 299 | style->PopupBorderSize = 1.00f; 300 | style->FrameBorderSize = 1.00f; 301 | } 302 | 303 | void Theme_Red(ImGuiStyle* style) 304 | { 305 | ImVec4* colors = style->Colors; 306 | colors[ImGuiCol_Text] = ImVec4(0.83f, 0.13f, 0.07f, 1.0f); 307 | colors[ImGuiCol_TextDisabled] = ImVec4(0.6f, 0.34f, 0.07f, 1.0f); 308 | colors[ImGuiCol_WindowBg] = ImVec4(0.7f, 0.7f, 0.7f, 1.00f); 309 | colors[ImGuiCol_ChildBg] = ImVec4(0.92f, 0.92f, 0.92f, 1.00f); 310 | colors[ImGuiCol_PopupBg] = ImVec4(0.23f, 0.26f, 0.32f, 1.00f); 311 | colors[ImGuiCol_FrameBg] = ImVec4(0.8f, 0.8f, 0.7f, 1.00f); 312 | colors[ImGuiCol_FrameBgHovered] = ImVec4(0.6f, 0.8f, 0.7f, 1.00f); 313 | colors[ImGuiCol_FrameBgActive] = ImVec4(0.53f, 0.75f, 0.82f, 1.00f); 314 | colors[ImGuiCol_TitleBg] = ImVec4(0.16f, 0.16f, 0.20f, 1.00f); 315 | colors[ImGuiCol_TitleBgActive] = ImVec4(0.16f, 0.16f, 0.20f, 1.00f); 316 | colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.16f, 0.16f, 0.20f, 1.00f); 317 | colors[ImGuiCol_MenuBarBg] = ImVec4(0.16f, 0.16f, 0.20f, 1.00f); 318 | colors[ImGuiCol_ScrollbarBg] = ImVec4(0.18f, 0.20f, 0.25f, 1.00f); 319 | colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.23f, 0.26f, 0.32f, 0.60f); 320 | colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.23f, 0.26f, 0.32f, 1.00f); 321 | colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.23f, 0.26f, 0.32f, 1.00f); 322 | colors[ImGuiCol_CheckMark] = ImVec4(0.37f, 0.51f, 0.67f, 1.00f); 323 | colors[ImGuiCol_SliderGrab] = ImVec4(0.51f, 0.63f, 0.76f, 1.00f); 324 | colors[ImGuiCol_SliderGrabActive] = ImVec4(0.37f, 0.51f, 0.67f, 1.00f); 325 | colors[ImGuiCol_Button] = ImVec4(0.9f, 0.9f, 0.85f, 0.5f); 326 | colors[ImGuiCol_ButtonHovered] = ImVec4(0.85f, 0.9f, 0.92f, 1.00f); 327 | colors[ImGuiCol_ButtonActive] = ImVec4(0.83f, 0.13f, 0.07f, 1.0f); 328 | colors[ImGuiCol_Header] = ImVec4(0.51f, 0.63f, 0.76f, 1.00f); 329 | colors[ImGuiCol_HeaderHovered] = ImVec4(0.53f, 0.75f, 0.82f, 1.00f); 330 | colors[ImGuiCol_HeaderActive] = ImVec4(0.37f, 0.51f, 0.67f, 1.00f); 331 | colors[ImGuiCol_SeparatorHovered] = ImVec4(0.56f, 0.74f, 0.73f, 1.00f); 332 | colors[ImGuiCol_SeparatorActive] = ImVec4(0.53f, 0.75f, 0.82f, 1.00f); 333 | colors[ImGuiCol_ResizeGrip] = ImVec4(0.53f, 0.75f, 0.82f, 0.86f); 334 | colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.61f, 0.74f, 0.87f, 1.00f); 335 | colors[ImGuiCol_ResizeGripActive] = ImVec4(0.37f, 0.51f, 0.67f, 1.00f); 336 | colors[ImGuiCol_Tab] = ImVec4(0.18f, 0.20f, 0.25f, 1.00f); 337 | colors[ImGuiCol_TabHovered] = ImVec4(0.22f, 0.24f, 0.31f, 1.00f); 338 | colors[ImGuiCol_TabActive] = ImVec4(0.23f, 0.26f, 0.32f, 1.00f); 339 | colors[ImGuiCol_TabUnfocused] = ImVec4(0.13f, 0.15f, 0.18f, 1.00f); 340 | colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.17f, 0.19f, 0.23f, 1.00f); 341 | colors[ImGuiCol_PlotHistogram] = ImVec4(0.56f, 0.74f, 0.73f, 1.00f); 342 | colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.53f, 0.75f, 0.82f, 1.00f); 343 | colors[ImGuiCol_TextSelectedBg] = ImVec4(0.37f, 0.51f, 0.67f, 1.00f); 344 | colors[ImGuiCol_NavHighlight] = ImVec4(0.53f, 0.75f, 0.82f, 0.86f); 345 | } 346 | 347 | }; -------------------------------------------------------------------------------- /my_example/suspension_ball/widget.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ImGui/imgui_internal.h" 3 | 4 | void ToggleButton(const char* str_id, bool* v, ImVec4 ButtonHovered, ImVec4 Button) 5 | { 6 | ImVec2 p = ImGui::GetCursorScreenPos(); 7 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); 8 | 9 | float height = ImGui::GetFrameHeight(); 10 | float width = height * 1.55f; 11 | float radius = height * 0.50f; 12 | 13 | ImGui::InvisibleButton(str_id, ImVec2(width, height)); 14 | if (ImGui::IsItemClicked()) 15 | *v = !*v; 16 | 17 | float t = *v ? 1.0f : 0.0f; 18 | 19 | ImGuiContext& g = *GImGui; 20 | float ANIM_SPEED = 0.08f; 21 | if (g.LastActiveId == g.CurrentWindow->GetID(str_id)) 22 | { 23 | float t_anim = ImSaturate(g.LastActiveIdTimer / ANIM_SPEED); 24 | t = *v ? (t_anim) : (1.0f - t_anim); 25 | } 26 | 27 | ImU32 col_bg; 28 | if (ImGui::IsItemHovered()) 29 | col_bg = ImGui::GetColorU32(ImLerp(ImVec4(0.78f, 0.78f, 0.78f, 1.0f), ButtonHovered, t)); 30 | else 31 | col_bg = ImGui::GetColorU32(ImLerp(ImVec4(0.85f, 0.85f, 0.85f, 1.0f), Button, t)); 32 | 33 | draw_list->AddRectFilled(p, ImVec2(p.x + width, p.y + height), col_bg, height * 0.5f); 34 | draw_list->AddCircleFilled(ImVec2(p.x + radius + t * (width - radius * 2.0f), p.y + radius - 0.5f), radius - 1.5f, IM_COL32(255, 255, 255, 255)); 35 | } --------------------------------------------------------------------------------