├── LICENSE ├── Libraries ├── include │ ├── GLFW │ │ ├── glfw3.h │ │ └── glfw3native.h │ ├── KHR │ │ └── khrplatform.h │ ├── glad │ │ └── glad.h │ ├── imgui │ │ ├── desktop.ini │ │ ├── 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 │ │ ├── stb_image.h │ │ └── stb_image_write.h └── lib │ ├── glfw3.lib │ └── glfw3.pdb ├── OpenGL.sln ├── OpenGL.vcxproj ├── OpenGL.vcxproj.filters ├── OpenGL.vcxproj.user ├── README.md ├── images ├── screenshots │ ├── 24ZsLp6o.png │ ├── 9hVcJMGF.png │ ├── BA0GHUpS.png │ ├── CAJZ0V4q.png │ ├── DnjAa6IF.png │ ├── FxeQQMXC.png │ ├── HEHRIg5i.png │ ├── IiX6BrZ3.png │ ├── M7DTM7AU.png │ ├── ctYlvdlk.png │ ├── ghPbH6m7.png │ ├── rsu6tCdx.png │ └── snbCPh1l.png └── skybox │ ├── belfast_sunset_puresky_2k.hdr │ ├── christmas_photo_studio_01_2k.hdr │ ├── rainforest_trail_2k.hdr │ ├── small_cave_2k.hdr │ ├── syferfontein_0d_clear_puresky_2k.hdr │ ├── the_sky_is_on_fire_2k.hdr │ └── vestibule_2k.hdr ├── scenes ├── many spheres 2 │ ├── data.txt │ └── objects.txt └── many spheres │ ├── data.txt │ └── objects.txt ├── shaders ├── bloom.frag ├── default.frag ├── default.vert ├── display.frag └── postProcess.frag └── source ├── Main.cpp ├── camera.cpp ├── camera.h ├── framebuffer.cpp ├── framebuffer.h ├── glad.c ├── mygui.cpp ├── mygui.h ├── object.cpp ├── object.h ├── scene.cpp ├── scene.h ├── shader.cpp ├── shader.h ├── skybox.cpp ├── skybox.h ├── stb.cpp ├── texture.cpp ├── texture.h ├── vao.cpp └── vao.h /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Eduard0110 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Libraries/include/GLFW/glfw3native.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * GLFW 3.3 - www.glfw.org 3 | * A library for OpenGL, window and input 4 | *------------------------------------------------------------------------ 5 | * Copyright (c) 2002-2006 Marcus Geelnard 6 | * Copyright (c) 2006-2018 Camilla Löwy 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 | * @brief Functions related to accessing native handles. 49 | * 50 | * **By using the native access functions you assert that you know what you're 51 | * doing and how to fix problems caused by using them. If you don't, you 52 | * shouldn't be using them.** 53 | * 54 | * Before the inclusion of @ref glfw3native.h, you may define zero or more 55 | * window system API macro and zero or more context creation API macros. 56 | * 57 | * The chosen backends must match those the library was compiled for. Failure 58 | * to do this will cause a link-time error. 59 | * 60 | * The available window API macros are: 61 | * * `GLFW_EXPOSE_NATIVE_WIN32` 62 | * * `GLFW_EXPOSE_NATIVE_COCOA` 63 | * * `GLFW_EXPOSE_NATIVE_X11` 64 | * * `GLFW_EXPOSE_NATIVE_WAYLAND` 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 | * * `GLFW_EXPOSE_NATIVE_OSMESA` 72 | * 73 | * These macros select which of the native access functions that are declared 74 | * and which platform-specific headers to include. It is then up your (by 75 | * definition platform-specific) code to handle which of these should be 76 | * defined. 77 | * 78 | * If you do not want the platform-specific headers to be included, define 79 | * `GLFW_NATIVE_INCLUDE_NONE` before including the @ref glfw3native.h header. 80 | * 81 | * @code 82 | * #define GLFW_EXPOSE_NATIVE_WIN32 83 | * #define GLFW_EXPOSE_NATIVE_WGL 84 | * #define GLFW_NATIVE_INCLUDE_NONE 85 | * #include 86 | * @endcode 87 | */ 88 | 89 | 90 | /************************************************************************* 91 | * System headers and types 92 | *************************************************************************/ 93 | 94 | #if !defined(GLFW_NATIVE_INCLUDE_NONE) 95 | 96 | #if defined(GLFW_EXPOSE_NATIVE_WIN32) || defined(GLFW_EXPOSE_NATIVE_WGL) 97 | /* This is a workaround for the fact that glfw3.h needs to export APIENTRY (for 98 | * example to allow applications to correctly declare a GL_KHR_debug callback) 99 | * but windows.h assumes no one will define APIENTRY before it does 100 | */ 101 | #if defined(GLFW_APIENTRY_DEFINED) 102 | #undef APIENTRY 103 | #undef GLFW_APIENTRY_DEFINED 104 | #endif 105 | #include 106 | #elif defined(GLFW_EXPOSE_NATIVE_COCOA) || defined(GLFW_EXPOSE_NATIVE_NSGL) 107 | #if defined(__OBJC__) 108 | #import 109 | #else 110 | #include 111 | #include 112 | #endif 113 | #elif defined(GLFW_EXPOSE_NATIVE_X11) || defined(GLFW_EXPOSE_NATIVE_GLX) 114 | #include 115 | #include 116 | #elif defined(GLFW_EXPOSE_NATIVE_WAYLAND) 117 | #include 118 | #endif 119 | 120 | #if defined(GLFW_EXPOSE_NATIVE_WGL) 121 | /* WGL is declared by windows.h */ 122 | #endif 123 | #if defined(GLFW_EXPOSE_NATIVE_NSGL) 124 | /* NSGL is declared by Cocoa.h */ 125 | #endif 126 | #if defined(GLFW_EXPOSE_NATIVE_GLX) 127 | /* This is a workaround for the fact that glfw3.h defines GLAPIENTRY because by 128 | * default it also acts as an OpenGL header 129 | * However, glx.h will include gl.h, which will define it unconditionally 130 | */ 131 | #if defined(GLFW_GLAPIENTRY_DEFINED) 132 | #undef GLAPIENTRY 133 | #undef GLFW_GLAPIENTRY_DEFINED 134 | #endif 135 | #include 136 | #endif 137 | #if defined(GLFW_EXPOSE_NATIVE_EGL) 138 | #include 139 | #endif 140 | #if defined(GLFW_EXPOSE_NATIVE_OSMESA) 141 | /* This is a workaround for the fact that glfw3.h defines GLAPIENTRY because by 142 | * default it also acts as an OpenGL header 143 | * However, osmesa.h will include gl.h, which will define it unconditionally 144 | */ 145 | #if defined(GLFW_GLAPIENTRY_DEFINED) 146 | #undef GLAPIENTRY 147 | #undef GLFW_GLAPIENTRY_DEFINED 148 | #endif 149 | #include 150 | #endif 151 | 152 | #endif /*GLFW_NATIVE_INCLUDE_NONE*/ 153 | 154 | 155 | /************************************************************************* 156 | * Functions 157 | *************************************************************************/ 158 | 159 | #if defined(GLFW_EXPOSE_NATIVE_WIN32) 160 | /*! @brief Returns the adapter device name of the specified monitor. 161 | * 162 | * @return The UTF-8 encoded adapter device name (for example `\\.\DISPLAY1`) 163 | * of the specified monitor, or `NULL` if an [error](@ref error_handling) 164 | * occurred. 165 | * 166 | * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. 167 | * 168 | * @thread_safety This function may be called from any thread. Access is not 169 | * synchronized. 170 | * 171 | * @since Added in version 3.1. 172 | * 173 | * @ingroup native 174 | */ 175 | GLFWAPI const char* glfwGetWin32Adapter(GLFWmonitor* monitor); 176 | 177 | /*! @brief Returns the display device name of the specified monitor. 178 | * 179 | * @return The UTF-8 encoded display device name (for example 180 | * `\\.\DISPLAY1\Monitor0`) of the specified monitor, or `NULL` if an 181 | * [error](@ref error_handling) occurred. 182 | * 183 | * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. 184 | * 185 | * @thread_safety This function may be called from any thread. Access is not 186 | * synchronized. 187 | * 188 | * @since Added in version 3.1. 189 | * 190 | * @ingroup native 191 | */ 192 | GLFWAPI const char* glfwGetWin32Monitor(GLFWmonitor* monitor); 193 | 194 | /*! @brief Returns the `HWND` of the specified window. 195 | * 196 | * @return The `HWND` of the specified window, or `NULL` if an 197 | * [error](@ref error_handling) occurred. 198 | * 199 | * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. 200 | * 201 | * @remark The `HDC` associated with the window can be queried with the 202 | * [GetDC](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdc) 203 | * function. 204 | * @code 205 | * HDC dc = GetDC(glfwGetWin32Window(window)); 206 | * @endcode 207 | * This DC is private and does not need to be released. 208 | * 209 | * @thread_safety This function may be called from any thread. Access is not 210 | * synchronized. 211 | * 212 | * @since Added in version 3.0. 213 | * 214 | * @ingroup native 215 | */ 216 | GLFWAPI HWND glfwGetWin32Window(GLFWwindow* window); 217 | #endif 218 | 219 | #if defined(GLFW_EXPOSE_NATIVE_WGL) 220 | /*! @brief Returns the `HGLRC` of the specified window. 221 | * 222 | * @return The `HGLRC` of the specified window, or `NULL` if an 223 | * [error](@ref error_handling) occurred. 224 | * 225 | * @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref 226 | * GLFW_NOT_INITIALIZED. 227 | * 228 | * @remark The `HDC` associated with the window can be queried with the 229 | * [GetDC](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdc) 230 | * function. 231 | * @code 232 | * HDC dc = GetDC(glfwGetWin32Window(window)); 233 | * @endcode 234 | * This DC is private and does not need to be released. 235 | * 236 | * @thread_safety This function may be called from any thread. Access is not 237 | * synchronized. 238 | * 239 | * @since Added in version 3.0. 240 | * 241 | * @ingroup native 242 | */ 243 | GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* window); 244 | #endif 245 | 246 | #if defined(GLFW_EXPOSE_NATIVE_COCOA) 247 | /*! @brief Returns the `CGDirectDisplayID` of the specified monitor. 248 | * 249 | * @return The `CGDirectDisplayID` of the specified monitor, or 250 | * `kCGNullDirectDisplay` if an [error](@ref error_handling) occurred. 251 | * 252 | * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. 253 | * 254 | * @thread_safety This function may be called from any thread. Access is not 255 | * synchronized. 256 | * 257 | * @since Added in version 3.1. 258 | * 259 | * @ingroup native 260 | */ 261 | GLFWAPI CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* monitor); 262 | 263 | /*! @brief Returns the `NSWindow` of the specified window. 264 | * 265 | * @return The `NSWindow` of the specified window, or `nil` if an 266 | * [error](@ref error_handling) occurred. 267 | * 268 | * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. 269 | * 270 | * @thread_safety This function may be called from any thread. Access is not 271 | * synchronized. 272 | * 273 | * @since Added in version 3.0. 274 | * 275 | * @ingroup native 276 | */ 277 | GLFWAPI id glfwGetCocoaWindow(GLFWwindow* window); 278 | #endif 279 | 280 | #if defined(GLFW_EXPOSE_NATIVE_NSGL) 281 | /*! @brief Returns the `NSOpenGLContext` of the specified window. 282 | * 283 | * @return The `NSOpenGLContext` of the specified window, or `nil` if an 284 | * [error](@ref error_handling) occurred. 285 | * 286 | * @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref 287 | * GLFW_NOT_INITIALIZED. 288 | * 289 | * @thread_safety This function may be called from any thread. Access is not 290 | * synchronized. 291 | * 292 | * @since Added in version 3.0. 293 | * 294 | * @ingroup native 295 | */ 296 | GLFWAPI id glfwGetNSGLContext(GLFWwindow* window); 297 | #endif 298 | 299 | #if defined(GLFW_EXPOSE_NATIVE_X11) 300 | /*! @brief Returns the `Display` used by GLFW. 301 | * 302 | * @return The `Display` used by GLFW, or `NULL` if an 303 | * [error](@ref error_handling) occurred. 304 | * 305 | * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. 306 | * 307 | * @thread_safety This function may be called from any thread. Access is not 308 | * synchronized. 309 | * 310 | * @since Added in version 3.0. 311 | * 312 | * @ingroup native 313 | */ 314 | GLFWAPI Display* glfwGetX11Display(void); 315 | 316 | /*! @brief Returns the `RRCrtc` of the specified monitor. 317 | * 318 | * @return The `RRCrtc` of the specified monitor, or `None` if an 319 | * [error](@ref error_handling) occurred. 320 | * 321 | * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. 322 | * 323 | * @thread_safety This function may be called from any thread. Access is not 324 | * synchronized. 325 | * 326 | * @since Added in version 3.1. 327 | * 328 | * @ingroup native 329 | */ 330 | GLFWAPI RRCrtc glfwGetX11Adapter(GLFWmonitor* monitor); 331 | 332 | /*! @brief Returns the `RROutput` of the specified monitor. 333 | * 334 | * @return The `RROutput` of the specified monitor, or `None` if an 335 | * [error](@ref error_handling) occurred. 336 | * 337 | * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. 338 | * 339 | * @thread_safety This function may be called from any thread. Access is not 340 | * synchronized. 341 | * 342 | * @since Added in version 3.1. 343 | * 344 | * @ingroup native 345 | */ 346 | GLFWAPI RROutput glfwGetX11Monitor(GLFWmonitor* monitor); 347 | 348 | /*! @brief Returns the `Window` of the specified window. 349 | * 350 | * @return The `Window` of the specified window, or `None` if an 351 | * [error](@ref error_handling) occurred. 352 | * 353 | * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. 354 | * 355 | * @thread_safety This function may be called from any thread. Access is not 356 | * synchronized. 357 | * 358 | * @since Added in version 3.0. 359 | * 360 | * @ingroup native 361 | */ 362 | GLFWAPI Window glfwGetX11Window(GLFWwindow* window); 363 | 364 | /*! @brief Sets the current primary selection to the specified string. 365 | * 366 | * @param[in] string A UTF-8 encoded string. 367 | * 368 | * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref 369 | * GLFW_PLATFORM_ERROR. 370 | * 371 | * @pointer_lifetime The specified string is copied before this function 372 | * returns. 373 | * 374 | * @thread_safety This function must only be called from the main thread. 375 | * 376 | * @sa @ref clipboard 377 | * @sa glfwGetX11SelectionString 378 | * @sa glfwSetClipboardString 379 | * 380 | * @since Added in version 3.3. 381 | * 382 | * @ingroup native 383 | */ 384 | GLFWAPI void glfwSetX11SelectionString(const char* string); 385 | 386 | /*! @brief Returns the contents of the current primary selection as a string. 387 | * 388 | * If the selection is empty or if its contents cannot be converted, `NULL` 389 | * is returned and a @ref GLFW_FORMAT_UNAVAILABLE error is generated. 390 | * 391 | * @return The contents of the selection as a UTF-8 encoded string, or `NULL` 392 | * if an [error](@ref error_handling) occurred. 393 | * 394 | * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref 395 | * GLFW_PLATFORM_ERROR. 396 | * 397 | * @pointer_lifetime The returned string is allocated and freed by GLFW. You 398 | * should not free it yourself. It is valid until the next call to @ref 399 | * glfwGetX11SelectionString or @ref glfwSetX11SelectionString, or until the 400 | * library is terminated. 401 | * 402 | * @thread_safety This function must only be called from the main thread. 403 | * 404 | * @sa @ref clipboard 405 | * @sa glfwSetX11SelectionString 406 | * @sa glfwGetClipboardString 407 | * 408 | * @since Added in version 3.3. 409 | * 410 | * @ingroup native 411 | */ 412 | GLFWAPI const char* glfwGetX11SelectionString(void); 413 | #endif 414 | 415 | #if defined(GLFW_EXPOSE_NATIVE_GLX) 416 | /*! @brief Returns the `GLXContext` of the specified window. 417 | * 418 | * @return The `GLXContext` of the specified window, or `NULL` if an 419 | * [error](@ref error_handling) occurred. 420 | * 421 | * @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref 422 | * GLFW_NOT_INITIALIZED. 423 | * 424 | * @thread_safety This function may be called from any thread. Access is not 425 | * synchronized. 426 | * 427 | * @since Added in version 3.0. 428 | * 429 | * @ingroup native 430 | */ 431 | GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* window); 432 | 433 | /*! @brief Returns the `GLXWindow` of the specified window. 434 | * 435 | * @return The `GLXWindow` of the specified window, or `None` if an 436 | * [error](@ref error_handling) occurred. 437 | * 438 | * @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref 439 | * GLFW_NOT_INITIALIZED. 440 | * 441 | * @thread_safety This function may be called from any thread. Access is not 442 | * synchronized. 443 | * 444 | * @since Added in version 3.2. 445 | * 446 | * @ingroup native 447 | */ 448 | GLFWAPI GLXWindow glfwGetGLXWindow(GLFWwindow* window); 449 | #endif 450 | 451 | #if defined(GLFW_EXPOSE_NATIVE_WAYLAND) 452 | /*! @brief Returns the `struct wl_display*` used by GLFW. 453 | * 454 | * @return The `struct wl_display*` used by GLFW, or `NULL` if an 455 | * [error](@ref error_handling) occurred. 456 | * 457 | * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. 458 | * 459 | * @thread_safety This function may be called from any thread. Access is not 460 | * synchronized. 461 | * 462 | * @since Added in version 3.2. 463 | * 464 | * @ingroup native 465 | */ 466 | GLFWAPI struct wl_display* glfwGetWaylandDisplay(void); 467 | 468 | /*! @brief Returns the `struct wl_output*` of the specified monitor. 469 | * 470 | * @return The `struct wl_output*` of the specified monitor, or `NULL` if an 471 | * [error](@ref error_handling) occurred. 472 | * 473 | * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. 474 | * 475 | * @thread_safety This function may be called from any thread. Access is not 476 | * synchronized. 477 | * 478 | * @since Added in version 3.2. 479 | * 480 | * @ingroup native 481 | */ 482 | GLFWAPI struct wl_output* glfwGetWaylandMonitor(GLFWmonitor* monitor); 483 | 484 | /*! @brief Returns the main `struct wl_surface*` of the specified window. 485 | * 486 | * @return The main `struct wl_surface*` of the specified window, or `NULL` if 487 | * an [error](@ref error_handling) occurred. 488 | * 489 | * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. 490 | * 491 | * @thread_safety This function may be called from any thread. Access is not 492 | * synchronized. 493 | * 494 | * @since Added in version 3.2. 495 | * 496 | * @ingroup native 497 | */ 498 | GLFWAPI struct wl_surface* glfwGetWaylandWindow(GLFWwindow* window); 499 | #endif 500 | 501 | #if defined(GLFW_EXPOSE_NATIVE_EGL) 502 | /*! @brief Returns the `EGLDisplay` used by GLFW. 503 | * 504 | * @return The `EGLDisplay` used by GLFW, or `EGL_NO_DISPLAY` if an 505 | * [error](@ref error_handling) occurred. 506 | * 507 | * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. 508 | * 509 | * @remark Because EGL is initialized on demand, this function will return 510 | * `EGL_NO_DISPLAY` until the first context has been created via EGL. 511 | * 512 | * @thread_safety This function may be called from any thread. Access is not 513 | * synchronized. 514 | * 515 | * @since Added in version 3.0. 516 | * 517 | * @ingroup native 518 | */ 519 | GLFWAPI EGLDisplay glfwGetEGLDisplay(void); 520 | 521 | /*! @brief Returns the `EGLContext` of the specified window. 522 | * 523 | * @return The `EGLContext` of the specified window, or `EGL_NO_CONTEXT` if an 524 | * [error](@ref error_handling) occurred. 525 | * 526 | * @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref 527 | * GLFW_NOT_INITIALIZED. 528 | * 529 | * @thread_safety This function may be called from any thread. Access is not 530 | * synchronized. 531 | * 532 | * @since Added in version 3.0. 533 | * 534 | * @ingroup native 535 | */ 536 | GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* window); 537 | 538 | /*! @brief Returns the `EGLSurface` of the specified window. 539 | * 540 | * @return The `EGLSurface` of the specified window, or `EGL_NO_SURFACE` if an 541 | * [error](@ref error_handling) occurred. 542 | * 543 | * @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref 544 | * GLFW_NOT_INITIALIZED. 545 | * 546 | * @thread_safety This function may be called from any thread. Access is not 547 | * synchronized. 548 | * 549 | * @since Added in version 3.0. 550 | * 551 | * @ingroup native 552 | */ 553 | GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* window); 554 | #endif 555 | 556 | #if defined(GLFW_EXPOSE_NATIVE_OSMESA) 557 | /*! @brief Retrieves the color buffer associated with the specified window. 558 | * 559 | * @param[in] window The window whose color buffer to retrieve. 560 | * @param[out] width Where to store the width of the color buffer, or `NULL`. 561 | * @param[out] height Where to store the height of the color buffer, or `NULL`. 562 | * @param[out] format Where to store the OSMesa pixel format of the color 563 | * buffer, or `NULL`. 564 | * @param[out] buffer Where to store the address of the color buffer, or 565 | * `NULL`. 566 | * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an 567 | * [error](@ref error_handling) occurred. 568 | * 569 | * @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref 570 | * GLFW_NOT_INITIALIZED. 571 | * 572 | * @thread_safety This function may be called from any thread. Access is not 573 | * synchronized. 574 | * 575 | * @since Added in version 3.3. 576 | * 577 | * @ingroup native 578 | */ 579 | GLFWAPI int glfwGetOSMesaColorBuffer(GLFWwindow* window, int* width, int* height, int* format, void** buffer); 580 | 581 | /*! @brief Retrieves the depth buffer associated with the specified window. 582 | * 583 | * @param[in] window The window whose depth buffer to retrieve. 584 | * @param[out] width Where to store the width of the depth buffer, or `NULL`. 585 | * @param[out] height Where to store the height of the depth buffer, or `NULL`. 586 | * @param[out] bytesPerValue Where to store the number of bytes per depth 587 | * buffer element, or `NULL`. 588 | * @param[out] buffer Where to store the address of the depth buffer, or 589 | * `NULL`. 590 | * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an 591 | * [error](@ref error_handling) occurred. 592 | * 593 | * @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref 594 | * GLFW_NOT_INITIALIZED. 595 | * 596 | * @thread_safety This function may be called from any thread. Access is not 597 | * synchronized. 598 | * 599 | * @since Added in version 3.3. 600 | * 601 | * @ingroup native 602 | */ 603 | GLFWAPI int glfwGetOSMesaDepthBuffer(GLFWwindow* window, int* width, int* height, int* bytesPerValue, void** buffer); 604 | 605 | /*! @brief Returns the `OSMesaContext` of the specified window. 606 | * 607 | * @return The `OSMesaContext` of the specified window, or `NULL` if an 608 | * [error](@ref error_handling) occurred. 609 | * 610 | * @errors Possible errors include @ref GLFW_NO_WINDOW_CONTEXT and @ref 611 | * GLFW_NOT_INITIALIZED. 612 | * 613 | * @thread_safety This function may be called from any thread. Access is not 614 | * synchronized. 615 | * 616 | * @since Added in version 3.3. 617 | * 618 | * @ingroup native 619 | */ 620 | GLFWAPI OSMesaContext glfwGetOSMesaContext(GLFWwindow* window); 621 | #endif 622 | 623 | #ifdef __cplusplus 624 | } 625 | #endif 626 | 627 | #endif /* _glfw3_native_h_ */ 628 | 629 | -------------------------------------------------------------------------------- /Libraries/include/KHR/khrplatform.h: -------------------------------------------------------------------------------- 1 | #ifndef __khrplatform_h_ 2 | #define __khrplatform_h_ 3 | 4 | /* 5 | ** Copyright (c) 2008-2018 The Khronos Group Inc. 6 | ** 7 | ** Permission is hereby granted, free of charge, to any person obtaining a 8 | ** copy of this software and/or associated documentation files (the 9 | ** "Materials"), to deal in the Materials without restriction, including 10 | ** without limitation the rights to use, copy, modify, merge, publish, 11 | ** distribute, sublicense, and/or sell copies of the Materials, and to 12 | ** permit persons to whom the Materials are furnished to do so, subject to 13 | ** the following conditions: 14 | ** 15 | ** The above copyright notice and this permission notice shall be included 16 | ** in all copies or substantial portions of the Materials. 17 | ** 18 | ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 25 | */ 26 | 27 | /* Khronos platform-specific types and definitions. 28 | * 29 | * The master copy of khrplatform.h is maintained in the Khronos EGL 30 | * Registry repository at https://github.com/KhronosGroup/EGL-Registry 31 | * The last semantic modification to khrplatform.h was at commit ID: 32 | * 67a3e0864c2d75ea5287b9f3d2eb74a745936692 33 | * 34 | * Adopters may modify this file to suit their platform. Adopters are 35 | * encouraged to submit platform specific modifications to the Khronos 36 | * group so that they can be included in future versions of this file. 37 | * Please submit changes by filing pull requests or issues on 38 | * the EGL Registry repository linked above. 39 | * 40 | * 41 | * See the Implementer's Guidelines for information about where this file 42 | * should be located on your system and for more details of its use: 43 | * http://www.khronos.org/registry/implementers_guide.pdf 44 | * 45 | * This file should be included as 46 | * #include 47 | * by Khronos client API header files that use its types and defines. 48 | * 49 | * The types in khrplatform.h should only be used to define API-specific types. 50 | * 51 | * Types defined in khrplatform.h: 52 | * khronos_int8_t signed 8 bit 53 | * khronos_uint8_t unsigned 8 bit 54 | * khronos_int16_t signed 16 bit 55 | * khronos_uint16_t unsigned 16 bit 56 | * khronos_int32_t signed 32 bit 57 | * khronos_uint32_t unsigned 32 bit 58 | * khronos_int64_t signed 64 bit 59 | * khronos_uint64_t unsigned 64 bit 60 | * khronos_intptr_t signed same number of bits as a pointer 61 | * khronos_uintptr_t unsigned same number of bits as a pointer 62 | * khronos_ssize_t signed size 63 | * khronos_usize_t unsigned size 64 | * khronos_float_t signed 32 bit floating point 65 | * khronos_time_ns_t unsigned 64 bit time in nanoseconds 66 | * khronos_utime_nanoseconds_t unsigned time interval or absolute time in 67 | * nanoseconds 68 | * khronos_stime_nanoseconds_t signed time interval in nanoseconds 69 | * khronos_boolean_enum_t enumerated boolean type. This should 70 | * only be used as a base type when a client API's boolean type is 71 | * an enum. Client APIs which use an integer or other type for 72 | * booleans cannot use this as the base type for their boolean. 73 | * 74 | * Tokens defined in khrplatform.h: 75 | * 76 | * KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values. 77 | * 78 | * KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0. 79 | * KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0. 80 | * 81 | * Calling convention macros defined in this file: 82 | * KHRONOS_APICALL 83 | * KHRONOS_APIENTRY 84 | * KHRONOS_APIATTRIBUTES 85 | * 86 | * These may be used in function prototypes as: 87 | * 88 | * KHRONOS_APICALL void KHRONOS_APIENTRY funcname( 89 | * int arg1, 90 | * int arg2) KHRONOS_APIATTRIBUTES; 91 | */ 92 | 93 | #if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC) 94 | # define KHRONOS_STATIC 1 95 | #endif 96 | 97 | /*------------------------------------------------------------------------- 98 | * Definition of KHRONOS_APICALL 99 | *------------------------------------------------------------------------- 100 | * This precedes the return type of the function in the function prototype. 101 | */ 102 | #if defined(KHRONOS_STATIC) 103 | /* If the preprocessor constant KHRONOS_STATIC is defined, make the 104 | * header compatible with static linking. */ 105 | # define KHRONOS_APICALL 106 | #elif defined(_WIN32) 107 | # define KHRONOS_APICALL __declspec(dllimport) 108 | #elif defined (__SYMBIAN32__) 109 | # define KHRONOS_APICALL IMPORT_C 110 | #elif defined(__ANDROID__) 111 | # define KHRONOS_APICALL __attribute__((visibility("default"))) 112 | #else 113 | # define KHRONOS_APICALL 114 | #endif 115 | 116 | /*------------------------------------------------------------------------- 117 | * Definition of KHRONOS_APIENTRY 118 | *------------------------------------------------------------------------- 119 | * This follows the return type of the function and precedes the function 120 | * name in the function prototype. 121 | */ 122 | #if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__) 123 | /* Win32 but not WinCE */ 124 | # define KHRONOS_APIENTRY __stdcall 125 | #else 126 | # define KHRONOS_APIENTRY 127 | #endif 128 | 129 | /*------------------------------------------------------------------------- 130 | * Definition of KHRONOS_APIATTRIBUTES 131 | *------------------------------------------------------------------------- 132 | * This follows the closing parenthesis of the function prototype arguments. 133 | */ 134 | #if defined (__ARMCC_2__) 135 | #define KHRONOS_APIATTRIBUTES __softfp 136 | #else 137 | #define KHRONOS_APIATTRIBUTES 138 | #endif 139 | 140 | /*------------------------------------------------------------------------- 141 | * basic type definitions 142 | *-----------------------------------------------------------------------*/ 143 | #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__) 144 | 145 | 146 | /* 147 | * Using 148 | */ 149 | #include 150 | typedef int32_t khronos_int32_t; 151 | typedef uint32_t khronos_uint32_t; 152 | typedef int64_t khronos_int64_t; 153 | typedef uint64_t khronos_uint64_t; 154 | #define KHRONOS_SUPPORT_INT64 1 155 | #define KHRONOS_SUPPORT_FLOAT 1 156 | /* 157 | * To support platform where unsigned long cannot be used interchangeably with 158 | * inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t. 159 | * Ideally, we could just use (u)intptr_t everywhere, but this could result in 160 | * ABI breakage if khronos_uintptr_t is changed from unsigned long to 161 | * unsigned long long or similar (this results in different C++ name mangling). 162 | * To avoid changes for existing platforms, we restrict usage of intptr_t to 163 | * platforms where the size of a pointer is larger than the size of long. 164 | */ 165 | #if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__) 166 | #if __SIZEOF_POINTER__ > __SIZEOF_LONG__ 167 | #define KHRONOS_USE_INTPTR_T 168 | #endif 169 | #endif 170 | 171 | #elif defined(__VMS ) || defined(__sgi) 172 | 173 | /* 174 | * Using 175 | */ 176 | #include 177 | typedef int32_t khronos_int32_t; 178 | typedef uint32_t khronos_uint32_t; 179 | typedef int64_t khronos_int64_t; 180 | typedef uint64_t khronos_uint64_t; 181 | #define KHRONOS_SUPPORT_INT64 1 182 | #define KHRONOS_SUPPORT_FLOAT 1 183 | 184 | #elif defined(_WIN32) && !defined(__SCITECH_SNAP__) 185 | 186 | /* 187 | * Win32 188 | */ 189 | typedef __int32 khronos_int32_t; 190 | typedef unsigned __int32 khronos_uint32_t; 191 | typedef __int64 khronos_int64_t; 192 | typedef unsigned __int64 khronos_uint64_t; 193 | #define KHRONOS_SUPPORT_INT64 1 194 | #define KHRONOS_SUPPORT_FLOAT 1 195 | 196 | #elif defined(__sun__) || defined(__digital__) 197 | 198 | /* 199 | * Sun or Digital 200 | */ 201 | typedef int khronos_int32_t; 202 | typedef unsigned int khronos_uint32_t; 203 | #if defined(__arch64__) || defined(_LP64) 204 | typedef long int khronos_int64_t; 205 | typedef unsigned long int khronos_uint64_t; 206 | #else 207 | typedef long long int khronos_int64_t; 208 | typedef unsigned long long int khronos_uint64_t; 209 | #endif /* __arch64__ */ 210 | #define KHRONOS_SUPPORT_INT64 1 211 | #define KHRONOS_SUPPORT_FLOAT 1 212 | 213 | #elif 0 214 | 215 | /* 216 | * Hypothetical platform with no float or int64 support 217 | */ 218 | typedef int khronos_int32_t; 219 | typedef unsigned int khronos_uint32_t; 220 | #define KHRONOS_SUPPORT_INT64 0 221 | #define KHRONOS_SUPPORT_FLOAT 0 222 | 223 | #else 224 | 225 | /* 226 | * Generic fallback 227 | */ 228 | #include 229 | typedef int32_t khronos_int32_t; 230 | typedef uint32_t khronos_uint32_t; 231 | typedef int64_t khronos_int64_t; 232 | typedef uint64_t khronos_uint64_t; 233 | #define KHRONOS_SUPPORT_INT64 1 234 | #define KHRONOS_SUPPORT_FLOAT 1 235 | 236 | #endif 237 | 238 | 239 | /* 240 | * Types that are (so far) the same on all platforms 241 | */ 242 | typedef signed char khronos_int8_t; 243 | typedef unsigned char khronos_uint8_t; 244 | typedef signed short int khronos_int16_t; 245 | typedef unsigned short int khronos_uint16_t; 246 | 247 | /* 248 | * Types that differ between LLP64 and LP64 architectures - in LLP64, 249 | * pointers are 64 bits, but 'long' is still 32 bits. Win64 appears 250 | * to be the only LLP64 architecture in current use. 251 | */ 252 | #ifdef KHRONOS_USE_INTPTR_T 253 | typedef intptr_t khronos_intptr_t; 254 | typedef uintptr_t khronos_uintptr_t; 255 | #elif defined(_WIN64) 256 | typedef signed long long int khronos_intptr_t; 257 | typedef unsigned long long int khronos_uintptr_t; 258 | #else 259 | typedef signed long int khronos_intptr_t; 260 | typedef unsigned long int khronos_uintptr_t; 261 | #endif 262 | 263 | #if defined(_WIN64) 264 | typedef signed long long int khronos_ssize_t; 265 | typedef unsigned long long int khronos_usize_t; 266 | #else 267 | typedef signed long int khronos_ssize_t; 268 | typedef unsigned long int khronos_usize_t; 269 | #endif 270 | 271 | #if KHRONOS_SUPPORT_FLOAT 272 | /* 273 | * Float type 274 | */ 275 | typedef float khronos_float_t; 276 | #endif 277 | 278 | #if KHRONOS_SUPPORT_INT64 279 | /* Time types 280 | * 281 | * These types can be used to represent a time interval in nanoseconds or 282 | * an absolute Unadjusted System Time. Unadjusted System Time is the number 283 | * of nanoseconds since some arbitrary system event (e.g. since the last 284 | * time the system booted). The Unadjusted System Time is an unsigned 285 | * 64 bit value that wraps back to 0 every 584 years. Time intervals 286 | * may be either signed or unsigned. 287 | */ 288 | typedef khronos_uint64_t khronos_utime_nanoseconds_t; 289 | typedef khronos_int64_t khronos_stime_nanoseconds_t; 290 | #endif 291 | 292 | /* 293 | * Dummy value used to pad enum types to 32 bits. 294 | */ 295 | #ifndef KHRONOS_MAX_ENUM 296 | #define KHRONOS_MAX_ENUM 0x7FFFFFFF 297 | #endif 298 | 299 | /* 300 | * Enumerated boolean type 301 | * 302 | * Values other than zero should be considered to be true. Therefore 303 | * comparisons should not be made against KHRONOS_TRUE. 304 | */ 305 | typedef enum { 306 | KHRONOS_FALSE = 0, 307 | KHRONOS_TRUE = 1, 308 | KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM 309 | } khronos_boolean_enum_t; 310 | 311 | #endif /* __khrplatform_h_ */ 312 | -------------------------------------------------------------------------------- /Libraries/include/imgui/desktop.ini: -------------------------------------------------------------------------------- 1 | [LocalizedFileNames] 2 | imgui_impl_opengl3_loader.h=@imgui_impl_opengl3_loader.h,0 3 | -------------------------------------------------------------------------------- /Libraries/include/imgui/imconfig.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // DEAR IMGUI COMPILE-TIME OPTIONS 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 file 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 clean your code of 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 IMGUI_USE_STB_SPRINTF is defined. 66 | //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION 67 | //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION 68 | //#define IMGUI_DISABLE_STB_SPRINTF_IMPLEMENTATION // only disabled if IMGUI_USE_STB_SPRINTF is defined. 69 | 70 | //---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined) 71 | // 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. 72 | //#define IMGUI_USE_STB_SPRINTF 73 | 74 | //---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui) 75 | // 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). 76 | // On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'. 77 | //#define IMGUI_ENABLE_FREETYPE 78 | 79 | //---- Use FreeType+lunasvg library to render OpenType SVG fonts (SVGinOT) 80 | // Requires lunasvg headers to be available in the include path + program to be linked with the lunasvg library (not provided). 81 | // Only works in combination with IMGUI_ENABLE_FREETYPE. 82 | // (implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement) 83 | //#define IMGUI_ENABLE_FREETYPE_LUNASVG 84 | 85 | //---- Use stb_truetype to build and rasterize the font atlas (default) 86 | // The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend. 87 | //#define IMGUI_ENABLE_STB_TRUETYPE 88 | 89 | //---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4. 90 | // This will be inlined as part of ImVec2 and ImVec4 class declarations. 91 | /* 92 | #define IM_VEC2_CLASS_EXTRA \ 93 | constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \ 94 | operator MyVec2() const { return MyVec2(x,y); } 95 | 96 | #define IM_VEC4_CLASS_EXTRA \ 97 | constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \ 98 | operator MyVec4() const { return MyVec4(x,y,z,w); } 99 | */ 100 | //---- ...Or use Dear ImGui's own very basic math operators. 101 | //#define IMGUI_DEFINE_MATH_OPERATORS 102 | 103 | //---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices. 104 | // Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices). 105 | // Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer. 106 | // Read about ImGuiBackendFlags_RendererHasVtxOffset for details. 107 | //#define ImDrawIdx unsigned int 108 | 109 | //---- Override ImDrawCallback signature (will need to modify renderer backends accordingly) 110 | //struct ImDrawList; 111 | //struct ImDrawCmd; 112 | //typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data); 113 | //#define ImDrawCallback MyImDrawCallback 114 | 115 | //---- Debug Tools: Macro to break in Debugger (we provide a default implementation of this in the codebase) 116 | // (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.) 117 | //#define IM_DEBUG_BREAK IM_ASSERT(0) 118 | //#define IM_DEBUG_BREAK __debugbreak() 119 | 120 | //---- Debug Tools: Enable slower asserts 121 | //#define IMGUI_DEBUG_PARANOID 122 | 123 | //---- Tip: You can add extra functions within the ImGui:: namespace from anywhere (e.g. your own sources/header files) 124 | /* 125 | namespace ImGui 126 | { 127 | void MyFunction(const char* name, MyMatrix44* mtx); 128 | } 129 | */ 130 | -------------------------------------------------------------------------------- /Libraries/include/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 | 5 | // Implemented features: 6 | // [X] Platform: Clipboard support. 7 | // [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen (Windows only). 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 | 12 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 13 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 14 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 15 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 16 | 17 | #pragma once 18 | #include "imgui.h" // IMGUI_IMPL_API 19 | #ifndef IMGUI_DISABLE 20 | 21 | struct GLFWwindow; 22 | struct GLFWmonitor; 23 | 24 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks); 25 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks); 26 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool install_callbacks); 27 | IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown(); 28 | IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame(); 29 | 30 | // GLFW callbacks install 31 | // - 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. 32 | // - 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. 33 | IMGUI_IMPL_API void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window); 34 | IMGUI_IMPL_API void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window); 35 | 36 | // GFLW callbacks options: 37 | // - Set 'chain_for_all_windows=true' to enable chaining callbacks for all windows (including secondary viewports created by backends or by user) 38 | IMGUI_IMPL_API void ImGui_ImplGlfw_SetCallbacksChainForAllWindows(bool chain_for_all_windows); 39 | 40 | // GLFW callbacks (individual callbacks to call yourself if you didn't install callbacks) 41 | IMGUI_IMPL_API void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused); // Since 1.84 42 | IMGUI_IMPL_API void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered); // Since 1.84 43 | IMGUI_IMPL_API void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y); // Since 1.87 44 | IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods); 45 | IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset); 46 | IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); 47 | IMGUI_IMPL_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c); 48 | IMGUI_IMPL_API void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor* monitor, int event); 49 | 50 | #endif // #ifndef IMGUI_DISABLE 51 | -------------------------------------------------------------------------------- /Libraries/include/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: Large meshes support (64k+ vertices) with 16-bit indices (Desktop OpenGL only). 9 | 10 | // About WebGL/ES: 11 | // - You need to '#define IMGUI_IMPL_OPENGL_ES2' or '#define IMGUI_IMPL_OPENGL_ES3' to use WebGL or OpenGL ES. 12 | // - This is done automatically on iOS, Android and Emscripten targets. 13 | // - For other targets, the define needs to be visible from the imgui_impl_opengl3.cpp compilation unit. If unsure, define globally or in imconfig.h. 14 | 15 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 16 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 17 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 18 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 19 | 20 | // About GLSL version: 21 | // The 'glsl_version' initialization parameter should be nullptr (default) or a "#version XXX" string. 22 | // On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es" 23 | // Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp. 24 | 25 | #pragma once 26 | #include "imgui.h" // IMGUI_IMPL_API 27 | #ifndef IMGUI_DISABLE 28 | 29 | // Backend API 30 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = nullptr); 31 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown(); 32 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame(); 33 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data); 34 | 35 | // (Optional) Called by Init/NewFrame/Shutdown 36 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture(); 37 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyFontsTexture(); 38 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects(); 39 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects(); 40 | 41 | // Specific OpenGL ES versions 42 | //#define IMGUI_IMPL_OPENGL_ES2 // Auto-detected on Emscripten 43 | //#define IMGUI_IMPL_OPENGL_ES3 // Auto-detected on iOS/Android 44 | 45 | // 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. 46 | #if !defined(IMGUI_IMPL_OPENGL_ES2) \ 47 | && !defined(IMGUI_IMPL_OPENGL_ES3) 48 | 49 | // Try to detect GLES on matching platforms 50 | #if defined(__APPLE__) 51 | #include 52 | #endif 53 | #if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__)) 54 | #define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es" 55 | #elif defined(__EMSCRIPTEN__) || defined(__amigaos4__) 56 | #define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100" 57 | #else 58 | // Otherwise imgui_impl_opengl3_loader.h will be used. 59 | #endif 60 | 61 | #endif 62 | 63 | #endif // #ifndef IMGUI_DISABLE 64 | -------------------------------------------------------------------------------- /Libraries/include/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 0x0404 158 | #define GL_BACK 0x0405 159 | #define GL_FRONT_AND_BACK 0x0408 160 | #define GL_POLYGON_MODE 0x0B40 161 | #define GL_CULL_FACE 0x0B44 162 | #define GL_DEPTH_TEST 0x0B71 163 | #define GL_STENCIL_TEST 0x0B90 164 | #define GL_VIEWPORT 0x0BA2 165 | #define GL_BLEND 0x0BE2 166 | #define GL_SCISSOR_BOX 0x0C10 167 | #define GL_SCISSOR_TEST 0x0C11 168 | #define GL_UNPACK_ROW_LENGTH 0x0CF2 169 | #define GL_PACK_ALIGNMENT 0x0D05 170 | #define GL_TEXTURE_2D 0x0DE1 171 | #define GL_UNSIGNED_BYTE 0x1401 172 | #define GL_UNSIGNED_SHORT 0x1403 173 | #define GL_UNSIGNED_INT 0x1405 174 | #define GL_FLOAT 0x1406 175 | #define GL_RGBA 0x1908 176 | #define GL_FILL 0x1B02 177 | #define GL_VENDOR 0x1F00 178 | #define GL_RENDERER 0x1F01 179 | #define GL_VERSION 0x1F02 180 | #define GL_EXTENSIONS 0x1F03 181 | #define GL_LINEAR 0x2601 182 | #define GL_TEXTURE_MAG_FILTER 0x2800 183 | #define GL_TEXTURE_MIN_FILTER 0x2801 184 | typedef void (APIENTRYP PFNGLPOLYGONMODEPROC) (GLenum face, GLenum mode); 185 | typedef void (APIENTRYP PFNGLSCISSORPROC) (GLint x, GLint y, GLsizei width, GLsizei height); 186 | typedef void (APIENTRYP PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param); 187 | typedef void (APIENTRYP PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels); 188 | typedef void (APIENTRYP PFNGLCLEARPROC) (GLbitfield mask); 189 | typedef void (APIENTRYP PFNGLCLEARCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); 190 | typedef void (APIENTRYP PFNGLDISABLEPROC) (GLenum cap); 191 | typedef void (APIENTRYP PFNGLENABLEPROC) (GLenum cap); 192 | typedef void (APIENTRYP PFNGLFLUSHPROC) (void); 193 | typedef void (APIENTRYP PFNGLPIXELSTOREIPROC) (GLenum pname, GLint param); 194 | typedef void (APIENTRYP PFNGLREADPIXELSPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels); 195 | typedef GLenum (APIENTRYP PFNGLGETERRORPROC) (void); 196 | typedef void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *data); 197 | typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGPROC) (GLenum name); 198 | typedef GLboolean (APIENTRYP PFNGLISENABLEDPROC) (GLenum cap); 199 | typedef void (APIENTRYP PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height); 200 | #ifdef GL_GLEXT_PROTOTYPES 201 | GLAPI void APIENTRY glPolygonMode (GLenum face, GLenum mode); 202 | GLAPI void APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height); 203 | GLAPI void APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param); 204 | GLAPI void APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels); 205 | GLAPI void APIENTRY glClear (GLbitfield mask); 206 | GLAPI void APIENTRY glClearColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); 207 | GLAPI void APIENTRY glDisable (GLenum cap); 208 | GLAPI void APIENTRY glEnable (GLenum cap); 209 | GLAPI void APIENTRY glFlush (void); 210 | GLAPI void APIENTRY glPixelStorei (GLenum pname, GLint param); 211 | GLAPI void APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels); 212 | GLAPI GLenum APIENTRY glGetError (void); 213 | GLAPI void APIENTRY glGetIntegerv (GLenum pname, GLint *data); 214 | GLAPI const GLubyte *APIENTRY glGetString (GLenum name); 215 | GLAPI GLboolean APIENTRY glIsEnabled (GLenum cap); 216 | GLAPI void APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height); 217 | #endif 218 | #endif /* GL_VERSION_1_0 */ 219 | #ifndef GL_VERSION_1_1 220 | typedef khronos_float_t GLclampf; 221 | typedef double GLclampd; 222 | #define GL_TEXTURE_BINDING_2D 0x8069 223 | typedef void (APIENTRYP PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices); 224 | typedef void (APIENTRYP PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture); 225 | typedef void (APIENTRYP PFNGLDELETETEXTURESPROC) (GLsizei n, const GLuint *textures); 226 | typedef void (APIENTRYP PFNGLGENTEXTURESPROC) (GLsizei n, GLuint *textures); 227 | #ifdef GL_GLEXT_PROTOTYPES 228 | GLAPI void APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const void *indices); 229 | GLAPI void APIENTRY glBindTexture (GLenum target, GLuint texture); 230 | GLAPI void APIENTRY glDeleteTextures (GLsizei n, const GLuint *textures); 231 | GLAPI void APIENTRY glGenTextures (GLsizei n, GLuint *textures); 232 | #endif 233 | #endif /* GL_VERSION_1_1 */ 234 | #ifndef GL_VERSION_1_3 235 | #define GL_TEXTURE0 0x84C0 236 | #define GL_ACTIVE_TEXTURE 0x84E0 237 | typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); 238 | #ifdef GL_GLEXT_PROTOTYPES 239 | GLAPI void APIENTRY glActiveTexture (GLenum texture); 240 | #endif 241 | #endif /* GL_VERSION_1_3 */ 242 | #ifndef GL_VERSION_1_4 243 | #define GL_BLEND_DST_RGB 0x80C8 244 | #define GL_BLEND_SRC_RGB 0x80C9 245 | #define GL_BLEND_DST_ALPHA 0x80CA 246 | #define GL_BLEND_SRC_ALPHA 0x80CB 247 | #define GL_FUNC_ADD 0x8006 248 | typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); 249 | typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode); 250 | #ifdef GL_GLEXT_PROTOTYPES 251 | GLAPI void APIENTRY glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); 252 | GLAPI void APIENTRY glBlendEquation (GLenum mode); 253 | #endif 254 | #endif /* GL_VERSION_1_4 */ 255 | #ifndef GL_VERSION_1_5 256 | typedef khronos_ssize_t GLsizeiptr; 257 | typedef khronos_intptr_t GLintptr; 258 | #define GL_ARRAY_BUFFER 0x8892 259 | #define GL_ELEMENT_ARRAY_BUFFER 0x8893 260 | #define GL_ARRAY_BUFFER_BINDING 0x8894 261 | #define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 262 | #define GL_STREAM_DRAW 0x88E0 263 | typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer); 264 | typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers); 265 | typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers); 266 | typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const void *data, GLenum usage); 267 | typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const void *data); 268 | #ifdef GL_GLEXT_PROTOTYPES 269 | GLAPI void APIENTRY glBindBuffer (GLenum target, GLuint buffer); 270 | GLAPI void APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers); 271 | GLAPI void APIENTRY glGenBuffers (GLsizei n, GLuint *buffers); 272 | GLAPI void APIENTRY glBufferData (GLenum target, GLsizeiptr size, const void *data, GLenum usage); 273 | GLAPI void APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const void *data); 274 | #endif 275 | #endif /* GL_VERSION_1_5 */ 276 | #ifndef GL_VERSION_2_0 277 | typedef char GLchar; 278 | typedef khronos_int16_t GLshort; 279 | typedef khronos_int8_t GLbyte; 280 | typedef khronos_uint16_t GLushort; 281 | #define GL_BLEND_EQUATION_RGB 0x8009 282 | #define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 283 | #define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 284 | #define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 285 | #define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 286 | #define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 287 | #define GL_BLEND_EQUATION_ALPHA 0x883D 288 | #define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A 289 | #define GL_FRAGMENT_SHADER 0x8B30 290 | #define GL_VERTEX_SHADER 0x8B31 291 | #define GL_COMPILE_STATUS 0x8B81 292 | #define GL_LINK_STATUS 0x8B82 293 | #define GL_INFO_LOG_LENGTH 0x8B84 294 | #define GL_CURRENT_PROGRAM 0x8B8D 295 | #define GL_UPPER_LEFT 0x8CA2 296 | typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha); 297 | typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader); 298 | typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader); 299 | typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void); 300 | typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type); 301 | typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program); 302 | typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader); 303 | typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader); 304 | typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index); 305 | typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index); 306 | typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name); 307 | typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params); 308 | typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); 309 | typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params); 310 | typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); 311 | typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name); 312 | typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params); 313 | typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, void **pointer); 314 | typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC) (GLuint program); 315 | typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program); 316 | typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length); 317 | typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program); 318 | typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0); 319 | typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); 320 | typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer); 321 | #ifdef GL_GLEXT_PROTOTYPES 322 | GLAPI void APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha); 323 | GLAPI void APIENTRY glAttachShader (GLuint program, GLuint shader); 324 | GLAPI void APIENTRY glCompileShader (GLuint shader); 325 | GLAPI GLuint APIENTRY glCreateProgram (void); 326 | GLAPI GLuint APIENTRY glCreateShader (GLenum type); 327 | GLAPI void APIENTRY glDeleteProgram (GLuint program); 328 | GLAPI void APIENTRY glDeleteShader (GLuint shader); 329 | GLAPI void APIENTRY glDetachShader (GLuint program, GLuint shader); 330 | GLAPI void APIENTRY glDisableVertexAttribArray (GLuint index); 331 | GLAPI void APIENTRY glEnableVertexAttribArray (GLuint index); 332 | GLAPI GLint APIENTRY glGetAttribLocation (GLuint program, const GLchar *name); 333 | GLAPI void APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint *params); 334 | GLAPI void APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); 335 | GLAPI void APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint *params); 336 | GLAPI void APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); 337 | GLAPI GLint APIENTRY glGetUniformLocation (GLuint program, const GLchar *name); 338 | GLAPI void APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint *params); 339 | GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, void **pointer); 340 | GLAPI GLboolean APIENTRY glIsProgram (GLuint program); 341 | GLAPI void APIENTRY glLinkProgram (GLuint program); 342 | GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length); 343 | GLAPI void APIENTRY glUseProgram (GLuint program); 344 | GLAPI void APIENTRY glUniform1i (GLint location, GLint v0); 345 | GLAPI void APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); 346 | GLAPI void APIENTRY glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer); 347 | #endif 348 | #endif /* GL_VERSION_2_0 */ 349 | #ifndef GL_VERSION_3_0 350 | typedef khronos_uint16_t GLhalf; 351 | #define GL_MAJOR_VERSION 0x821B 352 | #define GL_MINOR_VERSION 0x821C 353 | #define GL_NUM_EXTENSIONS 0x821D 354 | #define GL_FRAMEBUFFER_SRGB 0x8DB9 355 | #define GL_VERTEX_ARRAY_BINDING 0x85B5 356 | typedef void (APIENTRYP PFNGLGETBOOLEANI_VPROC) (GLenum target, GLuint index, GLboolean *data); 357 | typedef void (APIENTRYP PFNGLGETINTEGERI_VPROC) (GLenum target, GLuint index, GLint *data); 358 | typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint index); 359 | typedef void (APIENTRYP PFNGLBINDVERTEXARRAYPROC) (GLuint array); 360 | typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint *arrays); 361 | typedef void (APIENTRYP PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays); 362 | #ifdef GL_GLEXT_PROTOTYPES 363 | GLAPI const GLubyte *APIENTRY glGetStringi (GLenum name, GLuint index); 364 | GLAPI void APIENTRY glBindVertexArray (GLuint array); 365 | GLAPI void APIENTRY glDeleteVertexArrays (GLsizei n, const GLuint *arrays); 366 | GLAPI void APIENTRY glGenVertexArrays (GLsizei n, GLuint *arrays); 367 | #endif 368 | #endif /* GL_VERSION_3_0 */ 369 | #ifndef GL_VERSION_3_1 370 | #define GL_VERSION_3_1 1 371 | #define GL_PRIMITIVE_RESTART 0x8F9D 372 | #endif /* GL_VERSION_3_1 */ 373 | #ifndef GL_VERSION_3_2 374 | #define GL_VERSION_3_2 1 375 | typedef struct __GLsync *GLsync; 376 | typedef khronos_uint64_t GLuint64; 377 | typedef khronos_int64_t GLint64; 378 | #define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002 379 | #define GL_CONTEXT_PROFILE_MASK 0x9126 380 | typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex); 381 | typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data); 382 | #ifdef GL_GLEXT_PROTOTYPES 383 | GLAPI void APIENTRY glDrawElementsBaseVertex (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex); 384 | #endif 385 | #endif /* GL_VERSION_3_2 */ 386 | #ifndef GL_VERSION_3_3 387 | #define GL_VERSION_3_3 1 388 | #define GL_SAMPLER_BINDING 0x8919 389 | typedef void (APIENTRYP PFNGLBINDSAMPLERPROC) (GLuint unit, GLuint sampler); 390 | #ifdef GL_GLEXT_PROTOTYPES 391 | GLAPI void APIENTRY glBindSampler (GLuint unit, GLuint sampler); 392 | #endif 393 | #endif /* GL_VERSION_3_3 */ 394 | #ifndef GL_VERSION_4_1 395 | typedef void (APIENTRYP PFNGLGETFLOATI_VPROC) (GLenum target, GLuint index, GLfloat *data); 396 | typedef void (APIENTRYP PFNGLGETDOUBLEI_VPROC) (GLenum target, GLuint index, GLdouble *data); 397 | #endif /* GL_VERSION_4_1 */ 398 | #ifndef GL_VERSION_4_3 399 | typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam); 400 | #endif /* GL_VERSION_4_3 */ 401 | #ifndef GL_VERSION_4_5 402 | #define GL_CLIP_ORIGIN 0x935C 403 | typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKI_VPROC) (GLuint xfb, GLenum pname, GLuint index, GLint *param); 404 | typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKI64_VPROC) (GLuint xfb, GLenum pname, GLuint index, GLint64 *param); 405 | #endif /* GL_VERSION_4_5 */ 406 | #ifndef GL_ARB_bindless_texture 407 | typedef khronos_uint64_t GLuint64EXT; 408 | #endif /* GL_ARB_bindless_texture */ 409 | #ifndef GL_ARB_cl_event 410 | struct _cl_context; 411 | struct _cl_event; 412 | #endif /* GL_ARB_cl_event */ 413 | #ifndef GL_ARB_clip_control 414 | #define GL_ARB_clip_control 1 415 | #endif /* GL_ARB_clip_control */ 416 | #ifndef GL_ARB_debug_output 417 | typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam); 418 | #endif /* GL_ARB_debug_output */ 419 | #ifndef GL_EXT_EGL_image_storage 420 | typedef void *GLeglImageOES; 421 | #endif /* GL_EXT_EGL_image_storage */ 422 | #ifndef GL_EXT_direct_state_access 423 | typedef void (APIENTRYP PFNGLGETFLOATI_VEXTPROC) (GLenum pname, GLuint index, GLfloat *params); 424 | typedef void (APIENTRYP PFNGLGETDOUBLEI_VEXTPROC) (GLenum pname, GLuint index, GLdouble *params); 425 | typedef void (APIENTRYP PFNGLGETPOINTERI_VEXTPROC) (GLenum pname, GLuint index, void **params); 426 | typedef void (APIENTRYP PFNGLGETVERTEXARRAYINTEGERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, GLint *param); 427 | typedef void (APIENTRYP PFNGLGETVERTEXARRAYPOINTERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, void **param); 428 | #endif /* GL_EXT_direct_state_access */ 429 | #ifndef GL_NV_draw_vulkan_image 430 | typedef void (APIENTRY *GLVULKANPROCNV)(void); 431 | #endif /* GL_NV_draw_vulkan_image */ 432 | #ifndef GL_NV_gpu_shader5 433 | typedef khronos_int64_t GLint64EXT; 434 | #endif /* GL_NV_gpu_shader5 */ 435 | #ifndef GL_NV_vertex_buffer_unified_memory 436 | typedef void (APIENTRYP PFNGLGETINTEGERUI64I_VNVPROC) (GLenum value, GLuint index, GLuint64EXT *result); 437 | #endif /* GL_NV_vertex_buffer_unified_memory */ 438 | #ifdef __cplusplus 439 | } 440 | #endif 441 | #endif 442 | 443 | #ifndef GL3W_API 444 | #define GL3W_API 445 | #endif 446 | 447 | #ifndef __gl_h_ 448 | #define __gl_h_ 449 | #endif 450 | 451 | #ifdef __cplusplus 452 | extern "C" { 453 | #endif 454 | 455 | #define GL3W_OK 0 456 | #define GL3W_ERROR_INIT -1 457 | #define GL3W_ERROR_LIBRARY_OPEN -2 458 | #define GL3W_ERROR_OPENGL_VERSION -3 459 | 460 | typedef void (*GL3WglProc)(void); 461 | typedef GL3WglProc (*GL3WGetProcAddressProc)(const char *proc); 462 | 463 | /* gl3w api */ 464 | GL3W_API int imgl3wInit(void); 465 | GL3W_API int imgl3wInit2(GL3WGetProcAddressProc proc); 466 | GL3W_API int imgl3wIsSupported(int major, int minor); 467 | GL3W_API GL3WglProc imgl3wGetProcAddress(const char *proc); 468 | 469 | /* gl3w internal state */ 470 | union GL3WProcs { 471 | GL3WglProc ptr[59]; 472 | struct { 473 | PFNGLACTIVETEXTUREPROC ActiveTexture; 474 | PFNGLATTACHSHADERPROC AttachShader; 475 | PFNGLBINDBUFFERPROC BindBuffer; 476 | PFNGLBINDSAMPLERPROC BindSampler; 477 | PFNGLBINDTEXTUREPROC BindTexture; 478 | PFNGLBINDVERTEXARRAYPROC BindVertexArray; 479 | PFNGLBLENDEQUATIONPROC BlendEquation; 480 | PFNGLBLENDEQUATIONSEPARATEPROC BlendEquationSeparate; 481 | PFNGLBLENDFUNCSEPARATEPROC BlendFuncSeparate; 482 | PFNGLBUFFERDATAPROC BufferData; 483 | PFNGLBUFFERSUBDATAPROC BufferSubData; 484 | PFNGLCLEARPROC Clear; 485 | PFNGLCLEARCOLORPROC ClearColor; 486 | PFNGLCOMPILESHADERPROC CompileShader; 487 | PFNGLCREATEPROGRAMPROC CreateProgram; 488 | PFNGLCREATESHADERPROC CreateShader; 489 | PFNGLDELETEBUFFERSPROC DeleteBuffers; 490 | PFNGLDELETEPROGRAMPROC DeleteProgram; 491 | PFNGLDELETESHADERPROC DeleteShader; 492 | PFNGLDELETETEXTURESPROC DeleteTextures; 493 | PFNGLDELETEVERTEXARRAYSPROC DeleteVertexArrays; 494 | PFNGLDETACHSHADERPROC DetachShader; 495 | PFNGLDISABLEPROC Disable; 496 | PFNGLDISABLEVERTEXATTRIBARRAYPROC DisableVertexAttribArray; 497 | PFNGLDRAWELEMENTSPROC DrawElements; 498 | PFNGLDRAWELEMENTSBASEVERTEXPROC DrawElementsBaseVertex; 499 | PFNGLENABLEPROC Enable; 500 | PFNGLENABLEVERTEXATTRIBARRAYPROC EnableVertexAttribArray; 501 | PFNGLFLUSHPROC Flush; 502 | PFNGLGENBUFFERSPROC GenBuffers; 503 | PFNGLGENTEXTURESPROC GenTextures; 504 | PFNGLGENVERTEXARRAYSPROC GenVertexArrays; 505 | PFNGLGETATTRIBLOCATIONPROC GetAttribLocation; 506 | PFNGLGETERRORPROC GetError; 507 | PFNGLGETINTEGERVPROC GetIntegerv; 508 | PFNGLGETPROGRAMINFOLOGPROC GetProgramInfoLog; 509 | PFNGLGETPROGRAMIVPROC GetProgramiv; 510 | PFNGLGETSHADERINFOLOGPROC GetShaderInfoLog; 511 | PFNGLGETSHADERIVPROC GetShaderiv; 512 | PFNGLGETSTRINGPROC GetString; 513 | PFNGLGETSTRINGIPROC GetStringi; 514 | PFNGLGETUNIFORMLOCATIONPROC GetUniformLocation; 515 | PFNGLGETVERTEXATTRIBPOINTERVPROC GetVertexAttribPointerv; 516 | PFNGLGETVERTEXATTRIBIVPROC GetVertexAttribiv; 517 | PFNGLISENABLEDPROC IsEnabled; 518 | PFNGLISPROGRAMPROC IsProgram; 519 | PFNGLLINKPROGRAMPROC LinkProgram; 520 | PFNGLPIXELSTOREIPROC PixelStorei; 521 | PFNGLPOLYGONMODEPROC PolygonMode; 522 | PFNGLREADPIXELSPROC ReadPixels; 523 | PFNGLSCISSORPROC Scissor; 524 | PFNGLSHADERSOURCEPROC ShaderSource; 525 | PFNGLTEXIMAGE2DPROC TexImage2D; 526 | PFNGLTEXPARAMETERIPROC TexParameteri; 527 | PFNGLUNIFORM1IPROC Uniform1i; 528 | PFNGLUNIFORMMATRIX4FVPROC UniformMatrix4fv; 529 | PFNGLUSEPROGRAMPROC UseProgram; 530 | PFNGLVERTEXATTRIBPOINTERPROC VertexAttribPointer; 531 | PFNGLVIEWPORTPROC Viewport; 532 | } gl; 533 | }; 534 | 535 | GL3W_API extern union GL3WProcs imgl3wProcs; 536 | 537 | /* OpenGL functions */ 538 | #define glActiveTexture imgl3wProcs.gl.ActiveTexture 539 | #define glAttachShader imgl3wProcs.gl.AttachShader 540 | #define glBindBuffer imgl3wProcs.gl.BindBuffer 541 | #define glBindSampler imgl3wProcs.gl.BindSampler 542 | #define glBindTexture imgl3wProcs.gl.BindTexture 543 | #define glBindVertexArray imgl3wProcs.gl.BindVertexArray 544 | #define glBlendEquation imgl3wProcs.gl.BlendEquation 545 | #define glBlendEquationSeparate imgl3wProcs.gl.BlendEquationSeparate 546 | #define glBlendFuncSeparate imgl3wProcs.gl.BlendFuncSeparate 547 | #define glBufferData imgl3wProcs.gl.BufferData 548 | #define glBufferSubData imgl3wProcs.gl.BufferSubData 549 | #define glClear imgl3wProcs.gl.Clear 550 | #define glClearColor imgl3wProcs.gl.ClearColor 551 | #define glCompileShader imgl3wProcs.gl.CompileShader 552 | #define glCreateProgram imgl3wProcs.gl.CreateProgram 553 | #define glCreateShader imgl3wProcs.gl.CreateShader 554 | #define glDeleteBuffers imgl3wProcs.gl.DeleteBuffers 555 | #define glDeleteProgram imgl3wProcs.gl.DeleteProgram 556 | #define glDeleteShader imgl3wProcs.gl.DeleteShader 557 | #define glDeleteTextures imgl3wProcs.gl.DeleteTextures 558 | #define glDeleteVertexArrays imgl3wProcs.gl.DeleteVertexArrays 559 | #define glDetachShader imgl3wProcs.gl.DetachShader 560 | #define glDisable imgl3wProcs.gl.Disable 561 | #define glDisableVertexAttribArray imgl3wProcs.gl.DisableVertexAttribArray 562 | #define glDrawElements imgl3wProcs.gl.DrawElements 563 | #define glDrawElementsBaseVertex imgl3wProcs.gl.DrawElementsBaseVertex 564 | #define glEnable imgl3wProcs.gl.Enable 565 | #define glEnableVertexAttribArray imgl3wProcs.gl.EnableVertexAttribArray 566 | #define glFlush imgl3wProcs.gl.Flush 567 | #define glGenBuffers imgl3wProcs.gl.GenBuffers 568 | #define glGenTextures imgl3wProcs.gl.GenTextures 569 | #define glGenVertexArrays imgl3wProcs.gl.GenVertexArrays 570 | #define glGetAttribLocation imgl3wProcs.gl.GetAttribLocation 571 | #define glGetError imgl3wProcs.gl.GetError 572 | #define glGetIntegerv imgl3wProcs.gl.GetIntegerv 573 | #define glGetProgramInfoLog imgl3wProcs.gl.GetProgramInfoLog 574 | #define glGetProgramiv imgl3wProcs.gl.GetProgramiv 575 | #define glGetShaderInfoLog imgl3wProcs.gl.GetShaderInfoLog 576 | #define glGetShaderiv imgl3wProcs.gl.GetShaderiv 577 | #define glGetString imgl3wProcs.gl.GetString 578 | #define glGetStringi imgl3wProcs.gl.GetStringi 579 | #define glGetUniformLocation imgl3wProcs.gl.GetUniformLocation 580 | #define glGetVertexAttribPointerv imgl3wProcs.gl.GetVertexAttribPointerv 581 | #define glGetVertexAttribiv imgl3wProcs.gl.GetVertexAttribiv 582 | #define glIsEnabled imgl3wProcs.gl.IsEnabled 583 | #define glIsProgram imgl3wProcs.gl.IsProgram 584 | #define glLinkProgram imgl3wProcs.gl.LinkProgram 585 | #define glPixelStorei imgl3wProcs.gl.PixelStorei 586 | #define glPolygonMode imgl3wProcs.gl.PolygonMode 587 | #define glReadPixels imgl3wProcs.gl.ReadPixels 588 | #define glScissor imgl3wProcs.gl.Scissor 589 | #define glShaderSource imgl3wProcs.gl.ShaderSource 590 | #define glTexImage2D imgl3wProcs.gl.TexImage2D 591 | #define glTexParameteri imgl3wProcs.gl.TexParameteri 592 | #define glUniform1i imgl3wProcs.gl.Uniform1i 593 | #define glUniformMatrix4fv imgl3wProcs.gl.UniformMatrix4fv 594 | #define glUseProgram imgl3wProcs.gl.UseProgram 595 | #define glVertexAttribPointer imgl3wProcs.gl.VertexAttribPointer 596 | #define glViewport imgl3wProcs.gl.Viewport 597 | 598 | #ifdef __cplusplus 599 | } 600 | #endif 601 | 602 | #endif 603 | 604 | #ifdef IMGL3W_IMPL 605 | #ifdef __cplusplus 606 | extern "C" { 607 | #endif 608 | 609 | #include 610 | 611 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 612 | 613 | #if defined(_WIN32) 614 | #ifndef WIN32_LEAN_AND_MEAN 615 | #define WIN32_LEAN_AND_MEAN 1 616 | #endif 617 | #include 618 | 619 | static HMODULE libgl; 620 | typedef PROC(__stdcall* GL3WglGetProcAddr)(LPCSTR); 621 | static GL3WglGetProcAddr wgl_get_proc_address; 622 | 623 | static int open_libgl(void) 624 | { 625 | libgl = LoadLibraryA("opengl32.dll"); 626 | if (!libgl) 627 | return GL3W_ERROR_LIBRARY_OPEN; 628 | wgl_get_proc_address = (GL3WglGetProcAddr)GetProcAddress(libgl, "wglGetProcAddress"); 629 | return GL3W_OK; 630 | } 631 | 632 | static void close_libgl(void) { FreeLibrary(libgl); } 633 | static GL3WglProc get_proc(const char *proc) 634 | { 635 | GL3WglProc res; 636 | res = (GL3WglProc)wgl_get_proc_address(proc); 637 | if (!res) 638 | res = (GL3WglProc)GetProcAddress(libgl, proc); 639 | return res; 640 | } 641 | #elif defined(__APPLE__) 642 | #include 643 | 644 | static void *libgl; 645 | static int open_libgl(void) 646 | { 647 | libgl = dlopen("/System/Library/Frameworks/OpenGL.framework/OpenGL", RTLD_LAZY | RTLD_LOCAL); 648 | if (!libgl) 649 | return GL3W_ERROR_LIBRARY_OPEN; 650 | return GL3W_OK; 651 | } 652 | 653 | static void close_libgl(void) { dlclose(libgl); } 654 | 655 | static GL3WglProc get_proc(const char *proc) 656 | { 657 | GL3WglProc res; 658 | *(void **)(&res) = dlsym(libgl, proc); 659 | return res; 660 | } 661 | #else 662 | #include 663 | 664 | static void *libgl; 665 | static GL3WglProc (*glx_get_proc_address)(const GLubyte *); 666 | 667 | static int open_libgl(void) 668 | { 669 | libgl = dlopen("libGL.so.1", RTLD_LAZY | RTLD_LOCAL); 670 | if (!libgl) 671 | return GL3W_ERROR_LIBRARY_OPEN; 672 | *(void **)(&glx_get_proc_address) = dlsym(libgl, "glXGetProcAddressARB"); 673 | return GL3W_OK; 674 | } 675 | 676 | static void close_libgl(void) { dlclose(libgl); } 677 | 678 | static GL3WglProc get_proc(const char *proc) 679 | { 680 | GL3WglProc res; 681 | res = glx_get_proc_address((const GLubyte *)proc); 682 | if (!res) 683 | *(void **)(&res) = dlsym(libgl, proc); 684 | return res; 685 | } 686 | #endif 687 | 688 | static struct { int major, minor; } version; 689 | 690 | static int parse_version(void) 691 | { 692 | if (!glGetIntegerv) 693 | return GL3W_ERROR_INIT; 694 | glGetIntegerv(GL_MAJOR_VERSION, &version.major); 695 | glGetIntegerv(GL_MINOR_VERSION, &version.minor); 696 | if (version.major == 0 && version.minor == 0) 697 | { 698 | // Query GL_VERSION in desktop GL 2.x, the string will start with "." 699 | if (const char* gl_version = (const char*)glGetString(GL_VERSION)) 700 | sscanf(gl_version, "%d.%d", &version.major, &version.minor); 701 | } 702 | if (version.major < 2) 703 | return GL3W_ERROR_OPENGL_VERSION; 704 | return GL3W_OK; 705 | } 706 | 707 | static void load_procs(GL3WGetProcAddressProc proc); 708 | 709 | int imgl3wInit(void) 710 | { 711 | int res = open_libgl(); 712 | if (res) 713 | return res; 714 | atexit(close_libgl); 715 | return imgl3wInit2(get_proc); 716 | } 717 | 718 | int imgl3wInit2(GL3WGetProcAddressProc proc) 719 | { 720 | load_procs(proc); 721 | return parse_version(); 722 | } 723 | 724 | int imgl3wIsSupported(int major, int minor) 725 | { 726 | if (major < 2) 727 | return 0; 728 | if (version.major == major) 729 | return version.minor >= minor; 730 | return version.major >= major; 731 | } 732 | 733 | GL3WglProc imgl3wGetProcAddress(const char *proc) { return get_proc(proc); } 734 | 735 | static const char *proc_names[] = { 736 | "glActiveTexture", 737 | "glAttachShader", 738 | "glBindBuffer", 739 | "glBindSampler", 740 | "glBindTexture", 741 | "glBindVertexArray", 742 | "glBlendEquation", 743 | "glBlendEquationSeparate", 744 | "glBlendFuncSeparate", 745 | "glBufferData", 746 | "glBufferSubData", 747 | "glClear", 748 | "glClearColor", 749 | "glCompileShader", 750 | "glCreateProgram", 751 | "glCreateShader", 752 | "glDeleteBuffers", 753 | "glDeleteProgram", 754 | "glDeleteShader", 755 | "glDeleteTextures", 756 | "glDeleteVertexArrays", 757 | "glDetachShader", 758 | "glDisable", 759 | "glDisableVertexAttribArray", 760 | "glDrawElements", 761 | "glDrawElementsBaseVertex", 762 | "glEnable", 763 | "glEnableVertexAttribArray", 764 | "glFlush", 765 | "glGenBuffers", 766 | "glGenTextures", 767 | "glGenVertexArrays", 768 | "glGetAttribLocation", 769 | "glGetError", 770 | "glGetIntegerv", 771 | "glGetProgramInfoLog", 772 | "glGetProgramiv", 773 | "glGetShaderInfoLog", 774 | "glGetShaderiv", 775 | "glGetString", 776 | "glGetStringi", 777 | "glGetUniformLocation", 778 | "glGetVertexAttribPointerv", 779 | "glGetVertexAttribiv", 780 | "glIsEnabled", 781 | "glIsProgram", 782 | "glLinkProgram", 783 | "glPixelStorei", 784 | "glPolygonMode", 785 | "glReadPixels", 786 | "glScissor", 787 | "glShaderSource", 788 | "glTexImage2D", 789 | "glTexParameteri", 790 | "glUniform1i", 791 | "glUniformMatrix4fv", 792 | "glUseProgram", 793 | "glVertexAttribPointer", 794 | "glViewport", 795 | }; 796 | 797 | GL3W_API union GL3WProcs imgl3wProcs; 798 | 799 | static void load_procs(GL3WGetProcAddressProc proc) 800 | { 801 | size_t i; 802 | for (i = 0; i < ARRAY_SIZE(proc_names); i++) 803 | imgl3wProcs.ptr[i] = proc(proc_names[i]); 804 | } 805 | 806 | #ifdef __cplusplus 807 | } 808 | #endif 809 | #endif 810 | -------------------------------------------------------------------------------- /Libraries/include/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 | -------------------------------------------------------------------------------- /Libraries/lib/glfw3.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eduard0110/Path-tracer-using-OpenGL/25e9850e167be4b532969c91370ff0df5a08eba7/Libraries/lib/glfw3.lib -------------------------------------------------------------------------------- /Libraries/lib/glfw3.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eduard0110/Path-tracer-using-OpenGL/25e9850e167be4b532969c91370ff0df5a08eba7/Libraries/lib/glfw3.pdb -------------------------------------------------------------------------------- /OpenGL.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.6.33829.357 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OpenGL", "OpenGL.vcxproj", "{F753D6CC-AF44-4888-8E50-C8E3EC988EEE}" 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 | {F753D6CC-AF44-4888-8E50-C8E3EC988EEE}.Debug|x64.ActiveCfg = Debug|x64 17 | {F753D6CC-AF44-4888-8E50-C8E3EC988EEE}.Debug|x64.Build.0 = Debug|x64 18 | {F753D6CC-AF44-4888-8E50-C8E3EC988EEE}.Debug|x86.ActiveCfg = Debug|Win32 19 | {F753D6CC-AF44-4888-8E50-C8E3EC988EEE}.Debug|x86.Build.0 = Debug|Win32 20 | {F753D6CC-AF44-4888-8E50-C8E3EC988EEE}.Release|x64.ActiveCfg = Release|x64 21 | {F753D6CC-AF44-4888-8E50-C8E3EC988EEE}.Release|x64.Build.0 = Release|x64 22 | {F753D6CC-AF44-4888-8E50-C8E3EC988EEE}.Release|x86.ActiveCfg = Release|Win32 23 | {F753D6CC-AF44-4888-8E50-C8E3EC988EEE}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {16BCFC8A-170D-454E-84C3-E4CEC88F4457} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /OpenGL.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 16.0 71 | Win32Proj 72 | {f753d6cc-af44-4888-8e50-c8e3ec988eee} 73 | OpenGL 74 | 10.0 75 | 76 | 77 | 78 | Application 79 | true 80 | v143 81 | Unicode 82 | 83 | 84 | Application 85 | false 86 | v143 87 | true 88 | Unicode 89 | 90 | 91 | Application 92 | true 93 | v143 94 | Unicode 95 | 96 | 97 | Application 98 | false 99 | v143 100 | true 101 | Unicode 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | $(ProjectDir)Libraries\include;$(IncludePath) 123 | $(ProjectDir)Libraries\lib;$(LibraryPath) 124 | 125 | 126 | $(ProjectDir)Libraries\include;$(IncludePath) 127 | $(ProjectDir)Libraries\lib;$(LibraryPath) 128 | 129 | 130 | $(ProjectDir)Libraries\include;$(IncludePath) 131 | $(ProjectDir)Libraries\lib;$(LibraryPath) 132 | 133 | 134 | $(ProjectDir)Libraries\include;$(IncludePath) 135 | $(ProjectDir)Libraries\lib;$(LibraryPath) 136 | 137 | 138 | 139 | Level3 140 | true 141 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 142 | true 143 | MultiThreadedDebugDLL 144 | stdcpp20 145 | 146 | 147 | Console 148 | true 149 | glfw3.lib;opengl32.lib;%(AdditionalDependencies) 150 | 151 | 152 | 153 | 154 | Level3 155 | true 156 | true 157 | true 158 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 159 | true 160 | stdcpp20 161 | 162 | 163 | Console 164 | true 165 | true 166 | true 167 | glfw3.lib;opengl32.lib;%(AdditionalDependencies) 168 | 169 | 170 | 171 | 172 | Level3 173 | true 174 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 175 | true 176 | MultiThreadedDebugDLL 177 | stdcpp20 178 | 179 | 180 | Console 181 | true 182 | glfw3.lib;opengl32.lib;%(AdditionalDependencies) 183 | 184 | 185 | 186 | 187 | Level3 188 | true 189 | true 190 | true 191 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 192 | true 193 | stdcpp20 194 | 195 | 196 | Console 197 | true 198 | true 199 | true 200 | glfw3.lib;opengl32.lib;%(AdditionalDependencies) 201 | 202 | 203 | 204 | 205 | 206 | -------------------------------------------------------------------------------- /OpenGL.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 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {98104abb-2098-49be-9eb7-9f0b62942c05} 18 | 19 | 20 | {b9a08750-4696-48f2-9172-274adce2cd31} 21 | 22 | 23 | {e888925c-f6e5-4d73-9d43-a8b77a6e61d1} 24 | 25 | 26 | 27 | 28 | Resource Files\shaders 29 | 30 | 31 | Resource Files\shaders 32 | 33 | 34 | Resource Files\shaders 35 | 36 | 37 | Resource Files\shaders 38 | 39 | 40 | Resource Files\shaders 41 | 42 | 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files 52 | 53 | 54 | Source Files 55 | 56 | 57 | Source Files 58 | 59 | 60 | Source Files 61 | 62 | 63 | Source Files 64 | 65 | 66 | Source Files 67 | 68 | 69 | Source Files 70 | 71 | 72 | Source Files 73 | 74 | 75 | Source Files 76 | 77 | 78 | Source Files 79 | 80 | 81 | Source Files\imgui 82 | 83 | 84 | Source Files\imgui 85 | 86 | 87 | Source Files\imgui 88 | 89 | 90 | Source Files\imgui 91 | 92 | 93 | Source Files\imgui 94 | 95 | 96 | Source Files\imgui 97 | 98 | 99 | Source Files\imgui 100 | 101 | 102 | 103 | 104 | Header Files 105 | 106 | 107 | Header Files 108 | 109 | 110 | Header Files 111 | 112 | 113 | Header Files 114 | 115 | 116 | Header Files 117 | 118 | 119 | Header Files 120 | 121 | 122 | Header Files 123 | 124 | 125 | Header Files 126 | 127 | 128 | Header Files\imgui 129 | 130 | 131 | Header Files\imgui 132 | 133 | 134 | Header Files\imgui 135 | 136 | 137 | Header Files\imgui 138 | 139 | 140 | Header Files\imgui 141 | 142 | 143 | Header Files\imgui 144 | 145 | 146 | Header Files\imgui 147 | 148 | 149 | Header Files\imgui 150 | 151 | 152 | Header Files\imgui 153 | 154 | 155 | Header Files\imgui 156 | 157 | 158 | -------------------------------------------------------------------------------- /OpenGL.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Path-tracer-using-OpenGL 2 | 3 | A path tracer made using OpenGL with decent UI. This path tracing works with non-polygon graphics, which means that all distance calculations are based on the position and direction of the ray. 4 | 5 | 6 | ![BA0GHUpS](https://github.com/Eduard0110/Path-tracer-using-OpenGL/assets/120855690/a2ac6c3e-0641-4897-b8e5-d5121087f831) 7 | ![CAJZ0V4q](https://github.com/Eduard0110/Path-tracer-using-OpenGL/assets/120855690/fbcd8508-6409-437a-94cd-ba0d8986d5da) 8 | ![rsu6tCdx](https://github.com/Eduard0110/Path-tracer-using-OpenGL/assets/120855690/f21eb4d4-a7df-4af5-8363-63ea44306c0d) 9 | 10 | Features 11 | * 3 different types of object - Cube, Sphere and Plane 12 | * 3 types of materials - Rougth - Metalic, Lens, Light source (emissive material) 13 | * Depth Of Field effect 14 | * Accumulation of previous frames to denoise the image 15 | * You can load any images you want for the skybox (.png or .hdr) 16 | 17 | 18 | Controls 19 | * W, A, S, D, left Shift and Space - Move the camera 20 | * Mouse - Rotate the camera 21 | * E - Disable or Enable the camera movement 22 | * R - Disable or Enable the Render mode 23 | * F - Hide or Display the User Interface 24 | * T - Make a screenshot of the scene 25 | 26 | 27 | Useful links that helped me with this project 28 | * Ray-Surface intersection functions https://iquilezles.org/articles/intersectors/ 29 | * Cool article about path tracing https://blog.demofox.org/2016/09/21/path-tracing-getting-started-with-diffuse-and-emissive/ 30 | * And one more https://blog.demofox.org/2017/01/09/raytracing-reflection-refraction-fresnel-total-internal-reflection-and-beers-law/ 31 | -------------------------------------------------------------------------------- /images/screenshots/24ZsLp6o.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eduard0110/Path-tracer-using-OpenGL/25e9850e167be4b532969c91370ff0df5a08eba7/images/screenshots/24ZsLp6o.png -------------------------------------------------------------------------------- /images/screenshots/9hVcJMGF.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eduard0110/Path-tracer-using-OpenGL/25e9850e167be4b532969c91370ff0df5a08eba7/images/screenshots/9hVcJMGF.png -------------------------------------------------------------------------------- /images/screenshots/BA0GHUpS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eduard0110/Path-tracer-using-OpenGL/25e9850e167be4b532969c91370ff0df5a08eba7/images/screenshots/BA0GHUpS.png -------------------------------------------------------------------------------- /images/screenshots/CAJZ0V4q.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eduard0110/Path-tracer-using-OpenGL/25e9850e167be4b532969c91370ff0df5a08eba7/images/screenshots/CAJZ0V4q.png -------------------------------------------------------------------------------- /images/screenshots/DnjAa6IF.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eduard0110/Path-tracer-using-OpenGL/25e9850e167be4b532969c91370ff0df5a08eba7/images/screenshots/DnjAa6IF.png -------------------------------------------------------------------------------- /images/screenshots/FxeQQMXC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eduard0110/Path-tracer-using-OpenGL/25e9850e167be4b532969c91370ff0df5a08eba7/images/screenshots/FxeQQMXC.png -------------------------------------------------------------------------------- /images/screenshots/HEHRIg5i.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eduard0110/Path-tracer-using-OpenGL/25e9850e167be4b532969c91370ff0df5a08eba7/images/screenshots/HEHRIg5i.png -------------------------------------------------------------------------------- /images/screenshots/IiX6BrZ3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eduard0110/Path-tracer-using-OpenGL/25e9850e167be4b532969c91370ff0df5a08eba7/images/screenshots/IiX6BrZ3.png -------------------------------------------------------------------------------- /images/screenshots/M7DTM7AU.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eduard0110/Path-tracer-using-OpenGL/25e9850e167be4b532969c91370ff0df5a08eba7/images/screenshots/M7DTM7AU.png -------------------------------------------------------------------------------- /images/screenshots/ctYlvdlk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eduard0110/Path-tracer-using-OpenGL/25e9850e167be4b532969c91370ff0df5a08eba7/images/screenshots/ctYlvdlk.png -------------------------------------------------------------------------------- /images/screenshots/ghPbH6m7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eduard0110/Path-tracer-using-OpenGL/25e9850e167be4b532969c91370ff0df5a08eba7/images/screenshots/ghPbH6m7.png -------------------------------------------------------------------------------- /images/screenshots/rsu6tCdx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eduard0110/Path-tracer-using-OpenGL/25e9850e167be4b532969c91370ff0df5a08eba7/images/screenshots/rsu6tCdx.png -------------------------------------------------------------------------------- /images/screenshots/snbCPh1l.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eduard0110/Path-tracer-using-OpenGL/25e9850e167be4b532969c91370ff0df5a08eba7/images/screenshots/snbCPh1l.png -------------------------------------------------------------------------------- /images/skybox/belfast_sunset_puresky_2k.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eduard0110/Path-tracer-using-OpenGL/25e9850e167be4b532969c91370ff0df5a08eba7/images/skybox/belfast_sunset_puresky_2k.hdr -------------------------------------------------------------------------------- /images/skybox/christmas_photo_studio_01_2k.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eduard0110/Path-tracer-using-OpenGL/25e9850e167be4b532969c91370ff0df5a08eba7/images/skybox/christmas_photo_studio_01_2k.hdr -------------------------------------------------------------------------------- /images/skybox/rainforest_trail_2k.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eduard0110/Path-tracer-using-OpenGL/25e9850e167be4b532969c91370ff0df5a08eba7/images/skybox/rainforest_trail_2k.hdr -------------------------------------------------------------------------------- /images/skybox/small_cave_2k.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eduard0110/Path-tracer-using-OpenGL/25e9850e167be4b532969c91370ff0df5a08eba7/images/skybox/small_cave_2k.hdr -------------------------------------------------------------------------------- /images/skybox/syferfontein_0d_clear_puresky_2k.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eduard0110/Path-tracer-using-OpenGL/25e9850e167be4b532969c91370ff0df5a08eba7/images/skybox/syferfontein_0d_clear_puresky_2k.hdr -------------------------------------------------------------------------------- /images/skybox/the_sky_is_on_fire_2k.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eduard0110/Path-tracer-using-OpenGL/25e9850e167be4b532969c91370ff0df5a08eba7/images/skybox/the_sky_is_on_fire_2k.hdr -------------------------------------------------------------------------------- /images/skybox/vestibule_2k.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eduard0110/Path-tracer-using-OpenGL/25e9850e167be4b532969c91370ff0df5a08eba7/images/skybox/vestibule_2k.hdr -------------------------------------------------------------------------------- /scenes/many spheres 2/data.txt: -------------------------------------------------------------------------------- 1 | 0 -1 0 0.435294 0.435294 0.435294 3 1 1 1 1 0 0 -1 0 1 1 0 0 0 1 1 1 -3.294 -0.3 -1.176 1 1 1 1 0.7 1 1 1 0 0 -1 1 0.711 1 0 0 0 1 1 1 0 0 0 1 1 1 1 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 -1.412 -0.499 -2.824 1 1 1 1 0.5 1 1 1 0 0.294 1.176 0 0 1 0 0 0 1 1 1 -3.765 -0.699 -3.765 1 1 1 1 0.3 1 1 1 0 0 -1 0.824 0.541 1 0 0 0 1 1 1 -1.176 -0.7 -4.235 1 1 1 1 0.3 1 1 1 0 0 -1 1 0.271 1 0 0 0 1 1 1 -4.706 -0.799 -2.353 1 1 1 1 0.2 1 1 1 0 0.447 1.106 0 0 1 0 0 0 1 1 1 -3.294 -0.799 -4.824 1 1 1 1 0.2 1 1 1 0 0.4 1.176 0 0 1 0 0 0 1 1 1 -1.647 -0.85 -4 1 1 1 1 0.15 1 1 1 0 0 -1 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 -------------------------------------------------------------------------------- /scenes/many spheres 2/objects.txt: -------------------------------------------------------------------------------- 1 | plane 2 | s1 3 | s2 4 | s3 5 | s4 6 | s5 7 | s6 8 | s7 9 | s8 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /scenes/many spheres/data.txt: -------------------------------------------------------------------------------- 1 | 0 -1 0 0.606557 0.606557 0.606557 3 1 1 1 1 0 0 -1 0.432 0.065 1 0 0 0 0.45082 0.45082 0.45082 0 0 0 0.364485 0.508197 0.370375 1 1 1 1 1 0 0 -1 0.511 0.119 1 0 0 0 1 0.852459 0.852459 -2.215 -0.3 0.475 0.881148 0.881148 0.881148 1 0.7 1 1 1 0 0.407 1.356 0 0 1 0 0 0 1 1 1 -1.297 -0.6 -1.962 1 1 1 1 0.4 1 1 1 0 0 -1 0.479 0.062 1 0 0 0 1 1 1 0.412 -0.7 -2.247 1 1 1 1 0.3 1 1 1 0 0.366 1.28 0 0 1 0 0 0 1 1 1 -3.576 -0.7 -1.867 1 1 1 1 0.3 1 1 1 0 0 -1 0 1 1 0 0 0 1 1 1 -1.203 -0.7 -3.703 1 1 1 1 0.3 1 1 1 0 0 -1 0 1 1 0 0 0 1 1 1 -4.525 -0.65 1.456 1 1 1 1 0.35 1 1 1 0 0 -1 0.739 0.157 1 0 0 0 1 1 1 1.994 -0.8 0 1 1 1 1 0.2 1 1 1 0 0.71 1.403 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 -1 0 0 1 0 0 0 1 1 1 -------------------------------------------------------------------------------- /scenes/many spheres/objects.txt: -------------------------------------------------------------------------------- 1 | plane 2 | s1 3 | s2 4 | s3 5 | s4 6 | s5 7 | s6 8 | s7 9 | s8 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /shaders/bloom.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | uniform sampler2D tex; 4 | uniform bool horizontal; 5 | uniform int uMaxLod; 6 | 7 | uniform float weight[5] = float[] (0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162); 8 | 9 | void main() 10 | { 11 | int level = uMaxLod; 12 | vec2 uv = gl_FragCoord.xy / textureSize(tex, 0); 13 | vec3 result = vec3(0.0); 14 | 15 | while (level >= 0) { 16 | vec2 tex_offset = 1.0 / textureSize(tex, level); // gets size of single texel 17 | result += textureLod(tex, uv, level).rgb * weight[0]; 18 | 19 | 20 | if (horizontal) 21 | { 22 | for (int i = 1; i < 5; ++i) 23 | { 24 | result += textureLod(tex, uv + vec2(tex_offset.x * i, 0.0), level).rgb * weight[i]; 25 | result += textureLod(tex, uv - vec2(tex_offset.x * i, 0.0), level).rgb * weight[i]; 26 | } 27 | } 28 | else 29 | { 30 | for (int i = 1; i < 5; ++i) 31 | { 32 | result += textureLod(tex, uv + vec2(0.0, tex_offset.y * i), level).rgb * weight[i]; 33 | result += textureLod(tex, uv - vec2(0.0, tex_offset.y * i), level).rgb * weight[i]; 34 | } 35 | } 36 | 37 | level--; 38 | } 39 | 40 | vec3 fColor = vec3(result) / (uMaxLod + 1); 41 | gl_FragColor = vec4(fColor, 1.0); 42 | } -------------------------------------------------------------------------------- /shaders/default.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout (location = 0) out vec4 FragColor; 4 | layout (location = 1) out vec4 BloomColor; 5 | 6 | uniform float framesStill; 7 | uniform float NUMBER_OF_SAMPLES; 8 | uniform float MAX_REFLECTIONS; 9 | uniform float apertureSize; 10 | uniform float focusDistance; 11 | uniform float zoom; 12 | uniform float colorMultiplierWhenReachedMaxRef; 13 | uniform bool showNormals; 14 | uniform vec2 rSeed1; 15 | uniform vec2 rSeed2; 16 | uniform vec2 resolution; 17 | uniform vec3 CameraRotation; 18 | uniform vec3 CameraPosition; 19 | uniform vec3 skyboxRotation; 20 | uniform sampler2D skybox; 21 | uniform sampler2D tex; 22 | uniform bool planeGrid; 23 | uniform vec3 gridCol2; 24 | uniform float tileSize; 25 | uniform bool useSkyboxColor; 26 | uniform vec3 skyboxColor; 27 | uniform float treshHoldIntensity; 28 | uniform float highestColValue; 29 | 30 | const int MAX_OBJECTS = 30; 31 | const int ELEMENTS_IN_1OBJ = 23; 32 | uniform float objects[MAX_OBJECTS*ELEMENTS_IN_1OBJ]; 33 | 34 | #define MAX_DIST 1000.0 35 | #define PI 3.141592 36 | 37 | uvec4 R_STATE; 38 | float degree = 2.0 * PI / 360.0; 39 | vec3 bloomWeights = vec3(0.2126, 0.7152, 0.0722); 40 | 41 | struct Sdf { 42 | float d; 43 | float d2; 44 | vec3 n; 45 | vec3 n2; 46 | }; 47 | 48 | struct Ray { 49 | Sdf sdf; 50 | vec3 col; 51 | vec3 specularCol; 52 | vec3 pos; 53 | float percentSpecular; 54 | float roughness; 55 | float refractionIndex; 56 | float reflectivity; 57 | float isLight; 58 | float type; 59 | }; 60 | 61 | uint TausStep(uint z, int S1, int S2, int S3, uint M) { 62 | uint b = (((z << S1) ^ z) >> S2); 63 | return (((z & M) << S3) ^ b); 64 | } 65 | 66 | uint LCGStep(uint z, uint A, uint C) { 67 | return (A * z + C); 68 | } 69 | 70 | vec2 hash22(vec2 p) { 71 | p += rSeed1.x; 72 | vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973)); 73 | p3 += dot(p3, p3.yzx+33.33); 74 | return fract((p3.xx+p3.yz)*p3.zy); 75 | } 76 | 77 | float random() { 78 | R_STATE.x = TausStep(R_STATE.x, 4, 12, 9, uint(4294967294)); 79 | R_STATE.y = TausStep(R_STATE.y, 2, 3, 4, uint(4294967288)); 80 | R_STATE.z = TausStep(R_STATE.z, 3, 1, 10, uint(4294967280)); 81 | R_STATE.w = LCGStep(R_STATE.w, uint(1664525), uint(1013904223)); 82 | return 2.3283064365387e-10 * float((R_STATE.x ^ R_STATE.y ^ R_STATE.z ^ R_STATE.w)); 83 | } 84 | 85 | vec3 randomOnSphere() { 86 | vec3 rand = vec3(random(), random(), random()); 87 | float theta = rand.x * 2.0 * 3.14159265; 88 | float v = rand.y; 89 | float phi = acos(2.0 * v - 1.0); 90 | float r = pow(rand.z, 1.0 / 3.0); 91 | float x = r * sin(phi) * cos(theta); 92 | float y = r * sin(phi) * sin(theta); 93 | float z = r * cos(phi); 94 | return vec3(x, y, z); 95 | } 96 | 97 | mat3 Pitch(float a) { 98 | float Sin = sin(a); 99 | float Cos = cos(a); 100 | 101 | return mat3(1, 0, 0, 102 | 0, Cos, -Sin, 103 | 0, Sin, Cos); 104 | } 105 | 106 | mat3 Yaw(float a) { 107 | float Sin = sin(a); 108 | float Cos = cos(a); 109 | 110 | return mat3(Cos, 0, Sin, 111 | 0, 1, 0, 112 | -Sin, 0, Cos); 113 | } 114 | 115 | mat3 Roll(float a) { 116 | float Sin = sin(a); 117 | float Cos = cos(a); 118 | 119 | return mat3(Cos, -Sin, 0, 120 | Sin, Cos, 0, 121 | 0, 0, 1); 122 | } 123 | 124 | vec3 applySkyBox(vec3 rd, sampler2D skybox) { 125 | if (useSkyboxColor) return skyboxColor; 126 | rd *= Pitch(skyboxRotation[0] * degree); 127 | rd *= Yaw(skyboxRotation[1] * degree); 128 | rd *= Roll(skyboxRotation[2] * degree); 129 | // Convert the ray direction to 2D texture coordinates 130 | vec2 st; 131 | st.x = 0.5 + atan(rd.z, rd.x) / (2.0 * PI); 132 | st.y = 0.5 - asin(rd.y) / PI; 133 | // Sample the cube map using the texture coordinates 134 | vec3 col = texture(skybox, st).rgb; 135 | 136 | col = clamp(col, 0.0, highestColValue); 137 | 138 | return col; 139 | } 140 | 141 | Ray Min(Ray minIt, Ray obj) { 142 | return (obj.sdf.d > 0.0 && obj.sdf.d < minIt.sdf.d) ? obj : minIt; 143 | } 144 | 145 | Sdf sdSphere( in vec3 ro, in vec3 rd, in vec3 ce, float ra ) { 146 | vec3 oc = ro - ce; 147 | float b = dot( oc, rd ); 148 | vec3 qc = oc - b*rd; 149 | float h = ra*ra - dot( qc, qc ); 150 | // no intersection 151 | if( h<0.0 ) return Sdf(MAX_DIST, MAX_DIST, vec3(-1.0), vec3(0)); 152 | h = sqrt( h ); 153 | float d = -b - h; 154 | float d2 = -b + h; 155 | // normal of the nearest hit 156 | vec3 n = normalize((ro + rd * (d - 0.001)) - ce); 157 | // normal of the farest hit 158 | vec3 n2 = normalize((ro + rd * (d2 - 0.001)) - ce); 159 | 160 | return Sdf(d, d2, n, n2); 161 | } 162 | 163 | Sdf sdCube( in vec3 ro, in vec3 rd, in vec3 ce, vec3 boxSize, float IOR) { 164 | ro -= ce; 165 | vec3 m = 1.0/rd; 166 | vec3 n = m*ro; 167 | vec3 k = abs(m)*boxSize; 168 | vec3 t1 = -n - k; 169 | vec3 t2 = -n + k; 170 | float tN = max( max( t1.x, t1.y ), t1.z ); 171 | float tF = min( min( t2.x, t2.y ), t2.z ); 172 | // no intersection 173 | if( tN>tF || tF<0.0) return Sdf(MAX_DIST, MAX_DIST, vec3(0), vec3(0)); 174 | // normal of the nearest hit 175 | vec3 N = (tN>0.0) ? step(vec3(tN),t1) : step(t2,vec3(tF)); 176 | N *= -sign(rd); 177 | // normal of the farest hit 178 | // there is no need to calculate object's N2 if it is not a lense as it will not be used 179 | vec3 N2 = vec3(0); 180 | if (IOR != -1.0){ 181 | N2 = (tF > 0.0) ? step(t1, vec3(tN)) : step(vec3(tF), t2); 182 | N2 *= sign(rd); 183 | } 184 | 185 | return Sdf(tN, tF, N, N2); 186 | } 187 | 188 | Sdf sdPlane(in vec3 ro, in vec3 rd, in vec4 p) { 189 | float d = -(dot(ro, p.xyz) + p.w) / dot(rd, p.xyz); 190 | return Sdf(d, d, p.xyz, vec3(0)); 191 | } 192 | 193 | float fresnelReflectAmount (vec3 rd, vec3 normal, float n1, float n2, float object_reflectivity) { 194 | // Schlick aproximation 195 | float r0 = (n1-n2) / (n1+n2); 196 | r0 *= r0; 197 | float cosX = -dot(normal, rd); 198 | if (n1 > n2) 199 | { 200 | float n = n1/n2; 201 | float sinT2 = n*n*(1.0-cosX*cosX); 202 | // Total internal reflection 203 | if (sinT2 > 1.0) 204 | return 1.0; 205 | cosX = sqrt(1.0-sinT2); 206 | } 207 | float x = 1.0-cosX; 208 | float ret = r0+(1.0-r0)*x*x*x*x*x; 209 | 210 | ret = (object_reflectivity + (1.0-object_reflectivity) * ret); 211 | return ret; 212 | } 213 | 214 | Ray GetClosestObj(vec3 ro, vec3 rd) { 215 | Ray minIt; 216 | minIt.sdf.d = MAX_DIST; 217 | // x, y, z, r, g, b, type, radius, cubeSize, isLigjt, reflectivity, refract, specularPercent, roughtness, powerOfLight, rotation, specularColour 218 | // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 219 | for (int i=0; i 1.0) BloomColor = FragColor; 386 | else BloomColor = vec4(0.0); 387 | } -------------------------------------------------------------------------------- /shaders/default.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout (location = 0) in vec3 aPos; 4 | 5 | out vec2 coord; 6 | 7 | void main() 8 | { 9 | gl_Position = vec4(aPos, 1.0); 10 | } -------------------------------------------------------------------------------- /shaders/display.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | uniform sampler2D tex; 4 | uniform vec2 resolution; 5 | 6 | void main() { 7 | gl_FragColor = texture(tex, gl_FragCoord.xy / resolution); 8 | } -------------------------------------------------------------------------------- /shaders/postProcess.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout (location = 0) out vec4 FragColor; 4 | 5 | uniform sampler2D bloomTex; 6 | uniform sampler2D tex; 7 | uniform vec2 resolution; 8 | 9 | uniform float brightness; 10 | uniform float expousure; 11 | uniform float contrast; 12 | uniform float bloomIntensity; 13 | 14 | void main() { 15 | vec2 uv = gl_FragCoord.xy / resolution; 16 | vec3 col = texture(tex, uv).rgb + texture(bloomTex, uv).rgb * bloomIntensity; 17 | 18 | // post processing 19 | col.rgb += brightness; 20 | col.rgb = (col.rgb - 0.5) * (contrast + 1.0) + 0.5; 21 | col *= pow(2.0, expousure); 22 | 23 | FragColor = vec4(col, 1.0); 24 | } -------------------------------------------------------------------------------- /source/Main.cpp: -------------------------------------------------------------------------------- 1 | #include "imgui/imgui.h" 2 | #include "imgui/imgui_impl_glfw.h" 3 | #include "imgui/imgui_impl_opengl3.h" 4 | #include "mygui.h" 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "shader.h" 16 | #include "camera.h" 17 | #include "vao.h" 18 | #include "skybox.h" 19 | #include "scene.h" 20 | #include "texture.h" 21 | #include "framebuffer.h" 22 | 23 | void updateRandomSeeds(double[3], double[3]); 24 | void saveTextureAsImage(GLFWwindow*, GLuint, int, int, const char*); 25 | void printOpenGLInfo(); 26 | bool checkKey(GLuint, GLuint&, GLFWwindow*); 27 | std::string randomName(int); 28 | 29 | 30 | int main() 31 | { 32 | glfwInit(); 33 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 34 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 35 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 36 | 37 | // get the resolution of the monitor 38 | const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); 39 | int WIDTH = mode->width; 40 | int HEIGHT = mode->height; 41 | 42 | // put glfwGetPrimaryMonitor() instead of the first NULL argument to create a full screen window 43 | GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "Ray tracing", glfwGetPrimaryMonitor(), NULL); 44 | // Error check if the window fails to create 45 | if (window == NULL) { 46 | std::cout << "Failed to create GLFW window" << std::endl; 47 | glfwTerminate(); 48 | return -1; 49 | } 50 | glfwMakeContextCurrent(window); 51 | gladLoadGL(); 52 | glViewport(0, 0, WIDTH, HEIGHT); 53 | printOpenGLInfo(); 54 | 55 | // create shaders 56 | Shader defaultShader("shaders/default.frag", "shaders/default.vert"); 57 | Shader bloomShader("shaders/bloom.frag", "shaders/default.vert"); 58 | Shader postProccesShader("shaders/postProcess.frag", "shaders/default.vert"); 59 | Shader displayShader("shaders/display.frag", "shaders/default.vert"); 60 | // create vao 61 | RectVAO rectVao; 62 | // camera 63 | float cameraPos[3] = { 0.0f, 1.0f, -3.0f }; 64 | float cameraRotation[3] = { 0.0f, 0.0f, 0.0f }; 65 | float cameraSpeed = 0.1f; 66 | float mouseSensitivity = 1.0f; 67 | Camera camera(window, cameraPos, cameraRotation, cameraSpeed, mouseSensitivity); 68 | 69 | // random seeds 70 | srand(static_cast(time(0))); // init random with time 71 | double rSeed1[2], rSeed2[2]; 72 | 73 | // variables to track if a button was pressed in previous frame 74 | GLuint keyRlastFrame = GLFW_RELEASE; 75 | GLuint keyElastFrame = GLFW_RELEASE; 76 | GLuint keyFlastFrame = GLFW_RELEASE; 77 | GLuint keyTlastFrame = GLFW_RELEASE; 78 | GLuint keyEscapelastFrame = GLFW_RELEASE; 79 | 80 | // skybox texture 81 | Skybox skybox = Skybox(WIDTH, HEIGHT); 82 | 83 | Texture texture1(WIDTH, HEIGHT); 84 | Texture texture2(WIDTH, HEIGHT); 85 | Texture bloomTexture(WIDTH, HEIGHT); 86 | Texture postProcessTexture(WIDTH, HEIGHT); 87 | 88 | FrameBuffer framebuffer1(2, texture1.tex, bloomTexture.tex); 89 | FrameBuffer framebuffer2(2, texture2.tex, bloomTexture.tex); 90 | FrameBuffer postProcessFBuffer(1, postProcessTexture.tex, 0); 91 | 92 | Scene scene; 93 | MyGui mygui(&scene, &skybox, &camera, WIDTH, HEIGHT, window); 94 | 95 | // frames without camera movement 96 | int framesStill = 0; 97 | 98 | // Create Ping Pong Framebuffers for repetitive blurring 99 | GLuint pingpongFBO[2]; 100 | GLuint pingpongTexture[2]; 101 | glGenFramebuffers(2, pingpongFBO); 102 | glGenTextures(2, pingpongTexture); 103 | for (int i = 0; i < 2; i++) 104 | { 105 | glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[i]); 106 | glBindTexture(GL_TEXTURE_2D, pingpongTexture[i]); 107 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, WIDTH, HEIGHT, 0, GL_RGB, GL_FLOAT, NULL); 108 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 109 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 110 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 111 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 112 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 7); 113 | glGenerateMipmap(GL_TEXTURE_2D); 114 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pingpongTexture[i], 0); 115 | } 116 | 117 | glfwSwapInterval(mygui.vSync); 118 | while (!glfwWindowShouldClose(window)) 119 | { 120 | framesStill++; 121 | if (mygui.isMouseControl) { camera.CheckForUpdate(framesStill); camera.Update(); } 122 | 123 | updateRandomSeeds(rSeed1, rSeed2); 124 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 125 | glClear(GL_COLOR_BUFFER_BIT); 126 | 127 | ImGui_ImplOpenGL3_NewFrame(); 128 | ImGui_ImplGlfw_NewFrame(); 129 | ImGui::NewFrame(); 130 | 131 | Texture currentTexture = (framesStill % 2 == 1) ? texture1 : texture2; 132 | Texture lastTexture = (framesStill % 2 == 0) ? texture1 : texture2; 133 | FrameBuffer currentFramebuffer = (framesStill % 2 == 1) ? framebuffer2 : framebuffer1; 134 | 135 | glBindFramebuffer(GL_FRAMEBUFFER, currentFramebuffer.buf); 136 | defaultShader.Active(); 137 | // pass in all the uniforms 138 | defaultShader.U2f("resolution", WIDTH, HEIGHT); 139 | defaultShader.U1f("framesStill", framesStill); 140 | defaultShader.U2f("rSeed1", rSeed1[0], rSeed1[1]); 141 | defaultShader.U2f("rSeed2", rSeed2[0], rSeed2[1]); 142 | defaultShader.U3f("CameraPosition", camera.Pos[0], camera.Pos[1], camera.Pos[2]); 143 | defaultShader.U3f("CameraRotation", camera.Rot[0], camera.Rot[1], camera.Rot[2]); 144 | defaultShader.U1f("treshHoldIntensity", mygui.tresholdIntensity); 145 | if (mygui.renderMode) { 146 | defaultShader.U1f("MAX_REFLECTIONS", mygui.MAX_REFLECTIONS_RENDER_MODE); 147 | defaultShader.U1f("NUMBER_OF_SAMPLES", mygui.NUMBER_OF_SAMPLES_RENDER_MODE); 148 | } 149 | else { 150 | defaultShader.U1f("MAX_REFLECTIONS", mygui.MAX_REFLECTIONS_PREVIEW_MODE); 151 | defaultShader.U1f("NUMBER_OF_SAMPLES", mygui.NUMBER_OF_SAMPLES_PREVIEW_MODE); 152 | } 153 | defaultShader.U1f("focusDistance", mygui.focusDistance); 154 | defaultShader.U1f("apertureSize", mygui.apertureSize); 155 | defaultShader.U1f("zoom", mygui.zoom); 156 | defaultShader.U1f("colorMultiplierWhenReachedMaxRef", mygui.colourMultiplier); 157 | defaultShader.U1i("showNormals", mygui.showNormals); 158 | if (!mygui.renderMode) defaultShader.U1fv("objects", MAX_OBJECTS * 20, scene.sceneData1D); 159 | defaultShader.U3f("skyboxRotation", mygui.skybox->rotation[0], mygui.skybox->rotation[1], mygui.skybox->rotation[2]); 160 | defaultShader.U1f("highestColValue", mygui.skybox->highestColValue); 161 | defaultShader.U1i("planeGrid", mygui.planeGrid); 162 | defaultShader.U3f("gridCol2", mygui.gridCol2[0], mygui.gridCol2[1], mygui.gridCol2[2]); 163 | defaultShader.U1f("tileSize", mygui.tileSize); 164 | defaultShader.U1i("useSkyboxColor", mygui.useSkyboxColour); 165 | defaultShader.U3f("skyboxColor", skybox.col[0], skybox.col[1], skybox.col[2]); 166 | defaultShader.U1i("skybox", 0); 167 | defaultShader.U1i("tex", 1); 168 | 169 | glBindVertexArray(rectVao.VAO); 170 | skybox.ActiveAndBind(GL_TEXTURE0); 171 | currentTexture.ActiveAndBind(GL_TEXTURE1); 172 | glDrawArrays(GL_TRIANGLES, 0, 6); // render 173 | 174 | 175 | // bloom 176 | // Bounce the image data around to blur multiple times 177 | bool horizontal = true, first_iteration = true; 178 | if (mygui.doBloom) { 179 | bloomShader.Active(); 180 | for (int i = 0; i < mygui.numberOfBounces; i++) 181 | { 182 | glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[horizontal]); 183 | bloomShader.U1i("horizontal", horizontal); 184 | bloomShader.U1i("tex", 2); 185 | bloomShader.U1i("uMaxLod", mygui.bloomMaxLod); 186 | 187 | glActiveTexture(GL_TEXTURE2); 188 | if (first_iteration) 189 | { 190 | glBindTexture(GL_TEXTURE_2D, bloomTexture.tex); 191 | first_iteration = false; 192 | } 193 | else 194 | { 195 | glBindTexture(GL_TEXTURE_2D, pingpongTexture[!horizontal]); 196 | } 197 | glDrawArrays(GL_TRIANGLES, 0, 6); 198 | glGenerateMipmap(GL_TEXTURE_2D); 199 | horizontal = !horizontal; 200 | } 201 | } 202 | 203 | // post procesing 204 | postProcessFBuffer.Bind(); 205 | postProccesShader.Active(); 206 | postProccesShader.U1i("tex", 3); 207 | postProccesShader.U1i("bloomTex", 4); 208 | postProccesShader.U1f("bloomIntensity", mygui.bloomIntensity); 209 | postProccesShader.U2f("resolution", WIDTH, HEIGHT); 210 | postProccesShader.U1f("brightness", mygui.brightness); 211 | postProccesShader.U1f("expousure", mygui.expousure); 212 | postProccesShader.U1f("contrast", mygui.contrast); 213 | lastTexture.ActiveAndBind(GL_TEXTURE3); 214 | glActiveTexture(GL_TEXTURE4); 215 | glBindTexture(GL_TEXTURE_2D, pingpongTexture[!horizontal]); 216 | glDrawArrays(GL_TRIANGLES, 0, 6); 217 | 218 | // display texture 219 | glBindFramebuffer(GL_FRAMEBUFFER, 0); 220 | displayShader.Active(); 221 | displayShader.U1i("tex", 5); 222 | displayShader.U2f("resolution", WIDTH, HEIGHT); 223 | postProcessTexture.ActiveAndBind(GL_TEXTURE5); 224 | glDrawArrays(GL_TRIANGLES, 0, 6); 225 | // update 226 | mygui.Update(); 227 | glfwSwapBuffers(window); 228 | glfwPollEvents(); 229 | 230 | if (mygui.onConstantUpdate && !mygui.renderMode) framesStill = 0; 231 | if (!mygui.addObjectName && !mygui.isSaveFile) 232 | { 233 | // change render mode 234 | if (checkKey(GLFW_KEY_R, keyRlastFrame, window)) { framesStill = 0; mygui.renderMode = !mygui.renderMode; } 235 | // check if the Escape button is pressed 236 | if (checkKey(GLFW_KEY_ESCAPE, keyEscapelastFrame, window)) break; 237 | // change mouse control 238 | if (checkKey(GLFW_KEY_E, keyElastFrame, window)) mygui.isMouseControl = !mygui.isMouseControl; 239 | // hide gui 240 | if (checkKey(GLFW_KEY_F, keyFlastFrame, window)) mygui.hideGUI = !mygui.hideGUI; 241 | // make screenshot 242 | if (checkKey(GLFW_KEY_T, keyTlastFrame, window)) 243 | { 244 | mygui.showMessage = true; 245 | std::string path = "images/screenshots/" + randomName(8) + ".png"; 246 | saveTextureAsImage(window, lastTexture.tex, WIDTH, HEIGHT, path.c_str()); 247 | } 248 | } 249 | } 250 | 251 | // Delete all the objects we've created 252 | ImGui_ImplOpenGL3_Shutdown(); 253 | ImGui_ImplGlfw_Shutdown(); 254 | ImGui::DestroyContext(); 255 | rectVao.Delete(); // delete VAO 256 | defaultShader.Delete(); // delete Shaders 257 | bloomShader.Delete(); 258 | postProccesShader.Delete(); 259 | skybox.Delete(); // delete Textures 260 | texture1.Delete(); 261 | texture2.Delete(); 262 | bloomTexture.Delete(); 263 | postProcessTexture.Delete(); 264 | framebuffer1.Delete(); // delete framebuffers 265 | framebuffer2.Delete(); 266 | postProcessFBuffer.Delete(); 267 | glfwDestroyWindow(window); // and delete window 268 | glfwTerminate(); 269 | 270 | return 0; 271 | } 272 | 273 | void updateRandomSeeds(double rSeed1[3], double rSeed2[3]) { 274 | rSeed1[0] = rand() % 10000 / 100.0; 275 | rSeed1[1] = rand() % 10000 / 100.0; 276 | 277 | rSeed2[0] = rand() % 10000 / 100.0; 278 | rSeed2[1] = rand() % 10000 / 100.0; 279 | } 280 | 281 | void saveTextureAsImage(GLFWwindow* window, GLuint textureID, int width, int height, const char* filename) { 282 | glActiveTexture(GL_TEXTURE0); 283 | glBindTexture(GL_TEXTURE_2D, textureID); 284 | 285 | unsigned char* pixels = new unsigned char[width * height * 3]; 286 | glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels); 287 | 288 | // Flip the pixel data vertically 289 | unsigned char* flippedPixels = new unsigned char[width * height * 3]; 290 | for (int y = 0; y < height; ++y) { 291 | memcpy(flippedPixels + y * width * 3, pixels + (height - y - 1) * width * 3, width * 3); 292 | } 293 | 294 | stbi_write_png(filename, width, height, 3, flippedPixels, width * 3); 295 | 296 | delete[] pixels; 297 | delete[] flippedPixels; 298 | 299 | glBindTexture(GL_TEXTURE_2D, 0); 300 | } 301 | 302 | std::string randomName(int length) { 303 | const std::string charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"; 304 | const int charsetLength = charset.length(); 305 | 306 | std::string name; 307 | name.reserve(length); 308 | 309 | for (int i = 0; i < length; ++i) { 310 | name += charset[rand() % charsetLength]; 311 | } 312 | 313 | return name; 314 | } 315 | 316 | void printOpenGLInfo() { 317 | const GLubyte* renderer = glGetString(GL_RENDERER); 318 | const GLubyte* version = glGetString(GL_VERSION); 319 | const GLubyte* vendor = glGetString(GL_VENDOR); 320 | const GLubyte* shadingLanguageVersion = glGetString(GL_SHADING_LANGUAGE_VERSION); 321 | std::cout << "Renderer: " << renderer << std::endl; 322 | std::cout << "OpenGL version supported: " << version << std::endl; 323 | std::cout << "Vendor: " << vendor << std::endl; 324 | std::cout << "GLSL version: " << shadingLanguageVersion << std::endl; 325 | } 326 | 327 | bool checkKey(GLuint keyToBePressed, GLuint& keyLastFrame, GLFWwindow* window) { 328 | bool pressed = false; 329 | if (glfwGetKey(window, keyToBePressed) == GLFW_PRESS && !keyLastFrame == GLFW_PRESS) { 330 | pressed = true; 331 | } 332 | keyLastFrame = glfwGetKey(window, keyToBePressed); 333 | return pressed; 334 | } 335 | -------------------------------------------------------------------------------- /source/camera.cpp: -------------------------------------------------------------------------------- 1 | #include "camera.h" 2 | 3 | 4 | Camera::Camera(GLFWwindow* window, float position[3], float rotation[3], float speed, float sensitivity) { 5 | Pos[0] = position[0]; 6 | Pos[1] = position[1]; 7 | Pos[2] = position[2]; 8 | Rot[0] = rotation[0]; 9 | Rot[1] = rotation[1]; 10 | Rot[2] = rotation[2]; 11 | Speed = speed; 12 | Window = window; 13 | Sensitivity = sensitivity; 14 | glfwGetWindowSize(Window, &WIDTH, &HEIGHT); 15 | } 16 | 17 | void Camera::rotateCamera() { 18 | // mouse position 19 | double xPos, yPos; 20 | glfwGetCursorPos(Window, &xPos, &yPos); 21 | 22 | // normalized mouse position 23 | float normalizedX = (xPos - WIDTH / 2.0f) / WIDTH; 24 | float normalizedY = (yPos - HEIGHT / 2.0f) / HEIGHT; 25 | 26 | float x = normalizedX * 360.0f * Sensitivity; 27 | float y = normalizedY * 180.0f * Sensitivity; 28 | 29 | if (x != Rot[0] || y != Rot[1]) isUpdate = true; 30 | Rot[0] = x; 31 | Rot[1] = y; 32 | } 33 | 34 | void Camera::moveCamera() { 35 | float cos_a = cos(Rot[0] * (3.141592f / 180.0f)); 36 | float sin_a = sin(Rot[0] * (3.141592f / 180.0f)); 37 | 38 | if (glfwGetKey(Window, GLFW_KEY_W) == GLFW_PRESS) { // forward 39 | Pos[2] += Speed * cos_a; 40 | Pos[0] += Speed * sin_a; 41 | isUpdate = true; 42 | } 43 | if (glfwGetKey(Window, GLFW_KEY_S) == GLFW_PRESS) { // backward 44 | Pos[2] -= Speed * cos_a; 45 | Pos[0] -= Speed * sin_a; 46 | isUpdate = true; 47 | } 48 | if (glfwGetKey(Window, GLFW_KEY_D) == GLFW_PRESS) { // right 49 | Pos[2] -= Speed * sin_a; 50 | Pos[0] += Speed * cos_a; 51 | isUpdate = true; 52 | } 53 | if (glfwGetKey(Window, GLFW_KEY_A) == GLFW_PRESS) { // left 54 | Pos[2] += Speed * sin_a; 55 | Pos[0] -= Speed * cos_a; 56 | isUpdate = true; 57 | } 58 | if (glfwGetKey(Window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) { // down 59 | Pos[1] -= Speed; 60 | isUpdate = true; 61 | } 62 | if (glfwGetKey(Window, GLFW_KEY_SPACE) == GLFW_PRESS) { // up 63 | Pos[1] += Speed; 64 | isUpdate = true; 65 | } 66 | } 67 | 68 | void Camera::CheckForUpdate(int &updateVariable) { 69 | if (isUpdate) { 70 | updateVariable = 1; 71 | isUpdate = false; 72 | } 73 | } 74 | 75 | void Camera::Update() { 76 | rotateCamera(); 77 | moveCamera(); 78 | } -------------------------------------------------------------------------------- /source/camera.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | class Camera { 9 | public: 10 | float Pos[3]; 11 | float Rot[3]; 12 | float Speed; 13 | float Sensitivity; 14 | GLFWwindow* Window; 15 | bool isUpdate = false; 16 | int WIDTH, HEIGHT; 17 | 18 | Camera(GLFWwindow* window, float position[3], float rotation[3], float speed, float sensitivity); 19 | 20 | void rotateCamera(); 21 | 22 | void moveCamera(); 23 | 24 | void CheckForUpdate(int&); 25 | 26 | void Update(); 27 | }; 28 | -------------------------------------------------------------------------------- /source/framebuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "framebuffer.h" 2 | 3 | FrameBuffer::FrameBuffer(int attachments, GLuint tex1, GLuint tex2) { 4 | glGenFramebuffers(1, &buf); 5 | glBindFramebuffer(GL_FRAMEBUFFER, buf); 6 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex1, 0); 7 | 8 | if (attachments == 2) { 9 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex2, 0); 10 | GLuint colorAttachments[2] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 }; 11 | glDrawBuffers(2, colorAttachments); 12 | } 13 | } 14 | 15 | void FrameBuffer::Bind() { 16 | glBindFramebuffer(GL_FRAMEBUFFER, buf); 17 | } 18 | 19 | void FrameBuffer::Delete() { 20 | glDeleteFramebuffers(1, &buf); 21 | } -------------------------------------------------------------------------------- /source/framebuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class FrameBuffer { 6 | public: 7 | GLuint buf; 8 | FrameBuffer(int attachments, GLuint tex1, GLuint tex2); 9 | 10 | void Bind(); 11 | void Delete(); 12 | }; -------------------------------------------------------------------------------- /source/mygui.cpp: -------------------------------------------------------------------------------- 1 | #include "mygui.h" 2 | 3 | MyGui::MyGui(Scene* sceneP, Skybox* skyboxP, Camera* cameraP, int width, int height, GLFWwindow* window) { 4 | WIDTH = width; 5 | HEIGHT = height; 6 | windowP = window; 7 | scene = sceneP; 8 | skybox = skyboxP; 9 | camera = cameraP; 10 | 11 | // initialising ImGui 12 | IMGUI_CHECKVERSION(); 13 | ImGui::CreateContext(); 14 | ImGuiIO& io = ImGui::GetIO(); (void)io; 15 | ImGui_ImplGlfw_InitForOpenGL(window, true); 16 | ImGui_ImplOpenGL3_Init("#version 330"); 17 | 18 | { 19 | ImGuiStyle* style = &ImGui::GetStyle(); 20 | style->WindowPadding = ImVec2(15, 15); 21 | style->WindowRounding = 5.0f; 22 | style->FramePadding = ImVec2(5, 5); 23 | style->FrameRounding = 4.0f; 24 | style->ItemSpacing = ImVec2(12, 8); 25 | style->ItemInnerSpacing = ImVec2(8, 6); 26 | style->IndentSpacing = 25.0f; 27 | style->ScrollbarSize = 15.0f; 28 | style->ScrollbarRounding = 9.0f; 29 | style->GrabMinSize = 5.0f; 30 | style->GrabRounding = 3.0f; 31 | style->Colors[ImGuiCol_Text] = ImVec4(0.80f, 0.80f, 0.83f, 1.00f); 32 | style->Colors[ImGuiCol_TextDisabled] = ImVec4(0.24f, 0.23f, 0.29f, 1.00f); 33 | style->Colors[ImGuiCol_WindowBg] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f); 34 | style->Colors[ImGuiCol_PopupBg] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f); 35 | style->Colors[ImGuiCol_Border] = ImVec4(0.80f, 0.80f, 0.83f, 0.88f); 36 | style->Colors[ImGuiCol_BorderShadow] = ImVec4(0.92f, 0.91f, 0.88f, 0.00f); 37 | style->Colors[ImGuiCol_FrameBg] = ImVec4(0.20f, 0.19f, 0.22f, 1.00f); // 38 | style->Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.24f, 0.23f, 0.29f, 1.00f); 39 | style->Colors[ImGuiCol_FrameBgActive] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f); 40 | style->Colors[ImGuiCol_TitleBg] = ImVec4(0.20f, 0.19f, 0.22f, 1.00f);// 41 | style->Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(1.00f, 0.98f, 0.95f, 0.75f); 42 | style->Colors[ImGuiCol_TitleBgActive] = ImVec4(0.07f, 0.07f, 0.09f, 1.00f); 43 | style->Colors[ImGuiCol_MenuBarBg] = ImVec4(0.20f, 0.19f, 0.22f, 1.00f);// 44 | style->Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.20f, 0.19f, 0.22f, 1.00f);// 45 | style->Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.80f, 0.80f, 0.83f, 0.31f); 46 | style->Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f); 47 | style->Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f); 48 | style->Colors[ImGuiCol_CheckMark] = ImVec4(0.80f, 0.80f, 0.83f, 0.31f); 49 | style->Colors[ImGuiCol_SliderGrab] = ImVec4(0.80f, 0.80f, 0.83f, 0.31f); 50 | style->Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f); 51 | style->Colors[ImGuiCol_Button] = ImVec4(0.20f, 0.19f, 0.22f, 1.00f);// 52 | style->Colors[ImGuiCol_ButtonHovered] = ImVec4(0.24f, 0.23f, 0.29f, 1.00f); 53 | style->Colors[ImGuiCol_ButtonActive] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f); 54 | style->Colors[ImGuiCol_Header] = ImVec4(0.20f, 0.19f, 0.22f, 1.00f);// 55 | style->Colors[ImGuiCol_HeaderHovered] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f); 56 | style->Colors[ImGuiCol_HeaderActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f); 57 | style->Colors[ImGuiCol_ResizeGrip] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); 58 | style->Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.56f, 0.56f, 0.58f, 1.00f); 59 | style->Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.06f, 0.05f, 0.07f, 1.00f); 60 | style->Colors[ImGuiCol_PlotLines] = ImVec4(0.40f, 0.39f, 0.38f, 0.63f); 61 | style->Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f); 62 | style->Colors[ImGuiCol_PlotHistogram] = ImVec4(0.40f, 0.39f, 0.38f, 0.63f); 63 | style->Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.25f, 1.00f, 0.00f, 1.00f); 64 | style->Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.25f, 0.70f, 0.00f, 0.43f); 65 | } 66 | } 67 | 68 | void MyGui::calcFps() { 69 | double currentTime = glfwGetTime(); 70 | frameCount++; 71 | if (currentTime - previousTime >= 1.0) 72 | { 73 | fps = frameCount / (currentTime - previousTime); 74 | previousTime = currentTime; 75 | frameCount = 0; 76 | } 77 | } 78 | 79 | void MyGui::sceneCollectionWindow() { 80 | // scene collection window 81 | ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_FirstUseEver); 82 | ImGui::SetNextWindowSize(ImVec2(400, 600), ImGuiCond_FirstUseEver); 83 | if (ImGui::Begin("Scene collection"), NULL, ImGuiWindowFlags_NoCollapse) { 84 | ImGui::Text(std::format("FPS: {}", fps).c_str()); 85 | ImVec2 SceneWindowSize = ImGui::GetWindowContentRegionMax(); 86 | float offset = 8.0f; 87 | 88 | for (int i = 0; i < MAX_OBJECTS; i++) { 89 | if (!scene->objects[i].name.empty()) { 90 | if (ImGui::Button(scene->objects[i].name.c_str(), ImVec2(SceneWindowSize.x - offset, 30))) { 91 | if (selectedObjectFromCollection == i) objectProperties = !objectProperties; 92 | else objectProperties = true; 93 | selectedObjectFromCollection = i; 94 | selectedItemFromCombo = (int)scene->objects[selectedObjectFromCollection].type - 1; 95 | selectedMaterialFromCombo = 0; 96 | if (scene->objects[selectedObjectFromCollection].isLight == 1.0) selectedMaterialFromCombo = 1; 97 | else if (scene->objects[selectedObjectFromCollection].refractionIndex != -1.0) selectedMaterialFromCombo = 2; 98 | } 99 | } 100 | } 101 | if (ImGui::Button("Add object", ImVec2(SceneWindowSize.x - offset, 30))) { 102 | addObjectName = !addObjectName; 103 | } 104 | } ImGui::End(); 105 | } 106 | 107 | void MyGui::inputWindow() { 108 | ImGui::SetNextWindowPos(ImVec2(411, 230), ImGuiCond_FirstUseEver); 109 | ImGui::SetNextWindowSize(ImVec2(384, 105), ImGuiCond_FirstUseEver); 110 | // input window 111 | if (addObjectName) { 112 | ImGui::Begin("Add a new object"); 113 | ImVec2 windowSize = ImGui::GetWindowContentRegionMax(); 114 | 115 | ImGui::InputText("Object name", inputBuffer, IM_ARRAYSIZE(inputBuffer)); 116 | if (ImGui::Button("Submit", ImVec2(windowSize.x/2-10, 20))) { 117 | scene->objects[nextObjectToAdd].name = inputBuffer; 118 | scene->objects[nextObjectToAdd].type = 1.0; 119 | nextObjectToAdd++; 120 | // clean input buffer 121 | strcpy_s(inputBuffer, ""); 122 | // close window 123 | addObjectName = false; 124 | } 125 | // close button 126 | ImGui::SameLine(); 127 | if (ImGui::Button("Close", ImVec2(windowSize.x / 2 - 10, 20))) addObjectName = false; 128 | 129 | ImGui::End(); 130 | } 131 | } 132 | 133 | void MyGui::skyboxWindow() { 134 | ImGui::SetNextWindowPos(ImVec2(405, 714), ImGuiCond_FirstUseEver); 135 | ImGui::SetNextWindowSize(ImVec2(395, 360), ImGuiCond_FirstUseEver); 136 | if (changeSkybox) { 137 | if (ImGui::Begin("Skybox settings")) { 138 | ImGui::Text(std::format("Current image used: {}", skybox->skybox_file_name).c_str()); 139 | if (ImGui::CollapsingHeader("Skybox rotation")) { 140 | ImGui::SliderFloat("Pitch (x)", &skybox->rotation[0], 0.0f, 360.0f); 141 | ImGui::SliderFloat("Yaw (y)", &skybox->rotation[1], 0.0f, 360.0f); 142 | ImGui::SliderFloat("Roll (z)", &skybox->rotation[2], 0.0f, 360.0f); 143 | } 144 | 145 | if (ImGui::CollapsingHeader("Use just a color")) { 146 | ImGui::Checkbox("Use a colour", &useSkyboxColour); 147 | if (useSkyboxColour) ImGui::ColorEdit3("Sky color", skybox->col); 148 | } 149 | ImGui::Text("Highest colour value"); 150 | ImGui::SliderFloat(" ", &skybox->highestColValue, 1.0f, 100.0f); 151 | 152 | ImGui::Spacing(); 153 | ImGui::Text("All images in 'images/skybox'"); 154 | 155 | ImVec2 windowSize = ImGui::GetWindowContentRegionMax(); 156 | for (const auto& entry : std::filesystem::directory_iterator("images/skybox/")) { 157 | std::string fileName = entry.path().filename().string(); 158 | // get the extension 159 | size_t pos = fileName.rfind('.'); 160 | std::string fileType; 161 | if (pos != std::string::npos) { 162 | fileType = fileName.substr(pos + 1); 163 | } 164 | // if the extension is allowed 165 | if (fileType == "jpg" || fileType == "png" || fileType == "hdr"){ 166 | if (ImGui::Button(fileName.c_str(), ImVec2(windowSize.x - 8, 30))) { 167 | skybox->ChangeTexture(fileName.c_str(), loadImageError, fileType == "hdr" ? true : false); 168 | } 169 | } 170 | } 171 | if (ImGui::Button("Close", ImVec2(windowSize.x - 8, 30))) changeSkybox = false; 172 | 173 | } ImGui::End(); 174 | } 175 | } 176 | 177 | void MyGui::objectPropertiesWindow() { 178 | ImGui::SetNextWindowPos(ImVec2(1420, 376), ImGuiCond_FirstUseEver); 179 | ImGui::SetNextWindowSize(ImVec2(500, 600), ImGuiCond_FirstUseEver); 180 | // object properties window 181 | if (objectProperties && !scene->objects[selectedObjectFromCollection].name.empty()) { 182 | std::string name = scene->objects[selectedObjectFromCollection].name; 183 | if (ImGui::Begin("Object properties", NULL)) { 184 | ImGui::Text(name.c_str()); 185 | ImGui::Text("Object type"); 186 | ImGui::Combo(" ", &selectedItemFromCombo, items, IM_ARRAYSIZE(items)); 187 | ImGui::Text("Material type"); 188 | ImGui::Combo(" ", &selectedMaterialFromCombo, materials, IM_ARRAYSIZE(materials)); 189 | // sphere 190 | if (items[selectedItemFromCombo] == "Sphere") { 191 | scene->objects[selectedObjectFromCollection].type = 1.0; 192 | ImGui::Text("Size settings"); 193 | ImGui::SliderFloat("Radius", &scene->objects[selectedObjectFromCollection].radius, 0.1f, 10.0f); 194 | ImGui::Text("Position settings"); 195 | ImGui::SliderFloat("X", &scene->objects[selectedObjectFromCollection].pos[0], -10.0f, 10.0f); 196 | ImGui::SliderFloat("Y", &scene->objects[selectedObjectFromCollection].pos[1], -10.0f, 10.0f); 197 | ImGui::SliderFloat("Z", &scene->objects[selectedObjectFromCollection].pos[2], -10.0f, 10.0f); 198 | 199 | } 200 | // cube 201 | else if (items[selectedItemFromCombo] == "Cube") { 202 | scene->objects[selectedObjectFromCollection].type = 2.0; 203 | ImGui::Text("Size settings"); 204 | ImGui::SliderFloat("Width", &scene->objects[selectedObjectFromCollection].cubeSize[0], 0.1f, 10.0f); 205 | ImGui::SliderFloat("Height", &scene->objects[selectedObjectFromCollection].cubeSize[1], 0.1f, 10.0f); 206 | ImGui::SliderFloat("Length", &scene->objects[selectedObjectFromCollection].cubeSize[2], 0.1f, 10.0f); 207 | ImGui::Text("Position settings"); 208 | ImGui::SliderFloat("X", &scene->objects[selectedObjectFromCollection].pos[0], -10.0f, 10.0f); 209 | ImGui::SliderFloat("Y", &scene->objects[selectedObjectFromCollection].pos[1], -10.0f, 10.0f); 210 | ImGui::SliderFloat("Z", &scene->objects[selectedObjectFromCollection].pos[2], -10.0f, 10.0f); 211 | ImGui::Text("Rotation"); 212 | ImGui::SliderFloat("Pitch (X)", &scene->objects[selectedObjectFromCollection].rot[0], 0.0f, 360.0f, "%.0f"); 213 | ImGui::SliderFloat("Yaw (Y)", &scene->objects[selectedObjectFromCollection].rot[1], 0.0f, 360.0f, "%.0f"); 214 | ImGui::SliderFloat("Roll (Z)", &scene->objects[selectedObjectFromCollection].rot[2], 0.0f, 360.0f, "%.0f"); 215 | } 216 | // plane 217 | else if (items[selectedItemFromCombo] == "Plane") { 218 | scene->objects[selectedObjectFromCollection].type = 3.0; 219 | ImGui::Text("Position settings"); 220 | ImGui::SliderFloat("Y", &scene->objects[selectedObjectFromCollection].pos[1], -10.0f, 10.0f); 221 | } 222 | // material 223 | ImGui::Text("Material settings"); 224 | // Matte - Specular 225 | if (materials[selectedMaterialFromCombo] == "Matte - Specular") { 226 | scene->objects[selectedObjectFromCollection].set_default_settings(0); 227 | ImGui::SliderFloat("Roughness", &scene->objects[selectedObjectFromCollection].roughness, 0.0f, 1.0f); 228 | ImGui::SliderFloat("percentSpecular", &scene->objects[selectedObjectFromCollection].percentSpecular, 0.0f, 1.0f); 229 | } 230 | // Light source 231 | else if (materials[selectedMaterialFromCombo] == "Light source") { 232 | scene->objects[selectedObjectFromCollection].set_default_settings(1); 233 | ImGui::SliderFloat("Power of light", &scene->objects[selectedObjectFromCollection].powerOfLight, 0.0f, 20.0f); 234 | } 235 | // Lens 236 | else if (materials[selectedMaterialFromCombo] == "Lens") { 237 | scene->objects[selectedObjectFromCollection].set_default_settings(2); 238 | ImGui::SliderFloat("Index of refraction", &scene->objects[selectedObjectFromCollection].refractionIndex, 1.0f, 4.0f); 239 | ImGui::SliderFloat("Reflectivity", &scene->objects[selectedObjectFromCollection].reflectivity, 0.0f, 1.0f); 240 | } 241 | // grid 242 | if (items[selectedItemFromCombo] == "Plane") ImGui::Checkbox("Plane grid", &planeGrid); 243 | if (planeGrid && items[selectedItemFromCombo] == "Plane") { 244 | ImGui::SliderFloat("Tile size", &tileSize, 0.0f, 5.0f); 245 | ImGui::ColorEdit3("Colour 1", scene->objects[selectedObjectFromCollection].colour); 246 | ImGui::ColorEdit3("Colour 2", gridCol2); 247 | } else ImGui::ColorEdit3("Colour", scene->objects[selectedObjectFromCollection].colour); 248 | if (items[selectedItemFromCombo] != "Plane") ImGui::ColorEdit3("Specular colour", scene->objects[selectedObjectFromCollection].specularColour); 249 | // delete button 250 | if (ImGui::Button("Delete")) { 251 | scene->objects[selectedObjectFromCollection].set_default_settingsALL(); 252 | scene->rearrangeObjects(); 253 | nextObjectToAdd -= 1; 254 | } 255 | // update 256 | scene->convertTo1D(); 257 | } ImGui::End(); 258 | } 259 | } 260 | 261 | void MyGui::cameraSettingsWindow() { 262 | ImGui::SetNextWindowPos(ImVec2(0, 600), ImGuiCond_FirstUseEver); 263 | ImGui::SetNextWindowSize(ImVec2(400, 470), ImGuiCond_FirstUseEver); 264 | // camera settings menu 265 | if (ImGui::Begin("Camera settings")) { 266 | ImVec2 windowSize = ImGui::GetWindowContentRegionMax(); 267 | ImVec2 buttonSize = ImVec2(windowSize.x - 8, 30); 268 | 269 | if (ImGui::CollapsingHeader("Path tracing settings")) { 270 | ImGui::Text("Number of reflections"); 271 | ImGui::SliderInt("Render mode ", &MAX_REFLECTIONS_RENDER_MODE, 1, 30); 272 | ImGui::SliderInt("Preview mode", &MAX_REFLECTIONS_PREVIEW_MODE, 1, 30); 273 | ImGui::Text("Number of samples"); 274 | ImGui::SliderInt("Redner mode", &NUMBER_OF_SAMPLES_RENDER_MODE, 1, 30); 275 | ImGui::SliderInt("Preview mode ", &NUMBER_OF_SAMPLES_PREVIEW_MODE, 1, 30); 276 | ImGui::Text("Color multiplier when reached max relfections"); 277 | ImGui::SliderFloat("Multiplier", &colourMultiplier, 0.0, 1.0); 278 | } 279 | ImGui::Spacing(); 280 | if (ImGui::CollapsingHeader("Camera position and direction")) { 281 | ImGui::Text("Position"); 282 | ImGui::SliderFloat("X", &camera->Pos[0], -10.0f, 10.0f); 283 | ImGui::SliderFloat("Y", &camera->Pos[1], -10.0f, 10.0f); 284 | ImGui::SliderFloat("Z", &camera->Pos[2], -10.0f, 10.0f); 285 | ImGui::Text("Direction"); 286 | ImGui::SliderFloat("Pitch (X)", &camera->Rot[0], -360.0f, 360.0f); 287 | ImGui::SliderFloat("Yaw (Y)", &camera->Rot[1], -360.0f, 360.0f); 288 | ImGui::SliderFloat("Roll (Z)", &camera->Rot[2], -360.0f, 360.0f); 289 | ImGui::Text("Other"); 290 | ImGui::SliderFloat("Speed", &camera->Speed, 0.0f, 5.0f); 291 | ImGui::SliderFloat("Mouse sensitivity", &camera->Sensitivity, 0.1f, 5.0f); 292 | } 293 | ImGui::Spacing(); 294 | if (ImGui::CollapsingHeader("Camera settings")) { 295 | ImGui::Text("Lens settings"); 296 | ImGui::SliderFloat("Focus distance", &focusDistance, 0.0, 30.0); 297 | ImGui::SliderFloat("Aperture size", &apertureSize, 0.0, 1.0); 298 | ImGui::SliderFloat("Zoom", &zoom, 0.1, 2.0); 299 | } 300 | ImGui::Spacing(); 301 | ImGui::Checkbox("Show normals", &showNormals); 302 | ImGui::Checkbox("Camera movement", &isMouseControl); 303 | ImGui::Checkbox("Render mode ", &renderMode); 304 | ImGui::Checkbox("On constant update", &onConstantUpdate); 305 | if (ImGui::Checkbox("v-Sync", &vSync)) glfwSwapInterval(vSync);; 306 | // change skybox 307 | ImGui::Spacing(); 308 | if (ImGui::Button("Skybox settings", buttonSize)) changeSkybox = !changeSkybox; 309 | // change post process settings 310 | if (ImGui::Button("Post process settings", buttonSize)) postProcessSettings = !postProcessSettings; 311 | if (ImGui::Button("Save the scene", buttonSize)) isSaveFile = !isSaveFile; 312 | if (ImGui::Button("Load a scene", buttonSize)) isReadFile = !isReadFile; 313 | 314 | } ImGui::End(); 315 | } 316 | 317 | void MyGui::screenshotInfo() { 318 | ImGui::SetNextWindowPos(ImVec2(776, 493), ImGuiCond_FirstUseEver); 319 | ImGui::SetNextWindowSize(ImVec2(363, 94), ImGuiCond_FirstUseEver); 320 | // show message about successful screenshot 321 | if (showMessage) { 322 | ImGui::Begin("Info"); 323 | ImVec2 windowSize = ImGui::GetWindowContentRegionMax(); 324 | 325 | ImGui::Text("The screenshot has been saved successfully."); 326 | if (ImGui::Button("Ok", ImVec2(windowSize.x-8, 20))) showMessage = false; 327 | 328 | ImGui::End(); 329 | } 330 | } 331 | 332 | void MyGui::skyboxError() { 333 | if (loadImageError) 334 | { 335 | ImGui::Begin("Error"); 336 | 337 | ImGui::Text("An error has occurred while loading in the image.\nEnsure that you have specified the file name correctly and its format."); 338 | if (ImGui::Button("Okay")) loadImageError = false; 339 | 340 | ImGui::End(); 341 | } 342 | } 343 | 344 | void MyGui::postProcessWindow() { 345 | ImGui::SetNextWindowPos(ImVec2(1420, 0), ImGuiCond_FirstUseEver); 346 | ImGui::SetNextWindowSize(ImVec2(500, 370), ImGuiCond_FirstUseEver); 347 | if (postProcessSettings) { 348 | if (ImGui::Begin("Post process settings")) { 349 | 350 | ImGui::Text("Tonal settings"); 351 | ImGui::SliderFloat("Brightness", &brightness, -1.0f, 1.0f); 352 | ImGui::SliderFloat("Expousure", &expousure, -1.0f, 1.0f); 353 | ImGui::SliderFloat("Contrast", &contrast, 0.0f, 1.0f); 354 | 355 | ImGui::Text("Bloom settings"); 356 | ImGui::Checkbox("Bloom", &doBloom); 357 | ImGui::SliderInt("Max Lod", &bloomMaxLod, 0, 7); 358 | ImGui::SliderInt("Ping pong bounces", &numberOfBounces, 0, 10); 359 | ImGui::SliderFloat("Bloom intensity", &bloomIntensity, 0.0f, 10.0f); 360 | ImGui::SliderFloat("Intensity of treshold", &tresholdIntensity, 0.0f, 2.0f); 361 | 362 | } ImGui::End(); 363 | } 364 | } 365 | 366 | void MyGui::readFileWindow() { 367 | ImGui::SetNextWindowPos(ImVec2(811, 848), ImGuiCond_FirstUseEver); 368 | ImGui::SetNextWindowSize(ImVec2(515, 224), ImGuiCond_FirstUseEver); 369 | if (isReadFile) { 370 | ImGui::Begin("Load a scene"); 371 | ImVec2 windowSize = ImGui::GetWindowContentRegionMax(); 372 | for (const auto& entry : std::filesystem::directory_iterator("scenes/")) { 373 | std::string fileName = entry.path().filename().string(); 374 | 375 | if (ImGui::Button(fileName.c_str(), ImVec2(windowSize.x - 8, 30))) { 376 | scene->readFromAfile(std::format("scenes/{}", fileName.c_str()).c_str()); 377 | scene->updateObjectsFrom1D(); 378 | 379 | // get the index of last NOT empty object in list 380 | int i = 0; 381 | for (i = 0; i < MAX_OBJECTS; i++) 382 | { 383 | if (scene->objects[i].name.empty()) break; 384 | } nextObjectToAdd = i++; 385 | } 386 | } 387 | 388 | if (ImGui::Button("Close", ImVec2(windowSize.x - 8, 30))) 389 | { 390 | isReadFile = false; 391 | } 392 | 393 | ImGui::End(); 394 | } 395 | } 396 | 397 | 398 | void MyGui::saveFileWindow() { 399 | ImGui::SetNextWindowPos(ImVec2(411, 342), ImGuiCond_FirstUseEver); 400 | ImGui::SetNextWindowSize(ImVec2(384, 105), ImGuiCond_FirstUseEver); 401 | if (isSaveFile) { 402 | ImGui::Begin("Save a scene file"); 403 | ImVec2 windowSize = ImGui::GetWindowContentRegionMax(); 404 | ImGui::InputText("Scene name", inputBufferSaveFile, IM_ARRAYSIZE(inputBufferSaveFile)); 405 | 406 | if (ImGui::Button("Submit", ImVec2(windowSize.x/2-10, 20))) 407 | { 408 | scene->saveInFile(std::format("scenes/{}", inputBufferSaveFile).c_str()); 409 | isSaveFile = false; 410 | } 411 | ImGui::SameLine(); 412 | if (ImGui::Button("Close", ImVec2(windowSize.x/2-10, 20))) 413 | { 414 | isSaveFile = false; 415 | } 416 | 417 | ImGui::End(); 418 | } 419 | } 420 | 421 | void MyGui::renderMyGui() { 422 | if (!hideGUI) { 423 | sceneCollectionWindow(); 424 | inputWindow(); 425 | skyboxWindow(); 426 | objectPropertiesWindow(); 427 | cameraSettingsWindow(); 428 | postProcessWindow(); 429 | readFileWindow(); 430 | saveFileWindow(); 431 | } 432 | screenshotInfo(); 433 | skyboxError(); 434 | 435 | ImGui::Render(); 436 | ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); 437 | } 438 | 439 | void MyGui::Update() { 440 | calcFps(); 441 | renderMyGui(); 442 | } 443 | -------------------------------------------------------------------------------- /source/mygui.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "imgui/imgui.h" 7 | #include "imgui/imgui_impl_glfw.h" 8 | #include "imgui/imgui_impl_opengl3.h" 9 | 10 | #include "scene.h" 11 | #include "skybox.h" 12 | #include "GLFW/glfw3.h" 13 | #include "camera.h" 14 | 15 | 16 | class MyGui { 17 | public: 18 | // camera settings 19 | bool renderMode = false; // false stands for performance mode, when true for render mode 20 | int MAX_REFLECTIONS_RENDER_MODE = 12; 21 | int NUMBER_OF_SAMPLES_RENDER_MODE = 5; 22 | int MAX_REFLECTIONS_PREVIEW_MODE = 1; 23 | int NUMBER_OF_SAMPLES_PREVIEW_MODE = 1; 24 | 25 | float colourMultiplier = 1.0f; // colour multiplier when the a ray has reaches the maximum number of reflections 26 | float focusDistance = 5.0f; 27 | float apertureSize = 0.1f; 28 | float zoom = 1.0f; 29 | 30 | bool showNormals = false; 31 | bool onConstantUpdate = true; 32 | 33 | // post process 34 | float expousure = 0.0f; 35 | float brightness = 0.0f; 36 | float contrast = 0.0f; 37 | 38 | bool doBloom = false; 39 | float bloomIntensity = 2.0f; 40 | int bloomMaxLod = 4; 41 | int numberOfBounces = 4; 42 | float tresholdIntensity = 1.0f; 43 | 44 | // plane grid settings 45 | bool planeGrid = false; 46 | float gridCol2[3] = { 0.0f, 0.0f, 0.0f }; 47 | float tileSize = 2.0f; 48 | 49 | // imgui 50 | bool vSync = true; 51 | bool objectProperties = false; 52 | bool addObjectName = false; 53 | bool hideGUI = false; 54 | bool showMessage = false; 55 | bool loadImageError = false; 56 | bool changeSkybox = false; 57 | bool postProcessSettings = false; 58 | bool isSaveFile = false; 59 | bool isReadFile = false; 60 | bool isMouseControl = true; 61 | bool useSkyboxColour = false; 62 | const char* items[3] = { "Sphere", "Cube", "Plane" }; 63 | const char* materials[3] = { "Matte - Specular", "Light source", "Lens" }; 64 | int selectedItemFromCombo = 0; 65 | int nextObjectToAdd = 0; 66 | int selectedObjectFromCollection = 0; 67 | int selectedMaterialFromCombo = 0; 68 | char inputBuffer[20] = ""; // buffer for an object name 69 | char inputBufferSaveFile[20] = ""; // buffer for a scene name 70 | int WIDTH, HEIGHT, fps, frameCount = 0; 71 | 72 | // for FPS measurements 73 | double previousTime = glfwGetTime(); 74 | 75 | GLFWwindow* windowP; 76 | Scene* scene; 77 | Skybox* skybox; 78 | Camera* camera; 79 | 80 | MyGui(Scene* sceneP, Skybox* skyboxP, Camera* camera, int WIDTH, int HEIGHT, GLFWwindow* window); 81 | 82 | void calcFps(); 83 | 84 | void sceneCollectionWindow(); 85 | void inputWindow(); 86 | void skyboxWindow(); 87 | void objectPropertiesWindow(); 88 | void cameraSettingsWindow(); 89 | void postProcessWindow(); 90 | void screenshotInfo(); 91 | void skyboxError(); 92 | void readFileWindow(); 93 | void saveFileWindow(); 94 | 95 | void renderMyGui(); 96 | 97 | void Update(); 98 | 99 | }; -------------------------------------------------------------------------------- /source/object.cpp: -------------------------------------------------------------------------------- 1 | #include "object.h" 2 | 3 | void Object::set_default_settings(int objType) { 4 | if (objType == 0) { // Rought material 5 | isLight = 0.0; 6 | refractionIndex = -1.0; 7 | } 8 | else if (objType == 1) { // Light source 9 | isLight = 1.0; 10 | refractionIndex = -1.0; 11 | } 12 | else if (objType == 2) { // Lens 13 | isLight = 0.0; 14 | if (refractionIndex == -1.0) refractionIndex = 1.0; 15 | } 16 | } 17 | 18 | void Object::set_default_settingsALL() { 19 | name.clear(); 20 | // pos 21 | pos[0] = 0.0f; 22 | pos[1] = 0.0f; 23 | pos[2] = 0.0f; 24 | // rotation 25 | rot[0] = 0.0f; 26 | rot[1] = 0.0f; 27 | rot[2] = 0.0f; 28 | // colour 29 | colour[0] = 1.0f; 30 | colour[1] = 1.0f; 31 | colour[2] = 1.0f; 32 | // specular colour 33 | specularColour[0] = 1.0f; 34 | specularColour[1] = 1.0f; 35 | specularColour[2] = 1.0f; 36 | // cube size 37 | cubeSize[0] = 1.0f; 38 | cubeSize[1] = 1.0f; 39 | cubeSize[2] = 1.0f; 40 | // other 41 | type = 0.0; 42 | radius = 1.0; 43 | isLight = 0.0; 44 | powerOfLight = 1.0; 45 | reflectivity = 0.0; 46 | refractionIndex = -1.0; 47 | percentSpecular = 1.0; 48 | roughness = 0.0; 49 | } -------------------------------------------------------------------------------- /source/object.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class Object { 5 | public: 6 | std::string name; // for the gui 7 | float pos[3] = { 0.0f, 0.0f, 0.0f }; 8 | float rot[3] = { 0.0f, 0.0f, 0.0f }; 9 | 10 | // object type 11 | float type = 0.0f; // 0 - nothing, 1 - sphere, 2 - cube, 3 - plane 12 | float radius = 1.0f; 13 | float cubeSize[3] = { 1.0f, 1.0f, 1.0f }; 14 | 15 | // material properties 16 | float colour[3] = { 1.0f, 1.0f, 1.0f }; 17 | float specularColour[3] = { 1.0f, 1.0f, 1.0f }; 18 | float isLight = 0.0f; 19 | float powerOfLight = 1.0f; 20 | float reflectivity = 0.0f; 21 | float refractionIndex = -1.0f; 22 | float percentSpecular = 0.0f; 23 | float roughness = 0.0f; 24 | 25 | void set_default_settings(int); 26 | 27 | void set_default_settingsALL(); 28 | }; -------------------------------------------------------------------------------- /source/scene.cpp: -------------------------------------------------------------------------------- 1 | #include "object.h" 2 | #include "scene.h" 3 | 4 | 5 | void Scene::convertTo1D() { 6 | // x, y, z, r, g, b, type, radius, cubeSize, isLight, reflectivity, refract, percentSpecular, roughness powerOfLight rotationTransform 7 | // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 8 | float array2D[MAX_OBJECTS][ELMENTS_IN_1OBJ]; 9 | for (int i = 0; i < MAX_OBJECTS; i++) { 10 | array2D[i][0] = objects[i].pos[0]; 11 | array2D[i][1] = objects[i].pos[1]; 12 | array2D[i][2] = objects[i].pos[2]; 13 | 14 | array2D[i][3] = objects[i].colour[0]; 15 | array2D[i][4] = objects[i].colour[1]; 16 | array2D[i][5] = objects[i].colour[2]; 17 | 18 | array2D[i][6] = objects[i].type; 19 | array2D[i][7] = objects[i].radius; 20 | 21 | array2D[i][8] = objects[i].cubeSize[0]; 22 | array2D[i][9] = objects[i].cubeSize[1]; 23 | array2D[i][10] = objects[i].cubeSize[2]; 24 | 25 | array2D[i][11] = objects[i].isLight; 26 | array2D[i][12] = objects[i].reflectivity; 27 | array2D[i][13] = objects[i].refractionIndex; 28 | array2D[i][14] = objects[i].percentSpecular; 29 | array2D[i][15] = objects[i].roughness; 30 | array2D[i][16] = objects[i].powerOfLight; 31 | 32 | array2D[i][17] = objects[i].rot[0]; 33 | array2D[i][18] = objects[i].rot[1]; 34 | array2D[i][19] = objects[i].rot[2]; 35 | 36 | array2D[i][20] = objects[i].specularColour[0]; 37 | array2D[i][21] = objects[i].specularColour[1]; 38 | array2D[i][22] = objects[i].specularColour[2]; 39 | } 40 | 41 | for (int i = 0; i < MAX_OBJECTS; ++i) { 42 | for (int j = 0; j < ELMENTS_IN_1OBJ; ++j) { 43 | sceneData1D[i * ELMENTS_IN_1OBJ + j] = array2D[i][j]; 44 | } 45 | } 46 | } 47 | 48 | void Scene::updateObjectsFrom1D() { 49 | for (int i = 0; i < MAX_OBJECTS; ++i) { 50 | int index = i * ELMENTS_IN_1OBJ; // Calculate the starting index for each object in the 1D array 51 | 52 | objects[i].pos[0] = sceneData1D[index + 0]; 53 | objects[i].pos[1] = sceneData1D[index + 1]; 54 | objects[i].pos[2] = sceneData1D[index + 2]; 55 | 56 | objects[i].colour[0] = sceneData1D[index + 3]; 57 | objects[i].colour[1] = sceneData1D[index + 4]; 58 | objects[i].colour[2] = sceneData1D[index + 5]; 59 | 60 | objects[i].type = sceneData1D[index + 6]; 61 | objects[i].radius = sceneData1D[index + 7]; 62 | 63 | objects[i].cubeSize[0] = sceneData1D[index + 8]; 64 | objects[i].cubeSize[1] = sceneData1D[index + 9]; 65 | objects[i].cubeSize[2] = sceneData1D[index + 10]; 66 | 67 | objects[i].isLight = sceneData1D[index + 11]; 68 | objects[i].reflectivity = sceneData1D[index + 12]; 69 | objects[i].refractionIndex = sceneData1D[index + 13]; 70 | objects[i].percentSpecular = sceneData1D[index + 14]; 71 | objects[i].roughness = sceneData1D[index + 15]; 72 | objects[i].powerOfLight = sceneData1D[index + 16]; 73 | 74 | objects[i].rot[0] = sceneData1D[index + 17]; 75 | objects[i].rot[1] = sceneData1D[index + 18]; 76 | objects[i].rot[2] = sceneData1D[index + 19]; 77 | 78 | objects[i].specularColour[0] = sceneData1D[index + 20]; 79 | objects[i].specularColour[1] = sceneData1D[index + 21]; 80 | objects[i].specularColour[2] = sceneData1D[index + 22]; 81 | } 82 | } 83 | 84 | void Scene::rearrangeObjects() { 85 | int writeIndex = 0; 86 | 87 | // Move objects with type != 0 towards the front 88 | for (int readIndex = 0; readIndex < MAX_OBJECTS; ++readIndex) { 89 | if (objects[readIndex].type != 0) { 90 | objects[writeIndex] = objects[readIndex]; 91 | ++writeIndex; 92 | } 93 | } 94 | 95 | // Fill the rest of the array with objects of type 0 96 | while (writeIndex < MAX_OBJECTS) { 97 | Object obj; 98 | objects[writeIndex] = obj; // Set type to 0 for remaining elements 99 | ++writeIndex; 100 | } 101 | } 102 | 103 | void Scene::saveInFile(const char* dirName) { 104 | // create new directory 105 | if (std::filesystem::create_directory(dirName)) std::cout << "Folder created successfully." << std::endl; 106 | else std::cerr << "Failed to create folder." << std::endl; 107 | 108 | // Write the 1d array to a file 109 | int arraySize = sizeof(sceneData1D) / sizeof(sceneData1D[0]); 110 | std::ofstream ArrayFile1d(std::format("{}/data.txt", dirName).c_str()); 111 | if (!ArrayFile1d) std::cerr << "Error opening file for writing." << std::endl; 112 | for (int i = 0; i < arraySize; ++i) { 113 | ArrayFile1d << sceneData1D[i] << " "; 114 | } 115 | ArrayFile1d.close(); 116 | 117 | // write the object names to a file 118 | std::ofstream objectsFile(std::format("{}/objects.txt", dirName).c_str()); 119 | arraySize = sizeof(objects) / sizeof(objects[0]); 120 | for (int i = 0; i < arraySize; i++) { 121 | objectsFile << objects[i].name << std::endl; 122 | } 123 | objectsFile.close(); 124 | } 125 | 126 | void Scene::readFromAfile(const char* dirName) { 127 | // Read the array from the file and store it in sceneData1D 128 | const int maxSize = MAX_OBJECTS * ELMENTS_IN_1OBJ; 129 | int loadedSize = 0; 130 | std::ifstream ArrayFile1d(std::format("{}/data.txt", dirName).c_str()); 131 | if (!ArrayFile1d) std::cerr << "Error opening file for reading." << std::endl; 132 | float value; 133 | while (ArrayFile1d >> value && loadedSize < maxSize) { 134 | sceneData1D[loadedSize] = value; 135 | loadedSize++; 136 | } 137 | ArrayFile1d.close(); 138 | 139 | // read objects names 140 | std::ifstream objectsFile(std::format("{}/objects.txt", dirName).c_str()); 141 | std::string line; 142 | int count = 0; 143 | while (std::getline(objectsFile, line)) { 144 | objects[count].name = line; 145 | count++; 146 | } 147 | } -------------------------------------------------------------------------------- /source/scene.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "object.h" 4 | #include 5 | #include 6 | #include 7 | 8 | const int MAX_OBJECTS = 30; 9 | const int ELMENTS_IN_1OBJ = 23; 10 | 11 | class Scene { 12 | public: 13 | Object objects[MAX_OBJECTS]; 14 | float sceneData1D[MAX_OBJECTS * ELMENTS_IN_1OBJ]; 15 | 16 | Scene() { 17 | convertTo1D(); 18 | } 19 | 20 | void convertTo1D(); 21 | void updateObjectsFrom1D(); 22 | 23 | void rearrangeObjects(); 24 | 25 | void saveInFile(const char* fileName); 26 | 27 | void readFromAfile(const char* fileName); 28 | }; -------------------------------------------------------------------------------- /source/shader.cpp: -------------------------------------------------------------------------------- 1 | #include "shader.h" 2 | 3 | const char* Shader::fileRead(const char* fileName) { 4 | std::ifstream file(fileName, std::ios::binary | std::ios::ate); 5 | 6 | if (!file.is_open()) { 7 | std::cerr << "Error opening the file: " << fileName << std::endl; 8 | return nullptr; 9 | } 10 | 11 | std::streamsize fileSize = file.tellg(); 12 | file.seekg(0, std::ios::beg); 13 | 14 | char* buffer = new char[fileSize + 1]; // +1 for null terminator 15 | file.read(buffer, fileSize); 16 | buffer[fileSize] = '\0'; // Null-terminate the C-style string 17 | 18 | file.close(); 19 | 20 | return buffer; 21 | } 22 | 23 | void Shader::compileShader(GLuint shader, const char* shaderType) { 24 | glCompileShader(shader); 25 | GLint shaderCompileStatus; 26 | glGetShaderiv(shader, GL_COMPILE_STATUS, &shaderCompileStatus); 27 | if (shaderCompileStatus != GL_TRUE) 28 | { 29 | GLint infoLogLength; 30 | glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength); 31 | GLchar* infoLog = new GLchar[infoLogLength + 1]; 32 | glGetShaderInfoLog(shader, infoLogLength, NULL, infoLog); 33 | std::cout << shaderType << " Shader Compilation Error : " << infoLog << std::endl; 34 | delete[] infoLog; 35 | } 36 | } 37 | 38 | void Shader::U1f(const char* uName, float uValue) { 39 | glUniform1f(glGetUniformLocation(ID, uName), static_cast(uValue)); 40 | } 41 | 42 | void Shader::U2f(const char* uName, float uValue, float uValue2) { 43 | glUniform2f(glGetUniformLocation(ID, uName), static_cast(uValue), static_cast(uValue2)); 44 | } 45 | 46 | void Shader::U3f(const char* uName, float uValue, float uValue2, float uValue3) { 47 | glUniform3f(glGetUniformLocation(ID, uName), static_cast(uValue), static_cast(uValue2), static_cast(uValue3)); 48 | } 49 | 50 | void Shader::U1i(const char* uName, int uValue) { 51 | glUniform1i(glGetUniformLocation(ID, uName), uValue); 52 | } 53 | 54 | void Shader::U1fv(const char* uName, int uValue, float uValue2[]) { 55 | glUniform1fv(glGetUniformLocation(ID, uName), uValue, uValue2); 56 | } 57 | 58 | void Shader::Active() { 59 | glUseProgram(ID); 60 | } 61 | 62 | void Shader::Delete() { 63 | glDeleteProgram(ID); 64 | } 65 | -------------------------------------------------------------------------------- /source/shader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | class Shader { 9 | public: 10 | GLuint ID = glCreateProgram(); 11 | Shader(const char* fragPath, const char* vertPath) { 12 | const char* vertexShaderSource = fileRead(vertPath); 13 | const char* fragmentShaderSource = fileRead(fragPath); 14 | 15 | // Create Vertex Shader Object 16 | GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER); 17 | glShaderSource(vertexShader, 1, &vertexShaderSource, NULL); 18 | compileShader(vertexShader, "Vertex"); 19 | 20 | // Create Fragment Shader Object 21 | GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); 22 | glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL); 23 | compileShader(fragmentShader, "Fragment"); 24 | 25 | // Create Shader Program Object 26 | glAttachShader(ID, vertexShader); 27 | glAttachShader(ID, fragmentShader); 28 | glLinkProgram(ID); 29 | 30 | // Delete the now useless Vertex and Fragment Shader objects 31 | glDeleteShader(vertexShader); 32 | glDeleteShader(fragmentShader); 33 | delete[] vertexShaderSource; 34 | delete[] fragmentShaderSource; 35 | } 36 | 37 | const char* fileRead(const char* fileName); 38 | void compileShader(GLuint shader, const char* shaderType); 39 | 40 | void Active(); 41 | void Delete(); 42 | 43 | void U1f(const char* uName, float uValue); 44 | void U2f(const char* uName, float uValue, float uValue2); 45 | void U3f(const char* uName, float uValue, float uValue2, float uValue3); 46 | void U1i(const char* uName, int uValue); 47 | void U1fv(const char* uName, int uValue, float uValue2[]); 48 | }; -------------------------------------------------------------------------------- /source/skybox.cpp: -------------------------------------------------------------------------------- 1 | #include "skybox.h" 2 | 3 | 4 | Skybox::Skybox(int WIDTH, int HEIGHT) { 5 | float* newBytes = stbi_loadf(std::format("images/skybox/{}", skybox_file_name).c_str(), &widthImg, &heightImg, &numColCh, 0); 6 | glGenTextures(1, &Texture); 7 | glActiveTexture(GL_TEXTURE0); 8 | glBindTexture(GL_TEXTURE_2D, Texture); 9 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 10 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 11 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 12 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 13 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, widthImg, heightImg, 0, GL_RGB, GL_FLOAT, newBytes); 14 | stbi_image_free(newBytes); 15 | glBindTexture(GL_TEXTURE_2D, 0); 16 | } 17 | 18 | void Skybox::ChangeTexture(const char* inputBuffer, bool& loadImageError, bool isHdrFileType) { 19 | // Unload the previous texture if it exists 20 | if (Texture != 0) { 21 | glDeleteTextures(1, &Texture); 22 | Texture = 0; 23 | } 24 | skybox_file_name = inputBuffer; 25 | path_to_skybox = "images/skybox/" + skybox_file_name; 26 | // Load the new texture 27 | if (isHdrFileType) { 28 | float* newBytes = stbi_loadf(path_to_skybox.c_str(), &widthImg, &heightImg, &numColCh, 0); 29 | if (newBytes == NULL) { 30 | loadImageError = true; 31 | } 32 | else { 33 | glGenTextures(1, &Texture); 34 | glActiveTexture(GL_TEXTURE0); 35 | glBindTexture(GL_TEXTURE_2D, Texture); 36 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 37 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 38 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 39 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 40 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, widthImg, heightImg, 0, GL_RGB, GL_FLOAT, newBytes); 41 | stbi_image_free(newBytes); 42 | glBindTexture(GL_TEXTURE_2D, 0); 43 | } 44 | } 45 | 46 | else { 47 | unsigned char* newBytes = stbi_load(path_to_skybox.c_str(), &widthImg, &heightImg, &numColCh, 0); 48 | if (newBytes == NULL) { 49 | loadImageError = true; 50 | } 51 | else { 52 | glGenTextures(1, &Texture); 53 | glActiveTexture(GL_TEXTURE0); 54 | glBindTexture(GL_TEXTURE_2D, Texture); 55 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 56 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 57 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 58 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 59 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, widthImg, heightImg, 0, GL_RGBA, GL_UNSIGNED_BYTE, newBytes); 60 | stbi_image_free(newBytes); 61 | glBindTexture(GL_TEXTURE_2D, 0); 62 | } 63 | } 64 | } 65 | 66 | void Skybox::Delete() { 67 | glDeleteTextures(1, &Texture); 68 | } 69 | 70 | void Skybox::ActiveAndBind(GLuint textureUnit) { 71 | glActiveTexture(textureUnit); 72 | glBindTexture(GL_TEXTURE_2D, Texture); 73 | } -------------------------------------------------------------------------------- /source/skybox.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class Skybox { 10 | public: 11 | GLuint Texture; 12 | std::string skybox_file_name = "rainforest_trail_2k.hdr"; 13 | std::string path_to_skybox = "images/skybox/" + skybox_file_name; 14 | int widthImg, heightImg, numColCh; 15 | 16 | float rotation[3] = { 0.0f, 0.0f, 0.0f }; 17 | float col[3] = { 0.5f, 0.5f, 0.5f }; 18 | float highestColValue = 100.0f; 19 | 20 | Skybox(int WIDTH, int HEIGHT); 21 | 22 | void ChangeTexture(const char*, bool&, bool); 23 | 24 | void ActiveAndBind(GLuint textureUnit); 25 | void Delete(); 26 | }; -------------------------------------------------------------------------------- /source/stb.cpp: -------------------------------------------------------------------------------- 1 | #define STB_IMAGE_IMPLEMENTATION 2 | #include 3 | #define STB_IMAGE_WRITE_IMPLEMENTATION 4 | #include -------------------------------------------------------------------------------- /source/texture.cpp: -------------------------------------------------------------------------------- 1 | #include "texture.h" 2 | 3 | Texture::Texture(int width, int height) { 4 | WIDTH = width; 5 | HEIGHT = height; 6 | 7 | glGenTextures(1, &tex); 8 | glBindTexture(GL_TEXTURE_2D, tex); 9 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, WIDTH, HEIGHT, 0, GL_RGBA, GL_FLOAT, 0); 10 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 11 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 12 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 13 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 14 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 7); 15 | glGenerateMipmap(GL_TEXTURE_2D); 16 | } 17 | 18 | void Texture::ActiveAndBind(GLuint textureUnit) { 19 | glActiveTexture(textureUnit); 20 | glBindTexture(GL_TEXTURE_2D, tex); 21 | } 22 | 23 | void Texture::Delete() { 24 | glDeleteTextures(1, &tex); 25 | } -------------------------------------------------------------------------------- /source/texture.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class Texture { 6 | public: 7 | GLuint tex; 8 | int WIDTH, HEIGHT; 9 | Texture(int width, int height); 10 | 11 | void ActiveAndBind(GLuint textureUnit); 12 | void Delete(); 13 | }; -------------------------------------------------------------------------------- /source/vao.cpp: -------------------------------------------------------------------------------- 1 | #include "vao.h" 2 | 3 | RectVAO::RectVAO() { 4 | // Vertices coordinates 5 | GLfloat vertices[] = 6 | { 7 | // Positions // uv 8 | -1.0f, 1.0f, 0.0f, 1.0f, // left top 9 | -1.0f, -1.0f, 0.0f, 0.0f, // left bottom 10 | 1.0f, -1.0f, 1.0f, 0.0f, // right bottom 11 | 12 | -1.0f, 1.0f, 0.0f, 1.0f, // left top 13 | 1.0f, -1.0f, 1.0f, 0.0f, // right bottom 14 | 1.0f, 1.0f, 1.0f, 1.0f // right top 15 | }; 16 | 17 | glGenVertexArrays(1, &VAO); 18 | glGenBuffers(1, &VBO); 19 | glBindVertexArray(VAO); 20 | glBindBuffer(GL_ARRAY_BUFFER, VBO); 21 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); 22 | glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0); 23 | glEnableVertexAttribArray(0); 24 | glBindBuffer(GL_ARRAY_BUFFER, 0); 25 | glBindVertexArray(0); 26 | } 27 | 28 | void RectVAO::Delete() { 29 | glDeleteVertexArrays(1, &VAO); 30 | glDeleteBuffers(1, &VBO); 31 | } -------------------------------------------------------------------------------- /source/vao.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | 7 | class RectVAO { 8 | public: 9 | GLuint VAO, VBO; 10 | 11 | RectVAO(); 12 | 13 | void Delete(); 14 | }; --------------------------------------------------------------------------------