├── LICENSE-noto_sans_regular.txt ├── LICENSE.md ├── README.md ├── build_static_lib.bat ├── build_static_lib.sh ├── build_static_lib_debug.bat ├── doc ├── vdb-logo.svg └── vdb.svg ├── include ├── vdb.h └── vdb │ ├── compute.h │ ├── imgui.h │ ├── khrplatform.h │ ├── opengl.h │ ├── opengl_debug.h │ ├── stb_image.h │ └── stb_image_write.h ├── src ├── camera.h ├── colormap.h ├── config.h ├── data │ ├── colormap_data.h │ ├── generate_colormap_data.py │ ├── noto_sans_regular.h │ └── window_icon.h ├── framebuffer.h ├── framegrab.h ├── freetype.h ├── freetype │ ├── FTL.TXT │ ├── GPLv2.TXT │ ├── LICENSE.TXT │ ├── README.md │ ├── include │ │ ├── freetype │ │ │ ├── config │ │ │ │ ├── ftconfig.h │ │ │ │ ├── ftheader.h │ │ │ │ ├── ftmodule.h │ │ │ │ ├── ftoption.h │ │ │ │ └── ftstdlib.h │ │ │ ├── freetype.h │ │ │ ├── ftadvanc.h │ │ │ ├── ftbbox.h │ │ │ ├── ftbdf.h │ │ │ ├── ftbitmap.h │ │ │ ├── ftbzip2.h │ │ │ ├── ftcache.h │ │ │ ├── ftchapters.h │ │ │ ├── ftcid.h │ │ │ ├── ftdriver.h │ │ │ ├── fterrdef.h │ │ │ ├── fterrors.h │ │ │ ├── ftfntfmt.h │ │ │ ├── ftgasp.h │ │ │ ├── ftglyph.h │ │ │ ├── ftgxval.h │ │ │ ├── ftgzip.h │ │ │ ├── ftimage.h │ │ │ ├── ftincrem.h │ │ │ ├── ftlcdfil.h │ │ │ ├── ftlist.h │ │ │ ├── ftlzw.h │ │ │ ├── ftmac.h │ │ │ ├── ftmm.h │ │ │ ├── ftmodapi.h │ │ │ ├── ftmoderr.h │ │ │ ├── ftotval.h │ │ │ ├── ftoutln.h │ │ │ ├── ftparams.h │ │ │ ├── ftpfr.h │ │ │ ├── ftrender.h │ │ │ ├── ftsizes.h │ │ │ ├── ftsnames.h │ │ │ ├── ftstroke.h │ │ │ ├── ftsynth.h │ │ │ ├── ftsystem.h │ │ │ ├── fttrigon.h │ │ │ ├── fttypes.h │ │ │ ├── ftwinfnt.h │ │ │ ├── t1tables.h │ │ │ ├── ttnameid.h │ │ │ ├── tttables.h │ │ │ └── tttags.h │ │ └── ft2build.h │ ├── win32 │ │ ├── freetype.dll │ │ └── freetype.lib │ └── win64 │ │ ├── freetype.dll │ │ └── freetype.lib ├── glad │ ├── glad_3_1_debug.c │ └── glad_3_1_release.c ├── hints.h ├── image.h ├── imgui │ ├── LICENSE.txt │ ├── README.md │ ├── imconfig.h │ ├── imgui.cpp │ ├── imgui_demo.cpp │ ├── imgui_draw.cpp │ ├── imgui_freetype.cpp │ ├── imgui_freetype.h │ ├── imgui_impl_opengl3.cpp │ ├── imgui_impl_opengl3.h │ ├── imgui_impl_sdl.cpp │ ├── imgui_impl_sdl.h │ ├── imgui_internal.h │ ├── imgui_widgets.cpp │ ├── imstb_rectpack.h │ ├── imstb_textedit.h │ └── imstb_truetype.h ├── immediate.h ├── immediate_util.h ├── keys.h ├── log.h ├── matrix.h ├── matrix_stack.h ├── mouse.h ├── render_scaler.h ├── render_target.h ├── ruler.h ├── settings.h ├── shader.h ├── shaders │ ├── image.h │ ├── lines.h │ ├── points.h │ ├── points_sprite.h │ ├── thick_lines.h │ └── triangles.h ├── sketch.h ├── style.h ├── transform.h ├── ui.h ├── vdb.cpp ├── widgets.h └── window.h └── test ├── Makefile ├── build.bat └── test.cpp /LICENSE-noto_sans_regular.txt: -------------------------------------------------------------------------------- 1 | Noto is a trademark of Google Inc. Noto fonts are open source. All Noto fonts are published under the SIL Open Font License, Version 1.1. Language data and some sample texts are from the Unicode CLDR project. Noto Sans is obtained from Google Web Fonts using the Apache License Version 2.0. 2 | 3 | Apache License Version 2.0 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); you 6 | may not use this file except in compliance with the License. You may 7 | obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 14 | implied. See the License for the specific language governing 15 | permissions and limitations under the License. 16 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) Copyright (c) 2020 Simen Haugo 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 |

vdb - visual debugger

3 | 4 | vdb is a C++ library that lets you easily create interactive 2D/3D visualization breakpoints. It can be used for things like: 5 | 6 | * Analyzing intermediate results in steps of an algorithm 7 | * Visualizing and pre-processing 2D and 3D input data 8 | * Prototyping a GUI application for annotating data 9 | 10 | vdb runs on Windows, Linux and Mac OS, and requires only an OpenGL 3.1 compatible GPU (which even really old laptops have). 11 | 12 | 13 | 14 | 15 | 16 | 17 | **Basic example** 18 | 19 | vdb works like a breakpoint debugger: 20 | 21 | * you set breakpoints in your code by declaring named "blocks". 22 | * your visualization code goes inside the block. 23 | * inside the block you can access variables from outside. 24 | 25 | For example, here's a program that opens a window and clears the background color to red using data outside the breakpoint block. 26 | 27 | ```c++ 28 | #include 29 | int main(int, char**) { 30 | float color[3] = { 1.0f, 0.3f, 0.1f }; 31 | 32 | VDBB("Test window"); 33 | vdbClear(color[0], color[1], color[2], 1.0f); 34 | VDBE(); 35 | 36 | return 0; 37 | } 38 | ``` 39 | 40 | This program only has one breakpoint, but your program can have many. As with a normal debugger, you can resume control flow and step to the next breakpoint. 41 | 42 | **Quick start** 43 | 44 | For a quick start, compile and run [test/test.cpp](test/test.cpp) by following the instructions inside the file. This is a self-contained program that uses the library to show off basic usage patterns. 45 | 46 | **Using vdb in your project** 47 | 48 | Once you are able to compile and run [test/test.cpp](test/test.cpp) you should be good to go integrate the library into your own project! Here are some tips to get you further: 49 | 50 | * Use [test/Makefile](test/Makefile) or [test/build.bat](test/build.bat) to build vdb in with your application 51 | 52 | * Learn to use vdb by running the **interactive guide** [test/test.cpp](test/test.cpp) and following along in the source code. 53 | 54 | * Learn to use **Dear ImGui** by visiting its [project page](https://github.com/ocornut/imgui/). 55 | 56 | **Using vdb in other languages** 57 | 58 | vdb is currently a C++ library, but it should be possible to create bindings to other languages (such as Python). If anyone would like to assist with this I would gladly accept pull requests. 59 | -------------------------------------------------------------------------------- /build_static_lib.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | if not exist "lib" mkdir lib 4 | pushd lib 5 | 6 | set INCLUDES=-I..\include\ -I..\include\vdb\ -I%SDL2_DIR%\include -I..\src\freetype\include 7 | set FLAGS=-EHsc -MD -Oi -fp:fast -nologo -O2 -WX -W3 -wd4100 -wd4189 -wd4996 -wd4055 8 | 9 | cl %INCLUDES% %FLAGS% -c ..\src\vdb.cpp 10 | lib *.obj -nologo -out:vdb.lib 11 | 12 | popd 13 | -------------------------------------------------------------------------------- /build_static_lib.sh: -------------------------------------------------------------------------------- 1 | # This compiles vdb into a library (libvdb.a) in the directory ./lib 2 | # Make sure you have SDL2 (https://www.libsdl.org/). 3 | # For example (linux): sudo apt-get install libsdl2-dev 4 | 5 | g++ -std=c++11 -c -O2 -fPIC -Werror -Wall src/vdb.cpp -Iinclude/vdb -Isrc/freetype/include -Iinclude `sdl2-config --cflags` 6 | mkdir -p lib 7 | ar rvs lib/libvdb.a vdb.o 8 | rm vdb.o 9 | -------------------------------------------------------------------------------- /build_static_lib_debug.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | if not exist "lib" mkdir lib 4 | pushd lib 5 | 6 | set INCLUDES=-I..\include\ -I..\include\vdb\ -I%SDL2_DIR%\include -I..\src\freetype\include 7 | set FLAGS=-EHsc -MD -Zi -Oi -fp:fast -nologo -Od -WX -W3 -wd4100 -wd4189 -wd4996 -wd4055 -DVDB_DEBUG 8 | 9 | cl %INCLUDES% %FLAGS% -c ..\src\vdb.cpp 10 | lib *.obj -nologo -out:vdb.lib 11 | 12 | popd 13 | -------------------------------------------------------------------------------- /doc/vdb-logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | image/svg+xml 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /doc/vdb.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 20 | 38 | 40 | 41 | 43 | image/svg+xml 44 | 46 | 47 | 48 | 49 | 50 | 55 | 59 | 64 | 65 | 75 | 84 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /src/colormap.h: -------------------------------------------------------------------------------- 1 | #include "data/colormap_data.h" 2 | 3 | namespace colormap 4 | { 5 | static int current_colormap = 0; 6 | static int current_color = 0; 7 | 8 | static vdbColormapData *GetColormapData() 9 | { 10 | assert(current_colormap >= 0); 11 | assert(current_colormap < NUM_COLORMAPS); 12 | return &vdb_colormap_data[current_colormap]; 13 | } 14 | 15 | static void NewFrame() 16 | { 17 | current_colormap = 0; 18 | } 19 | 20 | static void BeginFrame() 21 | { 22 | current_color = 0; 23 | } 24 | } 25 | 26 | vdbVec3 vdbGetForegroundColor() 27 | { 28 | if (settings.global_theme == VDB_DARK_THEME) 29 | return vdbVec3(1,1,1); 30 | else 31 | return vdbVec3(0,0,0); 32 | } 33 | 34 | vdbVec3 vdbGetBackgroundColor() 35 | { 36 | if (settings.global_theme == VDB_DARK_THEME) 37 | return vdbVec3(VDB_DARK_THEME_BACKGROUND); 38 | else 39 | return vdbVec3(VDB_BRIGHT_THEME_BACKGROUND); 40 | } 41 | 42 | int vdbSetColormap(const char *name) 43 | { 44 | int found = 0; 45 | for (int i = 0; i < NUM_COLORMAPS; i++) 46 | { 47 | if (strcmp(vdb_colormap_data[i].name, name) == 0) 48 | { 49 | found = i; 50 | break; 51 | } 52 | } 53 | assert(found >= 0); 54 | assert(found < NUM_COLORMAPS); 55 | colormap::current_colormap = found; 56 | colormap::current_color = 0; 57 | return vdb_colormap_data[found].num_colors; 58 | } 59 | 60 | void vdbColor4ub(unsigned char,unsigned char,unsigned char,unsigned char); 61 | 62 | vdbVec4 vdbNextColor() 63 | { 64 | int n = vdb_colormap_data[colormap::current_colormap].num_colors; 65 | int i = colormap::current_color; 66 | unsigned char *rgb = vdb_colormap_data[colormap::current_colormap].colors + 3*i; 67 | colormap::current_color = (colormap::current_color + 1) % n; 68 | unsigned char a8 = 255; 69 | vdbColor4ub(rgb[0], rgb[1], rgb[2], a8); 70 | return vdbVec4(rgb[0]/255.0f, rgb[1]/255.0f, rgb[2]/255.0f, a8/255.0f); 71 | } 72 | 73 | vdbVec4 vdbResetColor(int offset) 74 | { 75 | colormap::current_color = 0; 76 | int n = vdb_colormap_data[colormap::current_colormap].num_colors; 77 | int i = colormap::current_color; 78 | unsigned char *rgb = vdb_colormap_data[colormap::current_colormap].colors + 3*i; 79 | unsigned char a8 = 255; 80 | vdbColor4ub(rgb[0], rgb[1], rgb[2], a8); 81 | return vdbVec4(rgb[0]/255.0f, rgb[1]/255.0f, rgb[2]/255.0f, a8/255.0f); 82 | } 83 | 84 | vdbVec4 vdbGetColor(float t, float alpha) 85 | { 86 | int n = vdb_colormap_data[colormap::current_colormap].num_colors; 87 | int i = (int)(t*n); 88 | if (i < 0) i = 0; 89 | if (i > n-1) i = n-1; 90 | unsigned char *rgb = vdb_colormap_data[colormap::current_colormap].colors + 3*i; 91 | return vdbVec4(rgb[0]/255.0f, rgb[1]/255.0f, rgb[2]/255.0f, alpha); 92 | } 93 | 94 | vdbVec4 vdbGetColor(int i, float alpha) 95 | { 96 | int n = vdb_colormap_data[colormap::current_colormap].num_colors; 97 | i = (colormap::current_color + i) % n; 98 | unsigned char *rgb = vdb_colormap_data[colormap::current_colormap].colors + 3*i; 99 | return vdbVec4(rgb[0]/255.0f, rgb[1]/255.0f, rgb[2]/255.0f, alpha); 100 | } 101 | 102 | void vdbColor(float t, float alpha) 103 | { 104 | int n = vdb_colormap_data[colormap::current_colormap].num_colors; 105 | int i = (int)(t*n); 106 | if (i < 0) i = 0; 107 | if (i > n-1) i = n-1; 108 | unsigned char *rgb = vdb_colormap_data[colormap::current_colormap].colors + 3*i; 109 | int a8 = (int)(alpha*255.0f); 110 | if (a8 < 0) a8 = 0; 111 | if (a8 > 255) a8 = 255; 112 | vdbColor4ub(rgb[0], rgb[1], rgb[2], (unsigned char)a8); 113 | } 114 | 115 | void vdbColor(int i, float alpha) 116 | { 117 | int n = vdb_colormap_data[colormap::current_colormap].num_colors; 118 | i = (colormap::current_color + i) % n; 119 | unsigned char *rgb = vdb_colormap_data[colormap::current_colormap].colors + 3*i; 120 | int a8 = (int)(alpha*255.0f); 121 | if (a8 < 0) a8 = 0; 122 | if (a8 > 255) a8 = 255; 123 | vdbColor4ub(rgb[0], rgb[1], rgb[2], (unsigned char)a8); 124 | } 125 | 126 | void vdbColorForeground(float alpha) 127 | { 128 | vdbColor(vdbGetForegroundColor(), alpha); 129 | } 130 | 131 | void vdbColorBackground(float alpha) 132 | { 133 | vdbColor(vdbGetBackgroundColor(), alpha); 134 | } 135 | -------------------------------------------------------------------------------- /src/config.h: -------------------------------------------------------------------------------- 1 | // COMPILE-TIME OPTIONS FOR VDB 2 | // You may edit this file in your local copy of vdb if you want to overwrite 3 | // the default configuration. 4 | 5 | // When enabled, ImGui will use FreeType for font rendering (less blurry for small 6 | // font sizes). Unless VDB_IMGUI_FREETYPE_DYNAMIC is enabled, you need to manually 7 | // link Freetype with your final executable. Precompiled library binaries for Win32 8 | // and Win64 are included in vdb/lib/freetype. 9 | #define VDB_IMGUI_FREETYPE 1 10 | 11 | // If enabled, VDB will try to locate freetype.dll on startup and link it for you 12 | // dynamically. This means you don't have to change the build system for your final 13 | // executable, and only need to make sure that freetype.dll is accessible (e.g. in 14 | // the same directory), and matches the version of the header files provided in 15 | // vdb/lib/freetype/include. If freetype.dll is not found, freetype is not used. 16 | #define VDB_IMGUI_FREETYPE_DYNAMIC 1 17 | 18 | // For small font sizes I recommend using the Freetype renderer. 19 | #define VDB_DEFAULT_FONT_SIZE 18 20 | 21 | // Set to > 0 to get smooth edges on points, lines and triangles. 22 | #define VDB_MULTISAMPLES 4 23 | 24 | // Set to > 0 to be able to take screenshots with transparent backgrounds. 25 | #define VDB_ALPHABITS 8 26 | 27 | // Set to > 0 if you want to use the OpenGL stencil operations. 28 | #define VDB_STENCILBITS 8 29 | 30 | // Set to > 0 if you want to use OpenGL depth testing. 31 | #define VDB_DEPTHBITS 24 32 | 33 | // The size of the vdb window is remembered between sessions. 34 | // This path specifies the path (relative to working directory) 35 | // where the information is stored. 36 | #define VDB_SETTINGS_FILENAME "./vdb.ini" 37 | 38 | // Number of frames to pass between saving settings to disk 39 | #define VDB_SAVE_SETTINGS_PERIOD 60*5 40 | 41 | // When true, save settings every SAVE_SAVE_SETTINGS_PERIOD frame 42 | #define VDB_SAVE_SETTINGS_REGULARLY false 43 | 44 | // The state of ImGui windows is remembered between sessions. 45 | // This path specifies the path (relative to working directory) 46 | // where the information is stored. 47 | #define VDB_IMGUI_INI_FILENAME "./imgui.ini" 48 | 49 | #define VDB_HOTKEY_FRAMEGRAB (keys::pressed[VDB_KEY_S] && keys::down[VDB_KEY_LALT]) 50 | #define VDB_HOTKEY_WINDOW_SIZE (keys::pressed[VDB_KEY_W] && keys::down[VDB_KEY_LALT]) 51 | #define VDB_HOTKEY_SKETCH_MODE (keys::pressed[VDB_KEY_D] && keys::down[VDB_KEY_LALT]) 52 | #define VDB_HOTKEY_RULER_MODE (keys::pressed[VDB_KEY_R] && keys::down[VDB_KEY_LALT]) 53 | #define VDB_HOTKEY_TOGGLE_MENU (keys::pressed[VDB_KEY_M] && keys::down[VDB_KEY_LALT]) 54 | #define VDB_HOTKEY_LOGS_WINDOW (keys::pressed[VDB_KEY_L] && keys::down[VDB_KEY_LALT]) 55 | #define VDB_HOTKEY_AUTO_STEP (keys::pressed[VDB_KEY_F6]) 56 | 57 | // Colors for standard themes 58 | #define VDB_DARK_THEME_BACKGROUND 0.22f, 0.22f, 0.22f 59 | #define VDB_DARK_THEME_X_AXIS 0.89f, 0.38f, 0.45f 60 | #define VDB_DARK_THEME_Y_AXIS 0.54f, 0.85f, 0.00f 61 | #define VDB_DARK_THEME_Z_AXIS 0.16f, 0.56f, 1.00f 62 | #define VDB_DARK_THEME_GRID_LINES 1.00f, 1.00f, 1.00f 63 | #define VDB_BRIGHT_THEME_BACKGROUND 1.00f, 1.00f, 1.00f 64 | #define VDB_BRIGHT_THEME_X_AXIS 0.71f, 0.05f, 0.10f 65 | #define VDB_BRIGHT_THEME_Y_AXIS 0.06f, 0.50f, 0.04f 66 | #define VDB_BRIGHT_THEME_Z_AXIS 0.20f, 0.40f, 0.84f 67 | #define VDB_BRIGHT_THEME_GRID_LINES 0.00f, 0.00f, 0.00f 68 | -------------------------------------------------------------------------------- /src/data/generate_colormap_data.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | from collections import OrderedDict 4 | 5 | cmaps = OrderedDict() 6 | 7 | cmaps['Perceptually Uniform Sequential'] = [ 8 | 'viridis', 'plasma', 'inferno', 'magma', 'cividis'] 9 | 10 | cmaps['Sequential'] = [ 11 | 'Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds', 12 | 'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu', 13 | 'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn', 'gray'] 14 | 15 | cmaps['Diverging'] = [ 16 | 'PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu', 17 | 'RdYlBu', 'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic'] 18 | 19 | cmaps['Cyclic'] = ['twilight', 'twilight_shifted', 'hsv'] 20 | 21 | cmaps['Qualitative'] = ['Pastel1', 'Pastel2', 'Paired', 'Accent', 22 | 'Dark2', 'Set1', 'Set2', 'Set3', 23 | 'tab10', 'tab20', 'tab20b', 'tab20c'] 24 | 25 | cmaps['Miscellaneous'] = [ 26 | 'flag', 'prism', 'ocean', 'gist_earth', 'terrain', 'gist_stern', 27 | 'gnuplot', 'gnuplot2', 'CMRmap', 'cubehelix', 'brg', 28 | 'gist_rainbow', 'rainbow', 'jet', 'nipy_spectral', 'gist_ncar'] 29 | 30 | def f32_to_u08(x): 31 | i = int(x*255.0) 32 | if i < 0: 33 | return 0 34 | elif i > 255: 35 | return 255 36 | else: 37 | return i 38 | 39 | print('// This file is automatically generated.') 40 | print('// Colormap data is obtained from Matplotlib:') 41 | print('// https://matplotlib.org/tutorials/colors/colormaps.html') 42 | 43 | print(""" 44 | struct vdbColormapData 45 | { 46 | const char *name; 47 | int num_colors; 48 | GLuint gl_texture; 49 | unsigned char colors[3*1024]; 50 | };""") 51 | 52 | print('#define NUM_COLORMAPS (sizeof(vdb_colormap_data)/sizeof(vdb_colormap_data[0]))') 53 | 54 | print("static vdbColormapData vdb_colormap_data[] = \n{") 55 | for cmap_category, names in cmaps.items(): 56 | for name in names: 57 | if name == 'gray': 58 | r = np.arange(256)/255.0 59 | colors = np.vstack((r,r,r)).T 60 | else: 61 | cmap = plt.cm.get_cmap(name) 62 | if hasattr(cmap, 'colors'): 63 | colors = cmap.colors 64 | else: 65 | colors = cmap(np.linspace(0.0,1.0,256)) 66 | colors = colors[:,:3] 67 | print(' {') 68 | print(' \"%s\",' % name) 69 | print(' %d,' % len(colors)) 70 | print(' 0,') 71 | for r,g,b in colors: 72 | r8 = f32_to_u08(r) 73 | g8 = f32_to_u08(g) 74 | b8 = f32_to_u08(b) 75 | print(' %d, %d, %d,' % (r8,g8,b8)) 76 | print(' },') 77 | num_colormaps += 1 78 | print("};") 79 | 80 | -------------------------------------------------------------------------------- /src/data/window_icon.h: -------------------------------------------------------------------------------- 1 | // File: 'icon2.png' (2336 bytes) 2 | // Exported using binary_to_compressed_c.cpp 3 | static const unsigned int window_icon_size = 2336; 4 | static const unsigned int window_icon_data[2336/4] = 5 | { 6 | 0x474e5089, 0x0a1a0a0d, 0x0d000000, 0x52444849, 0x80000000, 0x80000000, 0x00000608, 0x613ec300, 0x000000cb, 0x49427304, 0x08080854, 0x64087c08, 7 | 0x00000088, 0x59487009, 0x0d000073, 0x0d0000d7, 0x284201d7, 0x0000789b, 0x45741900, 0x6f537458, 0x61777466, 0x77006572, 0x692e7777, 0x63736b6e, 8 | 0x2e657061, 0x9b67726f, 0x001a3cee, 0x499d0800, 0x78544144, 0x6d9ded9c, 0x1d451e8c, 0x97db7fc0, 0x2223116b, 0x31115114, 0x055cc2f8, 0x930f5da9, 9 | 0x16c5a486, 0x1101b044, 0x80944d4c, 0x7cb6bb49, 0xb410b150, 0x0631a0b1, 0xb628a349, 0xa1fac553, 0x8a4a870d, 0x68989ad4, 0x244289a4, 0xe848529d, 10 | 0x06aa04ad, 0x4adaa4a3, 0xb85f4978, 0x761fadeb, 0xfb77b42f, 0xff2fb73c, 0x9ddd9e7d, 0x767c7df9, 0x7bff3fe7, 0x73b377e6, 0x5e733b33, 0xec384514, 11 | 0x13bf4665, 0x2717f470, 0x0138e580, 0x6009c72c, 0xcb004e39, 0x8e580271, 0x9c72c013, 0x04e39600, 0x80271cb0, 0x2c0138e5, 0x396009c7, 0x71cb004e, 12 | 0x138e5802, 0xf56672c0, 0xe13a813b, 0x819be107, 0xff568cd3, 0x6f7d51ea, 0x6ff01403, 0xab461fe0, 0x619cbf9e, 0x107e00b5, 0x808602ce, 0xe032c0a5, 13 | 0xe011e012, 0xf4eb0afa, 0x8b813b81, 0x709d7781, 0x083f35e9, 0x19b6019f, 0x555c7ead, 0x6cf193fd, 0x0fc8237b, 0x37120fc2, 0x096052f6, 0xb74996f0, 14 | 0x699c02bc, 0xae151ab4, 0x0df01677, 0xffd31d60, 0x6e04ede2, 0x941d5a32, 0xd68d21cc, 0xe107e00b, 0x3d8dc459, 0x4e7e5bf1, 0x8ccb6286, 0xcc107f56, 15 | 0x077e03c1, 0xd8a39e5c, 0x4685c00b, 0xf2a457ab, 0x8f75a348, 0xdf083f00, 0xdc4a5c04, 0x0b80cbd8, 0x98672f01, 0x013101ab, 0x6be49580, 0x8173807c, 16 | 0x135f026f, 0x8d0a63cc, 0x20fc01ef, 0xe42c019c, 0x117d6e8d, 0xec325030, 0xfbd5a37e, 0xe006e6ca, 0xc039e107, 0x6a3ea63e, 0x5c0a30b2, 0xabfab464, 17 | 0x34692e44, 0x83f007b2, 0x68de7cf0, 0xd380cbf0, 0xdf38ab85, 0x840bc20f, 0x1495f8be, 0xd9807c6b, 0x15c0bdc0, 0xd2a47902, 0x3f0079b8, 0xe7818708, 18 | 0x75c04d81, 0x04fe37c8, 0x738a129f, 0x97f2c951, 0x01f841fb, 0x68524c91, 0xd754009c, 0x5ab993e0, 0x01594e28, 0xc40be600, 0x0289a548, 0x0afc0d3c, 19 | 0x0f7011f8, 0x22789db0, 0x7e459a45, 0xcd929610, 0xc0d9c20f, 0x0cb90279, 0xa548c40a, 0xa3006371, 0x3f93edd5, 0x14f083f3, 0x04f12d60, 0x7f11de4b, 20 | 0x57026627, 0x0d140f02, 0xf51ab460, 0xe005f083, 0x7173253d, 0x8c37403d, 0x568c4756, 0x2dbe02df, 0x40997a1c, 0x6205278c, 0x464031b8, 0x087604ee, 21 | 0x10205bc6, 0x8c40b763, 0x52310263, 0xc9009569, 0xc02dca62, 0x95485098, 0xb0cbc73c, 0x64b17811, 0xcb25038c, 0x0255a477, 0xfead1800, 0x142c3c09, 22 | 0x0392806e, 0xcbd5a330, 0xe19652c4, 0x77cb253f, 0x240275a4, 0xeb182bdc, 0x180365c3, 0xbf03b6ad, 0xf5c2112e, 0x5a307900, 0x4dfc063d, 0x42c5dc28, 23 | 0x5e216e71, 0x15422c69, 0x2d02e67f, 0x8f612015, 0x3dd29c50, 0x92f24000, 0x8b051dc9, 0x872259ff, 0xc02cda34, 0x2238a15e, 0x066c2402, 0x79967246, 24 | 0x4fb568d1, 0x70938730, 0x19cf4c02, 0x695e8ac9, 0x81c7568c, 0xd3591329, 0xba897bf0, 0xc804e13b, 0x0038d486, 0x604ed5a3, 0x4e228e57, 0xad182280, 25 | 0x7837200e, 0x000c7c92, 0xbef19fdc, 0xa5009c51, 0x0038e3a8, 0xf78ca9e0, 0x5722270d, 0x1b201386, 0xcf71abd2, 0x6ef4fd32, 0xb84f7c04, 0x5db429de, 26 | 0xe2856780, 0x0e2853bc, 0x31ab4600, 0x07bdba60, 0xf472adbf, 0x05db413f, 0x9c031a90, 0x5ce107ee, 0x1b1358a1, 0xe69bce50, 0xeaa5bbb6, 0x05db46eb, 27 | 0x73e1dc90, 0x85ac60b6, 0x1feeff74, 0x36555a33, 0x6d2273f9, 0x0a724017, 0xb1821df5, 0x2d72e92e, 0xac156e02, 0x16ad2bab, 0x2af568c0, 0x3850aaf0, 28 | 0x50c071c9, 0x8c5b6b97, 0xd6084f56, 0x0b5695d5, 0x0bd52090, 0x7e00f488, 0x7c069e10, 0x97e5c3bc, 0x505ebe28, 0x76402708, 0x6b011ea4, 0xb876b781, 29 | 0xf568ceb6, 0x327aa15f, 0x52008361, 0x02d2c103, 0xbf14fb24, 0x53f2e1dc, 0x3d458bc4, 0xea0106c5, 0x1d7c03d4, 0xf3e53538, 0x2c935808, 0x1b14f516, 30 | 0x0f45a804, 0xb9e107e0, 0xf2e1d040, 0xe3d5a306, 0xc517e265, 0xd2ea0106, 0xe607ac03, 0x886e7ca4, 0xe0be867b, 0xbccec804, 0xdc8790e4, 0x49f841f8, 31 | 0x4b94a6e0, 0xa42b01af, 0x83c8a30f, 0x3d48020d, 0xace03c02, 0x20fc85bc, 0x8db02f7c, 0xab4b1df4, 0x97cf568d, 0x360cac4d, 0x67f92008, 0xae00da55, 32 | 0xb596c923, 0x686fa4ed, 0xdab466dd, 0x0955922a, 0xd1802f5a, 0x352030ea, 0xf07bceba, 0xdfd226c4, 0xac0fda26, 0x794e9f2e, 0x82402f5a, 0x993b39d4, 33 | 0x41f90977, 0x76370018, 0x64bae5c8, 0xd8efba9a, 0x97d48022, 0xf007a99d, 0xf4887083, 0x03af29cd, 0x9ead1ad7, 0x34a7ca16, 0xd52008b6, 0x802b4c03, 34 | 0x80f3841f, 0x8dee5287, 0x568d1b80, 0x45ca147f, 0x3e402704, 0x07e00aba, 0xfbc4a9e1, 0x729ddf12, 0xd5a356f9, 0x88794283, 0x47c804e1, 0x11920147, 35 | 0x53e24eff, 0xc1b326ca, 0xa17df568, 0x45b1441c, 0x00c74a80, 0x3b62ebc9, 0x9729c580, 0x015e201f, 0x08b625ac, 0xe00f5950, 0xe21ce107, 0xca697f6e, 36 | 0x2f815bfd, 0xe810e3f4, 0xf20138ac, 0x7e009271, 0x0f100e10, 0x72913ef8, 0xf41e26af, 0x2f857cf5, 0x243b8d0f, 0x8fe220aa, 0xe05d6480, 0x271fa417, 37 | 0xead18f77, 0x2b3aa136, 0xf900f5c5, 0x83f00018, 0x0c302670, 0xcf72935c, 0x3e34a6fa, 0x8803d3d8, 0xfe349009, 0x2933e056, 0xd75abfd7, 0x9c277ed1, 38 | 0x0b98f900, 0x31581cfc, 0x2071f3e9, 0x54fd5a30, 0x619e9ea8, 0x6352008b, 0x7980db80, 0x231b3e93, 0x0b0fe91e, 0x6c53d1d5, 0x07aa4011, 0xc7f8dc98, 39 | 0xad1acf80, 0xdf8a111e, 0xc5009c73, 0x635c0c39, 0xff74aab4, 0x0138d57e, 0x7032f18a, 0x591a7255, 0x0045b1a3, 0x43f7b5c9, 0x2b4615c0, 0xfac853a9, 40 | 0xc8079b8a, 0x4581dfc7, 0xb07c696d, 0xade48044, 0xc325a3db, 0x663e06ec, 0x743a92b4, 0x215816a2, 0x5e994240, 0xd8b00760, 0x99d95568, 0x26c2fdbd, 41 | 0x038e8a01, 0x8d7e23ee, 0x3264b0eb, 0x4196c175, 0x01efe420, 0xd1ad6022, 0xc915436a, 0x049b05d4, 0x7b2cb3c8, 0xd1bcf814, 0x92aaa1ea, 0x09360ba9, 42 | 0xfe9df590, 0x7ef2c043, 0x35ecd66d, 0xd993804e, 0xb4695c0f, 0x64eaae7a, 0x834d82ea, 0xf804e9c0, 0x799ff10b, 0xd83e34d6, 0xd6da4025, 0x03b609ec, 43 | 0xdfe2f597, 0x9b0dd7b5, 0x03d4e804, 0xdeb800fc, 0x97a47568, 0x9b05d4c9, 0xc0e300c7, 0x3f568c57, 0x753247ec, 0x8e0156c1, 0x5a339f00, 0x4e47f995, 44 | 0x0126c0ad, 0x3817e222, 0xee9f010e, 0x758c61e5, 0xdaa28bc6, 0xf47059ee, 0x81069b00, 0x009c148e, 0xb004e396, 0xe580271c, 0xc72c0138, 0x4e396009, 45 | 0x0271cb00, 0x052b4e58, 0x2ed77258, 0x4b38669b, 0xc0999ad1, 0x591eae8f, 0xcb7b8d1e, 0x9a21f3c1, 0x0c041c0f, 0xc607bb78, 0xfc7befc6, 0xf5ffc1fe, 46 | 0xd23ac73b, 0xd6860178, 0x7e3d9c8c, 0x5c08dbdc, 0x03b6e5db, 0xf697c791, 0xf70f526c, 0x50a6af2a, 0x87bb805a, 0x70dd940f, 0x2bedca91, 0x3fed3ede, 47 | 0x84105c6a, 0x4f099fef, 0xf3187e90, 0xef88a214, 0xd6acd9ec, 0xaab7b965, 0x2c9a4b9f, 0x243753df, 0xdedd959e, 0xcf0ca9b4, 0x8ab85bc3, 0xf1b1919f, 48 | 0xf8773293, 0x637e46ab, 0x59660f36, 0xcfcbec09, 0x3b1a6bd5, 0xcac8fc08, 0x69703570, 0xf03362ce, 0xba1f2dbc, 0xa9ef2461, 0xb1a5addf, 0x371e7802, 49 | 0x383a2c17, 0xffaecce7, 0x1a2ad3b9, 0x6abf8029, 0x7e606ccf, 0x71def2d1, 0xd3a60816, 0xc0291a68, 0x907737b8, 0xcf68cf32, 0x23413009, 0xd1c87005, 50 | 0x44660148, 0xdf884747, 0xc4462bef, 0x9a6cb95e, 0x3005234d, 0x028e179b, 0x8f968afb, 0x26013a66, 0x0000a468, 0x8296c451, 0x1d8e4745, 0x9c11bdc4, 51 | 0x9e0158d0, 0x08da89fc, 0xb16729fc, 0xe6e8a271, 0xf8397e67, 0x3539157a, 0x100ac691, 0xe1c74445, 0x394bc08b, 0xe3377cca, 0x9435a02c, 0x7a3e0a9e, 52 | 0x1229c8ec, 0xaf611489, 0xad0dcf56, 0xbccc1919, 0x2fb3a418, 0xe7f3f506, 0x5f8d25ea, 0x2dc09c0d, 0x35a31707, 0x92c89c02, 0x7acd76bb, 0xb1e2fd74, 53 | 0x04d1e77e, 0x2380295a, 0x041d8d3b, 0x0270643a, 0xc0138e58, 0x96009c72, 0x1cb004e3, 0x38e58027, 0x09c72c01, 0x004e3960, 0x580271cb, 0x72c0138e, 54 | 0xe396009c, 0x271cb004, 0x1ffce580, 0x722fcefa, 0x8e0b05c9, 0x00000000, 0x444e4549, 0x826042ae, 55 | }; 56 | 57 | -------------------------------------------------------------------------------- /src/framebuffer.h: -------------------------------------------------------------------------------- 1 | struct framebuffer_t 2 | { 3 | GLuint fbo; // usage: glBindFramebuffer(GL_FRAMEBUFFER, fbo) 4 | GLuint *color; // usage: glBindTexture(GL_TEXTURE_2D, color[i]) 5 | GLuint depth; 6 | int width, height; // usage: glViewport(0, 0, width, height) 7 | int num_color_attachments; 8 | GLint last_viewport[4]; 9 | framebuffer_t *last_framebuffer; 10 | 11 | GLenum internal_format; 12 | }; 13 | 14 | static framebuffer_t *current_framebuffer = NULL; 15 | 16 | static void EnableFramebuffer(framebuffer_t *fb) 17 | { 18 | fb->last_framebuffer = current_framebuffer; 19 | glGetIntegerv(GL_VIEWPORT, fb->last_viewport); 20 | glBindFramebuffer(GL_FRAMEBUFFER, fb->fbo); 21 | vdbViewporti(0, 0, fb->width, fb->height); 22 | current_framebuffer = fb; 23 | } 24 | 25 | static void DisableFramebuffer(framebuffer_t *fb) 26 | { 27 | current_framebuffer = fb->last_framebuffer; 28 | if (current_framebuffer) glBindFramebuffer(GL_FRAMEBUFFER, current_framebuffer->fbo); 29 | else glBindFramebuffer(GL_FRAMEBUFFER, 0); 30 | vdbViewporti(fb->last_viewport[0], fb->last_viewport[1], fb->last_viewport[2], fb->last_viewport[3]); 31 | } 32 | 33 | static void FreeFramebuffer(framebuffer_t *fb) 34 | { 35 | if (fb->fbo) glDeleteFramebuffers(1, &fb->fbo); 36 | if (fb->depth) glDeleteRenderbuffers(1, &fb->depth); 37 | if (fb->color) 38 | { 39 | for (int i = 0; i < fb->num_color_attachments; i++) 40 | glDeleteTextures(1, &fb->color[i]); 41 | free(fb->color); 42 | fb->color = NULL; 43 | } 44 | fb->num_color_attachments = 0; 45 | fb->width = 0; 46 | fb->height = 0; 47 | fb->fbo = 0; 48 | fb->depth = 0; 49 | } 50 | 51 | static framebuffer_t MakeFramebuffer( 52 | int width, int height, 53 | GLenum mag_filter=GL_LINEAR, 54 | GLenum min_filter=GL_LINEAR, 55 | bool enable_depth=false, 56 | GLenum internal_format=GL_RGBA, 57 | int num_color_attachments = 1) 58 | { 59 | static GLint max_color_attachments = 0; 60 | if (!max_color_attachments) 61 | glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &max_color_attachments); 62 | assert(num_color_attachments <= max_color_attachments && "Number of requested color attachments exceeds device capabilities"); 63 | 64 | framebuffer_t result = {0}; 65 | result.width = width; 66 | result.height = height; 67 | result.num_color_attachments = num_color_attachments; 68 | 69 | glGenFramebuffers(1, &result.fbo); 70 | glBindFramebuffer(GL_FRAMEBUFFER, result.fbo); 71 | 72 | result.color = new GLuint[num_color_attachments]; 73 | for (int i = 0; i < num_color_attachments; i++) 74 | { 75 | GLuint color = TexImage2D(NULL, width, height, GL_RGBA, GL_UNSIGNED_BYTE, 76 | mag_filter, min_filter, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, 77 | internal_format); 78 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, color, 0); 79 | result.color[i] = color; 80 | result.internal_format = internal_format; 81 | } 82 | 83 | if (enable_depth) 84 | { 85 | // DEPTH_COMPONENT16 86 | // DEPTH_COMPONENT24 87 | // DEPTH_COMPONENT32 88 | // DEPTH_COMPONENT32F 89 | result.depth = TexImage2D(NULL, width, height, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, GL_NEAREST, GL_NEAREST, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_DEPTH_COMPONENT24); 90 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, result.depth, 0); 91 | } 92 | 93 | GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); 94 | assert(status == GL_FRAMEBUFFER_COMPLETE); 95 | glBindFramebuffer(GL_FRAMEBUFFER, 0); 96 | 97 | return result; 98 | } 99 | -------------------------------------------------------------------------------- /src/framegrab.h: -------------------------------------------------------------------------------- 1 | struct framegrab_options_t 2 | { 3 | const char *filename; // If no extension is provided, file will be saved as .bmp. 4 | // If %d is present, it will be filled with screenshot counter 5 | 6 | bool alpha_channel; 7 | bool draw_imgui; // If disabled ImGui will not render at all (including overlays) 8 | bool draw_cursor; // If draw_imgui is false the cursor is a crosshair 9 | 10 | bool reset_counter; // Reset screenshot or image sequence counter 11 | int start_from; // Set initial screenshot or image sequence counter 12 | 13 | float ffmpeg_fps; 14 | int ffmpeg_crf; // Quality (lower is better) 15 | int video_frame_cap; // Stop after capturing this number of frames (0 -> no limit, call StopRecording to stop) 16 | }; 17 | 18 | #ifdef _MSC_VER 19 | #define popen _popen 20 | #define pclose _pclose 21 | #endif 22 | 23 | namespace framegrab 24 | { 25 | enum framegrab_mode_t { MODE_SCREENSHOT, MODE_SEQUENCE, MODE_FFMPEG }; 26 | static framegrab_options_t options; 27 | static framegrab_mode_t mode; 28 | static bool active; 29 | static int num_frames; 30 | static int suffix_counter; 31 | static bool should_stop; 32 | 33 | static void StopRecording() 34 | { 35 | should_stop = true; 36 | } 37 | 38 | static void StartFramegrab(framegrab_options_t _options) 39 | { 40 | options = _options; 41 | if (options.reset_counter) 42 | suffix_counter = options.start_from; 43 | num_frames = 0; 44 | active = true; 45 | should_stop = false; 46 | } 47 | 48 | static void TakeScreenshot(framegrab_options_t _options) 49 | // Save the back framebuffer of the current frame to file. 50 | { 51 | mode = MODE_SCREENSHOT; 52 | StartFramegrab(_options); 53 | } 54 | 55 | static void RecordImageSequence(framegrab_options_t _options) 56 | // Save the back framebuffer of the current and each subsequent frame to file. 57 | { 58 | mode = MODE_SEQUENCE; 59 | StartFramegrab(_options); 60 | } 61 | 62 | static void RecordFFmpeg(framegrab_options_t _options) 63 | // Pipe the back framebuffer of the current and each subsequent frame to ffmpeg. 64 | // The function uses _popen to open a pipe, and assumes that the ffmpeg executable is present on the 65 | // terminal that the application ran from (in the PATH variable). If you're on Windows, you will want 66 | // to change your PATH environment variable to point to the folder holding the ffmpeg executable. 67 | { 68 | mode = MODE_FFMPEG; 69 | StartFramegrab(_options); 70 | } 71 | 72 | static void SaveFrame(unsigned char *data, 73 | int width, 74 | int height, 75 | int channels, 76 | GLenum format) 77 | { 78 | if (mode == MODE_FFMPEG) 79 | { 80 | static FILE *ffmpeg = 0; 81 | if (!ffmpeg) 82 | { 83 | // todo: linux/osx 84 | char cmd[1024]; 85 | sprintf(cmd, "ffmpeg -r %f -f rawvideo -pix_fmt %s -s %dx%d -i - " 86 | "-threads 0 -preset fast -y -pix_fmt yuv420p -crf %d -vf vflip %s", 87 | options.ffmpeg_fps, // -r 88 | options.alpha_channel ? "rgba" : "rgb24", // -pix_fmt 89 | width, height, // -s 90 | options.ffmpeg_crf, // -crf 91 | options.filename); 92 | ffmpeg = popen(cmd, "wb"); 93 | } 94 | 95 | fwrite(data, width*height*channels, 1, ffmpeg); 96 | 97 | num_frames++; 98 | if (options.video_frame_cap && num_frames == options.video_frame_cap) 99 | { 100 | StopRecording(); 101 | } 102 | if (should_stop) 103 | { 104 | active = false; 105 | pclose(ffmpeg); 106 | ffmpeg = 0; 107 | } 108 | } 109 | else 110 | { 111 | bool save_as_bmp = false; 112 | bool save_as_png = false; 113 | 114 | if (strstr(options.filename, ".png")) 115 | { 116 | save_as_png = true; 117 | save_as_bmp = false; 118 | } 119 | else if (strstr(options.filename, ".bmp")) 120 | { 121 | save_as_bmp = true; 122 | save_as_png = false; 123 | } 124 | else 125 | { 126 | save_as_bmp = false; 127 | save_as_png = false; 128 | // did user specify any extension at all? 129 | } 130 | 131 | // todo: what happens if filename doesn't contain a %d? 132 | char filename[1024]; 133 | sprintf(filename, options.filename, suffix_counter); 134 | suffix_counter++; 135 | 136 | if (save_as_bmp) 137 | { 138 | stbi_write_bmp(filename, width, height, channels, data); 139 | printf("Saved %s...\n", filename); 140 | } 141 | else if (save_as_png) 142 | { 143 | int stride = width*channels; 144 | stbi_write_png(filename, width, height, channels, data+stride*(height-1), -stride); 145 | printf("Saved %s...\n", filename); 146 | } 147 | else 148 | { 149 | stbi_write_bmp(filename, width, height, channels, data); 150 | printf("Saved %s (bmp)...\n", filename); 151 | } 152 | 153 | if (mode == MODE_SEQUENCE) 154 | { 155 | num_frames++; 156 | if (options.video_frame_cap > 0 && num_frames == options.video_frame_cap) 157 | { 158 | StopRecording(); 159 | } 160 | if (should_stop) 161 | { 162 | active = false; 163 | } 164 | } 165 | else 166 | { 167 | active = false; 168 | } 169 | } 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /src/freetype.h: -------------------------------------------------------------------------------- 1 | // Obs! When copying latest version of ImGui into VDB, you need to disable 2 | // freetype includes in imgui_freetype.cpp in the unity build. 3 | 4 | // Obs! This file must be included before ImGui that uses freetype functions 5 | // because we redefine them. This is so that we don't have to change the ImGui 6 | // source code to use differently named functions (allow for easy updates). 7 | #if VDB_IMGUI_FREETYPE_DYNAMIC==1 8 | #include 9 | #include FT_FREETYPE_H 10 | #include FT_GLYPH_H 11 | #include FT_SYNTHESIS_H 12 | #include FT_MODULE_H 13 | typedef FT_Error (*PFNFTNEWLIBRARY)(FT_Memory memory, FT_Library *alibrary); 14 | typedef FT_Error (*PFNFTDONELIBRARY)(FT_Library library); 15 | typedef void (*PFNFTADDDEFAULTMODULES)(FT_Library library); 16 | typedef FT_Error (*PFNFTINITFREETYPE)(FT_Library *alibrary); 17 | typedef FT_Error (*PFNFTRENDERGLYPH)(FT_GlyphSlot slot, FT_Render_Mode render_mode); 18 | typedef FT_Error (*PFNFTNEWMEMORYFACE)(FT_Library library, const FT_Byte* file_base, FT_Long file_size, FT_Long face_index, FT_Face *aface); 19 | typedef FT_Error (*PFNFTSELECTCHARMAP)(FT_Face face, FT_Encoding encoding); 20 | typedef FT_Error (*PFNFTDONEFACE)(FT_Face face); 21 | typedef FT_Error (*PFNFTDONEFREETYPE)(FT_Library library); 22 | typedef FT_Error (*PFNFTREQUESTSIZE)(FT_Face face, FT_Size_Request req); 23 | typedef FT_UInt (*PFNFTGETCHARINDEX)(FT_Face face, FT_ULong charcode); 24 | typedef FT_Error (*PFNFTLOADGLYPH)(FT_Face face, FT_UInt glyph_index, FT_Int32 load_flags); 25 | typedef void (*PFNFTGLYPHSLOTEMBOLDEN)(FT_GlyphSlot slot); 26 | typedef void (*PFNFTGLYPHSLOTOBLIQUE)(FT_GlyphSlot slot); 27 | typedef FT_Error (*PFNFTGETGLYPH)(FT_GlyphSlot slot, FT_Glyph *aglyph); 28 | typedef FT_Error (*PFNFTGLYPHTOBITMAP)(FT_Glyph* the_glyph, FT_Render_Mode render_mode, FT_Vector* origin, FT_Bool destroy); 29 | typedef void (*PFNFTDONEGLYPH)(FT_Glyph glyph); 30 | PFNFTNEWLIBRARY VDB_FT_New_Library; 31 | PFNFTDONELIBRARY VDB_FT_Done_Library; 32 | PFNFTADDDEFAULTMODULES VDB_FT_Add_Default_Modules; 33 | PFNFTINITFREETYPE VDB_FT_Init_FreeType; 34 | PFNFTRENDERGLYPH VDB_FT_Render_Glyph; 35 | PFNFTNEWMEMORYFACE VDB_FT_New_Memory_Face; 36 | PFNFTSELECTCHARMAP VDB_FT_Select_Charmap; 37 | PFNFTDONEFACE VDB_FT_Done_Face; 38 | PFNFTDONEFREETYPE VDB_FT_Done_FreeType; 39 | PFNFTREQUESTSIZE VDB_FT_Request_Size; 40 | PFNFTGETCHARINDEX VDB_FT_Get_Char_Index; 41 | PFNFTLOADGLYPH VDB_FT_Load_Glyph; 42 | PFNFTGLYPHSLOTEMBOLDEN VDB_FT_GlyphSlot_Embolden; 43 | PFNFTGLYPHSLOTOBLIQUE VDB_FT_GlyphSlot_Oblique; 44 | PFNFTGETGLYPH VDB_FT_Get_Glyph; 45 | PFNFTGLYPHTOBITMAP VDB_FT_Glyph_To_Bitmap; 46 | PFNFTDONEGLYPH VDB_FT_Done_Glyph; 47 | #define FT_New_Library VDB_FT_New_Library 48 | #define FT_Done_Library VDB_FT_Done_Library 49 | #define FT_Add_Default_Modules VDB_FT_Add_Default_Modules 50 | #define FT_Init_FreeType VDB_FT_Init_FreeType 51 | #define FT_Render_Glyph VDB_FT_Render_Glyph 52 | #define FT_New_Memory_Face VDB_FT_New_Memory_Face 53 | #define FT_Select_Charmap VDB_FT_Select_Charmap 54 | #define FT_Done_Face VDB_FT_Done_Face 55 | #define FT_Done_FreeType VDB_FT_Done_FreeType 56 | #define FT_Request_Size VDB_FT_Request_Size 57 | #define FT_Get_Char_Index VDB_FT_Get_Char_Index 58 | #define FT_Load_Glyph VDB_FT_Load_Glyph 59 | #define FT_GlyphSlot_Embolden VDB_FT_GlyphSlot_Embolden 60 | #define FT_GlyphSlot_Oblique VDB_FT_GlyphSlot_Oblique 61 | #define FT_Get_Glyph VDB_FT_Get_Glyph 62 | #define FT_Glyph_To_Bitmap VDB_FT_Glyph_To_Bitmap 63 | #define FT_Done_Glyph VDB_FT_Done_Glyph 64 | #endif 65 | 66 | #include "imgui/imgui_freetype.cpp" 67 | 68 | bool TryLoadFreetype() 69 | { 70 | static bool ok = false; 71 | static bool have_tried = false; 72 | if (have_tried) 73 | return ok; 74 | have_tried = true; 75 | 76 | static void *freetype = SDL_LoadObject("freetype.dll"); 77 | if (freetype) 78 | { 79 | ok = true; 80 | FT_New_Library = (PFNFTNEWLIBRARY) SDL_LoadFunction(freetype, "FT_New_Library"); 81 | FT_Done_Library = (PFNFTDONELIBRARY) SDL_LoadFunction(freetype, "FT_Done_Library"); 82 | FT_Add_Default_Modules = (PFNFTADDDEFAULTMODULES) SDL_LoadFunction(freetype, "FT_Add_Default_Modules"); 83 | FT_Init_FreeType = (PFNFTINITFREETYPE) SDL_LoadFunction(freetype, "FT_Init_FreeType"); if (!VDB_FT_Init_FreeType) ok = false; 84 | FT_Render_Glyph = (PFNFTRENDERGLYPH) SDL_LoadFunction(freetype, "FT_Render_Glyph"); if (!VDB_FT_Render_Glyph) ok = false; 85 | FT_New_Memory_Face = (PFNFTNEWMEMORYFACE) SDL_LoadFunction(freetype, "FT_New_Memory_Face"); if (!VDB_FT_New_Memory_Face) ok = false; 86 | FT_Select_Charmap = (PFNFTSELECTCHARMAP) SDL_LoadFunction(freetype, "FT_Select_Charmap"); if (!VDB_FT_Select_Charmap) ok = false; 87 | FT_Done_Face = (PFNFTDONEFACE) SDL_LoadFunction(freetype, "FT_Done_Face"); if (!VDB_FT_Done_Face) ok = false; 88 | FT_Done_FreeType = (PFNFTDONEFREETYPE) SDL_LoadFunction(freetype, "FT_Done_FreeType"); if (!VDB_FT_Done_FreeType) ok = false; 89 | FT_Request_Size = (PFNFTREQUESTSIZE) SDL_LoadFunction(freetype, "FT_Request_Size"); if (!VDB_FT_Request_Size) ok = false; 90 | FT_Get_Char_Index = (PFNFTGETCHARINDEX) SDL_LoadFunction(freetype, "FT_Get_Char_Index"); if (!VDB_FT_Get_Char_Index) ok = false; 91 | FT_Load_Glyph = (PFNFTLOADGLYPH) SDL_LoadFunction(freetype, "FT_Load_Glyph"); if (!VDB_FT_Load_Glyph) ok = false; 92 | FT_GlyphSlot_Embolden = (PFNFTGLYPHSLOTEMBOLDEN) SDL_LoadFunction(freetype, "FT_GlyphSlot_Embolden"); if (!VDB_FT_GlyphSlot_Embolden) ok = false; 93 | FT_GlyphSlot_Oblique = (PFNFTGLYPHSLOTOBLIQUE) SDL_LoadFunction(freetype, "FT_GlyphSlot_Oblique"); if (!VDB_FT_GlyphSlot_Oblique) ok = false; 94 | FT_Get_Glyph = (PFNFTGETGLYPH) SDL_LoadFunction(freetype, "FT_Get_Glyph"); if (!VDB_FT_Get_Glyph) ok = false; 95 | FT_Glyph_To_Bitmap = (PFNFTGLYPHTOBITMAP) SDL_LoadFunction(freetype, "FT_Glyph_To_Bitmap"); if (!VDB_FT_Glyph_To_Bitmap) ok = false; 96 | FT_Done_Glyph = (PFNFTDONEGLYPH) SDL_LoadFunction(freetype, "FT_Done_Glyph"); if (!VDB_FT_Done_Glyph) ok = false; 97 | } 98 | return ok; 99 | } 100 | -------------------------------------------------------------------------------- /src/freetype/FTL.TXT: -------------------------------------------------------------------------------- 1 | The FreeType Project LICENSE 2 | ---------------------------- 3 | 4 | 2006-Jan-27 5 | 6 | Copyright 1996-2002, 2006 by 7 | David Turner, Robert Wilhelm, and Werner Lemberg 8 | 9 | 10 | 11 | Introduction 12 | ============ 13 | 14 | The FreeType Project is distributed in several archive packages; 15 | some of them may contain, in addition to the FreeType font engine, 16 | various tools and contributions which rely on, or relate to, the 17 | FreeType Project. 18 | 19 | This license applies to all files found in such packages, and 20 | which do not fall under their own explicit license. The license 21 | affects thus the FreeType font engine, the test programs, 22 | documentation and makefiles, at the very least. 23 | 24 | This license was inspired by the BSD, Artistic, and IJG 25 | (Independent JPEG Group) licenses, which all encourage inclusion 26 | and use of free software in commercial and freeware products 27 | alike. As a consequence, its main points are that: 28 | 29 | o We don't promise that this software works. However, we will be 30 | interested in any kind of bug reports. (`as is' distribution) 31 | 32 | o You can use this software for whatever you want, in parts or 33 | full form, without having to pay us. (`royalty-free' usage) 34 | 35 | o You may not pretend that you wrote this software. If you use 36 | it, or only parts of it, in a program, you must acknowledge 37 | somewhere in your documentation that you have used the 38 | FreeType code. (`credits') 39 | 40 | We specifically permit and encourage the inclusion of this 41 | software, with or without modifications, in commercial products. 42 | We disclaim all warranties covering The FreeType Project and 43 | assume no liability related to The FreeType Project. 44 | 45 | 46 | Finally, many people asked us for a preferred form for a 47 | credit/disclaimer to use in compliance with this license. We thus 48 | encourage you to use the following text: 49 | 50 | """ 51 | Portions of this software are copyright © The FreeType 52 | Project (www.freetype.org). All rights reserved. 53 | """ 54 | 55 | Please replace with the value from the FreeType version you 56 | actually use. 57 | 58 | 59 | Legal Terms 60 | =========== 61 | 62 | 0. Definitions 63 | -------------- 64 | 65 | Throughout this license, the terms `package', `FreeType Project', 66 | and `FreeType archive' refer to the set of files originally 67 | distributed by the authors (David Turner, Robert Wilhelm, and 68 | Werner Lemberg) as the `FreeType Project', be they named as alpha, 69 | beta or final release. 70 | 71 | `You' refers to the licensee, or person using the project, where 72 | `using' is a generic term including compiling the project's source 73 | code as well as linking it to form a `program' or `executable'. 74 | This program is referred to as `a program using the FreeType 75 | engine'. 76 | 77 | This license applies to all files distributed in the original 78 | FreeType Project, including all source code, binaries and 79 | documentation, unless otherwise stated in the file in its 80 | original, unmodified form as distributed in the original archive. 81 | If you are unsure whether or not a particular file is covered by 82 | this license, you must contact us to verify this. 83 | 84 | The FreeType Project is copyright (C) 1996-2000 by David Turner, 85 | Robert Wilhelm, and Werner Lemberg. All rights reserved except as 86 | specified below. 87 | 88 | 1. No Warranty 89 | -------------- 90 | 91 | THE FREETYPE PROJECT IS PROVIDED `AS IS' WITHOUT WARRANTY OF ANY 92 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 93 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 94 | PURPOSE. IN NO EVENT WILL ANY OF THE AUTHORS OR COPYRIGHT HOLDERS 95 | BE LIABLE FOR ANY DAMAGES CAUSED BY THE USE OR THE INABILITY TO 96 | USE, OF THE FREETYPE PROJECT. 97 | 98 | 2. Redistribution 99 | ----------------- 100 | 101 | This license grants a worldwide, royalty-free, perpetual and 102 | irrevocable right and license to use, execute, perform, compile, 103 | display, copy, create derivative works of, distribute and 104 | sublicense the FreeType Project (in both source and object code 105 | forms) and derivative works thereof for any purpose; and to 106 | authorize others to exercise some or all of the rights granted 107 | herein, subject to the following conditions: 108 | 109 | o Redistribution of source code must retain this license file 110 | (`FTL.TXT') unaltered; any additions, deletions or changes to 111 | the original files must be clearly indicated in accompanying 112 | documentation. The copyright notices of the unaltered, 113 | original files must be preserved in all copies of source 114 | files. 115 | 116 | o Redistribution in binary form must provide a disclaimer that 117 | states that the software is based in part of the work of the 118 | FreeType Team, in the distribution documentation. We also 119 | encourage you to put an URL to the FreeType web page in your 120 | documentation, though this isn't mandatory. 121 | 122 | These conditions apply to any software derived from or based on 123 | the FreeType Project, not just the unmodified files. If you use 124 | our work, you must acknowledge us. However, no fee need be paid 125 | to us. 126 | 127 | 3. Advertising 128 | -------------- 129 | 130 | Neither the FreeType authors and contributors nor you shall use 131 | the name of the other for commercial, advertising, or promotional 132 | purposes without specific prior written permission. 133 | 134 | We suggest, but do not require, that you use one or more of the 135 | following phrases to refer to this software in your documentation 136 | or advertising materials: `FreeType Project', `FreeType Engine', 137 | `FreeType library', or `FreeType Distribution'. 138 | 139 | As you have not signed this license, you are not required to 140 | accept it. However, as the FreeType Project is copyrighted 141 | material, only this license, or another one contracted with the 142 | authors, grants you the right to use, distribute, and modify it. 143 | Therefore, by using, distributing, or modifying the FreeType 144 | Project, you indicate that you understand and accept all the terms 145 | of this license. 146 | 147 | 4. Contacts 148 | ----------- 149 | 150 | There are two mailing lists related to FreeType: 151 | 152 | o freetype@nongnu.org 153 | 154 | Discusses general use and applications of FreeType, as well as 155 | future and wanted additions to the library and distribution. 156 | If you are looking for support, start in this list if you 157 | haven't found anything to help you in the documentation. 158 | 159 | o freetype-devel@nongnu.org 160 | 161 | Discusses bugs, as well as engine internals, design issues, 162 | specific licenses, porting, etc. 163 | 164 | Our home page can be found at 165 | 166 | https://www.freetype.org 167 | 168 | 169 | --- end of FTL.TXT --- 170 | -------------------------------------------------------------------------------- /src/freetype/LICENSE.TXT: -------------------------------------------------------------------------------- 1 | 2 | The FreeType 2 font engine is copyrighted work and cannot be used 3 | legally without a software license. In order to make this project 4 | usable to a vast majority of developers, we distribute it under two 5 | mutually exclusive open-source licenses. 6 | 7 | This means that *you* must choose *one* of the two licenses described 8 | below, then obey all its terms and conditions when using FreeType 2 in 9 | any of your projects or products. 10 | 11 | - The FreeType License, found in the file `FTL.TXT', which is similar 12 | to the original BSD license *with* an advertising clause that forces 13 | you to explicitly cite the FreeType project in your product's 14 | documentation. All details are in the license file. This license 15 | is suited to products which don't use the GNU General Public 16 | License. 17 | 18 | Note that this license is compatible to the GNU General Public 19 | License version 3, but not version 2. 20 | 21 | - The GNU General Public License version 2, found in `GPLv2.TXT' (any 22 | later version can be used also), for programs which already use the 23 | GPL. Note that the FTL is incompatible with GPLv2 due to its 24 | advertisement clause. 25 | 26 | The contributed BDF and PCF drivers come with a license similar to that 27 | of the X Window System. It is compatible to the above two licenses (see 28 | file src/bdf/README and src/pcf/README). The same holds for the files 29 | `fthash.c' and `fthash.h'; their code was part of the BDF driver in 30 | earlier FreeType versions. 31 | 32 | The gzip module uses the zlib license (see src/gzip/zlib.h) which too is 33 | compatible to the above two licenses. 34 | 35 | The MD5 checksum support (only used for debugging in development builds) 36 | is in the public domain. 37 | 38 | 39 | --- end of LICENSE.TXT --- 40 | -------------------------------------------------------------------------------- /src/freetype/README.md: -------------------------------------------------------------------------------- 1 | FreeType 2.9.1 2 | ========================= 3 | ###### Windows binaries (DLL) of FreeType (win32/win64) 4 | 5 | Compiled with VS Express 2015 6 | Compatible with Windows XP, Vista, 7, 8, 10 7 | 8 | > *freetype.dll* uses the *Universal CRT* and therefore **_requires_** Visual C++ 2017 Redistributable to be present on system (*VC++ 2017 Redistributable supersedes VC++ 2015 Redistributable*). 9 | 10 | | filename | sha256 | 11 | | :-- | :-- | 12 | | win32\\**freetype.dll** | `50BE9F0AAE77ED3419088168A3EE67FDF2A1C2B33A89D46548062B636B1EE893` | 13 | | win32\\**freetype.lib** | `184A993AD300F8CE39D48C0500CD0F34BB44C7DDAFDB22F8C1049F5031D4F6BF` | 14 | | win64\\**freetype.dll** | `8B0F1E91E80D441869169A3E9D924BAAFB2203A04CB90D1A11AC7ED22C81A24E` | 15 | | win64\\**freetype.lib** | `81C9050FE6C1A02D176131E45A37CC994AF027F94853EEAFFA06BB087ECCBF0A` | 16 | -------------------------------------------------------------------------------- /src/freetype/include/freetype/config/ftmodule.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file registers the FreeType modules compiled into the library. 3 | * 4 | * If you use GNU make, this file IS NOT USED! Instead, it is created in 5 | * the objects directory (normally `/objs/') based on information 6 | * from `/modules.cfg'. 7 | * 8 | * Please read `docs/INSTALL.ANY' and `docs/CUSTOMIZE' how to compile 9 | * FreeType without GNU make. 10 | * 11 | */ 12 | 13 | FT_USE_MODULE( FT_Module_Class, autofit_module_class ) 14 | FT_USE_MODULE( FT_Driver_ClassRec, tt_driver_class ) 15 | FT_USE_MODULE( FT_Driver_ClassRec, t1_driver_class ) 16 | FT_USE_MODULE( FT_Driver_ClassRec, cff_driver_class ) 17 | FT_USE_MODULE( FT_Driver_ClassRec, t1cid_driver_class ) 18 | FT_USE_MODULE( FT_Driver_ClassRec, pfr_driver_class ) 19 | FT_USE_MODULE( FT_Driver_ClassRec, t42_driver_class ) 20 | FT_USE_MODULE( FT_Driver_ClassRec, winfnt_driver_class ) 21 | FT_USE_MODULE( FT_Driver_ClassRec, pcf_driver_class ) 22 | FT_USE_MODULE( FT_Module_Class, psaux_module_class ) 23 | FT_USE_MODULE( FT_Module_Class, psnames_module_class ) 24 | FT_USE_MODULE( FT_Module_Class, pshinter_module_class ) 25 | FT_USE_MODULE( FT_Renderer_Class, ft_raster1_renderer_class ) 26 | FT_USE_MODULE( FT_Module_Class, sfnt_module_class ) 27 | FT_USE_MODULE( FT_Renderer_Class, ft_smooth_renderer_class ) 28 | FT_USE_MODULE( FT_Renderer_Class, ft_smooth_lcd_renderer_class ) 29 | FT_USE_MODULE( FT_Renderer_Class, ft_smooth_lcdv_renderer_class ) 30 | FT_USE_MODULE( FT_Driver_ClassRec, bdf_driver_class ) 31 | 32 | /* EOF */ 33 | -------------------------------------------------------------------------------- /src/freetype/include/freetype/config/ftstdlib.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************/ 2 | /* */ 3 | /* ftstdlib.h */ 4 | /* */ 5 | /* ANSI-specific library and header configuration file (specification */ 6 | /* only). */ 7 | /* */ 8 | /* Copyright 2002-2018 by */ 9 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 10 | /* */ 11 | /* This file is part of the FreeType project, and may only be used, */ 12 | /* modified, and distributed under the terms of the FreeType project */ 13 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 14 | /* this file you indicate that you have read the license and */ 15 | /* understand and accept it fully. */ 16 | /* */ 17 | /***************************************************************************/ 18 | 19 | 20 | /*************************************************************************/ 21 | /* */ 22 | /* This file is used to group all #includes to the ANSI C library that */ 23 | /* FreeType normally requires. It also defines macros to rename the */ 24 | /* standard functions within the FreeType source code. */ 25 | /* */ 26 | /* Load a file which defines FTSTDLIB_H_ before this one to override it. */ 27 | /* */ 28 | /*************************************************************************/ 29 | 30 | 31 | #ifndef FTSTDLIB_H_ 32 | #define FTSTDLIB_H_ 33 | 34 | 35 | #include 36 | 37 | #define ft_ptrdiff_t ptrdiff_t 38 | 39 | 40 | /**********************************************************************/ 41 | /* */ 42 | /* integer limits */ 43 | /* */ 44 | /* UINT_MAX and ULONG_MAX are used to automatically compute the size */ 45 | /* of `int' and `long' in bytes at compile-time. So far, this works */ 46 | /* for all platforms the library has been tested on. */ 47 | /* */ 48 | /* Note that on the extremely rare platforms that do not provide */ 49 | /* integer types that are _exactly_ 16 and 32 bits wide (e.g. some */ 50 | /* old Crays where `int' is 36 bits), we do not make any guarantee */ 51 | /* about the correct behaviour of FT2 with all fonts. */ 52 | /* */ 53 | /* In these case, `ftconfig.h' will refuse to compile anyway with a */ 54 | /* message like `couldn't find 32-bit type' or something similar. */ 55 | /* */ 56 | /**********************************************************************/ 57 | 58 | 59 | #include 60 | 61 | #define FT_CHAR_BIT CHAR_BIT 62 | #define FT_USHORT_MAX USHRT_MAX 63 | #define FT_INT_MAX INT_MAX 64 | #define FT_INT_MIN INT_MIN 65 | #define FT_UINT_MAX UINT_MAX 66 | #define FT_LONG_MIN LONG_MIN 67 | #define FT_LONG_MAX LONG_MAX 68 | #define FT_ULONG_MAX ULONG_MAX 69 | 70 | 71 | /**********************************************************************/ 72 | /* */ 73 | /* character and string processing */ 74 | /* */ 75 | /**********************************************************************/ 76 | 77 | 78 | #include 79 | 80 | #define ft_memchr memchr 81 | #define ft_memcmp memcmp 82 | #define ft_memcpy memcpy 83 | #define ft_memmove memmove 84 | #define ft_memset memset 85 | #define ft_strcat strcat 86 | #define ft_strcmp strcmp 87 | #define ft_strcpy strcpy 88 | #define ft_strlen strlen 89 | #define ft_strncmp strncmp 90 | #define ft_strncpy strncpy 91 | #define ft_strrchr strrchr 92 | #define ft_strstr strstr 93 | 94 | 95 | /**********************************************************************/ 96 | /* */ 97 | /* file handling */ 98 | /* */ 99 | /**********************************************************************/ 100 | 101 | 102 | #include 103 | 104 | #define FT_FILE FILE 105 | #define ft_fclose fclose 106 | #define ft_fopen fopen 107 | #define ft_fread fread 108 | #define ft_fseek fseek 109 | #define ft_ftell ftell 110 | #define ft_sprintf sprintf 111 | 112 | 113 | /**********************************************************************/ 114 | /* */ 115 | /* sorting */ 116 | /* */ 117 | /**********************************************************************/ 118 | 119 | 120 | #include 121 | 122 | #define ft_qsort qsort 123 | 124 | 125 | /**********************************************************************/ 126 | /* */ 127 | /* memory allocation */ 128 | /* */ 129 | /**********************************************************************/ 130 | 131 | 132 | #define ft_scalloc calloc 133 | #define ft_sfree free 134 | #define ft_smalloc malloc 135 | #define ft_srealloc realloc 136 | 137 | 138 | /**********************************************************************/ 139 | /* */ 140 | /* miscellaneous */ 141 | /* */ 142 | /**********************************************************************/ 143 | 144 | 145 | #define ft_strtol strtol 146 | #define ft_getenv getenv 147 | 148 | 149 | /**********************************************************************/ 150 | /* */ 151 | /* execution control */ 152 | /* */ 153 | /**********************************************************************/ 154 | 155 | 156 | #include 157 | 158 | #define ft_jmp_buf jmp_buf /* note: this cannot be a typedef since */ 159 | /* jmp_buf is defined as a macro */ 160 | /* on certain platforms */ 161 | 162 | #define ft_longjmp longjmp 163 | #define ft_setjmp( b ) setjmp( *(ft_jmp_buf*) &(b) ) /* same thing here */ 164 | 165 | 166 | /* the following is only used for debugging purposes, i.e., if */ 167 | /* FT_DEBUG_LEVEL_ERROR or FT_DEBUG_LEVEL_TRACE are defined */ 168 | 169 | #include 170 | 171 | 172 | #endif /* FTSTDLIB_H_ */ 173 | 174 | 175 | /* END */ 176 | -------------------------------------------------------------------------------- /src/freetype/include/freetype/ftbbox.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************/ 2 | /* */ 3 | /* ftbbox.h */ 4 | /* */ 5 | /* FreeType exact bbox computation (specification). */ 6 | /* */ 7 | /* Copyright 1996-2018 by */ 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 9 | /* */ 10 | /* This file is part of the FreeType project, and may only be used, */ 11 | /* modified, and distributed under the terms of the FreeType project */ 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 13 | /* this file you indicate that you have read the license and */ 14 | /* understand and accept it fully. */ 15 | /* */ 16 | /***************************************************************************/ 17 | 18 | 19 | /*************************************************************************/ 20 | /* */ 21 | /* This component has a _single_ role: to compute exact outline bounding */ 22 | /* boxes. */ 23 | /* */ 24 | /* It is separated from the rest of the engine for various technical */ 25 | /* reasons. It may well be integrated in `ftoutln' later. */ 26 | /* */ 27 | /*************************************************************************/ 28 | 29 | 30 | #ifndef FTBBOX_H_ 31 | #define FTBBOX_H_ 32 | 33 | 34 | #include 35 | #include FT_FREETYPE_H 36 | 37 | #ifdef FREETYPE_H 38 | #error "freetype.h of FreeType 1 has been loaded!" 39 | #error "Please fix the directory search order for header files" 40 | #error "so that freetype.h of FreeType 2 is found first." 41 | #endif 42 | 43 | 44 | FT_BEGIN_HEADER 45 | 46 | 47 | /*************************************************************************/ 48 | /* */ 49 | /*
*/ 50 | /* outline_processing */ 51 | /* */ 52 | /*************************************************************************/ 53 | 54 | 55 | /*************************************************************************/ 56 | /* */ 57 | /* */ 58 | /* FT_Outline_Get_BBox */ 59 | /* */ 60 | /* */ 61 | /* Compute the exact bounding box of an outline. This is slower */ 62 | /* than computing the control box. However, it uses an advanced */ 63 | /* algorithm that returns _very_ quickly when the two boxes */ 64 | /* coincide. Otherwise, the outline Bezier arcs are traversed to */ 65 | /* extract their extrema. */ 66 | /* */ 67 | /* */ 68 | /* outline :: A pointer to the source outline. */ 69 | /* */ 70 | /* */ 71 | /* abbox :: The outline's exact bounding box. */ 72 | /* */ 73 | /* */ 74 | /* FreeType error code. 0~means success. */ 75 | /* */ 76 | /* */ 77 | /* If the font is tricky and the glyph has been loaded with */ 78 | /* @FT_LOAD_NO_SCALE, the resulting BBox is meaningless. To get */ 79 | /* reasonable values for the BBox it is necessary to load the glyph */ 80 | /* at a large ppem value (so that the hinting instructions can */ 81 | /* properly shift and scale the subglyphs), then extracting the BBox, */ 82 | /* which can be eventually converted back to font units. */ 83 | /* */ 84 | FT_EXPORT( FT_Error ) 85 | FT_Outline_Get_BBox( FT_Outline* outline, 86 | FT_BBox *abbox ); 87 | 88 | /* */ 89 | 90 | 91 | FT_END_HEADER 92 | 93 | #endif /* FTBBOX_H_ */ 94 | 95 | 96 | /* END */ 97 | 98 | 99 | /* Local Variables: */ 100 | /* coding: utf-8 */ 101 | /* End: */ 102 | -------------------------------------------------------------------------------- /src/freetype/include/freetype/ftbdf.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************/ 2 | /* */ 3 | /* ftbdf.h */ 4 | /* */ 5 | /* FreeType API for accessing BDF-specific strings (specification). */ 6 | /* */ 7 | /* Copyright 2002-2018 by */ 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 9 | /* */ 10 | /* This file is part of the FreeType project, and may only be used, */ 11 | /* modified, and distributed under the terms of the FreeType project */ 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 13 | /* this file you indicate that you have read the license and */ 14 | /* understand and accept it fully. */ 15 | /* */ 16 | /***************************************************************************/ 17 | 18 | 19 | #ifndef FTBDF_H_ 20 | #define FTBDF_H_ 21 | 22 | #include 23 | #include FT_FREETYPE_H 24 | 25 | #ifdef FREETYPE_H 26 | #error "freetype.h of FreeType 1 has been loaded!" 27 | #error "Please fix the directory search order for header files" 28 | #error "so that freetype.h of FreeType 2 is found first." 29 | #endif 30 | 31 | 32 | FT_BEGIN_HEADER 33 | 34 | 35 | /*************************************************************************/ 36 | /* */ 37 | /*
*/ 38 | /* bdf_fonts */ 39 | /* */ 40 | /* */ 41 | /* BDF and PCF Files */ 42 | /* */ 43 | /* <Abstract> */ 44 | /* BDF and PCF specific API. */ 45 | /* */ 46 | /* <Description> */ 47 | /* This section contains the declaration of functions specific to BDF */ 48 | /* and PCF fonts. */ 49 | /* */ 50 | /*************************************************************************/ 51 | 52 | 53 | /********************************************************************** 54 | * 55 | * @enum: 56 | * BDF_PropertyType 57 | * 58 | * @description: 59 | * A list of BDF property types. 60 | * 61 | * @values: 62 | * BDF_PROPERTY_TYPE_NONE :: 63 | * Value~0 is used to indicate a missing property. 64 | * 65 | * BDF_PROPERTY_TYPE_ATOM :: 66 | * Property is a string atom. 67 | * 68 | * BDF_PROPERTY_TYPE_INTEGER :: 69 | * Property is a 32-bit signed integer. 70 | * 71 | * BDF_PROPERTY_TYPE_CARDINAL :: 72 | * Property is a 32-bit unsigned integer. 73 | */ 74 | typedef enum BDF_PropertyType_ 75 | { 76 | BDF_PROPERTY_TYPE_NONE = 0, 77 | BDF_PROPERTY_TYPE_ATOM = 1, 78 | BDF_PROPERTY_TYPE_INTEGER = 2, 79 | BDF_PROPERTY_TYPE_CARDINAL = 3 80 | 81 | } BDF_PropertyType; 82 | 83 | 84 | /********************************************************************** 85 | * 86 | * @type: 87 | * BDF_Property 88 | * 89 | * @description: 90 | * A handle to a @BDF_PropertyRec structure to model a given 91 | * BDF/PCF property. 92 | */ 93 | typedef struct BDF_PropertyRec_* BDF_Property; 94 | 95 | 96 | /********************************************************************** 97 | * 98 | * @struct: 99 | * BDF_PropertyRec 100 | * 101 | * @description: 102 | * This structure models a given BDF/PCF property. 103 | * 104 | * @fields: 105 | * type :: 106 | * The property type. 107 | * 108 | * u.atom :: 109 | * The atom string, if type is @BDF_PROPERTY_TYPE_ATOM. May be 110 | * NULL, indicating an empty string. 111 | * 112 | * u.integer :: 113 | * A signed integer, if type is @BDF_PROPERTY_TYPE_INTEGER. 114 | * 115 | * u.cardinal :: 116 | * An unsigned integer, if type is @BDF_PROPERTY_TYPE_CARDINAL. 117 | */ 118 | typedef struct BDF_PropertyRec_ 119 | { 120 | BDF_PropertyType type; 121 | union { 122 | const char* atom; 123 | FT_Int32 integer; 124 | FT_UInt32 cardinal; 125 | 126 | } u; 127 | 128 | } BDF_PropertyRec; 129 | 130 | 131 | /********************************************************************** 132 | * 133 | * @function: 134 | * FT_Get_BDF_Charset_ID 135 | * 136 | * @description: 137 | * Retrieve a BDF font character set identity, according to 138 | * the BDF specification. 139 | * 140 | * @input: 141 | * face :: 142 | * A handle to the input face. 143 | * 144 | * @output: 145 | * acharset_encoding :: 146 | * Charset encoding, as a C~string, owned by the face. 147 | * 148 | * acharset_registry :: 149 | * Charset registry, as a C~string, owned by the face. 150 | * 151 | * @return: 152 | * FreeType error code. 0~means success. 153 | * 154 | * @note: 155 | * This function only works with BDF faces, returning an error otherwise. 156 | */ 157 | FT_EXPORT( FT_Error ) 158 | FT_Get_BDF_Charset_ID( FT_Face face, 159 | const char* *acharset_encoding, 160 | const char* *acharset_registry ); 161 | 162 | 163 | /********************************************************************** 164 | * 165 | * @function: 166 | * FT_Get_BDF_Property 167 | * 168 | * @description: 169 | * Retrieve a BDF property from a BDF or PCF font file. 170 | * 171 | * @input: 172 | * face :: A handle to the input face. 173 | * 174 | * name :: The property name. 175 | * 176 | * @output: 177 | * aproperty :: The property. 178 | * 179 | * @return: 180 | * FreeType error code. 0~means success. 181 | * 182 | * @note: 183 | * This function works with BDF _and_ PCF fonts. It returns an error 184 | * otherwise. It also returns an error if the property is not in the 185 | * font. 186 | * 187 | * A `property' is a either key-value pair within the STARTPROPERTIES 188 | * ... ENDPROPERTIES block of a BDF font or a key-value pair from the 189 | * `info->props' array within a `FontRec' structure of a PCF font. 190 | * 191 | * Integer properties are always stored as `signed' within PCF fonts; 192 | * consequently, @BDF_PROPERTY_TYPE_CARDINAL is a possible return value 193 | * for BDF fonts only. 194 | * 195 | * In case of error, `aproperty->type' is always set to 196 | * @BDF_PROPERTY_TYPE_NONE. 197 | */ 198 | FT_EXPORT( FT_Error ) 199 | FT_Get_BDF_Property( FT_Face face, 200 | const char* prop_name, 201 | BDF_PropertyRec *aproperty ); 202 | 203 | /* */ 204 | 205 | FT_END_HEADER 206 | 207 | #endif /* FTBDF_H_ */ 208 | 209 | 210 | /* END */ 211 | -------------------------------------------------------------------------------- /src/freetype/include/freetype/ftbzip2.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************/ 2 | /* */ 3 | /* ftbzip2.h */ 4 | /* */ 5 | /* Bzip2-compressed stream support. */ 6 | /* */ 7 | /* Copyright 2010-2018 by */ 8 | /* Joel Klinghed. */ 9 | /* */ 10 | /* This file is part of the FreeType project, and may only be used, */ 11 | /* modified, and distributed under the terms of the FreeType project */ 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 13 | /* this file you indicate that you have read the license and */ 14 | /* understand and accept it fully. */ 15 | /* */ 16 | /***************************************************************************/ 17 | 18 | 19 | #ifndef FTBZIP2_H_ 20 | #define FTBZIP2_H_ 21 | 22 | #include <ft2build.h> 23 | #include FT_FREETYPE_H 24 | 25 | #ifdef FREETYPE_H 26 | #error "freetype.h of FreeType 1 has been loaded!" 27 | #error "Please fix the directory search order for header files" 28 | #error "so that freetype.h of FreeType 2 is found first." 29 | #endif 30 | 31 | 32 | FT_BEGIN_HEADER 33 | 34 | /*************************************************************************/ 35 | /* */ 36 | /* <Section> */ 37 | /* bzip2 */ 38 | /* */ 39 | /* <Title> */ 40 | /* BZIP2 Streams */ 41 | /* */ 42 | /* <Abstract> */ 43 | /* Using bzip2-compressed font files. */ 44 | /* */ 45 | /* <Description> */ 46 | /* This section contains the declaration of Bzip2-specific functions. */ 47 | /* */ 48 | /*************************************************************************/ 49 | 50 | 51 | /************************************************************************ 52 | * 53 | * @function: 54 | * FT_Stream_OpenBzip2 55 | * 56 | * @description: 57 | * Open a new stream to parse bzip2-compressed font files. This is 58 | * mainly used to support the compressed `*.pcf.bz2' fonts that come 59 | * with XFree86. 60 | * 61 | * @input: 62 | * stream :: 63 | * The target embedding stream. 64 | * 65 | * source :: 66 | * The source stream. 67 | * 68 | * @return: 69 | * FreeType error code. 0~means success. 70 | * 71 | * @note: 72 | * The source stream must be opened _before_ calling this function. 73 | * 74 | * Calling the internal function `FT_Stream_Close' on the new stream will 75 | * *not* call `FT_Stream_Close' on the source stream. None of the stream 76 | * objects will be released to the heap. 77 | * 78 | * The stream implementation is very basic and resets the decompression 79 | * process each time seeking backwards is needed within the stream. 80 | * 81 | * In certain builds of the library, bzip2 compression recognition is 82 | * automatically handled when calling @FT_New_Face or @FT_Open_Face. 83 | * This means that if no font driver is capable of handling the raw 84 | * compressed file, the library will try to open a bzip2 compressed stream 85 | * from it and re-open the face with it. 86 | * 87 | * This function may return `FT_Err_Unimplemented_Feature' if your build 88 | * of FreeType was not compiled with bzip2 support. 89 | */ 90 | FT_EXPORT( FT_Error ) 91 | FT_Stream_OpenBzip2( FT_Stream stream, 92 | FT_Stream source ); 93 | 94 | /* */ 95 | 96 | 97 | FT_END_HEADER 98 | 99 | #endif /* FTBZIP2_H_ */ 100 | 101 | 102 | /* END */ 103 | -------------------------------------------------------------------------------- /src/freetype/include/freetype/ftcid.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************/ 2 | /* */ 3 | /* ftcid.h */ 4 | /* */ 5 | /* FreeType API for accessing CID font information (specification). */ 6 | /* */ 7 | /* Copyright 2007-2018 by */ 8 | /* Dereg Clegg and Michael Toftdal. */ 9 | /* */ 10 | /* This file is part of the FreeType project, and may only be used, */ 11 | /* modified, and distributed under the terms of the FreeType project */ 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 13 | /* this file you indicate that you have read the license and */ 14 | /* understand and accept it fully. */ 15 | /* */ 16 | /***************************************************************************/ 17 | 18 | 19 | #ifndef FTCID_H_ 20 | #define FTCID_H_ 21 | 22 | #include <ft2build.h> 23 | #include FT_FREETYPE_H 24 | 25 | #ifdef FREETYPE_H 26 | #error "freetype.h of FreeType 1 has been loaded!" 27 | #error "Please fix the directory search order for header files" 28 | #error "so that freetype.h of FreeType 2 is found first." 29 | #endif 30 | 31 | 32 | FT_BEGIN_HEADER 33 | 34 | 35 | /*************************************************************************/ 36 | /* */ 37 | /* <Section> */ 38 | /* cid_fonts */ 39 | /* */ 40 | /* <Title> */ 41 | /* CID Fonts */ 42 | /* */ 43 | /* <Abstract> */ 44 | /* CID-keyed font specific API. */ 45 | /* */ 46 | /* <Description> */ 47 | /* This section contains the declaration of CID-keyed font specific */ 48 | /* functions. */ 49 | /* */ 50 | /*************************************************************************/ 51 | 52 | 53 | /********************************************************************** 54 | * 55 | * @function: 56 | * FT_Get_CID_Registry_Ordering_Supplement 57 | * 58 | * @description: 59 | * Retrieve the Registry/Ordering/Supplement triple (also known as the 60 | * "R/O/S") from a CID-keyed font. 61 | * 62 | * @input: 63 | * face :: 64 | * A handle to the input face. 65 | * 66 | * @output: 67 | * registry :: 68 | * The registry, as a C~string, owned by the face. 69 | * 70 | * ordering :: 71 | * The ordering, as a C~string, owned by the face. 72 | * 73 | * supplement :: 74 | * The supplement. 75 | * 76 | * @return: 77 | * FreeType error code. 0~means success. 78 | * 79 | * @note: 80 | * This function only works with CID faces, returning an error 81 | * otherwise. 82 | * 83 | * @since: 84 | * 2.3.6 85 | */ 86 | FT_EXPORT( FT_Error ) 87 | FT_Get_CID_Registry_Ordering_Supplement( FT_Face face, 88 | const char* *registry, 89 | const char* *ordering, 90 | FT_Int *supplement ); 91 | 92 | 93 | /********************************************************************** 94 | * 95 | * @function: 96 | * FT_Get_CID_Is_Internally_CID_Keyed 97 | * 98 | * @description: 99 | * Retrieve the type of the input face, CID keyed or not. In 100 | * contrast to the @FT_IS_CID_KEYED macro this function returns 101 | * successfully also for CID-keyed fonts in an SFNT wrapper. 102 | * 103 | * @input: 104 | * face :: 105 | * A handle to the input face. 106 | * 107 | * @output: 108 | * is_cid :: 109 | * The type of the face as an @FT_Bool. 110 | * 111 | * @return: 112 | * FreeType error code. 0~means success. 113 | * 114 | * @note: 115 | * This function only works with CID faces and OpenType fonts, 116 | * returning an error otherwise. 117 | * 118 | * @since: 119 | * 2.3.9 120 | */ 121 | FT_EXPORT( FT_Error ) 122 | FT_Get_CID_Is_Internally_CID_Keyed( FT_Face face, 123 | FT_Bool *is_cid ); 124 | 125 | 126 | /********************************************************************** 127 | * 128 | * @function: 129 | * FT_Get_CID_From_Glyph_Index 130 | * 131 | * @description: 132 | * Retrieve the CID of the input glyph index. 133 | * 134 | * @input: 135 | * face :: 136 | * A handle to the input face. 137 | * 138 | * glyph_index :: 139 | * The input glyph index. 140 | * 141 | * @output: 142 | * cid :: 143 | * The CID as an @FT_UInt. 144 | * 145 | * @return: 146 | * FreeType error code. 0~means success. 147 | * 148 | * @note: 149 | * This function only works with CID faces and OpenType fonts, 150 | * returning an error otherwise. 151 | * 152 | * @since: 153 | * 2.3.9 154 | */ 155 | FT_EXPORT( FT_Error ) 156 | FT_Get_CID_From_Glyph_Index( FT_Face face, 157 | FT_UInt glyph_index, 158 | FT_UInt *cid ); 159 | 160 | /* */ 161 | 162 | 163 | FT_END_HEADER 164 | 165 | #endif /* FTCID_H_ */ 166 | 167 | 168 | /* END */ 169 | -------------------------------------------------------------------------------- /src/freetype/include/freetype/ftfntfmt.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************/ 2 | /* */ 3 | /* ftfntfmt.h */ 4 | /* */ 5 | /* Support functions for font formats. */ 6 | /* */ 7 | /* Copyright 2002-2018 by */ 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 9 | /* */ 10 | /* This file is part of the FreeType project, and may only be used, */ 11 | /* modified, and distributed under the terms of the FreeType project */ 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 13 | /* this file you indicate that you have read the license and */ 14 | /* understand and accept it fully. */ 15 | /* */ 16 | /***************************************************************************/ 17 | 18 | 19 | #ifndef FTFNTFMT_H_ 20 | #define FTFNTFMT_H_ 21 | 22 | #include <ft2build.h> 23 | #include FT_FREETYPE_H 24 | 25 | #ifdef FREETYPE_H 26 | #error "freetype.h of FreeType 1 has been loaded!" 27 | #error "Please fix the directory search order for header files" 28 | #error "so that freetype.h of FreeType 2 is found first." 29 | #endif 30 | 31 | 32 | FT_BEGIN_HEADER 33 | 34 | 35 | /*************************************************************************/ 36 | /* */ 37 | /* <Section> */ 38 | /* font_formats */ 39 | /* */ 40 | /* <Title> */ 41 | /* Font Formats */ 42 | /* */ 43 | /* <Abstract> */ 44 | /* Getting the font format. */ 45 | /* */ 46 | /* <Description> */ 47 | /* The single function in this section can be used to get the font */ 48 | /* format. Note that this information is not needed normally; */ 49 | /* however, there are special cases (like in PDF devices) where it is */ 50 | /* important to differentiate, in spite of FreeType's uniform API. */ 51 | /* */ 52 | /*************************************************************************/ 53 | 54 | 55 | /*************************************************************************/ 56 | /* */ 57 | /* <Function> */ 58 | /* FT_Get_Font_Format */ 59 | /* */ 60 | /* <Description> */ 61 | /* Return a string describing the format of a given face. Possible */ 62 | /* values are `TrueType', `Type~1', `BDF', `PCF', `Type~42', */ 63 | /* `CID~Type~1', `CFF', `PFR', and `Windows~FNT'. */ 64 | /* */ 65 | /* The return value is suitable to be used as an X11 FONT_PROPERTY. */ 66 | /* */ 67 | /* <Input> */ 68 | /* face :: */ 69 | /* Input face handle. */ 70 | /* */ 71 | /* <Return> */ 72 | /* Font format string. NULL in case of error. */ 73 | /* */ 74 | /* <Note> */ 75 | /* A deprecated name for the same function is */ 76 | /* `FT_Get_X11_Font_Format'. */ 77 | /* */ 78 | FT_EXPORT( const char* ) 79 | FT_Get_Font_Format( FT_Face face ); 80 | 81 | 82 | /* deprecated */ 83 | FT_EXPORT( const char* ) 84 | FT_Get_X11_Font_Format( FT_Face face ); 85 | 86 | 87 | /* */ 88 | 89 | 90 | FT_END_HEADER 91 | 92 | #endif /* FTFNTFMT_H_ */ 93 | 94 | 95 | /* END */ 96 | -------------------------------------------------------------------------------- /src/freetype/include/freetype/ftgasp.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************/ 2 | /* */ 3 | /* ftgasp.h */ 4 | /* */ 5 | /* Access of TrueType's `gasp' table (specification). */ 6 | /* */ 7 | /* Copyright 2007-2018 by */ 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 9 | /* */ 10 | /* This file is part of the FreeType project, and may only be used, */ 11 | /* modified, and distributed under the terms of the FreeType project */ 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 13 | /* this file you indicate that you have read the license and */ 14 | /* understand and accept it fully. */ 15 | /* */ 16 | /***************************************************************************/ 17 | 18 | 19 | #ifndef FTGASP_H_ 20 | #define FTGASP_H_ 21 | 22 | #include <ft2build.h> 23 | #include FT_FREETYPE_H 24 | 25 | #ifdef FREETYPE_H 26 | #error "freetype.h of FreeType 1 has been loaded!" 27 | #error "Please fix the directory search order for header files" 28 | #error "so that freetype.h of FreeType 2 is found first." 29 | #endif 30 | 31 | 32 | FT_BEGIN_HEADER 33 | 34 | 35 | /*************************************************************************** 36 | * 37 | * @section: 38 | * gasp_table 39 | * 40 | * @title: 41 | * Gasp Table 42 | * 43 | * @abstract: 44 | * Retrieving TrueType `gasp' table entries. 45 | * 46 | * @description: 47 | * The function @FT_Get_Gasp can be used to query a TrueType or OpenType 48 | * font for specific entries in its `gasp' table, if any. This is 49 | * mainly useful when implementing native TrueType hinting with the 50 | * bytecode interpreter to duplicate the Windows text rendering results. 51 | */ 52 | 53 | /************************************************************************* 54 | * 55 | * @enum: 56 | * FT_GASP_XXX 57 | * 58 | * @description: 59 | * A list of values and/or bit-flags returned by the @FT_Get_Gasp 60 | * function. 61 | * 62 | * @values: 63 | * FT_GASP_NO_TABLE :: 64 | * This special value means that there is no GASP table in this face. 65 | * It is up to the client to decide what to do. 66 | * 67 | * FT_GASP_DO_GRIDFIT :: 68 | * Grid-fitting and hinting should be performed at the specified ppem. 69 | * This *really* means TrueType bytecode interpretation. If this bit 70 | * is not set, no hinting gets applied. 71 | * 72 | * FT_GASP_DO_GRAY :: 73 | * Anti-aliased rendering should be performed at the specified ppem. 74 | * If not set, do monochrome rendering. 75 | * 76 | * FT_GASP_SYMMETRIC_SMOOTHING :: 77 | * If set, smoothing along multiple axes must be used with ClearType. 78 | * 79 | * FT_GASP_SYMMETRIC_GRIDFIT :: 80 | * Grid-fitting must be used with ClearType's symmetric smoothing. 81 | * 82 | * @note: 83 | * The bit-flags `FT_GASP_DO_GRIDFIT' and `FT_GASP_DO_GRAY' are to be 84 | * used for standard font rasterization only. Independently of that, 85 | * `FT_GASP_SYMMETRIC_SMOOTHING' and `FT_GASP_SYMMETRIC_GRIDFIT' are to 86 | * be used if ClearType is enabled (and `FT_GASP_DO_GRIDFIT' and 87 | * `FT_GASP_DO_GRAY' are consequently ignored). 88 | * 89 | * `ClearType' is Microsoft's implementation of LCD rendering, partly 90 | * protected by patents. 91 | * 92 | * @since: 93 | * 2.3.0 94 | */ 95 | #define FT_GASP_NO_TABLE -1 96 | #define FT_GASP_DO_GRIDFIT 0x01 97 | #define FT_GASP_DO_GRAY 0x02 98 | #define FT_GASP_SYMMETRIC_GRIDFIT 0x04 99 | #define FT_GASP_SYMMETRIC_SMOOTHING 0x08 100 | 101 | 102 | /************************************************************************* 103 | * 104 | * @func: 105 | * FT_Get_Gasp 106 | * 107 | * @description: 108 | * For a TrueType or OpenType font file, return the rasterizer behaviour 109 | * flags from the font's `gasp' table corresponding to a given 110 | * character pixel size. 111 | * 112 | * @input: 113 | * face :: The source face handle. 114 | * 115 | * ppem :: The vertical character pixel size. 116 | * 117 | * @return: 118 | * Bit flags (see @FT_GASP_XXX), or @FT_GASP_NO_TABLE if there is no 119 | * `gasp' table in the face. 120 | * 121 | * @note: 122 | * If you want to use the MM functionality of OpenType variation fonts 123 | * (i.e., using @FT_Set_Var_Design_Coordinates and friends), call this 124 | * function *after* setting an instance since the return values can 125 | * change. 126 | * 127 | * @since: 128 | * 2.3.0 129 | */ 130 | FT_EXPORT( FT_Int ) 131 | FT_Get_Gasp( FT_Face face, 132 | FT_UInt ppem ); 133 | 134 | /* */ 135 | 136 | 137 | FT_END_HEADER 138 | 139 | #endif /* FTGASP_H_ */ 140 | 141 | 142 | /* END */ 143 | -------------------------------------------------------------------------------- /src/freetype/include/freetype/ftgzip.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************/ 2 | /* */ 3 | /* ftgzip.h */ 4 | /* */ 5 | /* Gzip-compressed stream support. */ 6 | /* */ 7 | /* Copyright 2002-2018 by */ 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 9 | /* */ 10 | /* This file is part of the FreeType project, and may only be used, */ 11 | /* modified, and distributed under the terms of the FreeType project */ 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 13 | /* this file you indicate that you have read the license and */ 14 | /* understand and accept it fully. */ 15 | /* */ 16 | /***************************************************************************/ 17 | 18 | 19 | #ifndef FTGZIP_H_ 20 | #define FTGZIP_H_ 21 | 22 | #include <ft2build.h> 23 | #include FT_FREETYPE_H 24 | 25 | #ifdef FREETYPE_H 26 | #error "freetype.h of FreeType 1 has been loaded!" 27 | #error "Please fix the directory search order for header files" 28 | #error "so that freetype.h of FreeType 2 is found first." 29 | #endif 30 | 31 | 32 | FT_BEGIN_HEADER 33 | 34 | /*************************************************************************/ 35 | /* */ 36 | /* <Section> */ 37 | /* gzip */ 38 | /* */ 39 | /* <Title> */ 40 | /* GZIP Streams */ 41 | /* */ 42 | /* <Abstract> */ 43 | /* Using gzip-compressed font files. */ 44 | /* */ 45 | /* <Description> */ 46 | /* This section contains the declaration of Gzip-specific functions. */ 47 | /* */ 48 | /*************************************************************************/ 49 | 50 | 51 | /************************************************************************ 52 | * 53 | * @function: 54 | * FT_Stream_OpenGzip 55 | * 56 | * @description: 57 | * Open a new stream to parse gzip-compressed font files. This is 58 | * mainly used to support the compressed `*.pcf.gz' fonts that come 59 | * with XFree86. 60 | * 61 | * @input: 62 | * stream :: 63 | * The target embedding stream. 64 | * 65 | * source :: 66 | * The source stream. 67 | * 68 | * @return: 69 | * FreeType error code. 0~means success. 70 | * 71 | * @note: 72 | * The source stream must be opened _before_ calling this function. 73 | * 74 | * Calling the internal function `FT_Stream_Close' on the new stream will 75 | * *not* call `FT_Stream_Close' on the source stream. None of the stream 76 | * objects will be released to the heap. 77 | * 78 | * The stream implementation is very basic and resets the decompression 79 | * process each time seeking backwards is needed within the stream. 80 | * 81 | * In certain builds of the library, gzip compression recognition is 82 | * automatically handled when calling @FT_New_Face or @FT_Open_Face. 83 | * This means that if no font driver is capable of handling the raw 84 | * compressed file, the library will try to open a gzipped stream from 85 | * it and re-open the face with it. 86 | * 87 | * This function may return `FT_Err_Unimplemented_Feature' if your build 88 | * of FreeType was not compiled with zlib support. 89 | */ 90 | FT_EXPORT( FT_Error ) 91 | FT_Stream_OpenGzip( FT_Stream stream, 92 | FT_Stream source ); 93 | 94 | 95 | /************************************************************************ 96 | * 97 | * @function: 98 | * FT_Gzip_Uncompress 99 | * 100 | * @description: 101 | * Decompress a zipped input buffer into an output buffer. This function 102 | * is modeled after zlib's `uncompress' function. 103 | * 104 | * @input: 105 | * memory :: 106 | * A FreeType memory handle. 107 | * 108 | * input :: 109 | * The input buffer. 110 | * 111 | * input_len :: 112 | * The length of the input buffer. 113 | * 114 | * @output: 115 | * output:: 116 | * The output buffer. 117 | * 118 | * @inout: 119 | * output_len :: 120 | * Before calling the function, this is the total size of the output 121 | * buffer, which must be large enough to hold the entire uncompressed 122 | * data (so the size of the uncompressed data must be known in 123 | * advance). After calling the function, `output_len' is the size of 124 | * the used data in `output'. 125 | * 126 | * @return: 127 | * FreeType error code. 0~means success. 128 | * 129 | * @note: 130 | * This function may return `FT_Err_Unimplemented_Feature' if your build 131 | * of FreeType was not compiled with zlib support. 132 | * 133 | * @since: 134 | * 2.5.1 135 | */ 136 | FT_EXPORT( FT_Error ) 137 | FT_Gzip_Uncompress( FT_Memory memory, 138 | FT_Byte* output, 139 | FT_ULong* output_len, 140 | const FT_Byte* input, 141 | FT_ULong input_len ); 142 | 143 | /* */ 144 | 145 | 146 | FT_END_HEADER 147 | 148 | #endif /* FTGZIP_H_ */ 149 | 150 | 151 | /* END */ 152 | -------------------------------------------------------------------------------- /src/freetype/include/freetype/ftlzw.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************/ 2 | /* */ 3 | /* ftlzw.h */ 4 | /* */ 5 | /* LZW-compressed stream support. */ 6 | /* */ 7 | /* Copyright 2004-2018 by */ 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 9 | /* */ 10 | /* This file is part of the FreeType project, and may only be used, */ 11 | /* modified, and distributed under the terms of the FreeType project */ 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 13 | /* this file you indicate that you have read the license and */ 14 | /* understand and accept it fully. */ 15 | /* */ 16 | /***************************************************************************/ 17 | 18 | 19 | #ifndef FTLZW_H_ 20 | #define FTLZW_H_ 21 | 22 | #include <ft2build.h> 23 | #include FT_FREETYPE_H 24 | 25 | #ifdef FREETYPE_H 26 | #error "freetype.h of FreeType 1 has been loaded!" 27 | #error "Please fix the directory search order for header files" 28 | #error "so that freetype.h of FreeType 2 is found first." 29 | #endif 30 | 31 | 32 | FT_BEGIN_HEADER 33 | 34 | /*************************************************************************/ 35 | /* */ 36 | /* <Section> */ 37 | /* lzw */ 38 | /* */ 39 | /* <Title> */ 40 | /* LZW Streams */ 41 | /* */ 42 | /* <Abstract> */ 43 | /* Using LZW-compressed font files. */ 44 | /* */ 45 | /* <Description> */ 46 | /* This section contains the declaration of LZW-specific functions. */ 47 | /* */ 48 | /*************************************************************************/ 49 | 50 | /************************************************************************ 51 | * 52 | * @function: 53 | * FT_Stream_OpenLZW 54 | * 55 | * @description: 56 | * Open a new stream to parse LZW-compressed font files. This is 57 | * mainly used to support the compressed `*.pcf.Z' fonts that come 58 | * with XFree86. 59 | * 60 | * @input: 61 | * stream :: The target embedding stream. 62 | * 63 | * source :: The source stream. 64 | * 65 | * @return: 66 | * FreeType error code. 0~means success. 67 | * 68 | * @note: 69 | * The source stream must be opened _before_ calling this function. 70 | * 71 | * Calling the internal function `FT_Stream_Close' on the new stream will 72 | * *not* call `FT_Stream_Close' on the source stream. None of the stream 73 | * objects will be released to the heap. 74 | * 75 | * The stream implementation is very basic and resets the decompression 76 | * process each time seeking backwards is needed within the stream 77 | * 78 | * In certain builds of the library, LZW compression recognition is 79 | * automatically handled when calling @FT_New_Face or @FT_Open_Face. 80 | * This means that if no font driver is capable of handling the raw 81 | * compressed file, the library will try to open a LZW stream from it 82 | * and re-open the face with it. 83 | * 84 | * This function may return `FT_Err_Unimplemented_Feature' if your build 85 | * of FreeType was not compiled with LZW support. 86 | */ 87 | FT_EXPORT( FT_Error ) 88 | FT_Stream_OpenLZW( FT_Stream stream, 89 | FT_Stream source ); 90 | 91 | /* */ 92 | 93 | 94 | FT_END_HEADER 95 | 96 | #endif /* FTLZW_H_ */ 97 | 98 | 99 | /* END */ 100 | -------------------------------------------------------------------------------- /src/freetype/include/freetype/ftotval.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************/ 2 | /* */ 3 | /* ftotval.h */ 4 | /* */ 5 | /* FreeType API for validating OpenType tables (specification). */ 6 | /* */ 7 | /* Copyright 2004-2018 by */ 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 9 | /* */ 10 | /* This file is part of the FreeType project, and may only be used, */ 11 | /* modified, and distributed under the terms of the FreeType project */ 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 13 | /* this file you indicate that you have read the license and */ 14 | /* understand and accept it fully. */ 15 | /* */ 16 | /***************************************************************************/ 17 | 18 | 19 | /***************************************************************************/ 20 | /* */ 21 | /* */ 22 | /* Warning: This module might be moved to a different library in the */ 23 | /* future to avoid a tight dependency between FreeType and the */ 24 | /* OpenType specification. */ 25 | /* */ 26 | /* */ 27 | /***************************************************************************/ 28 | 29 | 30 | #ifndef FTOTVAL_H_ 31 | #define FTOTVAL_H_ 32 | 33 | #include <ft2build.h> 34 | #include FT_FREETYPE_H 35 | 36 | #ifdef FREETYPE_H 37 | #error "freetype.h of FreeType 1 has been loaded!" 38 | #error "Please fix the directory search order for header files" 39 | #error "so that freetype.h of FreeType 2 is found first." 40 | #endif 41 | 42 | 43 | FT_BEGIN_HEADER 44 | 45 | 46 | /*************************************************************************/ 47 | /* */ 48 | /* <Section> */ 49 | /* ot_validation */ 50 | /* */ 51 | /* <Title> */ 52 | /* OpenType Validation */ 53 | /* */ 54 | /* <Abstract> */ 55 | /* An API to validate OpenType tables. */ 56 | /* */ 57 | /* <Description> */ 58 | /* This section contains the declaration of functions to validate */ 59 | /* some OpenType tables (BASE, GDEF, GPOS, GSUB, JSTF, MATH). */ 60 | /* */ 61 | /* <Order> */ 62 | /* FT_OpenType_Validate */ 63 | /* FT_OpenType_Free */ 64 | /* */ 65 | /* FT_VALIDATE_OTXXX */ 66 | /* */ 67 | /*************************************************************************/ 68 | 69 | 70 | /********************************************************************** 71 | * 72 | * @enum: 73 | * FT_VALIDATE_OTXXX 74 | * 75 | * @description: 76 | * A list of bit-field constants used with @FT_OpenType_Validate to 77 | * indicate which OpenType tables should be validated. 78 | * 79 | * @values: 80 | * FT_VALIDATE_BASE :: 81 | * Validate BASE table. 82 | * 83 | * FT_VALIDATE_GDEF :: 84 | * Validate GDEF table. 85 | * 86 | * FT_VALIDATE_GPOS :: 87 | * Validate GPOS table. 88 | * 89 | * FT_VALIDATE_GSUB :: 90 | * Validate GSUB table. 91 | * 92 | * FT_VALIDATE_JSTF :: 93 | * Validate JSTF table. 94 | * 95 | * FT_VALIDATE_MATH :: 96 | * Validate MATH table. 97 | * 98 | * FT_VALIDATE_OT :: 99 | * Validate all OpenType tables (BASE, GDEF, GPOS, GSUB, JSTF, MATH). 100 | * 101 | */ 102 | #define FT_VALIDATE_BASE 0x0100 103 | #define FT_VALIDATE_GDEF 0x0200 104 | #define FT_VALIDATE_GPOS 0x0400 105 | #define FT_VALIDATE_GSUB 0x0800 106 | #define FT_VALIDATE_JSTF 0x1000 107 | #define FT_VALIDATE_MATH 0x2000 108 | 109 | #define FT_VALIDATE_OT ( FT_VALIDATE_BASE | \ 110 | FT_VALIDATE_GDEF | \ 111 | FT_VALIDATE_GPOS | \ 112 | FT_VALIDATE_GSUB | \ 113 | FT_VALIDATE_JSTF | \ 114 | FT_VALIDATE_MATH ) 115 | 116 | /********************************************************************** 117 | * 118 | * @function: 119 | * FT_OpenType_Validate 120 | * 121 | * @description: 122 | * Validate various OpenType tables to assure that all offsets and 123 | * indices are valid. The idea is that a higher-level library that 124 | * actually does the text layout can access those tables without 125 | * error checking (which can be quite time consuming). 126 | * 127 | * @input: 128 | * face :: 129 | * A handle to the input face. 130 | * 131 | * validation_flags :: 132 | * A bit field that specifies the tables to be validated. See 133 | * @FT_VALIDATE_OTXXX for possible values. 134 | * 135 | * @output: 136 | * BASE_table :: 137 | * A pointer to the BASE table. 138 | * 139 | * GDEF_table :: 140 | * A pointer to the GDEF table. 141 | * 142 | * GPOS_table :: 143 | * A pointer to the GPOS table. 144 | * 145 | * GSUB_table :: 146 | * A pointer to the GSUB table. 147 | * 148 | * JSTF_table :: 149 | * A pointer to the JSTF table. 150 | * 151 | * @return: 152 | * FreeType error code. 0~means success. 153 | * 154 | * @note: 155 | * This function only works with OpenType fonts, returning an error 156 | * otherwise. 157 | * 158 | * After use, the application should deallocate the five tables with 159 | * @FT_OpenType_Free. A NULL value indicates that the table either 160 | * doesn't exist in the font, or the application hasn't asked for 161 | * validation. 162 | */ 163 | FT_EXPORT( FT_Error ) 164 | FT_OpenType_Validate( FT_Face face, 165 | FT_UInt validation_flags, 166 | FT_Bytes *BASE_table, 167 | FT_Bytes *GDEF_table, 168 | FT_Bytes *GPOS_table, 169 | FT_Bytes *GSUB_table, 170 | FT_Bytes *JSTF_table ); 171 | 172 | /********************************************************************** 173 | * 174 | * @function: 175 | * FT_OpenType_Free 176 | * 177 | * @description: 178 | * Free the buffer allocated by OpenType validator. 179 | * 180 | * @input: 181 | * face :: 182 | * A handle to the input face. 183 | * 184 | * table :: 185 | * The pointer to the buffer that is allocated by 186 | * @FT_OpenType_Validate. 187 | * 188 | * @note: 189 | * This function must be used to free the buffer allocated by 190 | * @FT_OpenType_Validate only. 191 | */ 192 | FT_EXPORT( void ) 193 | FT_OpenType_Free( FT_Face face, 194 | FT_Bytes table ); 195 | 196 | /* */ 197 | 198 | 199 | FT_END_HEADER 200 | 201 | #endif /* FTOTVAL_H_ */ 202 | 203 | 204 | /* END */ 205 | -------------------------------------------------------------------------------- /src/freetype/include/freetype/ftparams.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************/ 2 | /* */ 3 | /* ftparams.h */ 4 | /* */ 5 | /* FreeType API for possible FT_Parameter tags (specification only). */ 6 | /* */ 7 | /* Copyright 2017-2018 by */ 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 9 | /* */ 10 | /* This file is part of the FreeType project, and may only be used, */ 11 | /* modified, and distributed under the terms of the FreeType project */ 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 13 | /* this file you indicate that you have read the license and */ 14 | /* understand and accept it fully. */ 15 | /* */ 16 | /***************************************************************************/ 17 | 18 | 19 | #ifndef FTPARAMS_H_ 20 | #define FTPARAMS_H_ 21 | 22 | #include <ft2build.h> 23 | #include FT_FREETYPE_H 24 | 25 | #ifdef FREETYPE_H 26 | #error "freetype.h of FreeType 1 has been loaded!" 27 | #error "Please fix the directory search order for header files" 28 | #error "so that freetype.h of FreeType 2 is found first." 29 | #endif 30 | 31 | 32 | FT_BEGIN_HEADER 33 | 34 | 35 | /************************************************************************** 36 | * 37 | * @section: 38 | * parameter_tags 39 | * 40 | * @title: 41 | * Parameter Tags 42 | * 43 | * @abstract: 44 | * Macros for driver property and font loading parameter tags. 45 | * 46 | * @description: 47 | * This section contains macros for the @FT_Parameter structure that are 48 | * used with various functions to activate some special functionality or 49 | * different behaviour of various components of FreeType. 50 | * 51 | */ 52 | 53 | 54 | /*************************************************************************** 55 | * 56 | * @constant: 57 | * FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_FAMILY 58 | * 59 | * @description: 60 | * A tag for @FT_Parameter to make @FT_Open_Face ignore typographic 61 | * family names in the `name' table (introduced in OpenType version 62 | * 1.4). Use this for backward compatibility with legacy systems that 63 | * have a four-faces-per-family restriction. 64 | * 65 | * @since: 66 | * 2.8 67 | * 68 | */ 69 | #define FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_FAMILY \ 70 | FT_MAKE_TAG( 'i', 'g', 'p', 'f' ) 71 | 72 | 73 | /* this constant is deprecated */ 74 | #define FT_PARAM_TAG_IGNORE_PREFERRED_FAMILY \ 75 | FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_FAMILY 76 | 77 | 78 | /*************************************************************************** 79 | * 80 | * @constant: 81 | * FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_SUBFAMILY 82 | * 83 | * @description: 84 | * A tag for @FT_Parameter to make @FT_Open_Face ignore typographic 85 | * subfamily names in the `name' table (introduced in OpenType version 86 | * 1.4). Use this for backward compatibility with legacy systems that 87 | * have a four-faces-per-family restriction. 88 | * 89 | * @since: 90 | * 2.8 91 | * 92 | */ 93 | #define FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_SUBFAMILY \ 94 | FT_MAKE_TAG( 'i', 'g', 'p', 's' ) 95 | 96 | 97 | /* this constant is deprecated */ 98 | #define FT_PARAM_TAG_IGNORE_PREFERRED_SUBFAMILY \ 99 | FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_SUBFAMILY 100 | 101 | 102 | /*************************************************************************** 103 | * 104 | * @constant: 105 | * FT_PARAM_TAG_INCREMENTAL 106 | * 107 | * @description: 108 | * An @FT_Parameter tag to be used with @FT_Open_Face to indicate 109 | * incremental glyph loading. 110 | * 111 | */ 112 | #define FT_PARAM_TAG_INCREMENTAL \ 113 | FT_MAKE_TAG( 'i', 'n', 'c', 'r' ) 114 | 115 | 116 | /************************************************************************** 117 | * 118 | * @constant: 119 | * FT_PARAM_TAG_LCD_FILTER_WEIGHTS 120 | * 121 | * @description: 122 | * An @FT_Parameter tag to be used with @FT_Face_Properties. The 123 | * corresponding argument specifies the five LCD filter weights for a 124 | * given face (if using @FT_LOAD_TARGET_LCD, for example), overriding 125 | * the global default values or the values set up with 126 | * @FT_Library_SetLcdFilterWeights. 127 | * 128 | * @since: 129 | * 2.8 130 | * 131 | */ 132 | #define FT_PARAM_TAG_LCD_FILTER_WEIGHTS \ 133 | FT_MAKE_TAG( 'l', 'c', 'd', 'f' ) 134 | 135 | 136 | /************************************************************************** 137 | * 138 | * @constant: 139 | * FT_PARAM_TAG_RANDOM_SEED 140 | * 141 | * @description: 142 | * An @FT_Parameter tag to be used with @FT_Face_Properties. The 143 | * corresponding 32bit signed integer argument overrides the font 144 | * driver's random seed value with a face-specific one; see 145 | * @random-seed. 146 | * 147 | * @since: 148 | * 2.8 149 | * 150 | */ 151 | #define FT_PARAM_TAG_RANDOM_SEED \ 152 | FT_MAKE_TAG( 's', 'e', 'e', 'd' ) 153 | 154 | 155 | /************************************************************************** 156 | * 157 | * @constant: 158 | * FT_PARAM_TAG_STEM_DARKENING 159 | * 160 | * @description: 161 | * An @FT_Parameter tag to be used with @FT_Face_Properties. The 162 | * corresponding Boolean argument specifies whether to apply stem 163 | * darkening, overriding the global default values or the values set up 164 | * with @FT_Property_Set (see @no-stem-darkening). 165 | * 166 | * This is a passive setting that only takes effect if the font driver 167 | * or autohinter honors it, which the CFF, Type~1, and CID drivers 168 | * always do, but the autohinter only in `light' hinting mode (as of 169 | * version 2.9). 170 | * 171 | * @since: 172 | * 2.8 173 | * 174 | */ 175 | #define FT_PARAM_TAG_STEM_DARKENING \ 176 | FT_MAKE_TAG( 'd', 'a', 'r', 'k' ) 177 | 178 | 179 | /*************************************************************************** 180 | * 181 | * @constant: 182 | * FT_PARAM_TAG_UNPATENTED_HINTING 183 | * 184 | * @description: 185 | * Deprecated, no effect. 186 | * 187 | * Previously: A constant used as the tag of an @FT_Parameter structure to 188 | * indicate that unpatented methods only should be used by the TrueType 189 | * bytecode interpreter for a typeface opened by @FT_Open_Face. 190 | * 191 | */ 192 | #define FT_PARAM_TAG_UNPATENTED_HINTING \ 193 | FT_MAKE_TAG( 'u', 'n', 'p', 'a' ) 194 | 195 | 196 | /* */ 197 | 198 | 199 | FT_END_HEADER 200 | 201 | 202 | #endif /* FTPARAMS_H_ */ 203 | 204 | 205 | /* END */ 206 | -------------------------------------------------------------------------------- /src/freetype/include/freetype/ftpfr.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************/ 2 | /* */ 3 | /* ftpfr.h */ 4 | /* */ 5 | /* FreeType API for accessing PFR-specific data (specification only). */ 6 | /* */ 7 | /* Copyright 2002-2018 by */ 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 9 | /* */ 10 | /* This file is part of the FreeType project, and may only be used, */ 11 | /* modified, and distributed under the terms of the FreeType project */ 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 13 | /* this file you indicate that you have read the license and */ 14 | /* understand and accept it fully. */ 15 | /* */ 16 | /***************************************************************************/ 17 | 18 | 19 | #ifndef FTPFR_H_ 20 | #define FTPFR_H_ 21 | 22 | #include <ft2build.h> 23 | #include FT_FREETYPE_H 24 | 25 | #ifdef FREETYPE_H 26 | #error "freetype.h of FreeType 1 has been loaded!" 27 | #error "Please fix the directory search order for header files" 28 | #error "so that freetype.h of FreeType 2 is found first." 29 | #endif 30 | 31 | 32 | FT_BEGIN_HEADER 33 | 34 | 35 | /*************************************************************************/ 36 | /* */ 37 | /* <Section> */ 38 | /* pfr_fonts */ 39 | /* */ 40 | /* <Title> */ 41 | /* PFR Fonts */ 42 | /* */ 43 | /* <Abstract> */ 44 | /* PFR/TrueDoc specific API. */ 45 | /* */ 46 | /* <Description> */ 47 | /* This section contains the declaration of PFR-specific functions. */ 48 | /* */ 49 | /*************************************************************************/ 50 | 51 | 52 | /********************************************************************** 53 | * 54 | * @function: 55 | * FT_Get_PFR_Metrics 56 | * 57 | * @description: 58 | * Return the outline and metrics resolutions of a given PFR face. 59 | * 60 | * @input: 61 | * face :: Handle to the input face. It can be a non-PFR face. 62 | * 63 | * @output: 64 | * aoutline_resolution :: 65 | * Outline resolution. This is equivalent to `face->units_per_EM' 66 | * for non-PFR fonts. Optional (parameter can be NULL). 67 | * 68 | * ametrics_resolution :: 69 | * Metrics resolution. This is equivalent to `outline_resolution' 70 | * for non-PFR fonts. Optional (parameter can be NULL). 71 | * 72 | * ametrics_x_scale :: 73 | * A 16.16 fixed-point number used to scale distance expressed 74 | * in metrics units to device subpixels. This is equivalent to 75 | * `face->size->x_scale', but for metrics only. Optional (parameter 76 | * can be NULL). 77 | * 78 | * ametrics_y_scale :: 79 | * Same as `ametrics_x_scale' but for the vertical direction. 80 | * optional (parameter can be NULL). 81 | * 82 | * @return: 83 | * FreeType error code. 0~means success. 84 | * 85 | * @note: 86 | * If the input face is not a PFR, this function will return an error. 87 | * However, in all cases, it will return valid values. 88 | */ 89 | FT_EXPORT( FT_Error ) 90 | FT_Get_PFR_Metrics( FT_Face face, 91 | FT_UInt *aoutline_resolution, 92 | FT_UInt *ametrics_resolution, 93 | FT_Fixed *ametrics_x_scale, 94 | FT_Fixed *ametrics_y_scale ); 95 | 96 | 97 | /********************************************************************** 98 | * 99 | * @function: 100 | * FT_Get_PFR_Kerning 101 | * 102 | * @description: 103 | * Return the kerning pair corresponding to two glyphs in a PFR face. 104 | * The distance is expressed in metrics units, unlike the result of 105 | * @FT_Get_Kerning. 106 | * 107 | * @input: 108 | * face :: A handle to the input face. 109 | * 110 | * left :: Index of the left glyph. 111 | * 112 | * right :: Index of the right glyph. 113 | * 114 | * @output: 115 | * avector :: A kerning vector. 116 | * 117 | * @return: 118 | * FreeType error code. 0~means success. 119 | * 120 | * @note: 121 | * This function always return distances in original PFR metrics 122 | * units. This is unlike @FT_Get_Kerning with the @FT_KERNING_UNSCALED 123 | * mode, which always returns distances converted to outline units. 124 | * 125 | * You can use the value of the `x_scale' and `y_scale' parameters 126 | * returned by @FT_Get_PFR_Metrics to scale these to device subpixels. 127 | */ 128 | FT_EXPORT( FT_Error ) 129 | FT_Get_PFR_Kerning( FT_Face face, 130 | FT_UInt left, 131 | FT_UInt right, 132 | FT_Vector *avector ); 133 | 134 | 135 | /********************************************************************** 136 | * 137 | * @function: 138 | * FT_Get_PFR_Advance 139 | * 140 | * @description: 141 | * Return a given glyph advance, expressed in original metrics units, 142 | * from a PFR font. 143 | * 144 | * @input: 145 | * face :: A handle to the input face. 146 | * 147 | * gindex :: The glyph index. 148 | * 149 | * @output: 150 | * aadvance :: The glyph advance in metrics units. 151 | * 152 | * @return: 153 | * FreeType error code. 0~means success. 154 | * 155 | * @note: 156 | * You can use the `x_scale' or `y_scale' results of @FT_Get_PFR_Metrics 157 | * to convert the advance to device subpixels (i.e., 1/64th of pixels). 158 | */ 159 | FT_EXPORT( FT_Error ) 160 | FT_Get_PFR_Advance( FT_Face face, 161 | FT_UInt gindex, 162 | FT_Pos *aadvance ); 163 | 164 | /* */ 165 | 166 | 167 | FT_END_HEADER 168 | 169 | #endif /* FTPFR_H_ */ 170 | 171 | 172 | /* END */ 173 | -------------------------------------------------------------------------------- /src/freetype/include/freetype/ftsynth.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************/ 2 | /* */ 3 | /* ftsynth.h */ 4 | /* */ 5 | /* FreeType synthesizing code for emboldening and slanting */ 6 | /* (specification). */ 7 | /* */ 8 | /* Copyright 2000-2018 by */ 9 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 10 | /* */ 11 | /* This file is part of the FreeType project, and may only be used, */ 12 | /* modified, and distributed under the terms of the FreeType project */ 13 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 14 | /* this file you indicate that you have read the license and */ 15 | /* understand and accept it fully. */ 16 | /* */ 17 | /***************************************************************************/ 18 | 19 | 20 | /*************************************************************************/ 21 | /*************************************************************************/ 22 | /*************************************************************************/ 23 | /*************************************************************************/ 24 | /*************************************************************************/ 25 | /********* *********/ 26 | /********* WARNING, THIS IS ALPHA CODE! THIS API *********/ 27 | /********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE *********/ 28 | /********* FREETYPE DEVELOPMENT TEAM *********/ 29 | /********* *********/ 30 | /*************************************************************************/ 31 | /*************************************************************************/ 32 | /*************************************************************************/ 33 | /*************************************************************************/ 34 | /*************************************************************************/ 35 | 36 | 37 | /* Main reason for not lifting the functions in this module to a */ 38 | /* `standard' API is that the used parameters for emboldening and */ 39 | /* slanting are not configurable. Consider the functions as a */ 40 | /* code resource that should be copied into the application and */ 41 | /* adapted to the particular needs. */ 42 | 43 | 44 | #ifndef FTSYNTH_H_ 45 | #define FTSYNTH_H_ 46 | 47 | 48 | #include <ft2build.h> 49 | #include FT_FREETYPE_H 50 | 51 | #ifdef FREETYPE_H 52 | #error "freetype.h of FreeType 1 has been loaded!" 53 | #error "Please fix the directory search order for header files" 54 | #error "so that freetype.h of FreeType 2 is found first." 55 | #endif 56 | 57 | 58 | FT_BEGIN_HEADER 59 | 60 | /* Embolden a glyph by a `reasonable' value (which is highly a matter of */ 61 | /* taste). This function is actually a convenience function, providing */ 62 | /* a wrapper for @FT_Outline_Embolden and @FT_Bitmap_Embolden. */ 63 | /* */ 64 | /* For emboldened outlines the height, width, and advance metrics are */ 65 | /* increased by the strength of the emboldening -- this even affects */ 66 | /* mono-width fonts! */ 67 | /* */ 68 | /* You can also call @FT_Outline_Get_CBox to get precise values. */ 69 | FT_EXPORT( void ) 70 | FT_GlyphSlot_Embolden( FT_GlyphSlot slot ); 71 | 72 | /* Slant an outline glyph to the right by about 12 degrees. */ 73 | FT_EXPORT( void ) 74 | FT_GlyphSlot_Oblique( FT_GlyphSlot slot ); 75 | 76 | /* */ 77 | 78 | 79 | FT_END_HEADER 80 | 81 | #endif /* FTSYNTH_H_ */ 82 | 83 | 84 | /* END */ 85 | -------------------------------------------------------------------------------- /src/freetype/include/freetype/tttags.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************/ 2 | /* */ 3 | /* tttags.h */ 4 | /* */ 5 | /* Tags for TrueType and OpenType tables (specification only). */ 6 | /* */ 7 | /* Copyright 1996-2018 by */ 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 9 | /* */ 10 | /* This file is part of the FreeType project, and may only be used, */ 11 | /* modified, and distributed under the terms of the FreeType project */ 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 13 | /* this file you indicate that you have read the license and */ 14 | /* understand and accept it fully. */ 15 | /* */ 16 | /***************************************************************************/ 17 | 18 | 19 | #ifndef TTAGS_H_ 20 | #define TTAGS_H_ 21 | 22 | 23 | #include <ft2build.h> 24 | #include FT_FREETYPE_H 25 | 26 | #ifdef FREETYPE_H 27 | #error "freetype.h of FreeType 1 has been loaded!" 28 | #error "Please fix the directory search order for header files" 29 | #error "so that freetype.h of FreeType 2 is found first." 30 | #endif 31 | 32 | 33 | FT_BEGIN_HEADER 34 | 35 | 36 | #define TTAG_avar FT_MAKE_TAG( 'a', 'v', 'a', 'r' ) 37 | #define TTAG_BASE FT_MAKE_TAG( 'B', 'A', 'S', 'E' ) 38 | #define TTAG_bdat FT_MAKE_TAG( 'b', 'd', 'a', 't' ) 39 | #define TTAG_BDF FT_MAKE_TAG( 'B', 'D', 'F', ' ' ) 40 | #define TTAG_bhed FT_MAKE_TAG( 'b', 'h', 'e', 'd' ) 41 | #define TTAG_bloc FT_MAKE_TAG( 'b', 'l', 'o', 'c' ) 42 | #define TTAG_bsln FT_MAKE_TAG( 'b', 's', 'l', 'n' ) 43 | #define TTAG_CBDT FT_MAKE_TAG( 'C', 'B', 'D', 'T' ) 44 | #define TTAG_CBLC FT_MAKE_TAG( 'C', 'B', 'L', 'C' ) 45 | #define TTAG_CFF FT_MAKE_TAG( 'C', 'F', 'F', ' ' ) 46 | #define TTAG_CFF2 FT_MAKE_TAG( 'C', 'F', 'F', '2' ) 47 | #define TTAG_CID FT_MAKE_TAG( 'C', 'I', 'D', ' ' ) 48 | #define TTAG_cmap FT_MAKE_TAG( 'c', 'm', 'a', 'p' ) 49 | #define TTAG_cvar FT_MAKE_TAG( 'c', 'v', 'a', 'r' ) 50 | #define TTAG_cvt FT_MAKE_TAG( 'c', 'v', 't', ' ' ) 51 | #define TTAG_DSIG FT_MAKE_TAG( 'D', 'S', 'I', 'G' ) 52 | #define TTAG_EBDT FT_MAKE_TAG( 'E', 'B', 'D', 'T' ) 53 | #define TTAG_EBLC FT_MAKE_TAG( 'E', 'B', 'L', 'C' ) 54 | #define TTAG_EBSC FT_MAKE_TAG( 'E', 'B', 'S', 'C' ) 55 | #define TTAG_feat FT_MAKE_TAG( 'f', 'e', 'a', 't' ) 56 | #define TTAG_FOND FT_MAKE_TAG( 'F', 'O', 'N', 'D' ) 57 | #define TTAG_fpgm FT_MAKE_TAG( 'f', 'p', 'g', 'm' ) 58 | #define TTAG_fvar FT_MAKE_TAG( 'f', 'v', 'a', 'r' ) 59 | #define TTAG_gasp FT_MAKE_TAG( 'g', 'a', 's', 'p' ) 60 | #define TTAG_GDEF FT_MAKE_TAG( 'G', 'D', 'E', 'F' ) 61 | #define TTAG_glyf FT_MAKE_TAG( 'g', 'l', 'y', 'f' ) 62 | #define TTAG_GPOS FT_MAKE_TAG( 'G', 'P', 'O', 'S' ) 63 | #define TTAG_GSUB FT_MAKE_TAG( 'G', 'S', 'U', 'B' ) 64 | #define TTAG_gvar FT_MAKE_TAG( 'g', 'v', 'a', 'r' ) 65 | #define TTAG_HVAR FT_MAKE_TAG( 'H', 'V', 'A', 'R' ) 66 | #define TTAG_hdmx FT_MAKE_TAG( 'h', 'd', 'm', 'x' ) 67 | #define TTAG_head FT_MAKE_TAG( 'h', 'e', 'a', 'd' ) 68 | #define TTAG_hhea FT_MAKE_TAG( 'h', 'h', 'e', 'a' ) 69 | #define TTAG_hmtx FT_MAKE_TAG( 'h', 'm', 't', 'x' ) 70 | #define TTAG_JSTF FT_MAKE_TAG( 'J', 'S', 'T', 'F' ) 71 | #define TTAG_just FT_MAKE_TAG( 'j', 'u', 's', 't' ) 72 | #define TTAG_kern FT_MAKE_TAG( 'k', 'e', 'r', 'n' ) 73 | #define TTAG_lcar FT_MAKE_TAG( 'l', 'c', 'a', 'r' ) 74 | #define TTAG_loca FT_MAKE_TAG( 'l', 'o', 'c', 'a' ) 75 | #define TTAG_LTSH FT_MAKE_TAG( 'L', 'T', 'S', 'H' ) 76 | #define TTAG_LWFN FT_MAKE_TAG( 'L', 'W', 'F', 'N' ) 77 | #define TTAG_MATH FT_MAKE_TAG( 'M', 'A', 'T', 'H' ) 78 | #define TTAG_maxp FT_MAKE_TAG( 'm', 'a', 'x', 'p' ) 79 | #define TTAG_META FT_MAKE_TAG( 'M', 'E', 'T', 'A' ) 80 | #define TTAG_MMFX FT_MAKE_TAG( 'M', 'M', 'F', 'X' ) 81 | #define TTAG_MMSD FT_MAKE_TAG( 'M', 'M', 'S', 'D' ) 82 | #define TTAG_mort FT_MAKE_TAG( 'm', 'o', 'r', 't' ) 83 | #define TTAG_morx FT_MAKE_TAG( 'm', 'o', 'r', 'x' ) 84 | #define TTAG_MVAR FT_MAKE_TAG( 'M', 'V', 'A', 'R' ) 85 | #define TTAG_name FT_MAKE_TAG( 'n', 'a', 'm', 'e' ) 86 | #define TTAG_opbd FT_MAKE_TAG( 'o', 'p', 'b', 'd' ) 87 | #define TTAG_OS2 FT_MAKE_TAG( 'O', 'S', '/', '2' ) 88 | #define TTAG_OTTO FT_MAKE_TAG( 'O', 'T', 'T', 'O' ) 89 | #define TTAG_PCLT FT_MAKE_TAG( 'P', 'C', 'L', 'T' ) 90 | #define TTAG_POST FT_MAKE_TAG( 'P', 'O', 'S', 'T' ) 91 | #define TTAG_post FT_MAKE_TAG( 'p', 'o', 's', 't' ) 92 | #define TTAG_prep FT_MAKE_TAG( 'p', 'r', 'e', 'p' ) 93 | #define TTAG_prop FT_MAKE_TAG( 'p', 'r', 'o', 'p' ) 94 | #define TTAG_sbix FT_MAKE_TAG( 's', 'b', 'i', 'x' ) 95 | #define TTAG_sfnt FT_MAKE_TAG( 's', 'f', 'n', 't' ) 96 | #define TTAG_SING FT_MAKE_TAG( 'S', 'I', 'N', 'G' ) 97 | #define TTAG_trak FT_MAKE_TAG( 't', 'r', 'a', 'k' ) 98 | #define TTAG_true FT_MAKE_TAG( 't', 'r', 'u', 'e' ) 99 | #define TTAG_ttc FT_MAKE_TAG( 't', 't', 'c', ' ' ) 100 | #define TTAG_ttcf FT_MAKE_TAG( 't', 't', 'c', 'f' ) 101 | #define TTAG_TYP1 FT_MAKE_TAG( 'T', 'Y', 'P', '1' ) 102 | #define TTAG_typ1 FT_MAKE_TAG( 't', 'y', 'p', '1' ) 103 | #define TTAG_VDMX FT_MAKE_TAG( 'V', 'D', 'M', 'X' ) 104 | #define TTAG_vhea FT_MAKE_TAG( 'v', 'h', 'e', 'a' ) 105 | #define TTAG_vmtx FT_MAKE_TAG( 'v', 'm', 't', 'x' ) 106 | #define TTAG_VVAR FT_MAKE_TAG( 'V', 'V', 'A', 'R' ) 107 | #define TTAG_wOFF FT_MAKE_TAG( 'w', 'O', 'F', 'F' ) 108 | 109 | /* used by "Keyboard.dfont" on legacy Mac OS X */ 110 | #define TTAG_0xA5kbd FT_MAKE_TAG( 0xA5, 'k', 'b', 'd' ) 111 | 112 | /* used by "LastResort.dfont" on legacy Mac OS X */ 113 | #define TTAG_0xA5lst FT_MAKE_TAG( 0xA5, 'l', 's', 't' ) 114 | 115 | 116 | FT_END_HEADER 117 | 118 | #endif /* TTAGS_H_ */ 119 | 120 | 121 | /* END */ 122 | -------------------------------------------------------------------------------- /src/freetype/include/ft2build.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************/ 2 | /* */ 3 | /* ft2build.h */ 4 | /* */ 5 | /* FreeType 2 build and setup macros. */ 6 | /* */ 7 | /* Copyright 1996-2018 by */ 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 9 | /* */ 10 | /* This file is part of the FreeType project, and may only be used, */ 11 | /* modified, and distributed under the terms of the FreeType project */ 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 13 | /* this file you indicate that you have read the license and */ 14 | /* understand and accept it fully. */ 15 | /* */ 16 | /***************************************************************************/ 17 | 18 | 19 | /*************************************************************************/ 20 | /* */ 21 | /* This is the `entry point' for FreeType header file inclusions. It is */ 22 | /* the only header file which should be included directly; all other */ 23 | /* FreeType header files should be accessed with macro names (after */ 24 | /* including `ft2build.h'). */ 25 | /* */ 26 | /* A typical example is */ 27 | /* */ 28 | /* #include <ft2build.h> */ 29 | /* #include FT_FREETYPE_H */ 30 | /* */ 31 | /*************************************************************************/ 32 | 33 | 34 | #ifndef FT2BUILD_H_ 35 | #define FT2BUILD_H_ 36 | 37 | #include <freetype/config/ftheader.h> 38 | 39 | #endif /* FT2BUILD_H_ */ 40 | 41 | 42 | /* END */ 43 | -------------------------------------------------------------------------------- /src/freetype/win32/freetype.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbits/vdb/b3e1fa993b6466bb949897785aeadda70b9abf38/src/freetype/win32/freetype.dll -------------------------------------------------------------------------------- /src/freetype/win32/freetype.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbits/vdb/b3e1fa993b6466bb949897785aeadda70b9abf38/src/freetype/win32/freetype.lib -------------------------------------------------------------------------------- /src/freetype/win64/freetype.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbits/vdb/b3e1fa993b6466bb949897785aeadda70b9abf38/src/freetype/win64/freetype.dll -------------------------------------------------------------------------------- /src/freetype/win64/freetype.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbits/vdb/b3e1fa993b6466bb949897785aeadda70b9abf38/src/freetype/win64/freetype.lib -------------------------------------------------------------------------------- /src/hints.h: -------------------------------------------------------------------------------- 1 | namespace hints 2 | { 3 | static float view_scale; static bool view_scale_pending; 4 | static bool show_grid; static bool show_grid_pending; 5 | static vdbCameraType camera_type; static bool camera_type_pending; 6 | static vdbOrientation orientation; static bool orientation_pending; 7 | static vdbKey camera_key; static bool camera_key_pending; 8 | static void BeginFrame() 9 | { 10 | if (view_scale_pending) 11 | { 12 | GetFrameSettings()->grid.grid_scale = view_scale; 13 | GetFrameSettings()->grid.dirty = true; 14 | view_scale_pending = false; 15 | } 16 | if (show_grid_pending) 17 | { 18 | GetFrameSettings()->grid.grid_visible = show_grid; 19 | GetFrameSettings()->grid.dirty = true; 20 | show_grid_pending = false; 21 | } 22 | if (camera_type_pending) 23 | { 24 | GetFrameSettings()->camera.type = camera_type; 25 | GetFrameSettings()->camera.dirty = true; 26 | camera_type_pending = false; 27 | } 28 | if (orientation_pending) 29 | { 30 | // obs! this must be applied after we apply the new camera type! 31 | *GetCameraUp() = orientation; 32 | orientation_pending = false; 33 | } 34 | if (camera_key_pending) 35 | { 36 | GetFrameSettings()->camera.key = camera_key; 37 | camera_key_pending = false; 38 | } 39 | } 40 | } 41 | 42 | void vdbHint(vdbHintKey key, float value) 43 | { 44 | if (key == VDB_VIEW_SCALE) 45 | { 46 | hints::view_scale = value; 47 | hints::view_scale_pending = true; 48 | } 49 | } 50 | 51 | void vdbHint(vdbHintKey key, bool value) 52 | { 53 | if (key == VDB_SHOW_GRID) 54 | { 55 | hints::show_grid = value; 56 | hints::show_grid_pending = true; 57 | } 58 | } 59 | 60 | void vdbHint(vdbHintKey key, int value) 61 | { 62 | if (key == VDB_CAMERA_TYPE && 63 | (value == VDB_PLANAR || 64 | value == VDB_TRACKBALL || 65 | value == VDB_TURNTABLE)) 66 | { 67 | hints::camera_type = value; 68 | hints::camera_type_pending = true; 69 | } 70 | else if (key == VDB_ORIENTATION && 71 | (value == VDB_Y_UP || value == VDB_Y_DOWN || 72 | value == VDB_X_UP || value == VDB_X_DOWN || 73 | value == VDB_Z_UP || value == VDB_Z_DOWN)) 74 | { 75 | hints::orientation = value; 76 | hints::orientation_pending = true; 77 | } 78 | else if (key == VDB_CAMERA_KEY && 79 | (value >= 0 && value < VDB_NUM_KEYS)) 80 | { 81 | hints::camera_key = value; 82 | hints::camera_key_pending = true; 83 | } 84 | else if (key == VDB_THEME && (value == VDB_DARK_THEME || value == VDB_BRIGHT_THEME)) 85 | { 86 | settings.global_theme = value; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/imgui/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2019 Omar Cornut 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 | -------------------------------------------------------------------------------- /src/imgui/README.md: -------------------------------------------------------------------------------- 1 | # Updating ImGui 2 | 3 | Follow the instructions below to update [Dear ImGui](https://github.com/ocornut/imgui) to the latest release: 4 | 5 | * Copy the *.cpp files from the Dear ImGui repository into this directory, overwriting files. 6 | * Update include/vdb/imgui.h 7 | * Remove imconfig reference in imgui.h 8 | * Remove anonymous namespace in imgui_freetype.cpp 9 | 10 | In imgui_impl_opengl3.cpp:CheckShader: Some GLSL compilers like to output "There was no error" messages when shader compilation was successful. To avoid printing this message to console on start-up, do the log output only if shader compilation failed, i.e. replace 11 | 12 | ``` 13 | if ((GLboolean)status == GL_FALSE) 14 | ... 15 | if (log_length > 0) 16 | ... 17 | ``` 18 | 19 | with 20 | 21 | ``` 22 | if ((GLboolean)status == GL_FALSE) 23 | { 24 | ... 25 | if (log_length > 0) 26 | ... 27 | } 28 | ``` 29 | -------------------------------------------------------------------------------- /src/imgui/imconfig.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // COMPILE-TIME OPTIONS FOR DEAR IMGUI 3 | // Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure. 4 | // You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions. 5 | //----------------------------------------------------------------------------- 6 | // A) You may edit imconfig.h (and not overwrite it when updating imgui, or maintain a patch/branch with your modifications to imconfig.h) 7 | // B) or add configuration directives in your own file and compile with #define IMGUI_USER_CONFIG "myfilename.h" 8 | // If you do so you need to make sure that configuration settings are defined consistently _everywhere_ dear imgui is used, which include 9 | // the imgui*.cpp files but also _any_ of your code that uses imgui. This is because some compile-time options have an affect on data structures. 10 | // Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts. 11 | // Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using. 12 | //----------------------------------------------------------------------------- 13 | 14 | #pragma once 15 | 16 | //---- Define assertion handler. Defaults to calling assert(). 17 | //#define IM_ASSERT(_EXPR) MyAssert(_EXPR) 18 | //#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts 19 | 20 | //---- Define attributes of all API symbols declarations, e.g. for DLL under Windows. 21 | //#define IMGUI_API __declspec( dllexport ) 22 | //#define IMGUI_API __declspec( dllimport ) 23 | 24 | //---- Don't define obsolete functions/enums names. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names. 25 | //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS 26 | 27 | //---- Don't implement demo windows functionality (ShowDemoWindow()/ShowStyleEditor()/ShowUserGuide() methods will be empty) 28 | //---- It is very strongly recommended to NOT disable the demo windows during development. Please read the comments in imgui_demo.cpp. 29 | //#define IMGUI_DISABLE_DEMO_WINDOWS 30 | 31 | //---- Don't implement some functions to reduce linkage requirements. 32 | //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. 33 | //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] Don't implement default IME handler. Won't use and link with ImmGetContext/ImmSetCompositionWindow. 34 | //#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function. 35 | //#define IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself if you don't want to link with vsnprintf. 36 | //#define IMGUI_DISABLE_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 wrapper so you can implement them yourself. Declare your prototypes in imconfig.h. 37 | //#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(). 38 | 39 | //---- Include imgui_user.h at the end of imgui.h as a convenience 40 | //#define IMGUI_INCLUDE_IMGUI_USER_H 41 | 42 | //---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another) 43 | //#define IMGUI_USE_BGRA_PACKED_COLOR 44 | 45 | //---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version 46 | // By default the embedded implementations are declared static and not available outside of imgui cpp files. 47 | //#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h" 48 | //#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h" 49 | //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION 50 | //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION 51 | 52 | //---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4. 53 | // This will be inlined as part of ImVec2 and ImVec4 class declarations. 54 | /* 55 | #define IM_VEC2_CLASS_EXTRA \ 56 | ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \ 57 | operator MyVec2() const { return MyVec2(x,y); } 58 | 59 | #define IM_VEC4_CLASS_EXTRA \ 60 | ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \ 61 | operator MyVec4() const { return MyVec4(x,y,z,w); } 62 | */ 63 | 64 | //---- Use 32-bit vertex indices (default is 16-bit) to allow meshes with more than 64K vertices. Render function needs to support it. 65 | //#define ImDrawIdx unsigned int 66 | 67 | //---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files. 68 | /* 69 | namespace ImGui 70 | { 71 | void MyFunction(const char* name, const MyMatrix44& v); 72 | } 73 | */ 74 | -------------------------------------------------------------------------------- /src/imgui/imgui_freetype.h: -------------------------------------------------------------------------------- 1 | // Wrapper to use FreeType (instead of stb_truetype) for Dear ImGui 2 | // Get latest version at https://github.com/ocornut/imgui/tree/master/misc/freetype 3 | // Original code by @Vuhdo (Aleksei Skriabin), maintained by @ocornut 4 | 5 | #pragma once 6 | 7 | #include "imgui.h" // IMGUI_API, ImFontAtlas 8 | 9 | namespace ImGuiFreeType 10 | { 11 | // Hinting greatly impacts visuals (and glyph sizes). 12 | // When disabled, FreeType generates blurrier glyphs, more or less matches the stb's output. 13 | // The Default hinting mode usually looks good, but may distort glyphs in an unusual way. 14 | // The Light hinting mode generates fuzzier glyphs but better matches Microsoft's rasterizer. 15 | 16 | // You can set those flags on a per font basis in ImFontConfig::RasterizerFlags. 17 | // Use the 'extra_flags' parameter of BuildFontAtlas() to force a flag on all your fonts. 18 | enum RasterizerFlags 19 | { 20 | // By default, hinting is enabled and the font's native hinter is preferred over the auto-hinter. 21 | NoHinting = 1 << 0, // Disable hinting. This generally generates 'blurrier' bitmap glyphs when the glyph are rendered in any of the anti-aliased modes. 22 | NoAutoHint = 1 << 1, // Disable auto-hinter. 23 | ForceAutoHint = 1 << 2, // Indicates that the auto-hinter is preferred over the font's native hinter. 24 | LightHinting = 1 << 3, // A lighter hinting algorithm for gray-level modes. Many generated glyphs are fuzzier but better resemble their original shape. This is achieved by snapping glyphs to the pixel grid only vertically (Y-axis), as is done by Microsoft's ClearType and Adobe's proprietary font renderer. This preserves inter-glyph spacing in horizontal text. 25 | MonoHinting = 1 << 4, // Strong hinting algorithm that should only be used for monochrome output. 26 | Bold = 1 << 5, // Styling: Should we artificially embolden the font? 27 | Oblique = 1 << 6 // Styling: Should we slant the font, emulating italic style? 28 | }; 29 | 30 | IMGUI_API bool BuildFontAtlas(ImFontAtlas* atlas, unsigned int extra_flags = 0); 31 | } 32 | -------------------------------------------------------------------------------- /src/imgui/imgui_impl_opengl3.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer for OpenGL3 / OpenGL ES2 / OpenGL ES3 (modern OpenGL with shaders / programmatic pipeline) 2 | // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..) 3 | // (Note: We are using GL3W as a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc..) 4 | 5 | // Implemented features: 6 | // [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. 7 | 8 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. 9 | // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. 10 | // https://github.com/ocornut/imgui 11 | 12 | // About OpenGL function loaders: 13 | // About OpenGL function loaders: modern OpenGL doesn't have a standard header file and requires individual function pointers to be loaded manually. 14 | // Helper libraries are often used for this purpose! Here we are supporting a few common ones: gl3w, glew, glad. 15 | // You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own. 16 | 17 | // About GLSL version: 18 | // The 'glsl_version' initialization parameter should be NULL (default) or a "#version XXX" string. 19 | // On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es" 20 | // Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp. 21 | 22 | #pragma once 23 | 24 | // Set default OpenGL loader to be gl3w 25 | #if !defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) \ 26 | && !defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) \ 27 | && !defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) \ 28 | && !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM) 29 | #define IMGUI_IMPL_OPENGL_LOADER_GL3W 30 | #endif 31 | 32 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = NULL); 33 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown(); 34 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame(); 35 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data); 36 | 37 | // Called by Init/NewFrame/Shutdown 38 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture(); 39 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyFontsTexture(); 40 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects(); 41 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects(); 42 | -------------------------------------------------------------------------------- /src/imgui/imgui_impl_sdl.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Binding for SDL2 2 | // This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..) 3 | // (Info: SDL2 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.) 4 | 5 | // Implemented features: 6 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. 7 | // [X] Platform: Clipboard support. 8 | // [X] Platform: Keyboard arrays indexed using SDL_SCANCODE_* codes, e.g. ImGui::IsKeyPressed(SDL_SCANCODE_SPACE). 9 | // Missing features: 10 | // [ ] Platform: SDL2 handling of IME under Windows appears to be broken and it explicitly disable the regular Windows IME. You can restore Windows IME by compiling SDL with SDL_DISABLE_WINDOWS_IME. 11 | // [ ] Platform: Gamepad support (need to use SDL_GameController API to fill the io.NavInputs[] value when ImGuiConfigFlags_NavEnableGamepad is set). 12 | 13 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. 14 | // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. 15 | // https://github.com/ocornut/imgui 16 | 17 | #pragma once 18 | 19 | struct SDL_Window; 20 | typedef union SDL_Event SDL_Event; 21 | 22 | IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context); 23 | IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window); 24 | IMGUI_IMPL_API void ImGui_ImplSDL2_Shutdown(); 25 | IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame(SDL_Window* window); 26 | IMGUI_IMPL_API bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event); 27 | -------------------------------------------------------------------------------- /src/immediate_util.h: -------------------------------------------------------------------------------- 1 | namespace immediate_util 2 | { 3 | static int circle_segments; 4 | static int note_index; 5 | static float note_align_x; 6 | static float note_align_y; 7 | static char temp_buffer[1024*3 + 1]; 8 | static void BeginFrame() 9 | { 10 | note_index = 0; 11 | note_align_x = 0.0f; 12 | note_align_y = 0.0f; 13 | circle_segments = 64; 14 | } 15 | } 16 | 17 | void vdbCircleSegments(int segments) 18 | { 19 | immediate_util::circle_segments = segments; 20 | } 21 | 22 | void vdbNoteV(float x, float y, const char *fmt, va_list args) 23 | { 24 | using namespace immediate_util; 25 | vdbVec2 ndc = vdbModelToNDC(x,y,0.0f,1.0f); 26 | vdbVec2 win = vdbNDCToWindow(ndc.x,ndc.y); 27 | ImFormatString(temp_buffer, sizeof(temp_buffer), "vdb_tooltip_%d", note_index); 28 | ImGui::SetNextWindowPos(ImVec2(win.x, win.y), 0, ImVec2(note_align_x, note_align_y)); 29 | ImGui::Begin(temp_buffer, 0, ImGuiWindowFlags_NoInputs|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_AlwaysAutoResize); 30 | ImGui::TextV(fmt, args); 31 | ImGui::End(); 32 | note_index++; 33 | } 34 | 35 | void vdbNote(float x, float y, const char *fmt, ...) 36 | { 37 | va_list args; 38 | va_start(args, fmt); 39 | vdbNoteV(x, y, fmt, args); 40 | va_end(args); 41 | } 42 | 43 | void vdbNoteAlign(float x, float y) 44 | { 45 | immediate_util::note_align_x = x; 46 | immediate_util::note_align_y = y; 47 | } 48 | 49 | void vdbFillRect_(float x, float y, float w, float h) 50 | { 51 | vdbVertex(x, y); 52 | vdbVertex(x+w, y); 53 | vdbVertex(x+w, y+h); 54 | vdbVertex(x+w, y+h); 55 | vdbVertex(x, y+h); 56 | vdbVertex(x, y); 57 | } 58 | void vdbFillRect(float x, float y, float w, float h) 59 | { 60 | vdbBeginTriangles(); 61 | vdbFillRect_(x, y, w, h); 62 | vdbEnd(); 63 | } 64 | 65 | void vdbLineRect_(float x, float y, float w, float h) 66 | { 67 | vdbVertex(x, y); vdbVertex(x+w, y); 68 | vdbVertex(x+w, y); vdbVertex(x+w, y+h); 69 | vdbVertex(x+w, y+h); vdbVertex(x, y+h); 70 | vdbVertex(x, y+h); vdbVertex(x, y); 71 | } 72 | void vdbLineRect(float x, float y, float w, float h) 73 | { 74 | vdbBeginLines(); 75 | vdbLineRect_(x, y, w, h); 76 | vdbEnd(); 77 | } 78 | 79 | void vdbLineCircle_(float x, float y, float radius) 80 | { 81 | int segments = immediate_util::circle_segments; 82 | const float two_pi = 6.28318530718f; 83 | for (int i = 0; i < segments; i++) 84 | { 85 | int i1 = i; 86 | int i2 = (i + 1) % segments; 87 | float t0 = two_pi*i1/(float)segments; 88 | float t1 = two_pi*i2/(float)segments; 89 | vdbVertex(x + radius*cosf(t0),y + radius*sinf(t0)); 90 | vdbVertex(x + radius*cosf(t1),y + radius*sinf(t1)); 91 | } 92 | } 93 | void vdbLineCircle(float x, float y, float radius) 94 | { 95 | vdbBeginLines(); 96 | vdbLineCircle_(x, y, radius); 97 | vdbEnd(); 98 | } 99 | 100 | void vdbFillCircle_(float x, float y, float radius) 101 | { 102 | int segments = immediate_util::circle_segments; 103 | const float two_pi = 6.28318530718f; 104 | for (int i = 0; i < segments; i++) 105 | { 106 | int i1 = i; 107 | int i2 = (i + 1) % segments; 108 | float t0 = two_pi*i1/(float)segments; 109 | float t1 = two_pi*i2/(float)segments; 110 | vdbVertex(x, y); 111 | vdbVertex(x + radius*cosf(t0),y + radius*sinf(t0)); 112 | vdbVertex(x + radius*cosf(t1),y + radius*sinf(t1)); 113 | } 114 | } 115 | void vdbFillCircle(float x, float y, float radius) 116 | { 117 | vdbBeginTriangles(); 118 | vdbFillCircle_(x, y, radius); 119 | vdbEnd(); 120 | } 121 | 122 | void vdbFillTexturedRect_(float x, float y, float w, float h) 123 | { 124 | vdbTexel(0,0); vdbVertex(x, y); 125 | vdbTexel(1,0); vdbVertex(x+w, y); 126 | vdbTexel(1,1); vdbVertex(x+w, y+h); 127 | vdbTexel(1,1); vdbVertex(x+w, y+h); 128 | vdbTexel(0,1); vdbVertex(x, y+h); 129 | vdbTexel(0,0); vdbVertex(x, y); 130 | } 131 | void vdbFillTexturedRect(float x, float y, float w, float h) 132 | { 133 | vdbBeginTriangles(); 134 | vdbFillTexturedRect_(x, y, w, h); 135 | vdbEnd(); 136 | } 137 | 138 | void vdbLineCube_(float wx, float wy, float wz) 139 | { 140 | float x2 = wx/2.0f; 141 | float y2 = wy/2.0f; 142 | float z2 = wz/2.0f; 143 | vdbVertex(-x2, -y2, -z2); vdbVertex(+x2, -y2, -z2); 144 | vdbVertex(+x2, -y2, -z2); vdbVertex(+x2, +y2, -z2); 145 | vdbVertex(+x2, +y2, -z2); vdbVertex(-x2, +y2, -z2); 146 | vdbVertex(-x2, +y2, -z2); vdbVertex(-x2, -y2, -z2); 147 | 148 | vdbVertex(-x2, -y2, +z2); vdbVertex(+x2, -y2, +z2); 149 | vdbVertex(+x2, -y2, +z2); vdbVertex(+x2, +y2, +z2); 150 | vdbVertex(+x2, +y2, +z2); vdbVertex(-x2, +y2, +z2); 151 | vdbVertex(-x2, +y2, +z2); vdbVertex(-x2, -y2, +z2); 152 | 153 | vdbVertex(-x2, -y2, -z2); vdbVertex(-x2, -y2, +z2); 154 | vdbVertex(+x2, -y2, -z2); vdbVertex(+x2, -y2, +z2); 155 | vdbVertex(+x2, +y2, -z2); vdbVertex(+x2, +y2, +z2); 156 | vdbVertex(-x2, +y2, -z2); vdbVertex(-x2, +y2, +z2); 157 | } 158 | void vdbLineCube(float wx, float wy, float wz) 159 | { 160 | vdbBeginLines(); 161 | vdbLineCube_(wx, wy, wz); 162 | vdbEnd(); 163 | } 164 | 165 | void vdbLineCube_(vdbVec3 p_min, vdbVec3 p_max) 166 | { 167 | vdbVertex(p_min.x, p_min.y, p_min.z); vdbVertex(p_max.x, p_min.y, p_min.z); 168 | vdbVertex(p_max.x, p_min.y, p_min.z); vdbVertex(p_max.x, p_max.y, p_min.z); 169 | vdbVertex(p_max.x, p_max.y, p_min.z); vdbVertex(p_min.x, p_max.y, p_min.z); 170 | vdbVertex(p_min.x, p_max.y, p_min.z); vdbVertex(p_min.x, p_min.y, p_min.z); 171 | 172 | vdbVertex(p_min.x, p_min.y, p_max.z); vdbVertex(p_max.x, p_min.y, p_max.z); 173 | vdbVertex(p_max.x, p_min.y, p_max.z); vdbVertex(p_max.x, p_max.y, p_max.z); 174 | vdbVertex(p_max.x, p_max.y, p_max.z); vdbVertex(p_min.x, p_max.y, p_max.z); 175 | vdbVertex(p_min.x, p_max.y, p_max.z); vdbVertex(p_min.x, p_min.y, p_max.z); 176 | 177 | vdbVertex(p_min.x, p_min.y, p_min.z); vdbVertex(p_min.x, p_min.y, p_max.z); 178 | vdbVertex(p_max.x, p_min.y, p_min.z); vdbVertex(p_max.x, p_min.y, p_max.z); 179 | vdbVertex(p_max.x, p_max.y, p_min.z); vdbVertex(p_max.x, p_max.y, p_max.z); 180 | vdbVertex(p_min.x, p_max.y, p_min.z); vdbVertex(p_min.x, p_max.y, p_max.z); 181 | } 182 | void vdbLineCube(vdbVec3 p_min, vdbVec3 p_max) 183 | { 184 | vdbBeginLines(); 185 | vdbLineCube_(p_min, p_max); 186 | vdbEnd(); 187 | } 188 | 189 | void vdbFillArc_(vdbVec3 base, vdbVec3 p1, vdbVec3 p2) 190 | { 191 | int segments = immediate_util::circle_segments; 192 | float r1 = vdbVecLength(p1); 193 | float r2 = vdbVecLength(p2); 194 | for (int i = 0; i < segments; i++) 195 | { 196 | float t1 = (float)(i+0)/segments; 197 | float t2 = (float)(i+1)/segments; 198 | float rq1 = r1 + (r2-r1)*t1; 199 | float rq2 = r1 + (r2-r1)*t2; 200 | vdbVec3 q1 = vdbVecNormalize(p1 + (p2-p1)*t1)*rq1; 201 | vdbVec3 q2 = vdbVecNormalize(p1 + (p2-p1)*t2)*rq2; 202 | vdbVertex(0,0,0); 203 | vdbVertex(q1.x, q1.y, q1.z); 204 | vdbVertex(q2.x, q2.y, q2.z); 205 | } 206 | } 207 | void vdbFillArc(vdbVec3 base, vdbVec3 p1, vdbVec3 p2) 208 | { 209 | vdbBeginTriangles(); 210 | vdbFillArc_(base, p1, p2); 211 | vdbEnd(); 212 | } 213 | 214 | // void vdbDrawAxes(vdbVec3 center, vdbVec3 x, vdbVec3 y, vdbVec3 z, float scale=1.0f); 215 | // void vdbDrawTextV(float x, float y, const char *fmt, va_list args); 216 | // void vdbDrawText(float x, float y, const char *fmt, ...); 217 | -------------------------------------------------------------------------------- /src/keys.h: -------------------------------------------------------------------------------- 1 | // Subset of scancodes copied from SDL_scancodes.h 2 | vdbKey VDB_KEY_INVALID = 0; 3 | vdbKey VDB_KEY_A = 4; 4 | vdbKey VDB_KEY_B = 5; 5 | vdbKey VDB_KEY_C = 6; 6 | vdbKey VDB_KEY_D = 7; 7 | vdbKey VDB_KEY_E = 8; 8 | vdbKey VDB_KEY_F = 9; 9 | vdbKey VDB_KEY_G = 10; 10 | vdbKey VDB_KEY_H = 11; 11 | vdbKey VDB_KEY_I = 12; 12 | vdbKey VDB_KEY_J = 13; 13 | vdbKey VDB_KEY_K = 14; 14 | vdbKey VDB_KEY_L = 15; 15 | vdbKey VDB_KEY_M = 16; 16 | vdbKey VDB_KEY_N = 17; 17 | vdbKey VDB_KEY_O = 18; 18 | vdbKey VDB_KEY_P = 19; 19 | vdbKey VDB_KEY_Q = 20; 20 | vdbKey VDB_KEY_R = 21; 21 | vdbKey VDB_KEY_S = 22; 22 | vdbKey VDB_KEY_T = 23; 23 | vdbKey VDB_KEY_U = 24; 24 | vdbKey VDB_KEY_V = 25; 25 | vdbKey VDB_KEY_W = 26; 26 | vdbKey VDB_KEY_X = 27; 27 | vdbKey VDB_KEY_Y = 28; 28 | vdbKey VDB_KEY_Z = 29; 29 | vdbKey VDB_KEY_1 = 30; 30 | vdbKey VDB_KEY_2 = 31; 31 | vdbKey VDB_KEY_3 = 32; 32 | vdbKey VDB_KEY_4 = 33; 33 | vdbKey VDB_KEY_5 = 34; 34 | vdbKey VDB_KEY_6 = 35; 35 | vdbKey VDB_KEY_7 = 36; 36 | vdbKey VDB_KEY_8 = 37; 37 | vdbKey VDB_KEY_9 = 38; 38 | vdbKey VDB_KEY_0 = 39; 39 | vdbKey VDB_KEY_RETURN = 40; 40 | vdbKey VDB_KEY_ESCAPE = 41; 41 | vdbKey VDB_KEY_BACKSPACE = 42; 42 | vdbKey VDB_KEY_TAB = 43; 43 | vdbKey VDB_KEY_SPACE = 44; 44 | vdbKey VDB_KEY_F1 = 58; 45 | vdbKey VDB_KEY_F2 = 59; 46 | vdbKey VDB_KEY_F3 = 60; 47 | vdbKey VDB_KEY_F4 = 61; 48 | vdbKey VDB_KEY_F5 = 62; 49 | vdbKey VDB_KEY_F6 = 63; 50 | vdbKey VDB_KEY_F7 = 64; 51 | vdbKey VDB_KEY_F8 = 65; 52 | vdbKey VDB_KEY_F9 = 66; 53 | vdbKey VDB_KEY_F10 = 67; 54 | vdbKey VDB_KEY_F11 = 68; 55 | vdbKey VDB_KEY_F12 = 69; 56 | vdbKey VDB_KEY_HOME = 74; 57 | vdbKey VDB_KEY_PAGEUP = 75; 58 | vdbKey VDB_KEY_DELETE = 76; 59 | vdbKey VDB_KEY_END = 77; 60 | vdbKey VDB_KEY_PAGEDOWN = 78; 61 | vdbKey VDB_KEY_RIGHT = 79; 62 | vdbKey VDB_KEY_LEFT = 80; 63 | vdbKey VDB_KEY_DOWN = 81; 64 | vdbKey VDB_KEY_UP = 82; 65 | vdbKey VDB_KEY_LCTRL = 224; 66 | vdbKey VDB_KEY_LSHIFT = 225; 67 | vdbKey VDB_KEY_LALT = 226; 68 | vdbKey VDB_KEY_LGUI = 227; 69 | vdbKey VDB_KEY_RCTRL = 228; 70 | vdbKey VDB_KEY_RSHIFT = 229; 71 | vdbKey VDB_KEY_RALT = 230; 72 | vdbKey VDB_KEY_RGUI = 231; 73 | 74 | namespace keys 75 | { 76 | static bool pressed[VDB_NUM_KEYS]; 77 | static bool down[VDB_NUM_KEYS]; 78 | static bool released[VDB_NUM_KEYS]; 79 | } 80 | 81 | bool vdbWasKeyPressed(vdbKey key) { if (key >= 0 && key < VDB_NUM_KEYS) return keys::pressed[key] && !ImGui::GetIO().WantCaptureKeyboard; return false; } 82 | bool vdbWasKeyReleased(vdbKey key) { if (key >= 0 && key < VDB_NUM_KEYS) return keys::released[key] && !ImGui::GetIO().WantCaptureKeyboard; return false; } 83 | bool vdbIsKeyDown(vdbKey key) { if (key >= 0 && key < VDB_NUM_KEYS) return keys::down[key] && !ImGui::GetIO().WantCaptureKeyboard; return false; } 84 | -------------------------------------------------------------------------------- /src/matrix_stack.h: -------------------------------------------------------------------------------- 1 | struct matrix_stack_t 2 | { 3 | enum { stack_capacity = 1024 }; 4 | int stack_index; 5 | vdbMat4 data[stack_capacity]; 6 | 7 | void Reset() 8 | { 9 | stack_index = 0; 10 | LoadIdentity(); 11 | } 12 | 13 | vdbMat4 Top() 14 | { 15 | assert(stack_index >= 0 && stack_index < stack_capacity); 16 | return data[stack_index]; 17 | } 18 | 19 | void Push() 20 | { 21 | assert(stack_index + 1 < stack_capacity); 22 | stack_index++; 23 | data[stack_index] = data[stack_index-1]; 24 | } 25 | 26 | void Pop() 27 | { 28 | assert(stack_index > 0); 29 | stack_index--; 30 | } 31 | 32 | void LoadIdentity() 33 | { 34 | assert(stack_index >= 0 && stack_index < stack_capacity); 35 | data[stack_index] = vdbMatIdentity(); 36 | } 37 | 38 | void Load(vdbMat4 m) 39 | { 40 | assert(stack_index >= 0 && stack_index < stack_capacity); 41 | data[stack_index] = m; 42 | } 43 | 44 | void Multiply(vdbMat4 m) 45 | { 46 | assert(stack_index >= 0 && stack_index < stack_capacity); 47 | data[stack_index] = vdbMul4x4(data[stack_index], m); 48 | } 49 | }; 50 | -------------------------------------------------------------------------------- /src/mouse.h: -------------------------------------------------------------------------------- 1 | namespace mouse_over 2 | { 3 | static int index; 4 | static int closest_index; 5 | static int prev_closest_index; 6 | static float closest_distance; 7 | static float closest_x; 8 | static float closest_y; 9 | static float closest_z; 10 | } 11 | 12 | namespace mouse 13 | { 14 | static int x,y; // The position of the mouse in the client area in screen coordinates where (0,0):top-left 15 | static vdbVec2 ndc; // -||- in normalized device coordinates where (-1,-1):bottom-left (+1,+1):top-right 16 | static float wheel; 17 | static struct button_t 18 | { 19 | bool pressed,released,down; 20 | } left,right,middle; 21 | 22 | static void BeginFrame() 23 | { 24 | // Note: this must be called after viewport is set up 25 | ndc = vdbWindowToNDC((float)x, (float)y); 26 | 27 | mouse_over::closest_distance = FLT_MAX; 28 | mouse_over::prev_closest_index = mouse_over::closest_index; 29 | mouse_over::index = 0; 30 | mouse_over::closest_index = -1; 31 | } 32 | } 33 | 34 | bool vdbWasMouseOver(float x, float y, float z, float w) 35 | { 36 | // todo: find closest in z 37 | vdbVec2 ndc = vdbModelToNDC(x, y, z, w); 38 | vdbVec2 win = vdbNDCToWindow(ndc.x, ndc.y); 39 | 40 | float dx = win.x - (float)mouse::x; 41 | float dy = win.y - (float)mouse::y; 42 | 43 | float distance = dx*dx + dy*dy; 44 | 45 | if (distance < mouse_over::closest_distance) 46 | { 47 | mouse_over::closest_index = mouse_over::index; 48 | mouse_over::closest_x = x; 49 | mouse_over::closest_y = y; 50 | mouse_over::closest_z = z; 51 | mouse_over::closest_distance = distance; 52 | } 53 | 54 | bool active_last_frame = mouse_over::index == mouse_over::prev_closest_index; 55 | mouse_over::index++; 56 | return active_last_frame; 57 | } 58 | int vdbGetMouseOverIndex(float *x, float *y, float *z) 59 | { 60 | if (x) *x = mouse_over::closest_x; 61 | if (y) *y = mouse_over::closest_y; 62 | if (z) *z = mouse_over::closest_z; 63 | return mouse_over::closest_index; 64 | } 65 | 66 | vdbVec2 vdbGetMousePos() 67 | { 68 | return vdbVec2((float)mouse::x, (float)mouse::y); 69 | } 70 | 71 | vdbVec2 vdbGetMousePosNDC() 72 | { 73 | return mouse::ndc; 74 | } 75 | 76 | vdbVec3 vdbGetMousePosModel(float depth) 77 | { 78 | vdbVec2 ndc = vdbGetMousePosNDC(); 79 | vdbVec3 model = vdbNDCToModel(ndc.x, ndc.y, depth); 80 | return model; 81 | } 82 | 83 | float vdbGetMouseWheel() 84 | { 85 | return ImGui::GetIO().WantCaptureMouse ? 0.0f : mouse::wheel; 86 | } 87 | 88 | bool vdbWasMouseLeftPressed() { return mouse::left.pressed && !ImGui::GetIO().WantCaptureMouse; } 89 | bool vdbWasMouseRightPressed() { return mouse::right.pressed && !ImGui::GetIO().WantCaptureMouse; } 90 | bool vdbWasMouseMiddlePressed() { return mouse::middle.pressed && !ImGui::GetIO().WantCaptureMouse; } 91 | bool vdbWasMouseLeftReleased() { return mouse::left.released && !ImGui::GetIO().WantCaptureMouse; } 92 | bool vdbWasMouseRightReleased() { return mouse::right.released && !ImGui::GetIO().WantCaptureMouse; } 93 | bool vdbWasMouseMiddleReleased() { return mouse::middle.released && !ImGui::GetIO().WantCaptureMouse; } 94 | bool vdbIsMouseLeftDown() { return mouse::left.down && !ImGui::GetIO().WantCaptureMouse; } 95 | bool vdbIsMouseRightDown() { return mouse::right.down && !ImGui::GetIO().WantCaptureMouse; } 96 | bool vdbIsMouseMiddleDown() { return mouse::middle.down && !ImGui::GetIO().WantCaptureMouse; } 97 | -------------------------------------------------------------------------------- /src/render_target.h: -------------------------------------------------------------------------------- 1 | typedef framebuffer_t render_target_t; 2 | 3 | enum { MAX_RENDER_TARGETS = 1024 }; 4 | static framebuffer_t render_targets[MAX_RENDER_TARGETS]; 5 | 6 | void vdbBeginRenderTarget(int slot, vdbRenderTargetDesc desc) 7 | { 8 | assert(slot >= 0 && slot < MAX_RENDER_TARGETS && "You are trying to use a render texture beyond the available slots."); 9 | 10 | assert(desc.format == VDB_RGBA32F || desc.format == VDB_RGBA8); 11 | assert(desc.stencil_bits == 0 && "Stencil in RenderTarget is not implemented yet."); 12 | assert(desc.width > 0 && desc.height > 0 && "RenderTarget must have non-zero width and height."); 13 | 14 | render_target_t *rt = render_targets + slot; 15 | bool should_create = false; 16 | if (rt->fbo) 17 | { 18 | if (rt->width != desc.width || rt->height != desc.height) 19 | { 20 | FreeFramebuffer(rt); 21 | should_create = true; 22 | } 23 | } 24 | else 25 | { 26 | should_create = true; 27 | } 28 | 29 | if (should_create) 30 | { 31 | GLenum internal_format = TextureFormatToGL(desc.format); 32 | bool enable_depth = (desc.depth_bits > 0); 33 | 34 | *rt = MakeFramebuffer(desc.width, desc.height, GL_LINEAR, GL_LINEAR, enable_depth, internal_format); 35 | EnableFramebuffer(rt); 36 | glClearColor(0,0,0,0); 37 | if (enable_depth) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 38 | else glClear(GL_COLOR_BUFFER_BIT); 39 | DisableFramebuffer(rt); 40 | } 41 | 42 | EnableFramebuffer(rt); 43 | } 44 | 45 | void vdbEndRenderTarget() 46 | { 47 | assert(current_framebuffer && "vdbEndRenderTarget was called but no render target was bound."); 48 | DisableFramebuffer(current_framebuffer); 49 | 50 | // todo: if LINEAR_MIPMAP, regenerate mipmaps 51 | } 52 | 53 | void vdbBindRenderTarget(int slot, vdbTextureFilter filter, vdbTextureWrap wrap) 54 | { 55 | assert(slot >= 0 && slot < MAX_RENDER_TARGETS && "You are trying to use a render texture beyond the available slots."); 56 | glBindTexture(GL_TEXTURE_2D, render_targets[slot].color[0]); 57 | vdbSetTextureParameters(filter, wrap); 58 | } 59 | 60 | void vdbBindRenderTargetDepth(int slot, vdbTextureFilter filter, vdbTextureWrap wrap) 61 | { 62 | assert(slot >= 0 && slot < MAX_RENDER_TARGETS && "You are trying to use a render texture beyond the available slots."); 63 | glBindTexture(GL_TEXTURE_2D, render_targets[slot].depth); 64 | vdbSetTextureParameters(filter, wrap); 65 | } 66 | 67 | void DrawRenderTargetWithDepth(render_target_t rt, vdbTextureFilter filter, vdbTextureWrap wrap) 68 | { 69 | #define SHADER(S) "#version 150\n" #S 70 | const char *vs = SHADER( 71 | in vec2 position; 72 | out vec2 texel; 73 | void main() 74 | { 75 | texel = vec2(0.5) + 0.5*position; 76 | gl_Position = vec4(position, 0.0, 1.0); 77 | } 78 | ); 79 | 80 | const char *fs = SHADER( 81 | in vec2 texel; 82 | uniform sampler2D sampler0; 83 | uniform sampler2D sampler1; 84 | out vec4 out_color; 85 | void main() 86 | { 87 | out_color = texture(sampler0, texel); 88 | gl_FragDepth = texture(sampler1, texel).x; 89 | } 90 | ); 91 | #undef SHADER 92 | 93 | static GLuint program = LoadShaderFromMemory(vs,fs); 94 | static GLint attrib_position = glGetAttribLocation(program, "position"); 95 | static GLint uniform_sampler0 = glGetUniformLocation(program, "sampler0"); 96 | static GLint uniform_sampler1 = glGetUniformLocation(program, "sampler1"); 97 | 98 | static GLuint vao = 0; 99 | static GLuint vbo = 0; 100 | if (!vao) 101 | { 102 | static float position[] = { -1,-1, 1,-1, 1,1, 1,1, -1,1, -1,-1 }; 103 | glGenVertexArrays(1, &vao); 104 | glGenBuffers(1, &vbo); 105 | glBindBuffer(GL_ARRAY_BUFFER, vbo); 106 | glBufferData(GL_ARRAY_BUFFER, sizeof(position), position, GL_STATIC_DRAW); 107 | } 108 | assert(vao); 109 | assert(vbo); 110 | 111 | glBindVertexArray(vao); 112 | glBindBuffer(GL_ARRAY_BUFFER, vbo); 113 | glUseProgram(program); 114 | glActiveTexture(GL_TEXTURE1); 115 | glUniform1i(uniform_sampler1, 1); 116 | glBindTexture(GL_TEXTURE_2D, rt.depth); 117 | vdbSetTextureParameters(filter, wrap); 118 | glActiveTexture(GL_TEXTURE0); 119 | glUniform1i(uniform_sampler0, 0); 120 | glBindTexture(GL_TEXTURE_2D, rt.color[0]); 121 | vdbSetTextureParameters(filter, wrap); 122 | glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 0, 0); 123 | glEnableVertexAttribArray(attrib_position); 124 | glDrawArrays(GL_TRIANGLES, 0, 6); 125 | glDisableVertexAttribArray(attrib_position); 126 | glUseProgram(0); 127 | glBindBuffer(GL_ARRAY_BUFFER, 0); 128 | glBindVertexArray(0); 129 | } 130 | 131 | void vdbDrawRenderTargetWithDepth(int slot, vdbTextureFilter filter, vdbTextureWrap wrap) 132 | { 133 | assert(slot >= 0 && slot < MAX_RENDER_TARGETS && "You are trying to use a render texture beyond the available slots."); 134 | DrawRenderTargetWithDepth(render_targets[slot], filter, wrap); 135 | } 136 | 137 | void vdbDrawRenderTarget(int slot, vdbTextureFilter filter, vdbTextureWrap wrap) 138 | { 139 | assert(slot >= 0 && slot < MAX_RENDER_TARGETS && "You are trying to use a render texture beyond the available slots."); 140 | 141 | glActiveTexture(GL_TEXTURE0); 142 | glBindTexture(GL_TEXTURE_2D, render_targets[slot].color[0]); 143 | vdbSetTextureParameters(filter, wrap); 144 | vdbBeginTriangles(); 145 | vdbColor(1,1,1,1); 146 | vdbTexel(0,0); vdbVertex(-1,-1); 147 | vdbTexel(1,0); vdbVertex(+1,-1); 148 | vdbTexel(1,1); vdbVertex(+1,+1); 149 | vdbTexel(1,1); vdbVertex(+1,+1); 150 | vdbTexel(0,1); vdbVertex(-1,+1); 151 | vdbTexel(0,0); vdbVertex(-1,-1); 152 | vdbEnd(); 153 | glBindTexture(GL_TEXTURE_2D, 0); 154 | } 155 | -------------------------------------------------------------------------------- /src/ruler.h: -------------------------------------------------------------------------------- 1 | namespace ruler 2 | { 3 | static bool active; 4 | static bool dragging; 5 | static vdbVec2 a,b,mouse; // window coordinates 6 | static vdbVec3 a_model,b_model,mouse_model; // model coordinates 7 | static float distance_model; 8 | static float distance; 9 | static int max_text_length; 10 | 11 | static void BeginFrame(); 12 | static void EndFrame(); 13 | static void DrawOverlay(); 14 | } 15 | 16 | static void ruler::BeginFrame() 17 | { 18 | if (VDB_HOTKEY_RULER_MODE) 19 | active = !active; 20 | 21 | if (ui::ruler_should_open) 22 | { 23 | active = true; 24 | ui::ruler_should_open = false; 25 | } 26 | 27 | if (!active) 28 | { 29 | max_text_length = 0; 30 | return; 31 | } 32 | 33 | if (keys::pressed[VDB_KEY_ESCAPE]) 34 | { 35 | active = false; 36 | ui::escape_eaten = true; 37 | return; 38 | } 39 | 40 | mouse = vdbGetMousePos(); 41 | if (vdbIsMouseLeftDown()) 42 | { 43 | if (!dragging) 44 | { 45 | dragging = true; 46 | a = mouse; 47 | b = mouse; 48 | } 49 | else 50 | { 51 | b = mouse; 52 | } 53 | } 54 | else 55 | { 56 | dragging = false; 57 | } 58 | 59 | // force all subsequent calls to vdb{Is,Was}{Mouse,Key}{UpDownPressed} to return false 60 | ImGui::GetIO().WantCaptureKeyboard = true; 61 | ImGui::GetIO().WantCaptureMouse = true; 62 | } 63 | 64 | static void ruler::EndFrame() 65 | { 66 | if (!active) 67 | return; 68 | 69 | vdbVec2 a_ndc = vdbWindowToNDC(a.x, a.y); 70 | vdbVec2 b_ndc = vdbWindowToNDC(b.x, b.y); 71 | vdbVec2 mouse_ndc = vdbWindowToNDC(mouse.x, mouse.y); 72 | a_model = vdbNDCToModel(a_ndc.x, a_ndc.y); 73 | b_model = vdbNDCToModel(b_ndc.x, b_ndc.y); 74 | mouse_model = vdbNDCToModel(mouse_ndc.x, mouse_ndc.y); 75 | float dx = b_model.x - a_model.x; 76 | float dy = b_model.y - a_model.y; 77 | float dz = b_model.z - a_model.z; 78 | distance_model = sqrtf(dx*dx + dy*dy + dz*dz); 79 | distance = sqrtf((b.x-a.x)*(b.x-a.x) + (b.y-a.y)*(b.y-a.y)); 80 | } 81 | 82 | static void ruler::DrawOverlay() 83 | { 84 | if (!active) 85 | return; 86 | 87 | ImDrawList *draw = ImGui::GetOverlayDrawList(); 88 | 89 | ImU32 fg = IM_COL32(255,255,255,255); 90 | ImU32 bg = IM_COL32(0,0,0,255); 91 | 92 | if (distance > 1.0f) 93 | { 94 | float thickness = 2.0f; 95 | draw->AddLine(ImVec2(a.x,a.y), ImVec2(b.x,b.y), bg, thickness+2.0f); 96 | draw->AddCircleFilled(ImVec2(a.x,a.y), 5.0f, bg); 97 | draw->AddCircleFilled(ImVec2(b.x,b.y), 5.0f, bg); 98 | draw->AddLine(ImVec2(a.x,a.y), ImVec2(b.x,b.y), fg, thickness); 99 | draw->AddCircleFilled(ImVec2(a.x,a.y), 4.0f, fg); 100 | draw->AddCircleFilled(ImVec2(b.x,b.y), 4.0f, fg); 101 | } 102 | 103 | ImGui::BeginMainMenuBar(); 104 | ImGui::Separator(); 105 | ImGui::Text("Ruler: %10.6f (%d pixels)", distance_model, (int)distance); 106 | ImGui::EndMainMenuBar(); 107 | } 108 | -------------------------------------------------------------------------------- /src/shader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include <stdlib.h> // malloc, free 3 | #include <stdio.h> // printf 4 | 5 | static bool ShaderCompileStatus(GLuint shader) 6 | { 7 | GLint status; 8 | glGetShaderiv(shader, GL_COMPILE_STATUS, &status); 9 | if (!status) 10 | { 11 | GLint length; 12 | glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length); 13 | char *info = (char*)malloc(length); 14 | glGetShaderInfoLog(shader, length, NULL, info); 15 | fprintf(stderr, "Failed to compile shader:\n%s\n", info); 16 | free(info); 17 | return false; 18 | } 19 | return true; 20 | } 21 | 22 | static bool ProgramLinkStatus(GLuint program) 23 | { 24 | GLint status; 25 | glGetProgramiv(program, GL_LINK_STATUS, &status); 26 | if (!status) 27 | { 28 | GLint length; 29 | glGetProgramiv(program, GL_INFO_LOG_LENGTH, &length); 30 | char *info = (char*)malloc(length); 31 | glGetProgramInfoLog(program, length, NULL, info); 32 | fprintf(stderr, "Failed to link program:\n%s", info); 33 | free(info); 34 | return false; 35 | } 36 | return true; 37 | } 38 | 39 | static GLuint LoadShaderFromMemory( 40 | const char **vs_source, int num_vs_source, 41 | const char **fs_source, int num_fs_source) 42 | { 43 | GLuint vs = glCreateShader(GL_VERTEX_SHADER); 44 | { 45 | glShaderSource(vs, num_vs_source, vs_source, 0); 46 | glCompileShader(vs); 47 | if (!ShaderCompileStatus(vs)) 48 | { 49 | glDeleteShader(vs); 50 | return 0; 51 | } 52 | } 53 | 54 | GLuint fs = glCreateShader(GL_FRAGMENT_SHADER); 55 | { 56 | glShaderSource(fs, num_fs_source, fs_source, 0); 57 | glCompileShader(fs); 58 | if (!ShaderCompileStatus(fs)) 59 | { 60 | glDeleteShader(vs); 61 | glDeleteShader(fs); 62 | return 0; 63 | } 64 | } 65 | 66 | GLuint program = glCreateProgram(); 67 | glAttachShader(program, vs); 68 | glAttachShader(program, fs); 69 | glLinkProgram(program); 70 | glDetachShader(program, vs); 71 | glDetachShader(program, fs); 72 | glDeleteShader(vs); 73 | glDeleteShader(fs); 74 | if (!ProgramLinkStatus(program)) 75 | { 76 | glDeleteProgram(program); 77 | return 0; 78 | } 79 | 80 | return program; 81 | } 82 | 83 | static GLuint LoadShaderFromMemory( 84 | const char *vs_source, 85 | const char *fs_source) 86 | { 87 | return LoadShaderFromMemory(&vs_source, 1, &fs_source, 1); 88 | } 89 | 90 | GLuint vdb_gl_current_program = 0; 91 | enum { vdb_max_shaders = 1000 }; 92 | static GLuint vdb_gl_shaders[vdb_max_shaders]; 93 | 94 | bool vdbLoadShader(int slot, const char *user_fs_source) 95 | { 96 | assert(slot >= 0 && slot < vdb_max_shaders && "You are trying to set a pixel shader beyond the available number of slots."); 97 | 98 | const char *vs_source = 99 | "#version 150\n" 100 | "in vec2 in_position;\n" 101 | "void main()\n" 102 | "{\n" 103 | " gl_Position = vec4(in_position, 0.0, 1.0);\n" 104 | "}\n" 105 | ; 106 | 107 | const char *fs_source[] = 108 | { 109 | "#version 150\n" 110 | "uniform vec2 iResolution;\n" 111 | "uniform vec2 iFragCoordOffset;\n" 112 | "uniform mat4 iPVM;\n" 113 | "uniform mat4 iModelToView;\n" 114 | "out vec4 vdb_color0;\n" 115 | "#line 0\n", 116 | 117 | user_fs_source, 118 | 119 | "void main()\n" 120 | "{\n" 121 | " vec2 fragCoord = gl_FragCoord.xy + iFragCoordOffset;\n" 122 | " mainImage(vdb_color0, fragCoord);\n" 123 | "}\n" 124 | }; 125 | int num_fs_source = sizeof(fs_source)/sizeof(fs_source[0]); 126 | 127 | GLuint shader = LoadShaderFromMemory(&vs_source, 1, fs_source, num_fs_source); 128 | if (shader == 0) 129 | return false; 130 | if (vdb_gl_shaders[slot]) 131 | glDeleteProgram(vdb_gl_shaders[slot]); 132 | vdb_gl_shaders[slot] = shader; 133 | return true; 134 | } 135 | 136 | void vdbBeginShader(int slot) 137 | { 138 | assert(slot >= 0 && slot < vdb_max_shaders && "Attempted to use a shader slot outside the valid range."); 139 | assert(glIsProgram(vdb_gl_shaders[slot]) && "Shader at specified slot is invalid."); 140 | vdb_gl_current_program = vdb_gl_shaders[slot]; 141 | glUseProgram(vdb_gl_shaders[slot]); 142 | float pvm[4*4]; vdbGetPVM(pvm); 143 | float vm[4*4]; vdbGetMatrix(vm); 144 | vdbVec2 frag_offset = vdbGetRenderOffsetFramebuffer(); 145 | vdbUniform2f("iResolution", (float)vdbGetFramebufferWidth(), (float)vdbGetFramebufferHeight()); 146 | vdbUniform2f("iFragCoordOffset", frag_offset.x, frag_offset.y); 147 | vdbUniformMatrix4fv("iPVM", pvm); 148 | vdbUniformMatrix4fv("iModelToView", vm); 149 | } 150 | 151 | void vdbEndShader() 152 | { 153 | static GLuint vao = 0; 154 | static GLuint vbo = 0; 155 | if (!vao) 156 | { 157 | static float position[] = { -1,-1, 1,-1, 1,1, 1,1, -1,1, -1,-1 }; 158 | glGenVertexArrays(1, &vao); 159 | glGenBuffers(1, &vbo); 160 | glBindBuffer(GL_ARRAY_BUFFER, vbo); 161 | glBufferData(GL_ARRAY_BUFFER, sizeof(position), position, GL_STATIC_DRAW); 162 | } 163 | assert(vao); 164 | assert(vbo); 165 | 166 | glBindVertexArray(vao); 167 | glBindBuffer(GL_ARRAY_BUFFER, vbo); 168 | GLint attrib_in_position = glGetAttribLocation(vdb_gl_current_program, "in_position"); 169 | glEnableVertexAttribArray(attrib_in_position); 170 | glVertexAttribPointer(attrib_in_position, 2, GL_FLOAT, GL_FALSE, 0, 0); 171 | glDrawArrays(GL_TRIANGLES, 0, 6); 172 | glDisableVertexAttribArray(attrib_in_position); 173 | glUseProgram(0); 174 | glBindBuffer(GL_ARRAY_BUFFER, 0); 175 | glBindVertexArray(0); 176 | vdb_gl_current_program = 0; 177 | } 178 | void vdbUniform1f(const char *name, float x) { GLint program; glGetIntegerv(GL_CURRENT_PROGRAM, &program); glUniform1f(glGetUniformLocation(program, name), x); AssertGL("vdbUniform1f failed with name '%s'\n", name); } 179 | void vdbUniform2f(const char *name, float x, float y) { GLint program; glGetIntegerv(GL_CURRENT_PROGRAM, &program); glUniform2f(glGetUniformLocation(program, name), x,y); AssertGL("vdbUniform2f failed with name '%s'\n", name); } 180 | void vdbUniform3f(const char *name, float x, float y, float z) { GLint program; glGetIntegerv(GL_CURRENT_PROGRAM, &program); glUniform3f(glGetUniformLocation(program, name), x,y,z); AssertGL("vdbUniform3f failed with name '%s'\n", name); } 181 | void vdbUniform4f(const char *name, float x, float y, float z, float w) { GLint program; glGetIntegerv(GL_CURRENT_PROGRAM, &program); glUniform4f(glGetUniformLocation(program, name), x,y,z,w); AssertGL("vdbUniform4f failed with name '%s'\n", name); } 182 | void vdbUniform1i(const char *name, int x) { GLint program; glGetIntegerv(GL_CURRENT_PROGRAM, &program); glUniform1i(glGetUniformLocation(program, name), x); AssertGL("vdbUniform1i failed with name '%s'\n", name); } 183 | void vdbUniform2i(const char *name, int x, int y) { GLint program; glGetIntegerv(GL_CURRENT_PROGRAM, &program); glUniform2i(glGetUniformLocation(program, name), x,y); AssertGL("vdbUniform2i failed with name '%s'\n", name); } 184 | void vdbUniform3i(const char *name, int x, int y, int z) { GLint program; glGetIntegerv(GL_CURRENT_PROGRAM, &program); glUniform3i(glGetUniformLocation(program, name), x,y,z); AssertGL("vdbUniform3i failed with name '%s'\n", name); } 185 | void vdbUniform4i(const char *name, int x, int y, int z, int w) { GLint program; glGetIntegerv(GL_CURRENT_PROGRAM, &program); glUniform4i(glGetUniformLocation(program, name), x,y,z,w); AssertGL("vdbUniform4i failed with name '%s'\n", name); } 186 | void vdbUniformMatrix4fv(const char *name, float *x) { GLint program; glGetIntegerv(GL_CURRENT_PROGRAM, &program); glUniformMatrix4fv(glGetUniformLocation(program, name), 1, false, x); AssertGL("vdbUniformMatrix4fv failed with name '%s'\n", name); } 187 | void vdbUniformMatrix3fv(const char *name, float *x) { GLint program; glGetIntegerv(GL_CURRENT_PROGRAM, &program); glUniformMatrix3fv(glGetUniformLocation(program, name), 1, false, x); AssertGL("vdbUniformMatrix3fv failed with name '%s'\n", name); } 188 | void vdbUniformMatrix4fv_RowMaj(const char *name, float *x) { GLint program; glGetIntegerv(GL_CURRENT_PROGRAM, &program); glUniformMatrix4fv(glGetUniformLocation(program, name), 1, true, x); AssertGL("vdbUniformMatrix4fv_RowMaj failed with name '%s'\n", name); } 189 | void vdbUniformMatrix3fv_RowMaj(const char *name, float *x) { GLint program; glGetIntegerv(GL_CURRENT_PROGRAM, &program); glUniformMatrix3fv(glGetUniformLocation(program, name), 1, true, x); AssertGL("vdbUniformMatrix3fv_RowMaj failed with name '%s'\n", name); } 190 | -------------------------------------------------------------------------------- /src/shaders/image.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #define SHADER(S) "#version 150\n" #S 3 | const char *shader_image_vs = SHADER( 4 | in vec2 quad_pos; 5 | uniform mat4 pvm; 6 | uniform vec2 im_pos; 7 | uniform vec2 im_size; 8 | out vec2 texel; 9 | void main() 10 | { 11 | texel = quad_pos; 12 | gl_Position = pvm*vec4(im_pos + im_size*quad_pos, 0.0, 1.0); 13 | } 14 | ); 15 | 16 | const char *shader_image_fs = SHADER( 17 | in vec2 texel; 18 | uniform vec4 vmin; 19 | uniform vec4 vmax; 20 | uniform int is_mono; 21 | uniform int is_cmap; 22 | uniform sampler2D sampler0; 23 | uniform sampler2D sampler1; 24 | out vec4 color0; 25 | void main() 26 | { 27 | color0 = texture(sampler0, texel); 28 | color0 = (color0 - vmin) / (vmax - vmin); 29 | color0 = clamp(color0, vec4(0.0), vec4(1.0)); 30 | if (is_mono == 1) 31 | { 32 | float i = color0.x; 33 | if (is_cmap == 1) 34 | color0 = texture(sampler1, vec2(i, 0.0)); 35 | else 36 | color0 = vec4(i,i,i,1.0); 37 | } 38 | } 39 | ); 40 | #undef SHADER 41 | -------------------------------------------------------------------------------- /src/shaders/lines.h: -------------------------------------------------------------------------------- 1 | const char *shader_lines_vs = 2 | "#version 150\n" 3 | "in vec4 position;\n" 4 | "in vec2 texel;\n" 5 | "in vec4 color;\n" 6 | "uniform mat4 pvm;\n" 7 | "out vec4 vs_color;\n" 8 | "out vec2 vs_texel;\n" 9 | "void main()\n" 10 | "{\n" 11 | " gl_Position = pvm*position;\n" 12 | " vs_color = color;\n" 13 | " vs_texel = texel;\n" 14 | "}\n"; 15 | 16 | const char *shader_lines_fs = 17 | "#version 150\n" 18 | "in vec4 vs_color;\n" 19 | "in vec2 vs_texel;\n" 20 | "uniform sampler2D sampler0;\n" 21 | "out vec4 color0;\n" 22 | "void main()\n" 23 | "{\n" 24 | " color0 = vs_color*texture(sampler0, vs_texel);\n" 25 | "}\n"; 26 | -------------------------------------------------------------------------------- /src/shaders/points.h: -------------------------------------------------------------------------------- 1 | // 2 | // This shader can be used to render the points as colored meshes. This gives 3 | // you MSAA for free (if enabled), but you end up with non-perfect circles. 4 | // This option might be faster than the quad shader, especially for low 5 | // vertex counts. 6 | // 7 | #pragma once 8 | #define SHADER(S) "#version 150\n" #S 9 | const char *shader_points_vs = SHADER( 10 | in vec2 in_position; 11 | in vec4 instance_position; 12 | in vec2 instance_texel; 13 | in vec4 instance_color; 14 | uniform mat4 projection; 15 | uniform mat4 model_to_view; 16 | uniform vec2 point_size; 17 | uniform vec2 ndc_offset; 18 | uniform int size_is_3D; 19 | uniform sampler2D sampler0; 20 | out vec4 vertex_color; 21 | out vec2 quad_position; 22 | void main() 23 | { 24 | quad_position = in_position; 25 | vertex_color = instance_color*texture(sampler0, instance_texel); 26 | if (size_is_3D == 1) 27 | { 28 | vec4 position = model_to_view*instance_position; 29 | position.xy += point_size*in_position; 30 | gl_Position = projection*position; 31 | } 32 | else 33 | { 34 | vec4 position = model_to_view*instance_position; 35 | gl_Position = projection*position; 36 | float w = gl_Position.w; 37 | gl_Position.xy += point_size*in_position*w; 38 | } 39 | gl_Position.xy -= ndc_offset*gl_Position.w; 40 | } 41 | ); 42 | 43 | const char *shader_points_fs = SHADER( 44 | in vec4 vertex_color; 45 | in vec2 quad_position; 46 | out vec4 fragment_color; 47 | void main() 48 | { 49 | fragment_color = vertex_color; 50 | } 51 | ); 52 | #undef SHADER 53 | -------------------------------------------------------------------------------- /src/shaders/points_sprite.h: -------------------------------------------------------------------------------- 1 | // 2 | // This shader can be used to render the points as pixel-perfect circles, 3 | // using textured quads. This option might be slower than the vertex version 4 | // especially if you restrict yourself to low vertex count. 5 | // 6 | #pragma once 7 | #define SHADER(S) "#version 150\n" #S 8 | const char *point_shader_vs = SHADER( 9 | in vec2 in_position; 10 | in vec4 in_color; 11 | in vec3 instance_position; 12 | in vec4 instance_color; 13 | uniform mat4 projection; 14 | uniform mat4 model_to_view; 15 | uniform float point_size; 16 | out vec4 vertex_color; 17 | out vec2 quad_position; 18 | void main() 19 | { 20 | quad_position = in_position; 21 | vertex_color = instance_color*in_color; 22 | vec4 position = model_to_view*vec4(instance_position,1.0) + point_size*vec4(in_position,0.0,0.0); 23 | gl_Position = projection*position; 24 | } 25 | ); 26 | 27 | const char *point_shader_fs = SHADER( 28 | in vec4 vertex_color; 29 | in vec2 quad_position; 30 | out vec4 fragment_color; 31 | void main() 32 | { 33 | fragment_color = vertex_color; 34 | 35 | // NO ALPHA BLENDING 36 | if (dot(quad_position,quad_position) > 1.0) 37 | discard; 38 | } 39 | ); 40 | #undef SHADER 41 | -------------------------------------------------------------------------------- /src/shaders/thick_lines.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #define SHADER(S) "#version 150\n" #S 3 | const char *shader_thick_lines_vs = SHADER( 4 | in vec2 in_position; 5 | in vec4 instance_position0; 6 | in vec2 instance_texel0; 7 | in vec4 instance_color0; 8 | in vec4 instance_position1; 9 | in vec2 instance_texel1; 10 | in vec4 instance_color1; 11 | uniform mat4 projection; 12 | uniform mat4 model_to_view; 13 | uniform vec2 line_width; 14 | uniform float aspect; 15 | uniform vec2 ndc_offset; 16 | uniform int width_is_3D; 17 | uniform sampler2D sampler0; 18 | out vec4 vertex_color; 19 | void main() 20 | { 21 | { 22 | mat4 pvm = projection*model_to_view; 23 | vec4 clip0 = pvm*instance_position0; 24 | vec4 clip1 = pvm*instance_position1; 25 | vec2 tangent = (clip1.xy/clip1.w) - (clip0.xy/clip0.w); 26 | tangent.x *= aspect; 27 | vec2 normal = vec2(-tangent.y, tangent.x); 28 | normal = normalize(normal); 29 | 30 | // todo: normal not in right direction... 31 | 32 | if (in_position.x < 0.0) 33 | { 34 | gl_Position = clip0; 35 | gl_Position.xy += line_width*in_position.y*normal*clip0.w; 36 | vertex_color = instance_color0*texture(sampler0, instance_texel0); 37 | } 38 | else 39 | { 40 | gl_Position = clip1; 41 | gl_Position.xy += line_width*in_position.y*normal*clip1.w; 42 | vertex_color = instance_color1*texture(sampler0, instance_texel1); 43 | } 44 | } 45 | gl_Position.xy -= ndc_offset*gl_Position.w; 46 | } 47 | ); 48 | 49 | const char *shader_thick_lines_fs = SHADER( 50 | in vec4 vertex_color; 51 | out vec4 fragment_color; 52 | void main() 53 | { 54 | fragment_color = vertex_color; 55 | } 56 | ); 57 | #undef SHADER 58 | -------------------------------------------------------------------------------- /src/shaders/triangles.h: -------------------------------------------------------------------------------- 1 | const char *shader_triangles_vs = 2 | "#version 150\n" 3 | "in vec4 position;\n" 4 | "in vec2 texel;\n" 5 | "in vec4 color;\n" 6 | "uniform mat4 pvm;\n" 7 | "uniform vec2 ndc_offset;\n" 8 | "out vec4 vs_color;\n" 9 | "out vec2 vs_texel;\n" 10 | "void main()\n" 11 | "{\n" 12 | " gl_Position = pvm*position;\n" 13 | " gl_Position.xy -= ndc_offset*gl_Position.w;\n" 14 | " vs_color = color;\n" 15 | " vs_texel = texel;\n" 16 | "}\n"; 17 | 18 | const char *shader_triangles_fs = 19 | "#version 150\n" 20 | "in vec4 vs_color;\n" 21 | "in vec2 vs_texel;\n" 22 | "uniform sampler2D sampler0;\n" 23 | "out vec4 color0;\n" 24 | "void main()\n" 25 | "{\n" 26 | " color0 = vs_color*texture(sampler0, vs_texel);\n" 27 | "}\n"; 28 | -------------------------------------------------------------------------------- /src/sketch.h: -------------------------------------------------------------------------------- 1 | enum { SKETCH_MODE_MAX_LINES = 1024*256 }; 2 | struct sketch_mode_line_t 3 | { 4 | ImU32 color; 5 | bool connected; 6 | float x1,y1,x2,y2; 7 | }; 8 | struct sketch_mode_t 9 | { 10 | sketch_mode_line_t lines[SKETCH_MODE_MAX_LINES]; 11 | int num_lines; 12 | bool is_drawing; 13 | int color_index; 14 | float cursor_x,cursor_y; 15 | }; 16 | 17 | namespace sketch_mode 18 | { 19 | static sketch_mode_t s; 20 | 21 | static ImU32 palette[] = { 22 | IM_COL32(255*1.00f, 255*1.00f, 255*1.00f, 255), 23 | IM_COL32(255*0.29f, 255*0.50f, 255*0.67f, 255), 24 | IM_COL32(255*0.71f, 255*0.05f, 255*0.10f, 255), 25 | IM_COL32(255*0.91f, 255*0.76f, 255*0.41f, 255), 26 | IM_COL32(255*0.44f, 255*0.64f, 255*0.40f, 255), 27 | IM_COL32(255*0.10f, 255*0.10f, 255*0.10f, 255), 28 | IM_COL32(255*0.62f, 255*0.78f, 255*0.89f, 255), 29 | IM_COL32(255*0.92f, 255*0.60f, 255*0.61f, 255), 30 | IM_COL32(255*1.00f, 255*0.90f, 255*0.64f, 255), 31 | IM_COL32(255*0.71f, 255*0.84f, 255*0.67f, 255), 32 | }; 33 | 34 | enum { num_colors = sizeof(palette)/sizeof(palette[0]) }; 35 | 36 | static void Update(bool undo_button, 37 | bool redo_button, 38 | bool clear_button, 39 | bool mouse_left_down, 40 | float mouse_x, 41 | float mouse_y) 42 | { 43 | static int redo_num_lines = 0; 44 | 45 | bool &is_drawing = s.is_drawing; 46 | int &num_lines = s.num_lines; 47 | ImU32 current_color = palette[s.color_index]; 48 | sketch_mode_line_t *lines = s.lines; 49 | 50 | s.cursor_x = mouse_x; 51 | s.cursor_y = mouse_y; 52 | 53 | if (clear_button) 54 | { 55 | num_lines = 0; 56 | redo_num_lines = 0; 57 | } 58 | if (undo_button) 59 | { 60 | if (num_lines > 0) 61 | { 62 | if (lines[num_lines-1].connected) 63 | { 64 | while (num_lines > 1 && lines[num_lines-1].connected) 65 | num_lines--; 66 | num_lines--; 67 | } 68 | else 69 | { 70 | num_lines--; 71 | } 72 | } 73 | } 74 | if (redo_button) 75 | { 76 | if (num_lines < redo_num_lines) 77 | { 78 | num_lines++; 79 | while (num_lines < redo_num_lines && lines[num_lines].connected) 80 | num_lines++; 81 | } 82 | } 83 | 84 | static bool is_dragging = false; 85 | if (mouse_left_down) 86 | { 87 | if (!is_drawing && num_lines < SKETCH_MODE_MAX_LINES) 88 | { 89 | lines[num_lines].x1 = mouse_x; 90 | lines[num_lines].y1 = mouse_y; 91 | lines[num_lines].x2 = mouse_x; 92 | lines[num_lines].y2 = mouse_y; 93 | lines[num_lines].connected = false; 94 | lines[num_lines].color = current_color; 95 | is_drawing = true; 96 | } 97 | else if (num_lines < SKETCH_MODE_MAX_LINES) 98 | { 99 | float new_x = mouse_x; 100 | float new_y = mouse_y; 101 | float prev_x = lines[num_lines].x2; 102 | float prev_y = lines[num_lines].y2; 103 | float begin_x = lines[num_lines].x1; 104 | float begin_y = lines[num_lines].y1; 105 | 106 | float dx1 = prev_x - begin_x; 107 | float dy1 = prev_y - begin_y; 108 | float dx2 = new_x - begin_x; 109 | float dy2 = new_y - begin_y; 110 | float dx3 = new_x - prev_x; 111 | float dy3 = new_y - prev_y; 112 | float speed = sqrtf(dx3*dx3 + dy3*dy3) / (1.0f/60.0f); 113 | float delta = (dx1*dx2 + dy1*dy2) / sqrtf(dx1*dx1 + dy1*dy1); 114 | float threshold = sqrtf(speed)/1.5f; 115 | if (threshold < 2.0f) threshold = 2.0f; 116 | if (delta > threshold || delta < -threshold) 117 | { 118 | num_lines++; 119 | lines[num_lines].x1 = prev_x; 120 | lines[num_lines].y1 = prev_y; 121 | lines[num_lines].x2 = new_x; 122 | lines[num_lines].y2 = new_y; 123 | lines[num_lines].connected = true; 124 | lines[num_lines].color = current_color; 125 | } 126 | else 127 | { 128 | lines[num_lines].x2 = new_x; 129 | lines[num_lines].y2 = new_y; 130 | } 131 | } 132 | } 133 | else if (is_drawing) 134 | { 135 | num_lines++; 136 | redo_num_lines = num_lines; 137 | is_drawing = false; 138 | } 139 | else if (is_dragging) 140 | { 141 | is_dragging = false; 142 | } 143 | } 144 | } 145 | 146 | static void sketch::BeginFrame() 147 | { 148 | if (VDB_HOTKEY_SKETCH_MODE) 149 | sketch_mode_active = !sketch_mode_active; 150 | 151 | if (sketch_mode_active) 152 | { 153 | if (keys::pressed[VDB_KEY_ESCAPE]) 154 | { 155 | ui::sketch_mode_active = false; 156 | ui::escape_eaten = true; 157 | } 158 | bool undo = vdbIsKeyDown(VDB_KEY_LCTRL) && vdbWasKeyPressed(VDB_KEY_Z); 159 | bool redo = vdbIsKeyDown(VDB_KEY_LCTRL) && vdbWasKeyPressed(VDB_KEY_Y); 160 | bool clear = vdbWasKeyPressed(VDB_KEY_D); 161 | bool click = vdbIsMouseLeftDown(); 162 | float x = vdbGetMousePos().x; 163 | float y = vdbGetMousePos().y; 164 | sketch_mode::Update(undo, redo, clear, click, x, y); 165 | 166 | // force all subsequent calls to vdb{Is,Was}{Mouse,Key}{UpDownPressed} to return false 167 | ImGui::GetIO().WantCaptureKeyboard = true; 168 | ImGui::GetIO().WantCaptureMouse = true; 169 | } 170 | } 171 | 172 | static void sketch::EndFrame() 173 | { 174 | if (!ui::sketch_mode_active) 175 | return; 176 | 177 | static float width = 2.0f; 178 | static float brightness = 0.0f; 179 | 180 | // draw sketching tool bar 181 | ImGui::BeginMainMenuBar(); 182 | float h_menu = ImGui::GetFrameHeight(); 183 | float h_rect = ImGui::GetTextLineHeight(); 184 | { 185 | ImGui::Separator(); 186 | ImGui::PushID("sketch colors"); 187 | ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(2.0f,-1.0f)); 188 | ImDrawList *draw = ImGui::GetWindowDrawList(); 189 | for (int i = 0; i < sketch_mode::num_colors; i++) 190 | { 191 | ImGui::PushID(i); 192 | ImGui::InvisibleButton("##", ImVec2(16.0f, h_rect)); 193 | ImVec2 a = ImGui::GetItemRectMin(); 194 | ImVec2 b = ImGui::GetItemRectMax(); 195 | a.y = 0.5f*(h_menu - h_rect); 196 | b.y = 0.5f*(h_menu + h_rect); 197 | ImU32 color = sketch_mode::palette[i]; 198 | draw->AddRectFilled(a, b, color); 199 | if (ImGui::IsItemClicked()) 200 | sketch_mode::s.color_index = i; 201 | ImGui::PopID(); 202 | } 203 | ImGui::PopStyleVar(); 204 | ImGui::PushItemWidth(64.0f); 205 | ImGui::SliderFloat("brightness", &brightness, -1.0f, +1.0f); 206 | ImGui::PopItemWidth(); 207 | ImGui::PopID(); 208 | } 209 | ImGui::EndMainMenuBar(); 210 | 211 | int num_lines = sketch_mode::s.num_lines; 212 | sketch_mode_line_t *lines = sketch_mode::s.lines; 213 | bool is_drawing = sketch_mode::s.is_drawing; 214 | 215 | ImDrawList *user_draw_list = ImGui::GetOverlayDrawList(); 216 | 217 | // draw brightness overlay 218 | { 219 | int alpha = (int)(fabsf(brightness)*255); 220 | ImU32 color = brightness > 0.0f ? IM_COL32(255,255,255,alpha) : IM_COL32(0,0,0,alpha); 221 | ImVec2 a = ImVec2(0.0f, h_menu); 222 | ImVec2 b = ImGui::GetIO().DisplaySize; 223 | user_draw_list->AddRectFilled(a, b, color); 224 | } 225 | 226 | // draw lines 227 | { 228 | int n = (is_drawing) ? num_lines+1 : num_lines; 229 | ImVec2 next_a; 230 | for (int i = 0; i < n; i++) 231 | { 232 | ImVec2 a; 233 | if (lines[i].connected) 234 | { 235 | assert(i > 0); 236 | a = next_a; 237 | } 238 | else 239 | { 240 | a.x = lines[i].x1; 241 | a.y = lines[i].y1; 242 | } 243 | ImVec2 b = ImVec2(lines[i].x2, lines[i].y2); 244 | if (i < n-1 && lines[i+1].connected) 245 | next_a = b; 246 | user_draw_list->AddLine(a, b, lines[i].color, width); 247 | } 248 | } 249 | } 250 | -------------------------------------------------------------------------------- /src/style.h: -------------------------------------------------------------------------------- 1 | struct vdb_style_t 2 | { 3 | vdbVec3 x_axis; 4 | vdbVec3 y_axis; 5 | vdbVec3 z_axis; 6 | vdbVec3 grid; 7 | vdbVec3 cube; 8 | vdbVec3 clear; 9 | vdbVec3 text; 10 | float neg_alpha; 11 | float pos_alpha; 12 | float major_alpha; 13 | float minor_alpha; 14 | }; 15 | 16 | static vdb_style_t GetStyle() 17 | { 18 | vdb_style_t style; 19 | if (settings.global_theme == VDB_DARK_THEME) 20 | { 21 | style.x_axis = vdbVec3(VDB_DARK_THEME_X_AXIS); 22 | style.y_axis = vdbVec3(VDB_DARK_THEME_Y_AXIS); 23 | style.z_axis = vdbVec3(VDB_DARK_THEME_Z_AXIS); 24 | style.grid = vdbVec3(VDB_DARK_THEME_GRID_LINES); 25 | style.clear = vdbVec3(VDB_DARK_THEME_BACKGROUND); 26 | style.cube = vdbVec3(1.0f, 1.0f, 1.0f); 27 | style.text = vdbVec3(1.0f, 1.0f, 1.0f); 28 | style.neg_alpha = 0.3f; 29 | style.pos_alpha = 0.7f; 30 | style.minor_alpha = 0.3f; 31 | style.major_alpha = 0.5f; 32 | } 33 | else 34 | { 35 | style.x_axis = vdbVec3(VDB_BRIGHT_THEME_X_AXIS); 36 | style.y_axis = vdbVec3(VDB_BRIGHT_THEME_Y_AXIS); 37 | style.z_axis = vdbVec3(VDB_BRIGHT_THEME_Z_AXIS); 38 | style.grid = vdbVec3(VDB_BRIGHT_THEME_GRID_LINES); 39 | style.cube = vdbVec3(0.0f, 0.0f, 0.0f); 40 | style.clear = vdbVec3(VDB_BRIGHT_THEME_BACKGROUND); 41 | style.text = vdbVec3(0.0f, 0.0f, 0.0f); 42 | style.neg_alpha = 0.4f; 43 | style.pos_alpha = 0.6f; 44 | style.minor_alpha = 0.4f; 45 | style.major_alpha = 0.5f; 46 | } 47 | return style; 48 | } 49 | -------------------------------------------------------------------------------- /src/transform.h: -------------------------------------------------------------------------------- 1 | namespace transform 2 | { 3 | static vdbMat4 projection = vdbMatIdentity(); 4 | static vdbMat4 view_model = vdbMatIdentity(); 5 | static vdbMat4 pvm = vdbMatIdentity(); 6 | static matrix_stack_t matrix_stack = {0}; 7 | static matrix_stack_t projection_stack = {0}; 8 | int viewport_left; 9 | int viewport_bottom; 10 | int viewport_width; 11 | int viewport_height; 12 | 13 | static void BeginFrame() 14 | { 15 | projection = vdbMatIdentity(); 16 | view_model = vdbMatIdentity(); 17 | pvm = vdbMatIdentity(); 18 | matrix_stack.Reset(); 19 | projection_stack.Reset(); 20 | vdbViewporti(0, 0, window::framebuffer_width, window::framebuffer_height); 21 | } 22 | } 23 | 24 | void vdbPushMatrix() 25 | { 26 | using namespace transform; 27 | matrix_stack.Push(); 28 | view_model = matrix_stack.Top(); 29 | } 30 | 31 | void vdbPopMatrix() 32 | { 33 | using namespace transform; 34 | matrix_stack.Pop(); 35 | view_model = matrix_stack.Top(); 36 | pvm = vdbMul4x4(projection, view_model); 37 | } 38 | 39 | void vdbPushProjection() 40 | { 41 | using namespace transform; 42 | projection_stack.Push(); 43 | projection = projection_stack.Top(); 44 | } 45 | 46 | void vdbPopProjection() 47 | { 48 | using namespace transform; 49 | projection_stack.Pop(); 50 | projection = projection_stack.Top(); 51 | pvm = vdbMul4x4(projection, view_model); 52 | } 53 | 54 | void vdbLoadProjection(vdbMat4 m) 55 | { 56 | transform::projection_stack.Load(m); 57 | transform::projection = transform::projection_stack.Top(); 58 | transform::pvm = vdbMul4x4(m, transform::view_model); 59 | } 60 | 61 | void vdbMultProjection(vdbMat4 m) 62 | { 63 | transform::projection_stack.Multiply(m); 64 | transform::projection = transform::projection_stack.Top(); 65 | transform::pvm = vdbMul4x4(transform::projection, transform::view_model); 66 | } 67 | 68 | void vdbLoadMatrix(vdbMat4 m) 69 | { 70 | transform::matrix_stack.Load(m); 71 | transform::view_model = transform::matrix_stack.Top(); 72 | transform::pvm = vdbMul4x4(transform::projection, transform::view_model); 73 | } 74 | 75 | void vdbMultMatrix(vdbMat4 m) 76 | { 77 | transform::matrix_stack.Multiply(m); 78 | transform::view_model = transform::matrix_stack.Top(); 79 | transform::pvm = vdbMul4x4(transform::projection, transform::view_model); 80 | } 81 | 82 | void vdbLoadProjection(float *m) { vdbLoadProjection(m ? *(vdbMat4*)m : vdbMatIdentity()); } 83 | void vdbLoadProjection_RowMaj(float *m){ vdbLoadProjection(m ? vdbMatTranspose(*(vdbMat4*)m) : vdbMatIdentity()); } 84 | 85 | void vdbMultProjection(float *m) { vdbMultProjection(m ? *(vdbMat4*)m : vdbMatIdentity()); } 86 | void vdbMultProjection_RowMaj(float *m){ vdbMultProjection(m ? vdbMatTranspose(*(vdbMat4*)m) : vdbMatIdentity()); } 87 | 88 | void vdbLoadMatrix(float *m) { if (m) vdbLoadMatrix(*(vdbMat4*)m); else vdbLoadMatrix(vdbMatIdentity()); } 89 | void vdbLoadMatrix_RowMaj(float *m) { if (m) vdbLoadMatrix(vdbMatTranspose(*(vdbMat4*)m)); else vdbLoadMatrix(vdbMatIdentity()); } 90 | 91 | void vdbMultMatrix(float *m) { if (m) vdbMultMatrix(*(vdbMat4*)m); } 92 | void vdbMultMatrix_RowMaj(float *m) { if (m) vdbMultMatrix(vdbMatTranspose(*(vdbMat4*)m)); } 93 | 94 | void vdbGetMatrix(float *m) { assert(m); *(vdbMat4*)m = transform::view_model; } 95 | void vdbGetMatrix_RowMaj(float *m) { assert(m); *(vdbMat4*)m = vdbMatTranspose(transform::view_model); } 96 | 97 | void vdbGetProjection(float *m) { assert(m); *(vdbMat4*)m = transform::projection; } 98 | void vdbGetProjection_RowMaj(float *m) { assert(m); *(vdbMat4*)m = vdbMatTranspose(transform::projection); } 99 | 100 | void vdbGetPVM(float *m) { assert(m); *(vdbMat4*)m = transform::pvm; } 101 | void vdbGetPVM_RowMaj(float *m) { assert(m); *(vdbMat4*)m = vdbMatTranspose(transform::pvm); } 102 | 103 | void vdbTranslate(float x, float y, float z) { vdbMultMatrix(vdbMatTranslate(x,y,z).data); } 104 | void vdbRotateXYZ(float x, float y, float z) { vdbMultMatrix(vdbMatRotateXYZ(x,y,z).data); } 105 | void vdbRotateZYX(float z, float y, float x) { vdbMultMatrix(vdbMatRotateZYX(z,y,x).data); } 106 | 107 | void vdbOrtho(float x_left, float x_right, float y_bottom, float y_top, float z_near, float z_far) 108 | { 109 | vdbMat4 p = vdbMatIdentity(); 110 | p(0,0) = 2.0f/(x_right-x_left); 111 | p(0,3) = (x_left+x_right)/(x_left-x_right); 112 | p(1,1) = 2.0f/(y_top-y_bottom); 113 | p(1,3) = (y_bottom+y_top)/(y_bottom-y_top); 114 | p(2,2) = 2.0f/(z_near-z_far); 115 | p(2,3) = (z_near+z_far)/(z_near-z_far); 116 | vdbLoadProjection(p.data); 117 | } 118 | 119 | void vdbPerspective(float yfov, float z_near, float z_far, float x_offset, float y_offset) 120 | { 121 | float t = 1.0f/tanf(yfov/2.0f); 122 | vdbMat4 p = {0}; 123 | p(0,0) = t/(vdbGetAspectRatio()); 124 | p(0,2) = x_offset; 125 | p(1,1) = t; 126 | p(1,2) = y_offset; 127 | p(2,2) = (z_near+z_far)/(z_near-z_far); 128 | p(3,2) = -1.0f; 129 | p(2,3) = 2.0f*z_near*z_far/(z_near-z_far); 130 | vdbLoadProjection(p.data); 131 | } 132 | 133 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 134 | // § Window 135 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 136 | int vdbGetWindowWidth() { return window::window_width; } 137 | int vdbGetWindowHeight() { return window::window_height; } 138 | 139 | int vdbGetFramebufferWidth() 140 | { 141 | if (current_framebuffer) 142 | return current_framebuffer->width; 143 | else return window::framebuffer_width; 144 | } 145 | 146 | int vdbGetFramebufferHeight() 147 | { 148 | if (current_framebuffer) 149 | return current_framebuffer->height; 150 | else return window::framebuffer_height; 151 | } 152 | 153 | float vdbGetAspectRatio() 154 | { 155 | return (float)vdbGetFramebufferWidth()/vdbGetFramebufferHeight(); 156 | } 157 | 158 | void vdbViewporti(int left, int bottom, int width, int height) 159 | { 160 | glViewport(left, bottom, (GLsizei)width, (GLsizei)height); 161 | transform::viewport_left = left; 162 | transform::viewport_bottom = bottom; 163 | transform::viewport_width = width; 164 | transform::viewport_height = height; 165 | } 166 | 167 | void vdbViewport(float left, float bottom, float width, float height) 168 | { 169 | int fb_width = vdbGetFramebufferWidth(); 170 | int fb_height = vdbGetFramebufferHeight(); 171 | vdbViewporti((int)(left*fb_width), (int)(bottom*fb_height), 172 | (int)(width*fb_width), (int)(height*fb_height)); 173 | } 174 | 175 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 176 | // § Coordinate system conversions 177 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 178 | vdbVec2 vdbModelToNDC(float x, float y, float z, float w) 179 | { 180 | vdbVec4 model(x,y,z,w); 181 | vdbVec4 clip = vdbMul4x1(transform::pvm, model); 182 | vdbVec2 ndc(clip.x/clip.w, clip.y/clip.w); 183 | return ndc; 184 | } 185 | 186 | vdbVec3 vdbNDCToModel(float x, float y, float z) 187 | { 188 | using namespace transform; 189 | 190 | // assuming projection is of the form 191 | // ax bx 192 | // ay by 193 | // az bz 194 | // cw aw 195 | // (e.g. orthographic or perspective transform) 196 | 197 | // also assumes modelview matrix is SE3 198 | // (e.g. rotation and translation only) 199 | 200 | float ax = projection(0,0); 201 | float ay = projection(1,1); 202 | // float az = projection(2,2); 203 | float bx = projection(0,3); 204 | float by = projection(1,3); 205 | // float bz = projection(2,3); 206 | float cw = projection(3,2); 207 | float aw = projection(3,3); 208 | 209 | float w_clip = cw*z + aw; 210 | float x_clip = x*w_clip; 211 | float y_clip = y*w_clip; 212 | // float z_clip = az*z + bz; 213 | vdbVec4 view(0,0,0,0); 214 | view.x = (x_clip-bx)/ax; 215 | view.y = (y_clip-by)/ay; 216 | view.z = z; 217 | view.w = 1.0f; 218 | vdbVec4 model = vdbMulSim3Inverse(view_model, view); 219 | vdbVec3 result(model.x,model.y,model.z); 220 | return result; 221 | } 222 | 223 | vdbVec2 vdbWindowToNDC(float xw, float yw) 224 | { 225 | using namespace transform; 226 | float xf = vdbGetFramebufferWidth()*(xw/vdbGetWindowWidth()); 227 | float yf = vdbGetFramebufferHeight()*(1.0f - yw/vdbGetWindowHeight()); 228 | float xn = -1.0f+2.0f*(xf-viewport_left)/viewport_width; 229 | float yn = -1.0f+2.0f*(yf-viewport_bottom)/viewport_height; 230 | vdbVec2 result(xn,yn); 231 | return result; 232 | } 233 | 234 | vdbVec2 vdbNDCToWindow(float xn, float yn) 235 | { 236 | using namespace transform; 237 | float xf = viewport_left + (0.5f+0.5f*xn)*viewport_width; 238 | float yf = viewport_bottom + (0.5f+0.5f*yn)*viewport_height; 239 | float xw = vdbGetWindowWidth()*(xf/vdbGetFramebufferWidth()); 240 | float yw = vdbGetWindowHeight()*(1.0f - yf/vdbGetFramebufferHeight()); 241 | vdbVec2 result(xw,yw); 242 | return result; 243 | } 244 | 245 | vdbVec2 vdbModelToWindow(float x, float y, float z, float w) 246 | { 247 | vdbVec2 ndc = vdbModelToNDC(x, y, z, w); 248 | return vdbNDCToWindow(ndc.x, ndc.y); 249 | } 250 | -------------------------------------------------------------------------------- /test/Makefile: -------------------------------------------------------------------------------- 1 | # You will need SDL2 (http://www.libsdl.org): 2 | # Linux: apt-get install libsdl2-dev 3 | # Mac OS X: brew install sdl2 4 | # MSYS2: pacman -S mingw-w64-i686-SDL 5 | # 6 | #CXX = g++ 7 | #CXX = clang++ 8 | 9 | UNAME_S := $(shell uname -s) 10 | EXE := test 11 | 12 | ifeq ($(UNAME_S), Linux) #LINUX 13 | LIBS = -lvdb -lGL -ldl `sdl2-config --libs` 14 | CXXFLAGS = -I../include/ `sdl2-config --cflags` -L../lib/ -Wall -Wformat 15 | endif 16 | 17 | ifeq ($(UNAME_S), Darwin) #APPLE 18 | LIBS = -lvdb -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo `sdl2-config --libs` 19 | CXXFLAGS = -I../include/ -I/usr/local/include `sdl2-config --cflags` -L../lib/ -Wall -Wformat 20 | endif 21 | 22 | ifeq ($(findstring MINGW,$(UNAME_S)),MINGW) 23 | LIBS = -lvdb -lgdi32 -lopengl32 -limm32 `pkg-config --static --libs sdl2` 24 | CXXFLAGS = -I../include/ `pkg-config --cflags sdl2` -L../lib/ -Wall -Wformat 25 | endif 26 | 27 | all: test.cpp 28 | $(CXX) test.cpp $(CXXFLAGS) $(LIBS) -o $(EXE) 29 | -------------------------------------------------------------------------------- /test/build.bat: -------------------------------------------------------------------------------- 1 | @REM Build for Visual Studio compiler. 2 | @REM Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler. 3 | @REM Ensure that the environment variables SDL2_DIR and VDB_DIR are correct. 4 | set INCLUDES=/I..\include 5 | set SOURCES=test.cpp 6 | set LIBS=/libpath:%SDL2_DIR%\lib\x86 /libpath:%VDB_DIR%\lib vdb.lib SDL2.lib SDL2main.lib opengl32.lib 7 | cl /nologo /Zi /MD %INCLUDES% test.cpp /link %LIBS% /subsystem:console 8 | --------------------------------------------------------------------------------