├── .gitattributes ├── .gitignore ├── CMakeLists.txt ├── Installers ├── installDependenciesFedora.sh ├── installDependenciesUbuntu.sh ├── installDependenciesWindows-part1.bat ├── installDependenciesWindows-part2.bat └── unzipFreetype.sh ├── LICENSE.md ├── Other └── plotGif.gif ├── README.md ├── Shaders ├── font.frag ├── font.vs ├── plot2d.frag ├── plot2d.vs ├── plot2dLogx.vs ├── plot2dLogxLogy.vs ├── plot2dLogy.vs ├── plotPosNeg2d.frag ├── plotPosNeg2d.vs ├── plotText.frag ├── plotText.vs ├── plotTransparent2d.frag ├── plotTransparent2d.vs ├── scatter2d.frag ├── scatter2d.vs ├── scatter2dLogx.vs ├── scatter2dLogxLogy.vs ├── scatter2dLogy.vs ├── texture.frag └── texture.vs ├── apps ├── CMakeLists.txt ├── examplePlot.cpp └── movingTimeframe.cpp ├── cmake ├── FindFREETYPE.cmake ├── FindGLEW.cmake ├── FindGLFW3.cmake ├── FindGLM.cmake └── FindSphinx.cmake ├── docs ├── CMakeLists.txt ├── Doxyfile.in ├── Makefile ├── conf.py ├── index.rst └── make.bat ├── include ├── KHR │ └── khrplatform.h ├── glad.c ├── glad │ └── glad.h └── stb_image.h ├── src ├── CMakeLists.txt ├── axes │ ├── AxesArea.cpp │ ├── AxesArea.h │ ├── AxesLineTicks.cpp │ ├── AxesLineTicks.h │ ├── CMakeLists.txt │ ├── Grid.cpp │ ├── Grid.h │ ├── Legend.cpp │ ├── Legend.h │ ├── LegendMarkerRectangle.cpp │ ├── LegendMarkerRectangle.h │ ├── Plotable.cpp │ ├── Plotable.h │ ├── axes.cpp │ ├── axes.h │ ├── axes2D.cpp │ ├── axes2D.h │ ├── axes3D.cpp │ └── axes3D.h ├── dataTypes │ ├── CMakeLists.txt │ └── dataTypes.h ├── interaction │ ├── CMakeLists.txt │ ├── IClickable.cpp │ ├── IClickable.h │ ├── PressButton.cpp │ ├── PressButton.h │ ├── PressButtonWithImage.cpp │ ├── PressButtonWithImage.h │ ├── Tooltip.cpp │ └── Tooltip.h ├── lines │ ├── CMakeLists.txt │ ├── GLTypes.h │ ├── ILine2D.cpp │ ├── ILine2D.h │ ├── ILine2D_OLD.cpp │ ├── ILine2D_OLD.h │ ├── ISingleLine2D.cpp │ ├── ISingleLine2D.h │ ├── Line2D2CircularVecs.cpp │ ├── Line2D2CircularVecs.h │ ├── Line2D2CircularVecsPosNeg.cpp │ ├── Line2D2CircularVecsPosNeg.h │ ├── Line2D2Vecs.cpp │ ├── Line2D2Vecs.h │ ├── Line2DPts.cpp │ ├── Line2DPts.h │ ├── Line2DVec.cpp │ ├── Line2DVec.h │ ├── Line2DVecGLMV3.cpp │ ├── Line2DVecGLMV3.h │ ├── Line2DVecVec.cpp │ ├── Line2DVecVec.h │ ├── Line2DVecfVecGLMV3.cpp │ ├── Line2DVecfVecGLMV3.h │ ├── LineType.h │ └── lineColours.h ├── plot │ ├── CMakeLists.txt │ ├── plot.cpp │ └── plot.h ├── rendering │ ├── CMakeLists.txt │ ├── ConstantXYDrawable.cpp │ ├── ConstantXYDrawable.h │ ├── IDrawable.cpp │ ├── IDrawable.h │ ├── ShaderSet.cpp │ ├── ShaderSet.h │ ├── TopLevelDrawable.cpp │ ├── TopLevelDrawable.h │ ├── fonts.h │ ├── shader.h │ ├── transforms.cpp │ └── transforms.h ├── scatterPlot │ ├── CMakeLists.txt │ ├── IScatterPlot.cpp │ ├── IScatterPlot.h │ ├── IScatterPlot2D.cpp │ ├── IScatterPlot2D.h │ ├── Scatter2D2Vecs.cpp │ └── Scatter2D2Vecs.h ├── shadedLines │ ├── CMakeLists.txt │ ├── IShadedLine2D.cpp │ ├── IShadedLine2D.h │ ├── ShadedLine2D2CircularVecs.cpp │ └── ShadedLine2D2CircularVecs.h ├── shapes │ ├── CMakeLists.txt │ ├── Rectangle.cpp │ └── Rectangle.h ├── texts │ ├── CMakeLists.txt │ ├── CharacterLoader.cpp │ ├── CharacterLoader.h │ ├── TextString.cpp │ └── TextString.h ├── textures │ ├── CMakeLists.txt │ ├── TextureManager.cpp │ └── TextureManager.h ├── util │ ├── CMakeLists.txt │ ├── util.cpp │ └── util.h └── window │ ├── CMakeLists.txt │ ├── FramelessDraggableWindow.cpp │ ├── FramelessDraggableWindow.h │ ├── IWindow.cpp │ ├── IWindow.h │ ├── inputCallbacks.h │ ├── window.cpp │ └── window.h ├── tests ├── AxesLineTicks-test.cpp ├── CMakeLists.txt ├── Line2D2Vecs-test.cpp ├── PlotLayout-test.cpp └── main.cpp ├── textures ├── axes-box-white.png ├── axes-white.png ├── axes-x-limits-white.png ├── axes-y-limits-white.png ├── grid-white.png ├── interactor-white.png └── interactor.png └── third_party └── google-test ├── CMakeLists.txt └── CMakeLists.txt.in /.gitattributes: -------------------------------------------------------------------------------- 1 | include/KHR/khrplatform.h linguist-vendored 2 | include/glad/glad.h linguist-vendored 3 | include/glad.c linguist-vendored 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /Debug/ 2 | /build/ 3 | /Includes/* 4 | !/Includes/glad/ 5 | !/Includes/KHR/ 6 | !Includes/glad.c 7 | /Lib/ 8 | *.swp 9 | *.idea 10 | include 11 | /docs/doxygen 12 | /docs/sphinx 13 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Set minimum cmake 2 | cmake_minimum_required(VERSION 3.10) 3 | 4 | # Setup project 5 | project(openGLPlotLive-proj) 6 | 7 | # Resolves issue with unable to debug with CLion, reverts back to g++9 8 | add_compile_options(-gdwarf-4) 9 | 10 | # Set OpenGL Policy 11 | set(OpenGL_GL_PREFERENCE "GLVND") 12 | 13 | # Add c++14 flag to compiler 14 | set(CMAKE_CXX_STANDARD 14) 15 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall") 16 | 17 | # Add Cmake Module Path 18 | set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/") 19 | 20 | # Windows specific setup 21 | if(WIN32) 22 | message(${CMAKE_SOURCE_DIR}/include/) 23 | include_directories("${CMAKE_SOURCE_DIR}/include") 24 | set(GLM_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/include/glm/glm.h") 25 | set(GLFW3_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/include/GLFW/glfw3.h") 26 | set(GLFW3_LIBRARY "${CMAKE_SOURCE_DIR}/Lib/libglfw3.a") 27 | set(FREETYPE_LIBRARY "${CMAKE_SOURCE_DIR}/Lib/freetype.a") 28 | endif(WIN32) 29 | 30 | # Find Packages 31 | # GLM 32 | find_package(GLM REQUIRED) 33 | message(STATUS "GLM found: ${GLM_INCLUDE_DIR}") 34 | # FREETYPE 35 | find_package(FREETYPE REQUIRED) 36 | MESSAGE(STATUS "Found FREETYPE: ${FREETYPE_LIBRARY}") 37 | # GLFW3 38 | find_package(GLFW3 REQUIRED) 39 | message(STATUS "Found Glfw3: ${GLFW3_LIBRARY}") 40 | # OpenGL 41 | find_package(OpenGL REQUIRED) 42 | add_definitions(${OPENGL_DEFINITIONS}) 43 | # X11 44 | find_package(X11 REQUIRED) 45 | 46 | 47 | # Set libraries 48 | if(WIN32) 49 | set(LIBS ${FREETYPE_LIBRARY} ${GLFW3_LIBRARY} z opengl32 ) 50 | elseif(UNIX) 51 | set(LIBS ${GLFW3_LIBRARY} X11 Xrandr Xinerama Xi Xxf86vm Xcursor dl pthread freetype GL) 52 | endif(WIN32) 53 | 54 | # Stop conflicting order of GLAD and GLFW 55 | add_definitions(-DGLFW_INCLUDE_NONE) 56 | 57 | # Add subdirectories 58 | add_subdirectory(src) 59 | add_subdirectory(apps) 60 | add_subdirectory(docs) 61 | add_subdirectory(tests) 62 | add_subdirectory(third_party/google-test) 63 | -------------------------------------------------------------------------------- /Installers/installDependenciesFedora.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Make script executable with sudo chmod +x installDependenciesFedora.sh 3 | # Run script without sudo ./installDependenciesFedora.sh 4 | 5 | # Get number of cores 6 | NPROC=$(nproc) 7 | echo "Found" $NPROC "cores." 8 | 9 | # Get current directory 10 | cd .. 11 | curDIR=$PWD 12 | 13 | # Switch to downloads directory 14 | cd ~/Downloads 15 | echo "Switched to ~/Downloads" 16 | 17 | echo -e "\e[44m ================================ Build Dependencies =============================== \e[49m" 18 | sudo dnf -y install cmake 19 | 20 | echo -e "\e[44m ===================== GLFW (multi-platform library for OpenGL) ==================== \e[49m" 21 | if [ ! -d ~/Downloads/glfw/ ]; then 22 | git clone https://github.com/glfw/glfw.git 23 | else 24 | echo "glfw directory already exists! Not cloning." 25 | fi 26 | echo "Installing X11 and wayland dependencies, allowing either to be used." 27 | sudo dnf -y install libXcursor-devel libXi-devel libXinerama-devel libXrandr-devel libXxf86vm-devel 28 | sudo dnf -y install wayland-devel libxkbcommon-devel wayland-protocols-devel extra-cmake-modules 29 | echo "Building glfw." 30 | cd glfw 31 | mkdir build 32 | cmake -S . -B build -DGLFW_USE_WAYLAND=ON -G "Unix Makefiles" 33 | cd build 34 | make -j$NPROC 35 | sudo make install 36 | cd ../.. 37 | 38 | echo -e "\e[44m ================== GLEW (The OpenGL Extension Wrangler Library) =================== \e[49m" 39 | sudo dnf -y install glew-devel 40 | 41 | echo -e "\e[44m ======================= GLM (The OpenGL Mathematics Library) ====================== \e[49m" 42 | if [ ! -d ~/Downloads/glm/ ]; then 43 | git clone https://github.com/g-truc/glm.git 44 | else 45 | echo "GLM directory exists! Not cloning." 46 | fi 47 | # Make include folder 48 | echo "Copying GLM to" $curDIR"/include/" 49 | sudo cp -r ~/Downloads/glm/glm /usr/local/include 50 | 51 | echo -e "\e[44m ======================= FreeType - Font Rendering Library ========================= \e[49m" 52 | sudo dnf -y install freetype-devel 53 | if [ ! -f ~/Downloads/freetype.tar.bz2 ]; then 54 | wget -O ~/Downloads/freetype.tar.bz2 "http://download.savannah.gnu.org/releases/freetype/freetype-2.7.1.tar.bz2" 55 | fi 56 | tar xvjf ~/Downloads/freetype.tar.bz2 57 | cd ~/Downloads/freetype-2.7.1 58 | # Copy include files 59 | sudo cp -r include/* /usr/local/include 60 | -------------------------------------------------------------------------------- /Installers/installDependenciesUbuntu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Make script executable with sudo chmod +x installDependenciesUbuntu.sh 3 | # Run script without sudo ./installDependenciesUbuntu.sh 4 | 5 | # Get number of cores 6 | NPROC=$(nproc) 7 | echo "Found" $NPROC "cores." 8 | 9 | # Get current directory 10 | cd .. 11 | curDIR=$PWD 12 | 13 | # Switch to downloads directory 14 | cd ~/Downloads 15 | echo "Switched to ~/Downloads" 16 | 17 | echo -e "\e[44m ================================ Build Dependencies =============================== \e[49m" 18 | sudo apt-get -y install cmake 19 | 20 | echo -e "\e[44m ===================== GLFW (multi-platform library for OpenGL) ==================== \e[49m" 21 | if [ ! -d ~/Downloads/glfw/ ]; then 22 | git clone https://github.com/glfw/glfw.git 23 | else 24 | echo "glfw directory already exists! Not cloning." 25 | fi 26 | echo "Installing mesa depencies." 27 | sudo apt-get -y install xorg-dev libglu1-mesa-dev 28 | echo "Building glfw." 29 | cd glfw 30 | cmake -G "Unix Makefiles" 31 | make -j$NPROC 32 | sudo make install 33 | cd .. 34 | 35 | echo -e "\e[44m ================== GLEW (The OpenGL Extension Wrangler Library) =================== \e[49m" 36 | sudo apt-get -y install libglew-dev 37 | 38 | echo -e "\e[44m ======================= GLM (The OpenGL Mathematics Library) ====================== \e[49m" 39 | if [ ! -d ~/Downloads/glm/ ]; then 40 | git clone https://github.com/g-truc/glm.git 41 | else 42 | echo "GLM directory exists! Not cloning." 43 | fi 44 | # Make include folder 45 | echo "Copying GLM to" $curDIR"/include/" 46 | sudo cp -r ~/Downloads/glm/glm /usr/local/include 47 | 48 | echo -e "\e[44m ======================= FreeType - Font Rendering Library ========================= \e[49m" 49 | if [ ! -f ~/Downloads/freetype.tar.bz2 ]; then 50 | wget -O ~/Downloads/freetype.tar.bz2 "http://download.savannah.gnu.org/releases/freetype/freetype-2.7.1.tar.bz2" 51 | fi 52 | tar xvjf ~/Downloads/freetype.tar.bz2 53 | cd ~/Downloads/freetype-2.7.1 54 | # Copy include files 55 | sudo cp -r include/* /usr/local/include 56 | -------------------------------------------------------------------------------- /Installers/installDependenciesWindows-part1.bat: -------------------------------------------------------------------------------- 1 | echo off 2 | CALL:echored "IMPORTANT: REMOVE CYGWIN FROM PATH BEFORE INSTALLING." 3 | :: Change to download directory 4 | cd .. 5 | SET ORIGINAL=%CD% 6 | cd %UserProfile%\Downloads\ 7 | 8 | :: Download wget for later use 9 | call:echoblue " ==================================== wget ====================================" 10 | if not exist "%UserProfile%\Downloads\wget.exe" ( 11 | echo wget not installed. 12 | if exist "%UserProfile%\Downloads\wget.exe" ( 13 | echo wget-1.20.3 already downloaded. 14 | ) else ( 15 | echo Downloading wget for later use. 16 | bitsadmin.exe /transfer "wgetDownload" /priority Foreground http://eternallybored.org/misc/wget/1.20.3/64/wget.exe %UserProfile%\Downloads\wget.exe 17 | ) 18 | ) else ( 19 | echo wget already installed. 20 | ) 21 | 22 | :: Download MinGW 23 | call:echoblue " =================================== MingGW ===================================" 24 | if not exist "%ProgramFiles%\mingw-w64\" ( 25 | echo mingw-w64 not installed. 26 | if exist "%UserProfile%\Downloads\mingw-w64-install.exe" ( 27 | echo mingw-w64-install.exe already downloaded. 28 | ) else ( 29 | echo Downloading MinGW. 30 | "%UserProfile%\Downloads\wget.exe" --no-check-certificate "https://sourceforge.net/projects/mingw-w64/files/Toolchains targetting Win32/Personal Builds/mingw-builds/installer/mingw-w64-install.exe" -O %UserProfile%\Downloads\mingw-w64-install.exe 31 | ) 32 | echo Change Architecture to x86_64 if relevant. 33 | start /w %UserProfile%\Downloads\mingw-w64-install.exe 34 | ) else ( 35 | echo MinGW already installed. 36 | ) 37 | 38 | :: Download Cmake 39 | call:echoblue " =================================== CMake ====================================" 40 | if not exist "%ProgramFiles%\CMake\bin\" ( 41 | echo CMake not installed. 42 | if exist "%UserProfile%\Downloads\cmake-3.11.0-win64-x64.msi" ( 43 | echo cmake-3.7.1-win64-x64.msi already downloaded. 44 | ) else ( 45 | echo Downloading CMake. 46 | "%UserProfile%\Downloads\wget.exe" --no-check-certificate https://cmake.org/files/v3.11/cmake-3.11.0-win64-x64.msi 47 | ) 48 | start /w %UserProfile%\Downloads\cmake-3.11.0-win64-x64.msi 49 | ) else ( 50 | echo CMake already installed. 51 | ) 52 | 53 | :: Download Git 54 | call:echoblue " ==================================== Git =====================================" 55 | if not exist "%ProgramFiles%\Git\cmd\" ( 56 | echo Git not installed. 57 | if exist "%UserProfile%\Downloads\git-2.11.0-64-bit.exe" ( 58 | echo cmake-3.7.1-win64-x64.msi already downloaded. 59 | ) else ( 60 | echo Downloading Git. 61 | "%UserProfile%\Downloads\wget.exe" --no-check-certificate https://github.com/git-for-windows/git/releases/download/v2.11.0.windows.1/Git-2.11.0-64-bit.exe 62 | ) 63 | start /w %UserProfile%\Downloads\git-2.11.0-64-bit.exe 64 | ) else ( 65 | echo Git already installed. 66 | ) 67 | 68 | :: Download GnuMake for Windows 69 | call:echoblue " =================================== GnuMake ====================================" 70 | if not exist "%ProgramFiles(x86)%\GnuWin32\bin\make.exe" ( 71 | echo GnuMake not installed. 72 | if exist "%UserProfile%\Downloads\make-3.81.exe" ( 73 | echo make-3.81.exe already downloaded. 74 | ) else ( 75 | echo Downloading GnuMake. 76 | "%UserProfile%\Downloads\wget.exe" --no-check-certificate -O make-3.81.exe http://gnuwin32.sourceforge.net/downlinks/make.php 77 | ) 78 | start /w %UserProfile%\Downloads\make-3.81.exe 79 | ) else ( 80 | echo GnuMake already installed. 81 | ) 82 | 83 | :: Add to path 84 | call:ECHOGREEN "Add the following to your environmental variables." 85 | echo %ProgramFiles(x86)%\GnuWin32\bin 86 | call:echored "%ProgramFiles%\mingw-w64\x86_64-\mingw64\bin" 87 | echo %ProgramFiles%\CMake\bin 88 | echo %ProgramFiles%\Git\cmd 89 | call:ECHOGREEN "End of Vars." 90 | rundll32 sysdm.cpl,EditEnvironmentVariables 91 | 92 | :: Return to original directory 93 | cd %ORIGINAL%\Installers 94 | CALL:echored "IMPORTANT: Now open a NEW command prompt and run installDependenciesWindowsPart2.bat." 95 | 96 | :: Functions 97 | :ECHORED 98 | %Windir%\System32\WindowsPowerShell\v1.0\Powershell.exe write-host -backgroundcolor Red %1 99 | goto:eof 100 | 101 | :ECHOBLUE 102 | %Windir%\System32\WindowsPowerShell\v1.0\Powershell.exe write-host -backgroundcolor blue %1 103 | goto:eof 104 | 105 | :ECHOGREEN 106 | %Windir%\System32\WindowsPowerShell\v1.0\Powershell.exe write-host -backgroundcolor green -foreground black %1 107 | goto:eof -------------------------------------------------------------------------------- /Installers/installDependenciesWindows-part2.bat: -------------------------------------------------------------------------------- 1 | :: Only run after installDependenciesWindows.bat has completed successfully 2 | :: Must run in a new command prompt, to get the updated PATHS 3 | echo off 4 | CALL:echored "IMPORTANT: REMOVE CYGWIN FROM PATH BEFORE INSTALLING." 5 | :: Change to download directory 6 | cd .. 7 | SET ORIGINAL=%CD% 8 | cd %UserProfile%\Downloads\ 9 | 10 | 11 | :: Download GLFW 12 | call:echoblue " =================================== GLFW =====================================" 13 | if exist "%UserProfile%\Downloads\glfw\" ( 14 | echo GLFW already cloned. 15 | ) else ( 16 | echo Downloading GLFW. 17 | git clone https://github.com/glfw/glfw.git 18 | ) 19 | :: Copy Required includes and Libraries 20 | cd glfw 21 | mkdir build 22 | cd build 23 | cmake -DBUILD_SHARED_LIBS=OFF -G "MinGW Makefiles" .. 24 | make -j4 25 | cd .. 26 | if not exist %ORIGINAL%\include\ mkdir %ORIGINAL%\include\ 27 | xcopy include\GLFW\* %ORIGINAL%\include\GLFW\ /s/h/e/k/f/c/y 28 | if not exist %ORIGINAL%\Lib\ mkdir %ORIGINAL%\Lib\ 29 | xcopy build\src\libglfw3.a %ORIGINAL%\Lib\ /s/h/e/k/f/c/y 30 | cd .. 31 | 32 | 33 | :: Download GLM 34 | call:echoblue " =================================== GLM ======================================" 35 | if exist "%UserProfile%\Downloads\GLM\" ( 36 | echo GLM already cloned. 37 | ) else ( 38 | echo Downloading GLM. 39 | git clone https://github.com/g-truc/glm.git 40 | cd glm && git checkout 0.9.7 && cd .. 41 | ) 42 | xcopy /E/I/y glm\glm %ORIGINAL%\include\glm 43 | 44 | 45 | :: Download FreeType 46 | call:echoblue " =============================== FreeType ================================" 47 | if exist "%UserProfile%\Downloads\ft271.zip" ( 48 | echo ft271.zip already downloaded. 49 | ) else ( 50 | echo Downloading FreeType. 51 | %UserProfile%\Downloads\wget.exe --no-check-certificate https://sourceforge.net/projects/freetype/files/freetype2/2.7.1/ft271.zip 52 | call:ECHOGREEN "Please unzip %UserProfile%\Downloads\ft271.zip before pressing enter." 53 | set /p answer=Press enter to continue 54 | ) 55 | cd ft271 56 | cd freetype-2.7.1 57 | echo %CD% 58 | autogen.sh 59 | make -j4 60 | make -j4 61 | timeout 5 62 | xcopy /E/I/y %UserProfile%\Downloads\ft271\freetype-2.7.1\objs\freetype.a %ORIGINAL%\Lib\ 63 | cd .. 64 | cd .. 65 | xcopy /E/I/y "%UserProfile%\Downloads\ft271\freetype-2.7.1\include\ft2build.h" %ORIGINAL%\include\ 66 | xcopy /E/I/y "%UserProfile%\Downloads\ft271\freetype-2.7.1\include\*" %ORIGINAL%\include\ 67 | 68 | :: Return to original directory 69 | cd %ORIGINAL% 70 | 71 | :: Functions 72 | :ECHORED 73 | %Windir%\System32\WindowsPowerShell\v1.0\Powershell.exe write-host -backgroundcolor Red %1 74 | goto:eof 75 | 76 | :ECHOBLUE 77 | %Windir%\System32\WindowsPowerShell\v1.0\Powershell.exe write-host -backgroundcolor blue %1 78 | goto:eof 79 | 80 | :ECHOGREEN 81 | %Windir%\System32\WindowsPowerShell\v1.0\Powershell.exe write-host -backgroundcolor green -foreground black %1 82 | goto:eof -------------------------------------------------------------------------------- /Installers/unzipFreetype.sh: -------------------------------------------------------------------------------- 1 | unzip ft271.zip -d freetype -------------------------------------------------------------------------------- /Other/plotGif.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tbattz/openGLPlotLive/26ef4142f88370a62414b519b5d729d430a88165/Other/plotGif.gif -------------------------------------------------------------------------------- /Shaders/font.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | in vec2 TexCoords; 3 | out vec4 color; 4 | 5 | uniform sampler2D text; 6 | uniform vec3 textColor; 7 | 8 | void main() { 9 | vec4 sampled = vec4(1.0,1.0,1.0,texture(text, TexCoords).r); // Sample only red component 10 | color = vec4(textColor, 1.0) * sampled; 11 | } -------------------------------------------------------------------------------- /Shaders/font.vs: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec4 vertex; // 3 | 4 | out vec2 TexCoords; 5 | 6 | uniform mat4 transformViewport; 7 | 8 | void main() { 9 | gl_Position = transformViewport * vec4(vertex.xy, 0.5, 1.0); 10 | TexCoords = vertex.zw; 11 | } -------------------------------------------------------------------------------- /Shaders/plot2d.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | uniform vec4 inColor; 4 | 5 | out vec4 color; 6 | 7 | void main(void) { 8 | color = inColor; 9 | } -------------------------------------------------------------------------------- /Shaders/plot2d.vs: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec2 coord2d; 3 | 4 | uniform mat4 transformViewport; 5 | 6 | void main(void) { 7 | gl_Position = transformViewport * vec4(coord2d.x, coord2d.y, 0.5, 1); 8 | } -------------------------------------------------------------------------------- /Shaders/plot2dLogx.vs: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec2 coord2d; 3 | 4 | uniform mat4 transformViewport; 5 | uniform float logXBase; 6 | 7 | void main(void) { 8 | float logx = log(coord2d.x) / log(logXBase); 9 | gl_Position = transformViewport * vec4(logx, coord2d.y, 0.5, 1); 10 | } -------------------------------------------------------------------------------- /Shaders/plot2dLogxLogy.vs: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec2 coord2d; 3 | 4 | uniform mat4 transformViewport; 5 | uniform float logXBase; 6 | uniform float logYBase; 7 | 8 | void main(void) { 9 | float logx = log(coord2d.x) / log(logXBase); 10 | float logy = log(coord2d.y) / log(logYBase); 11 | gl_Position = transformViewport * vec4(logx, logy, 0.5, 1); 12 | } -------------------------------------------------------------------------------- /Shaders/plot2dLogy.vs: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec2 coord2d; 3 | 4 | uniform mat4 transformViewport; 5 | uniform float logYBase; 6 | 7 | void main(void) { 8 | float logy = log(coord2d.y) / log(logYBase); 9 | gl_Position = transformViewport * vec4(coord2d.x, logy, 0.5, 1); 10 | } -------------------------------------------------------------------------------- /Shaders/plotPosNeg2d.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | uniform vec4 colPos; 4 | uniform vec4 colNeg; 5 | 6 | in float yVals; 7 | out vec4 color; 8 | 9 | void main(void) { 10 | float ySign = sign(yVals); 11 | color = vec4(0.5f*(colPos[0]-colNeg[0])*ySign + 0.5f*(colPos[0]+colNeg[0]), 12 | 0.5f*(colPos[1]-colNeg[1])*ySign + 0.5f*(colPos[1]+colNeg[1]), 13 | 0.5f*(colPos[2]-colNeg[2])*ySign + 0.5f*(colPos[2]+colNeg[2]), 14 | 0.5f*(colPos[3]-colNeg[3])*ySign + 0.5f*(colPos[3]+colNeg[3])); 15 | } -------------------------------------------------------------------------------- /Shaders/plotPosNeg2d.vs: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout (location = 0) in vec2 coord2d; 4 | 5 | uniform mat4 transformViewport; 6 | 7 | out float yVals; 8 | 9 | void main(void) { 10 | gl_Position = transformViewport * vec4(coord2d.x, coord2d.y, 0, 1); 11 | yVals = coord2d.y; 12 | } -------------------------------------------------------------------------------- /Shaders/plotText.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | in vec2 TexCoords; 3 | out vec4 color; 4 | 5 | uniform sampler2D text; 6 | uniform vec3 textColor; 7 | 8 | void main() { 9 | vec4 sampled = vec4(1.0,1.0,1.0,texture(text, TexCoords).r); // Sample only red component 10 | color = vec4(textColor, 1.0) * sampled; 11 | } -------------------------------------------------------------------------------- /Shaders/plotText.vs: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec4 vertex; // 3 | 4 | out vec2 TexCoords; 5 | 6 | uniform mat4 textProjection; 7 | 8 | void main() { 9 | gl_Position = textProjection * vec4(vertex.xy, 0.0, 1.0); 10 | TexCoords = vertex.zw; 11 | } -------------------------------------------------------------------------------- /Shaders/plotTransparent2d.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | uniform vec4 inColor; 4 | 5 | out vec4 color; 6 | 7 | void main(void) { 8 | color = inColor; 9 | } -------------------------------------------------------------------------------- /Shaders/plotTransparent2d.vs: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec2 coord2d; 3 | 4 | uniform mat4 transformViewport; 5 | uniform float z; 6 | 7 | void main(void) { 8 | gl_Position = transformViewport * vec4(coord2d.x, coord2d.y, z, 1); 9 | } -------------------------------------------------------------------------------- /Shaders/scatter2d.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec4 FragColor; 3 | 4 | uniform vec4 inColor; 5 | 6 | void main() { 7 | FragColor = inColor; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /Shaders/scatter2d.vs: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec2 aPos; 3 | layout (location = 1) in vec2 aOffset; 4 | 5 | out vec3 fColor; 6 | 7 | uniform mat4 transformViewport; 8 | 9 | void main() { 10 | gl_Position = vec4(aPos, 0.0, 0.0) + (transformViewport * vec4(aOffset, 0.5, 1.0)); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /Shaders/scatter2dLogx.vs: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec2 aPos; 3 | layout (location = 1) in vec2 aOffset; 4 | 5 | out vec3 fColor; 6 | 7 | uniform mat4 transformViewport; 8 | uniform float logXBase; 9 | 10 | void main() { 11 | float logxOffset = log(aOffset.x) / log(logXBase); 12 | gl_Position = vec4(aPos, 0.0, 0.0) + (transformViewport * vec4(logxOffset, aOffset.y, 0.5, 1.0)); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Shaders/scatter2dLogxLogy.vs: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec2 aPos; 3 | layout (location = 1) in vec2 aOffset; 4 | 5 | out vec3 fColor; 6 | 7 | uniform mat4 transformViewport; 8 | uniform float logXBase; 9 | uniform float logYBase; 10 | 11 | void main() { 12 | float logxOffset = log(aOffset.x) / log(logXBase); 13 | float logyOffset = log(aOffset.y) / log(logYBase); 14 | gl_Position = vec4(aPos, 0.0, 0.0) + (transformViewport * vec4(logxOffset, logyOffset, 0.5, 1.0)); 15 | } 16 | 17 | -------------------------------------------------------------------------------- /Shaders/scatter2dLogy.vs: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec2 aPos; 3 | layout (location = 1) in vec2 aOffset; 4 | 5 | out vec3 fColor; 6 | 7 | uniform mat4 transformViewport; 8 | uniform float logYBase; 9 | 10 | void main() { 11 | float logyOffset = log(aOffset.y) / log(logYBase); 12 | gl_Position = vec4(aPos, 0.0, 0.0) + (transformViewport * vec4(aOffset.x, logyOffset, 0.5, 1.0)); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Shaders/texture.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | in vec2 TexCoord; 3 | out vec4 FragColor; 4 | 5 | uniform sampler2D ourTexture; 6 | 7 | 8 | void main(void) { 9 | FragColor = texture(ourTexture, TexCoord); 10 | } -------------------------------------------------------------------------------- /Shaders/texture.vs: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec2 coord2d; 3 | layout (location = 1) in vec2 aTexCoord; 4 | 5 | uniform mat4 transformViewport; 6 | 7 | out vec2 TexCoord; 8 | 9 | 10 | void main(void) { 11 | gl_Position = transformViewport * vec4(coord2d.x, coord2d.y, 0.5, 1); 12 | TexCoord = aTexCoord; 13 | } -------------------------------------------------------------------------------- /apps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(apps) 2 | 3 | # Resolves issue with unable to debug with CLion, reverts back to g++9 4 | add_compile_options(-gdwarf-4) 5 | 6 | # Create the exectuable 7 | add_executable(examplePlot examplePlot.cpp) 8 | add_executable(movingTimeframe movingTimeframe.cpp) 9 | 10 | 11 | # Link the static library from subproject 1 12 | target_link_libraries(examplePlot PRIVATE openGLPlotLive ${LIBS}) 13 | target_link_libraries(movingTimeframe PRIVATE openGLPlotLive ${LIBS}) 14 | 15 | # Copy Shader files to build directory 16 | add_custom_command(TARGET examplePlot PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/../Shaders $/Shaders) 17 | 18 | # Copy Texture files to build directory 19 | add_custom_command(TARGET examplePlot PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/../textures $/textures) -------------------------------------------------------------------------------- /cmake/FindFREETYPE.cmake: -------------------------------------------------------------------------------- 1 | # - Locate FREETYPE library 2 | # This module defines 3 | # FREETYPE_LIBRARY, the name of the library to link against 4 | # FREETYPE_FOUND 5 | # To Adding search path, set FREETYPE_ROOT_DIR as follows 6 | # set(FREETYPE_ROOT_DIR "path/to/FREETYPE") 7 | # or launch cmake with -DFREETYPE_ROOT_DIR="/path/to/FREETYPE_ROOT_DIR". 8 | 9 | find_library(FREETYPE_LIBRARY freetype 10 | /usr/lib64 11 | /usr/lib 12 | /usr/local/lib 13 | /opt/local/lib 14 | ${CMAKE_SOURCE_DIR}/Lib 15 | ) 16 | 17 | IF(FREETYPE_LIBRARY) 18 | SET( FREETYPE_FOUND TRUE ) 19 | SET( FREETYPE_LIBRARIES ${FREETYPE_LIBRARY} ) 20 | ENDIF(FREETYPE_LIBRARY) 21 | IF(FREETYPE_FOUND) 22 | IF(NOT FREETYPE_FIND_QUIETLY) 23 | ENDIF(NOT FREETYPE_FIND_QUIETLY) 24 | ELSE(FREETYPE_FOUND) 25 | IF(FREETYPE_FIND_REQUIRED) 26 | MESSAGE(FATAL_ERROR "Could not find libFREETYPE") 27 | ENDIF(FREETYPE_FIND_REQUIRED) 28 | ENDIF(FREETYPE_FOUND) -------------------------------------------------------------------------------- /cmake/FindGLEW.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Try to find GLEW library and include path. 3 | # Once done this will define 4 | # 5 | # GLEW_FOUND 6 | # GLEW_INCLUDE_PATH 7 | # GLEW_LIBRARY 8 | # 9 | IF (WIN32) 10 | FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h 11 | ${CMAKE_SOURCE_DIR}/../includes 12 | $ENV{PROGRAMFILES}/GLEW/include 13 | ${GLEW_ROOT_DIR}/includes 14 | DOC "The directory where GL/glew.h resides") 15 | IF (NV_SYSTEM_PROCESSOR STREQUAL "AMD64") 16 | FIND_LIBRARY( GLEW_LIBRARY 17 | NAMES glew64 glew64s 18 | PATHS 19 | $ENV{PROGRAMFILES}/GLEW/lib 20 | ${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin 21 | ${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib 22 | DOC "The GLEW library (64-bit)" 23 | ) 24 | ELSE(NV_SYSTEM_PROCESSOR STREQUAL "AMD64") 25 | FIND_LIBRARY( GLEW_LIBRARY 26 | NAMES glew GLEW glew32 glew32s 27 | PATHS 28 | ${CMAKE_SOURCE_DIR}/../lib 29 | $ENV{PROGRAMFILES}/GLEW/lib 30 | ${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin 31 | ${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib 32 | DOC "The GLEW library" 33 | ) 34 | ENDIF(NV_SYSTEM_PROCESSOR STREQUAL "AMD64") 35 | ELSE (WIN32) 36 | FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h 37 | /usr/include 38 | /usr/local/include 39 | /sw/include 40 | /opt/local/include 41 | ${GLEW_ROOT_DIR}/../include 42 | DOC "The directory where GL/glew.h resides") 43 | FIND_LIBRARY( GLEW_LIBRARY 44 | NAMES GLEW glew 45 | PATHS 46 | /usr/lib64 47 | /usr/lib 48 | /usr/local/lib64 49 | /usr/local/lib 50 | /sw/lib 51 | /opt/local/lib 52 | ${GLEW_ROOT_DIR}/../lib 53 | DOC "The GLEW library") 54 | ENDIF (WIN32) 55 | SET(GLEW_FOUND "NO") 56 | IF (GLEW_INCLUDE_PATH AND GLEW_LIBRARY) 57 | SET(GLEW_LIBRARIES ${GLEW_LIBRARY}) 58 | SET(GLEW_FOUND "YES") 59 | ENDIF (GLEW_INCLUDE_PATH AND GLEW_LIBRARY) 60 | include(FindPackageHandleStandardArgs) 61 | find_package_handle_standard_args(GLEW DEFAULT_MSG GLEW_LIBRARY GLEW_INCLUDE_PATH) 62 | -------------------------------------------------------------------------------- /cmake/FindGLFW3.cmake: -------------------------------------------------------------------------------- 1 | # Locate the glfw3 library 2 | # 3 | # This module defines the following variables: 4 | # 5 | # GLFW3_LIBRARY the name of the library; 6 | # GLFW3_INCLUDE_DIR where to find glfw include files. 7 | # GLFW3_FOUND true if both the GLFW3_LIBRARY and GLFW3_INCLUDE_DIR have been found. 8 | # 9 | # To help locate the library and include file, you can define a 10 | # variable called GLFW3_ROOT which points to the root of the glfw library 11 | # installation. 12 | # 13 | # default search dirs 14 | # 15 | # Cmake file from: https://github.com/daw42/glslcookbook 16 | 17 | set( _glfw3_HEADER_SEARCH_DIRS 18 | "/usr/include" 19 | "/usr/local/include" 20 | "${CMAKE_SOURCE_DIR}/../includes" 21 | "C:/Program Files (x86)/glfw/include" ) 22 | set( _glfw3_LIB_SEARCH_DIRS 23 | "/usr/lib" 24 | "/usr/local/lib" 25 | "${CMAKE_SOURCE_DIR}/../lib" 26 | "C:/Program Files (x86)/glfw/lib-msvc110" ) 27 | 28 | # Check environment for root search directory 29 | set( _glfw3_ENV_ROOT $ENV{GLFW3_ROOT} ) 30 | if( NOT GLFW3_ROOT AND _glfw3_ENV_ROOT ) 31 | set(GLFW3_ROOT ${_glfw3_ENV_ROOT} ) 32 | endif() 33 | 34 | # Put user specified location at beginning of search 35 | if( GLFW3_ROOT ) 36 | list( INSERT _glfw3_HEADER_SEARCH_DIRS 0 "${GLFW3_ROOT}/include" ) 37 | list( INSERT _glfw3_LIB_SEARCH_DIRS 0 "${GLFW3_ROOT}/lib" ) 38 | endif() 39 | 40 | # Search for the header 41 | FIND_PATH(GLFW3_INCLUDE_DIR "GLFW/glfw3.h" 42 | PATHS ${_glfw3_HEADER_SEARCH_DIRS} ) 43 | 44 | # Search for the library 45 | FIND_LIBRARY(GLFW3_LIBRARY NAMES glfw3 glfw 46 | PATHS ${_glfw3_LIB_SEARCH_DIRS} ) 47 | INCLUDE(FindPackageHandleStandardArgs) 48 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLFW3 DEFAULT_MSG 49 | GLFW3_LIBRARY GLFW3_INCLUDE_DIR) -------------------------------------------------------------------------------- /cmake/FindGLM.cmake: -------------------------------------------------------------------------------- 1 | # FindGLM - attempts to locate the glm matrix/vector library. 2 | # 3 | # This module defines the following variables (on success): 4 | # GLM_INCLUDE_DIRS - where to find glm/glm.hpp 5 | # GLM_FOUND - if the library was successfully located 6 | # 7 | # It is trying a few standard installation locations, but can be customized 8 | # with the following variables: 9 | # GLM_ROOT_DIR - root directory of a glm installation 10 | # Headers are expected to be found in either: 11 | # /glm/glm.hpp OR 12 | # /include/glm/glm.hpp 13 | # This variable can either be a cmake or environment 14 | # variable. Note however that changing the value 15 | # of the environment varible will NOT result in 16 | # re-running the header search and therefore NOT 17 | # adjust the variables set by this module. 18 | #============================================================================= 19 | # Copyright 2012 Carsten Neumann 20 | # 21 | # Distributed under the OSI-approved BSD License (the "License"); 22 | # see accompanying file Copyright.txt for details. 23 | # 24 | # This software is distributed WITHOUT ANY WARRANTY; without even the 25 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 26 | # See the License for more information. 27 | #============================================================================= 28 | # (To distribute this file outside of CMake, substitute the full 29 | # License text for the above reference.) 30 | # default search dirs 31 | 32 | SET(_glm_HEADER_SEARCH_DIRS 33 | "/usr/include" 34 | "/usr/local/include" 35 | "${CMAKE_SOURCE_DIR}/../includes" 36 | "C:/Program Files (x86)/glm" ) 37 | # check environment variable 38 | SET(_glm_ENV_ROOT_DIR "$ENV{GLM_ROOT_DIR}") 39 | IF(NOT GLM_ROOT_DIR AND _glm_ENV_ROOT_DIR) 40 | SET(GLM_ROOT_DIR "${_glm_ENV_ROOT_DIR}") 41 | ENDIF(NOT GLM_ROOT_DIR AND _glm_ENV_ROOT_DIR) 42 | # put user specified location at beginning of search 43 | IF(GLM_ROOT_DIR) 44 | SET(_glm_HEADER_SEARCH_DIRS "${GLM_ROOT_DIR}" 45 | "${GLM_ROOT_DIR}/include" 46 | ${_glm_HEADER_SEARCH_DIRS}) 47 | ENDIF(GLM_ROOT_DIR) 48 | # locate header 49 | FIND_PATH(GLM_INCLUDE_DIR "glm/glm.hpp" 50 | PATHS ${_glm_HEADER_SEARCH_DIRS}) 51 | INCLUDE(FindPackageHandleStandardArgs) 52 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLM DEFAULT_MSG 53 | GLM_INCLUDE_DIR) 54 | IF(GLM_FOUND) 55 | SET(GLM_INCLUDE_DIRS "${GLM_INCLUDE_DIR}") 56 | MESSAGE(STATUS "GLM_INCLUDE_DIR = ${GLM_INCLUDE_DIR}") 57 | ENDIF(GLM_FOUND) -------------------------------------------------------------------------------- /cmake/FindSphinx.cmake: -------------------------------------------------------------------------------- 1 | if(LINUX OR UNIX) 2 | # Try and find sphinx-build 3 | find_program(SPHINX_EXECUTABLE 4 | NAMES sphinx-build 5 | DOC "Path to sphinx-build exectuable") 6 | 7 | include(FindPackageHandleStandardArgs) 8 | 9 | # Handle standard arguments for find_package 10 | find_package_handle_standard_args(Sphinx "Failed to find sphinx-build executable" SPHINX_EXECUTABLE) 11 | endif() 12 | message("-- SPHINX: " ${SPHINX_EXECUTABLE}) 13 | -------------------------------------------------------------------------------- /docs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ## Based on https://devblogs.microsoft.com/cppblog/clear-functional-c-documentation-with-sphinx-breathe-doxygen-cmake/ 2 | 3 | find_package(Doxygen) 4 | find_package(Sphinx) 5 | 6 | # Find the headers 7 | get_target_property(OPENGLPLOTLIVE_PUBLIC_HEADER_DIR openGLPlotLive INTERFACE_INCLUDE_DIRECTORIES) 8 | file(GLOB_RECURSE OPENGLPLOTLIVE_PUBLIC_HEADERS ${OPENGLPLOTLIVE_PUBLIC_HEADER_DIR}/*.h) 9 | 10 | # Doxygen variables 11 | set(DOXYGEN_INPUT_DIR ${PROJECT_SOURCE_DIR}/src/) 12 | set(DOXYGEN_OUTPUT_DIR ${PROJECT_SOURCE_DIR}/docs/doxygen/) 13 | set(DOXYGEN_INDEX_FILE ${DOXYGEN_OUTPUT_DIR}/xml/index.xml) 14 | set(DOXYFILE_IN ${PROJECT_SOURCE_DIR}/docs/Doxyfile.in) 15 | set(DOXYFILE_OUT ${PROJECT_SOURCE_DIR}/docs/doxygen/Doxyfile) 16 | 17 | # Replace variables inside @@ witht he current values 18 | configure_file(${DOXYFILE_IN} ${DOXYFILE_OUT} @ONLY) 19 | 20 | # Create directory if required 21 | file(MAKE_DIRECTORY ${DOXYGEN_OUTPUT_DIR}) 22 | 23 | # Only regenerate doxygen when the doxyfile or public headers change 24 | add_custom_command(OUTPUT ${DOXYGEN_INDEX_FILE} 25 | DEPENDS ${OPENGLPLOTLIVE_PUBLIC_HEADERS} 26 | COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE_OUT} 27 | MAIN_DEPENDENCY ${DOXYFILE_OUT} ${DOXYFILE_IN} 28 | COMMENT "Generating documentation with doxygen" 29 | VERBATIM) 30 | 31 | # Target to run the job 32 | add_custom_target(doxygen ALL DEPENDS ${DOXYGEN_INDEX_FILE}) 33 | 34 | 35 | 36 | # Sphinx variables 37 | set(SPHINX_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}) 38 | set(SPHINX_BUILD ${PROJECT_SOURCE_DIR}/docs/sphinx) 39 | set(SPHINX_INDEX_FILE ${SPHINX_BUILD}/index.html) 40 | 41 | # Only regenerate Sphinx when: 42 | # - Doxygen has rerun 43 | # - Our doc files have been updated 44 | # - The Sphinx config has been updated 45 | add_custom_command(OUTPUT ${SPHINX_INDEX_FILE} 46 | COMMAND 47 | ${SPHINX_EXECUTABLE} -b html 48 | # Tell Breathe where to find the Doxygen output 49 | -Dbreathe_projects.openGLPlotLive=${DOXYGEN_OUTPUT_DIR}/xml 50 | ${SPHINX_SOURCE} ${SPHINX_BUILD} 51 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 52 | DEPENDS 53 | # Other docs files you want to track should go here (or in some variable) 54 | doxygen 55 | ${CMAKE_CURRENT_SOURCE_DIR}/index.rst 56 | ${DOXYGEN_INDEX_FILE} 57 | MAIN_DEPENDENCY ${SPHINX_SOURCE}/conf.py 58 | COMMENT "Generating documentation with Sphinx") 59 | 60 | # Nice named target so we can run the job easily 61 | add_custom_target(sphinx ALL DEPENDS ${SPHINX_INDEX_FILE}) 62 | 63 | # Add target that depends on both 64 | add_custom_target(docs) 65 | add_dependencies(docs doxygen sphinx) -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # This file only contains a selection of the most common options. For a full 4 | # list see the documentation: 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 6 | 7 | # -- Path setup -------------------------------------------------------------- 8 | 9 | # If extensions (or modules to document with autodoc) are in another directory, 10 | # add these directories to sys.path here. If the directory is relative to the 11 | # documentation root, use os.path.abspath to make it absolute, like shown here. 12 | # 13 | # import os 14 | # import sys 15 | # sys.path.insert(0, os.path.abspath('.')) 16 | import sphinx_rtd_theme 17 | 18 | 19 | # -- Project information ----------------------------------------------------- 20 | 21 | project = 'openGLPlotLive' 22 | copyright = '2020, Trevor Batty' 23 | author = 'Trevor Batty' 24 | 25 | # The full version, including alpha/beta/rc tags 26 | release = '0.1' 27 | 28 | 29 | # -- General configuration --------------------------------------------------- 30 | 31 | # Add any Sphinx extension module names here, as strings. They can be 32 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 33 | # ones. 34 | extensions = [ "breathe", 35 | "sphinx_rtd_theme"] 36 | 37 | # Breathe Configuration 38 | breathe_default_project = "openGLPlotLive" 39 | 40 | # Add any paths that contain templates here, relative to this directory. 41 | templates_path = ['_templates'] 42 | 43 | # List of patterns, relative to source directory, that match files and 44 | # directories to ignore when looking for source files. 45 | # This pattern also affects html_static_path and html_extra_path. 46 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] 47 | 48 | 49 | # -- Options for HTML output ------------------------------------------------- 50 | 51 | # The theme to use for HTML and HTML Help pages. See the documentation for 52 | # a list of builtin themes. 53 | # 54 | #html_theme = 'alabaster' 55 | html_theme = "sphinx_rtd_theme" 56 | 57 | # Add any paths that contain custom static files (such as style sheets) here, 58 | # relative to this directory. They are copied after the builtin static files, 59 | # so a file named "default.css" will overwrite the builtin "default.css". 60 | #html_static_path = ['_static'] -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. openGLPlotLive documentation master file, created by 2 | sphinx-quickstart on Fri Jun 19 23:11:22 2020. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to openGLPlotLive's documentation! 7 | ========================================== 8 | 9 | .. toctree:: 10 | :maxdepth: 2 11 | :caption: Contents: 12 | 13 | 14 | Docs 15 | ==== 16 | 17 | .. doxygenindex:: 18 | 19 | 20 | 21 | Indices and tables 22 | ================== 23 | 24 | * :ref:`genindex` 25 | * :ref:`modindex` 26 | * :ref:`search` 27 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | 13 | if "%1" == "" goto help 14 | 15 | %SPHINXBUILD% >NUL 2>NUL 16 | if errorlevel 9009 ( 17 | echo. 18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 19 | echo.installed, then set the SPHINXBUILD environment variable to point 20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 21 | echo.may add the Sphinx directory to PATH. 22 | echo. 23 | echo.If you don't have Sphinx installed, grab it from 24 | echo.http://sphinx-doc.org/ 25 | exit /b 1 26 | ) 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # cmake version 2 | cmake_minimum_required(VERSION 3.10) 3 | 4 | # Project Name 5 | project(openGLPlotLive) 6 | 7 | # Create library 8 | add_library(${PROJECT_NAME} "") 9 | 10 | # Glad 11 | target_sources(${PROJECT_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/include/glad.c) 12 | target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${CMAKE_SOURCE_DIR}/include) 13 | 14 | # Add subdirectories 15 | add_subdirectory(axes) 16 | add_subdirectory(dataTypes) 17 | add_subdirectory(lines) 18 | add_subdirectory(shadedLines) 19 | add_subdirectory(plot) 20 | add_subdirectory(rendering) 21 | add_subdirectory(window) 22 | add_subdirectory(texts) 23 | add_subdirectory(shapes) 24 | add_subdirectory(util) 25 | add_subdirectory(interaction) 26 | add_subdirectory(textures) 27 | add_subdirectory(scatterPlot) 28 | 29 | # Copy Shader files to build directory 30 | add_custom_command(TARGET openGLPlotLive PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/../Shaders $/Shaders) 31 | add_custom_command(TARGET openGLPlotLive PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/../textures $/../textures) 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/axes/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Add sources 2 | file(GLOB CPP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) 3 | file(GLOB H_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h) 4 | target_sources(${PROJECT_NAME} PRIVATE ${CPP_FILES}) 5 | target_sources(${PROJECT_NAME} PUBLIC "${H_FILES}") 6 | 7 | # Setup include directories 8 | target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/axes) -------------------------------------------------------------------------------- /src/axes/Grid.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 4/7/20. 3 | // 4 | 5 | #include "Grid.h" 6 | 7 | 8 | 9 | namespace GLPL { 10 | 11 | Grid::Grid(std::shared_ptr parentDimensions) : Plotable(std::move(parentDimensions)) { 12 | // Set Bounding Box Color 13 | boundingBoxColor = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f); 14 | // Set Not Hoverable 15 | setHoverable(false); 16 | 17 | // Setup Buffers 18 | Grid::createAndSetupAxesLineBuffers(); 19 | 20 | } 21 | 22 | void Grid::setMinMaxXAxes(float newXMin, float newXMax) { 23 | if (newXMin != newXMax) { 24 | xMin = newXMin; 25 | xMax = newXMax; 26 | // Regenerate axes lines 27 | genLines(); 28 | } 29 | } 30 | 31 | void Grid::setMinMaxYAxes(float newYMin, float newYMax) { 32 | if (newYMin != newYMax) { 33 | yMin = newYMin; 34 | yMax = newYMax; 35 | // Regenerate axes lines 36 | genLines(); 37 | } 38 | } 39 | 40 | void Grid::setMinMax(float newXMin, float newXMax, float newYMin, float newYMax) { 41 | if ((newXMin != newXMax) && (newYMin != newYMax)) { 42 | xMin = newXMin; 43 | xMax = newXMax; 44 | yMin = newYMin; 45 | yMax = newYMax; 46 | // Regenerate axes lines 47 | genLines(); 48 | } 49 | } 50 | 51 | void Grid::setXLines(std::vector xVals) { 52 | xAxesPos = std::move(xVals); 53 | Grid::genLines(); 54 | } 55 | 56 | void Grid::setYLines(std::vector yVals) { 57 | yAxesPos = std::move(yVals); 58 | Grid::genLines(); 59 | } 60 | 61 | void Grid::genLines() { 62 | verts.clear(); 63 | for(float xAxesPo : xAxesPos) { 64 | // Store relative position 65 | verts.push_back(xAxesPo); // x1 66 | verts.push_back(yMin); // y1 67 | verts.push_back(xAxesPo); // x2 68 | verts.push_back(yMax); // y2 69 | } 70 | for(float yAxesPo : yAxesPos) { 71 | // Store relative position 72 | verts.push_back(xMin); // x1 73 | verts.push_back(yAxesPo); // y1 74 | verts.push_back(xMax); // x2 75 | verts.push_back(yAxesPo); // y2 76 | } 77 | updateAxesLineBuffers(); 78 | } 79 | 80 | 81 | 82 | void Grid::createAndSetupAxesLineBuffers() { 83 | // Major Tick Buffers 84 | // Create Buffers 85 | glGenVertexArrays(1,&vertsVAO); 86 | glGenBuffers(1,&vertsVBO); 87 | 88 | // Setup Buffers 89 | glBindVertexArray(vertsVAO); 90 | glBindBuffer(GL_ARRAY_BUFFER, vertsVBO); 91 | glBufferData(GL_ARRAY_BUFFER, verts.size() * sizeof(GLfloat), &verts[0], GL_STATIC_DRAW); 92 | 93 | // Position Attributes 94 | glEnableVertexAttribArray(0); 95 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid*)0); 96 | 97 | glBindVertexArray(0); 98 | 99 | } 100 | 101 | void Grid::updateAxesLineBuffers() { 102 | // Major Ticks 103 | glBindVertexArray(vertsVAO); 104 | glBindBuffer(GL_ARRAY_BUFFER, vertsVBO); 105 | glBufferData(GL_ARRAY_BUFFER, verts.size() * sizeof(verts[0]), &verts[0], GL_STATIC_DRAW); 106 | glBindVertexArray(0); 107 | } 108 | 109 | void Grid::Draw() { 110 | // Draw Major Ticks 111 | std::shared_ptr shader = selectShader(); 112 | shader->Use(); 113 | glUniformMatrix4fv(glGetUniformLocation(shader->Program, "transformViewport"), 1, GL_FALSE, 114 | glm::value_ptr(*axesViewportTransform)); 115 | glUniform4fv(glGetUniformLocation(shader->Program, "inColor"), 1, glm::value_ptr(axesLineColor)); 116 | glBindVertexArray(vertsVAO); 117 | glDrawArrays(GL_LINES, 0, (int)verts.size() / 2.0); 118 | glBindVertexArray(0); 119 | } 120 | 121 | std::shared_ptr Grid::selectShader() { 122 | std::shared_ptr shader; 123 | if (logX) { 124 | if (logY) { 125 | // Both logX and logY 126 | shader = shaderSetPt->getPlot2dLogxLogyShader(); 127 | } else { 128 | // LogX only 129 | shader = shaderSetPt->getPlot2dLogxShader(); 130 | } 131 | } else { 132 | if (logY) { 133 | // LogY only 134 | shader = shaderSetPt->getPlot2dLogyShader(); 135 | } else { 136 | // Both Linear 137 | shader = shaderSetPt->getPlot2dShader(); 138 | } 139 | } 140 | 141 | return shader; 142 | } 143 | 144 | std::vector Grid::getMinMax(bool onlyPositiveX, bool onlyPositiveY) { 145 | return std::vector {}; 146 | } 147 | 148 | std::string Grid::getID() { 149 | return "Grid:" + std::to_string(x) + ":" + std::to_string(y); 150 | } 151 | 152 | std::tuple Grid::getClosestPoint(float xVal) { 153 | return std::make_tuple(0.0, 0.0); 154 | } 155 | 156 | std::tuple Grid::getClosestPoint(float xVal, float xmin, float xmax, float ymin, float ymax) { 157 | return std::make_tuple(0.0, 0.0); 158 | } 159 | 160 | void Grid::drawLegendEntry(glm::mat4 rectOverallTransform) { 161 | // Do nothing 162 | } 163 | 164 | } 165 | 166 | -------------------------------------------------------------------------------- /src/axes/Grid.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 4/7/20. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_GRID_H 6 | #define OPENGLPLOTLIVE_PROJ_GRID_H 7 | 8 | 9 | // Standard Includes 10 | #include 11 | 12 | // Project Includes 13 | #include "Plotable.h" 14 | 15 | 16 | namespace GLPL { 17 | 18 | class Grid : public Plotable { 19 | public: 20 | // Constructor 21 | Grid(std::shared_ptr parentDimensions); 22 | 23 | // Functions 24 | void Draw() override; 25 | std::vector getMinMax(bool onlyPositiveX = false, bool onlyPositiveY = false); 26 | std::string getID() override; 27 | void setMinMaxXAxes(float newXMin, float newXMax); 28 | void setMinMaxYAxes(float newYMin, float newYMax); 29 | void setMinMax(float newXMin, float newXMax, float newYMin, float newYMax); 30 | void setXLines(std::vector xVals); 31 | void setYLines(std::vector yVals); 32 | void genLines(); 33 | 34 | std::tuple getClosestPoint(float xVal); 35 | std::tuple getClosestPoint(float xVal, float xmin, float xmax, float ymin, float ymax); 36 | 37 | void drawLegendEntry(glm::mat4 rectOverallTransform); 38 | 39 | private: 40 | 41 | void createAndSetupAxesLineBuffers(); 42 | void updateAxesLineBuffers(); 43 | std::shared_ptr selectShader(); 44 | 45 | // Major Tick Buffers 46 | GLuint vertsVAO, vertsVBO; 47 | std::vector verts; // Holds the vertices (-1 to 1) to plot 48 | std::vector xAxesPos; // Holds the graph value at this vertex for the x axes 49 | std::vector yAxesPos; // Holds the graph value at this vertex for the y axes 50 | 51 | // Settings 52 | float xMin = 0; 53 | float xMax = 0; 54 | float yMin = 0; 55 | float yMax = 0; 56 | glm::vec4 axesLineColor = glm::vec4(0.75f, 0.75f, 0.75f, 0.75f); 57 | 58 | }; 59 | 60 | } 61 | 62 | 63 | #endif //OPENGLPLOTLIVE_PROJ_GRID_H 64 | -------------------------------------------------------------------------------- /src/axes/Legend.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 20/11/22. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_LEGEND_H 6 | #define OPENGLPLOTLIVE_PROJ_LEGEND_H 7 | 8 | 9 | // Project Includes 10 | #include "../texts/TextString.h" 11 | #include "../rendering/ConstantXYDrawable.h" 12 | #include "../shadedLines/ShadedLine2D2CircularVecs.h" 13 | #include "../shapes/Rectangle.h" 14 | #include "LegendMarkerRectangle.h" 15 | 16 | 17 | namespace GLPL { 18 | 19 | class Legend : public ConstantXYDrawable { 20 | public: 21 | // Constructor 22 | Legend(float x, float y, std::shared_ptr parentDimensions, AttachLocation attachLocation = BOTTOM_LEFT); 23 | 24 | // Functions 25 | std::string getID(); 26 | void Draw(); 27 | 28 | void addPlotableToLegend(std::string label, std::shared_ptr plotable); 29 | 30 | protected: 31 | // Functions 32 | void createRow(); 33 | 34 | // Data 35 | glm::vec4 legendBackgroundColor = glm::vec4(0.4f, 0.4f, 0.4f, 1.0f); 36 | glm::vec4 legendOutlineColor = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); 37 | std::shared_ptr rect; 38 | 39 | bool textChanged = false; 40 | unsigned legendItemCount = 0; 41 | std::unordered_map, std::shared_ptr, std::shared_ptr>> legendItemMap; 42 | 43 | // Can't do it this way because it shades to the axes, which isn't what we want 44 | std::vector vertsX = {0.0f, 1.0f}; 45 | std::vector vertsY = {-1.0f, 1.0f}; 46 | 47 | }; 48 | 49 | 50 | } 51 | 52 | #endif //OPENGLPLOTLIVE_PROJ_LEGEND_H 53 | -------------------------------------------------------------------------------- /src/axes/LegendMarkerRectangle.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-ryzen on 11/1/23. 3 | // 4 | 5 | #include "LegendMarkerRectangle.h" 6 | 7 | #include 8 | 9 | 10 | 11 | namespace GLPL { 12 | 13 | 14 | LegendMarkerRectangle::LegendMarkerRectangle(float x, float y, float width, float height, 15 | std::shared_ptr parentDimensions, 16 | std::shared_ptr plotable) : Rectangle(x, y, 17 | width, 18 | height, 19 | std::move(parentDimensions)) { 20 | 21 | this->plotable = std::move(plotable); 22 | 23 | } 24 | 25 | void LegendMarkerRectangle::Draw() { 26 | plotable->drawLegendEntry(overallTransform); 27 | } 28 | 29 | 30 | } 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/axes/LegendMarkerRectangle.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-ryzen on 11/1/23. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_LEGENDMARKERRECTANGLE_H 6 | #define OPENGLPLOTLIVE_PROJ_LEGENDMARKERRECTANGLE_H 7 | 8 | 9 | // Project Includes 10 | #include "../texts/TextString.h" 11 | #include "../rendering/ConstantXYDrawable.h" 12 | #include "../shadedLines/ShadedLine2D2CircularVecs.h" 13 | #include "../shapes/Rectangle.h" 14 | 15 | 16 | namespace GLPL { 17 | 18 | class LegendMarkerRectangle : public Rectangle { 19 | public: 20 | // Constructor 21 | LegendMarkerRectangle(float x, float y, float width, float height, 22 | std::shared_ptr parentDimensions, 23 | std::shared_ptr plotable); 24 | 25 | void Draw() override; 26 | 27 | 28 | private: 29 | std::shared_ptr plotable; 30 | }; 31 | 32 | } 33 | 34 | 35 | #endif //OPENGLPLOTLIVE_PROJ_LEGENDMARKERRECTANGLE_H 36 | -------------------------------------------------------------------------------- /src/axes/Plotable.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by tbatt on 24/06/2020. 3 | // 4 | 5 | #include "Plotable.h" 6 | 7 | #include 8 | 9 | 10 | namespace GLPL { 11 | 12 | Plotable::Plotable(std::shared_ptr parentDimensions) : 13 | ConstantXYDrawable(0.0f, 0.0f, 1.0f, 1.0f, CONSTANT_SCALE, CONSTANT_SCALE, std::move(parentDimensions)) { 14 | 15 | } 16 | 17 | void Plotable::setAxesViewportTransform(std::shared_ptr newAxesViewportTransform) { 18 | this->axesViewportTransform = std::move(newAxesViewportTransform); 19 | } 20 | 21 | void Plotable::setPlotableId(int newPlotableId) { 22 | plotableId = newPlotableId; 23 | } 24 | 25 | std::pair, std::vector> Plotable::genIndicesSortedVector(std::vector* unsortedVector) { 26 | // Create vector of indices to use for sorting other vectors 27 | std::vector indicesForSorting(unsortedVector->size()); 28 | std::iota(indicesForSorting.begin(), indicesForSorting.end(), 0); 29 | // Sort by values in unsorted vector 30 | std::stable_sort(indicesForSorting.begin(), indicesForSorting.end(), 31 | [&](unsigned int A, unsigned int B) -> bool { 32 | return (*unsortedVector)[A] < (*unsortedVector)[B]; 33 | }); 34 | 35 | // Create a new set of indices for the sorted data, that corresponds to the original order of the data 36 | std::vector finalIndices(indicesForSorting.size()); 37 | for(unsigned int i=0; i < indicesForSorting.size(); i++) { 38 | unsigned int newInd = indicesForSorting[i]; 39 | finalIndices[newInd] = i; 40 | } 41 | 42 | return std::pair, std::vector>(indicesForSorting, finalIndices); 43 | } 44 | 45 | std::vector Plotable::sortVectorByIndices(std::vector* unsortedVector, std::vector indices) { 46 | // Sort vector by indices vector 47 | std::vector sortedVector; 48 | sortedVector.reserve(unsortedVector->size()); 49 | for(unsigned int i=0; i < indices.size(); i++) { 50 | sortedVector.push_back((*unsortedVector)[indices[i]]); 51 | } 52 | 53 | return sortedVector; 54 | } 55 | 56 | void Plotable::setLogModes(bool newLogX, bool newLogY) { 57 | logX = newLogX; 58 | logY = newLogY; 59 | } 60 | 61 | void Plotable::setLogXBase(unsigned int newLogXBase) { 62 | logXBase = newLogXBase; 63 | } 64 | 65 | void Plotable::setLogYBase(unsigned int newLogYBase) { 66 | logYBase = newLogYBase; 67 | } 68 | 69 | void Plotable::setLabel(std::string newLabel) { 70 | label = std::move(newLabel); 71 | } 72 | 73 | std::string Plotable::getLabel() { 74 | return label; 75 | } 76 | 77 | 78 | } -------------------------------------------------------------------------------- /src/axes/Plotable.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by tbatt on 24/06/2020. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_PLOTABLE_H 6 | #define OPENGLPLOTLIVE_PROJ_PLOTABLE_H 7 | 8 | // Standard Includes 9 | #include 10 | 11 | // Project Includes 12 | #include "../rendering/ConstantXYDrawable.h" 13 | 14 | 15 | namespace GLPL { 16 | class Plotable : public ConstantXYDrawable { 17 | public: 18 | // Constructor 19 | Plotable(std::shared_ptr parentDimensions); 20 | 21 | // Functions 22 | virtual std::vector getMinMax(bool onlyPositiveX = false, bool onlyPositiveY = false) = 0; 23 | void setAxesViewportTransform(std::shared_ptr newAxesViewportTransform); 24 | void setPlotableId(int newPlotableId); 25 | 26 | std::pair, std::vector> genIndicesSortedVector(std::vector* unsortedVector); 27 | std::vector sortVectorByIndices(std::vector* unsortedVector, std::vector indices); 28 | 29 | virtual std::tuple getClosestPoint(float xVal) = 0; 30 | virtual std::tuple getClosestPoint(float xVal, float xmin, float xmax, float ymin, float ymax) = 0; 31 | 32 | virtual void drawLegendEntry(glm::mat4 rectOverallTransform) = 0; 33 | 34 | void setLogModes(bool newLogX, bool newLogY); 35 | void setLogXBase(unsigned int newLogXBase); 36 | void setLogYBase(unsigned int newLogYBase); 37 | 38 | void setLabel(std::string newLabel); 39 | std::string getLabel(); 40 | 41 | protected: 42 | std::shared_ptr axesViewportTransform = std::make_shared(glm::mat4(1.0f)); 43 | std::string label = ""; 44 | int plotableId = -1; 45 | bool logX = false; 46 | bool logY = false; 47 | unsigned int logXBase = 10; 48 | unsigned int logYBase = 10; 49 | 50 | }; 51 | } 52 | 53 | 54 | #endif //OPENGLPLOTLIVE_PROJ_PLOTABLE_H 55 | -------------------------------------------------------------------------------- /src/axes/axes.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by tbatt on 19/04/2020. 3 | // 4 | 5 | // Standard Includes 6 | #include 7 | 8 | // Project Includes 9 | #include "axes.h" 10 | 11 | 12 | 13 | namespace GLPL { 14 | 15 | Axes::Axes(float x, float y, float width, float height, 16 | std::shared_ptr parentDimensions) : 17 | ConstantXYDrawable(x, y, width, height, CONSTANT_SCALE, CONSTANT_SCALE, std::move(parentDimensions)) { 18 | 19 | // Set Bounding Box Color 20 | boundingBoxColor = glm::vec4(0.0f, 1.0f, 0.0f, 1.0f); 21 | // Set Not Hoverable 22 | setHoverable(false); 23 | 24 | // Add axes area 25 | Axes::createAxesArea(); 26 | 27 | } 28 | 29 | void Axes::createAxesArea() { 30 | // Create Parent Dimensions 31 | std::shared_ptr newParentPointers = IDrawable::createParentDimensions(); 32 | // Register Child 33 | std::shared_ptr axesAreaObj = std::make_shared(0.13, 0.1, 0.8, 0.75, newParentPointers); 34 | std::shared_ptr axesAreaPt = std::dynamic_pointer_cast(axesAreaObj); 35 | Axes::registerChild(axesAreaObj); 36 | // Store Text String 37 | this->axesArea = axesAreaPt; 38 | } 39 | 40 | void Axes::Draw() { 41 | // Sort children if required 42 | IDrawable::sortChildren(); 43 | // Draw children 44 | for(auto & i : children) { 45 | i->Draw(); 46 | } 47 | } 48 | 49 | std::string Axes::getID() { 50 | return "Axes:" + std::to_string(x) + ":" + std::to_string(y); 51 | } 52 | 53 | void Axes::setAxesBoxOn(bool axesBoxOnBool) { 54 | axesArea->setAxesBoxOn(axesBoxOnBool); 55 | } 56 | 57 | void Axes::setLogScale(bool logOn, unsigned int newLogBase, LogAxes logAxes) { 58 | axesArea->setLogScale(logOn, newLogBase, logAxes); 59 | } 60 | 61 | void Axes::setButtonState(const std::string& buttonName, bool activeState) { 62 | axesArea->setButtonState(buttonName, activeState); 63 | } 64 | 65 | void Axes::setXAxesLimits(float newXMin, float newXMax) { 66 | axesArea->setXAxesLimits(newXMin, newXMax); 67 | } 68 | 69 | void Axes::setYAxesLimits(float newYMin, float newYMax) { 70 | axesArea->setYAxesLimits(newYMin, newYMax); 71 | } 72 | 73 | void Axes::setAxesLimits(float newXMin, float newXMax, float newYMin, float newYMax) { 74 | axesArea->setAxesLimits(newXMin, newXMax, newYMin, newYMax); 75 | } 76 | 77 | void Axes::showLegend(bool legendVisibility) { 78 | axesArea->showLegend(legendVisibility); 79 | } 80 | 81 | void Axes::setLegendAttachLocation(AttachLocation newAttachLocation) { 82 | axesArea->setLegendAttachLocation(newAttachLocation); 83 | } 84 | 85 | std::vector Axes::getAxesInfo() { 86 | return std::vector {getX(), getY(), getWidth(), getHeight()}; 87 | } 88 | 89 | } -------------------------------------------------------------------------------- /src/axes/axes.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by tbatt on 19/04/2020. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_AXES_H 6 | #define OPENGLPLOTLIVE_PROJ_AXES_H 7 | 8 | // Project Includes 9 | #include "../texts/TextString.h" 10 | #include "AxesArea.h" 11 | #include "../rendering/ConstantXYDrawable.h" 12 | #include "AxesLineTicks.h" 13 | #include "../scatterPlot/IScatterPlot.h" 14 | 15 | 16 | namespace GLPL { 17 | 18 | enum AxesType { 19 | AXES_2D, 20 | AXES_3D 21 | }; 22 | 23 | class Axes : public ConstantXYDrawable { 24 | public: 25 | // Constructor 26 | Axes(float x, float y, float width, float height, std::shared_ptr parentDimensions); 27 | 28 | // Axes 29 | void setAxesBoxOn(bool axesBoxOnBool); 30 | void setLogScale(bool logOn, unsigned int newLogBase, LogAxes logAxes); 31 | void setXAxesLimits(float newXMin, float newXMax); 32 | void setYAxesLimits(float newYMin, float newYMax); 33 | void setAxesLimits(float newXMin, float newXMax, float newYMin, float newYMax); 34 | void showLegend(bool legendVisibility); 35 | void setLegendAttachLocation(AttachLocation newAttachLocation); 36 | 37 | // PressButton 38 | void setButtonState(const std::string& buttonName, bool activeState); 39 | 40 | void Draw(); 41 | std::string getID(); 42 | std::vector getAxesInfo(); 43 | 44 | protected: 45 | // Functions 46 | void createAxesArea(); 47 | 48 | // Data 49 | // Axes Area 50 | std::shared_ptr axesArea; 51 | }; 52 | } 53 | 54 | 55 | #endif //OPENGLPLOTLIVE_PROJ_AXES_H 56 | -------------------------------------------------------------------------------- /src/axes/axes2D.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 30/1/21. 3 | // 4 | 5 | #include "axes2D.h" 6 | 7 | 8 | namespace GLPL { 9 | 10 | 11 | Axes2D::Axes2D(float x, float y, float width, float height, std::shared_ptr parentDimensions) 12 | : Axes(x, y, width, height, parentDimensions) { 13 | 14 | // Create Axes 15 | Axes2D::createAxesLines(); 16 | 17 | } 18 | 19 | void Axes2D::createAxesLines() { 20 | // Get parent pointers 21 | std::shared_ptr ourParentDimensions = createParentDimensions(); 22 | // Create axes 23 | axesArea->addAxesLine("x", X_AXES_CENTRE); 24 | axesArea->addAxesLine("y", Y_AXES_CENTRE); 25 | } 26 | 27 | void Axes2D::addText(const char* textString, float x, float y, float fontSize, AttachLocation attachLocation) { 28 | // Create Parent Dimensions 29 | std::shared_ptr newParentPointers = IDrawable::createParentDimensions(); 30 | // Register Child 31 | std::shared_ptr textStringObj = std::make_shared(textString, x, y, fontSize, newParentPointers); 32 | std::shared_ptr textStringPt = std::dynamic_pointer_cast(textStringObj); 33 | // Set pin position 34 | textStringPt->setAttachLocation(attachLocation); 35 | // Register Child 36 | Axes::registerChild(textStringObj); 37 | // Store Text String 38 | textStringMap.insert(std::pair>(textStringCount, textStringPt)); 39 | textStringCount += 1; 40 | } 41 | 42 | std::shared_ptr Axes2D::getText(unsigned int textStringId) { 43 | if (textStringMap.count(textStringId) > 0) { 44 | return textStringMap.at(textStringId); 45 | } else { 46 | std::cout << "TextString " << textStringId << " does not exist!" << std::endl; 47 | return nullptr; 48 | } 49 | } 50 | 51 | void Axes2D::removeTextString(unsigned int textStringId) { 52 | if (textStringMap.count(textStringId) > 0) { 53 | std::shared_ptr textString2Remove = textStringMap.at(textStringId); 54 | // Remove child 55 | IDrawable::removeChild(textString2Remove); 56 | // Remove axes 57 | textStringMap.erase(textStringId); 58 | } else { 59 | std::cout << "Cannot remove TextString " << textStringId << ", TextString does not exist!" << std::endl; 60 | } 61 | } 62 | 63 | std::shared_ptr Axes2D::addLine(std::vector *dataPtX, std::vector *dataPtY, LineType lineType, glm::vec3 colour, 64 | float opacityRatio, std::string label) { 65 | return axesArea->addLine(dataPtX, dataPtY, lineType, colour, opacityRatio, std::move(label)); 66 | } 67 | 68 | std::shared_ptr Axes2D::addScatterPlot(std::vector *dataPtX, std::vector *dataPtY, 69 | glm::vec3 colour, float opacityRatio, MarkerType markerType, std::string label) { 70 | return axesArea->addScatterPlot(dataPtX, dataPtY, colour, opacityRatio, markerType, std::move(label)); 71 | } 72 | 73 | void Axes2D::setTitle(std::string newTitle) { 74 | axesArea->setText("axes-title", std::move(newTitle)); 75 | } 76 | 77 | void Axes2D::setXLabel(std::string newXLabel) { 78 | axesArea->setText("x-label", std::move(newXLabel)); 79 | } 80 | 81 | void Axes2D::setYLabel(std::string newYLabel) { 82 | axesArea->setText("y-label", std::move(newYLabel)); 83 | } 84 | 85 | void Axes2D::setXLabelRotation(TextRotation newTextRotation) { 86 | axesArea->setTextRotation("x-label", newTextRotation); 87 | } 88 | 89 | void Axes2D::setYLabelRotation(TextRotation newTextRotation) { 90 | axesArea->setTextRotation("y-label", newTextRotation); 91 | } 92 | 93 | 94 | } -------------------------------------------------------------------------------- /src/axes/axes2D.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 30/1/21. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_AXES2D_H 6 | #define OPENGLPLOTLIVE_PROJ_AXES2D_H 7 | 8 | // Project Includes 9 | #include "axes.h" 10 | 11 | 12 | namespace GLPL { 13 | 14 | 15 | class Axes2D : public Axes { 16 | public: 17 | // Constructor 18 | Axes2D(float x, float y, float width, float height, std::shared_ptr parentDimensions); 19 | 20 | // Functions 21 | // Text 22 | void addText(const char* textString, float x, float y, float fontSize, AttachLocation attachLocation=BOTTOM_LEFT); 23 | std::shared_ptr getText(unsigned int textStringId); 24 | void removeTextString(unsigned int textStringId); 25 | // Line 26 | std::shared_ptr addLine(std::vector *dataPtX, std::vector *dataPtY, LineType lineType = SINGLE_LINE, 27 | glm::vec3 colour = LC_WHITE, float opacityRatio=1.0, std::string label = ""); 28 | // Scatter Plots 29 | std::shared_ptr addScatterPlot(std::vector *dataPtX, std::vector *dataPtY, 30 | glm::vec3 colour = LC_WHITE, float opacityRatio=1.0, MarkerType markerType=MARKER_CIRCLE, std::string label = ""); 31 | 32 | // Labels 33 | void setTitle(std::string newTitle); 34 | void setXLabel(std::string newXLabel); 35 | void setYLabel(std::string newYLabel); 36 | void setXLabelRotation(TextRotation newTextRotation); 37 | void setYLabelRotation(TextRotation newTextRotation); 38 | 39 | private: 40 | // Functions 41 | void createAxesLines(); 42 | 43 | // Data 44 | // Text String 45 | unsigned int textStringCount = 0; 46 | std::unordered_map> textStringMap; 47 | 48 | }; 49 | 50 | } 51 | 52 | 53 | #endif //OPENGLPLOTLIVE_PROJ_AXES2D_H 54 | -------------------------------------------------------------------------------- /src/axes/axes3D.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 30/1/21. 3 | // 4 | 5 | #include "axes3D.h" 6 | 7 | 8 | namespace GLPL { 9 | 10 | 11 | Axes3D::Axes3D(float x, float y, float width, float height, std::shared_ptr parentDimensions) 12 | : Axes(x, y, width, height, parentDimensions) { 13 | 14 | // Create Axes 15 | Axes3D::createAxesLines(); 16 | 17 | } 18 | 19 | void Axes3D::createAxesLines() { 20 | // Get parent pointers 21 | std::shared_ptr ourParentDimensions = createParentDimensions(); 22 | // Create axes 23 | axesArea->addAxesLine("x", X_AXES_CENTRE); 24 | axesArea->addAxesLine("y", Y_AXES_CENTRE); 25 | } 26 | 27 | void Axes3D::addText(const char* textString, float x, float y, float fontSize, AttachLocation attachLocation) { 28 | // Create Parent Dimensions 29 | std::shared_ptr newParentPointers = IDrawable::createParentDimensions(); 30 | // Create Text String 31 | std::shared_ptr textStringObj = std::make_shared(textString, x, y, fontSize, newParentPointers); 32 | std::shared_ptr textStringPt = std::dynamic_pointer_cast(textStringObj); 33 | // Set pin position 34 | textStringPt->setAttachLocation(attachLocation); 35 | // Register Child 36 | Axes::registerChild(textStringObj); 37 | // Store Text String 38 | textStringMap.insert(std::pair>(textStringCount, textStringPt)); 39 | textStringCount += 1; 40 | } 41 | 42 | std::shared_ptr Axes3D::getText(unsigned int textStringId) { 43 | if (textStringMap.count(textStringId) > 0) { 44 | return textStringMap.at(textStringId); 45 | } else { 46 | std::cout << "TextString " << textStringId << " does not exist!" << std::endl; 47 | return nullptr; 48 | } 49 | } 50 | 51 | void Axes3D::removeTextString(unsigned int textStringId) { 52 | if (textStringMap.count(textStringId) > 0) { 53 | std::shared_ptr textString2Remove = textStringMap.at(textStringId); 54 | // Remove child 55 | IDrawable::removeChild(textString2Remove); 56 | // Remove axes 57 | textStringMap.erase(textStringId); 58 | } else { 59 | std::cout << "Cannot remove TextString " << textStringId << ", TextString does not exist!" << std::endl; 60 | } 61 | } 62 | 63 | std::shared_ptr Axes3D::addLine(std::vector *dataPtX, std::vector *dataPtY, LineType lineType, glm::vec3 colour, 64 | float opacityRatio, std::string label) { 65 | return axesArea->addLine(dataPtX, dataPtY, lineType, colour, opacityRatio, std::move(label)); 66 | } 67 | 68 | std::shared_ptr Axes3D::addScatterPlot(std::vector *dataPtX, std::vector *dataPtY, 69 | glm::vec3 colour, float opacityRatio, MarkerType markerType, std::string label) { 70 | return axesArea->addScatterPlot(dataPtX, dataPtY, colour, opacityRatio, markerType, std::move(label)); 71 | } 72 | 73 | void Axes3D::setTitle(std::string newTitle) { 74 | axesArea->setText("axes-title", std::move(newTitle)); 75 | } 76 | 77 | void Axes3D::setXLabel(std::string newXLabel) { 78 | axesArea->setText("x-label", std::move(newXLabel)); 79 | } 80 | 81 | void Axes3D::setYLabel(std::string newYLabel) { 82 | axesArea->setText("y-label", std::move(newYLabel)); 83 | } 84 | 85 | void Axes3D::setXLabelRotation(TextRotation newTextRotation) { 86 | axesArea->setTextRotation("x-label", newTextRotation); 87 | } 88 | 89 | void Axes3D::setYLabelRotation(TextRotation newTextRotation) { 90 | axesArea->setTextRotation("y-label", newTextRotation); 91 | } 92 | 93 | 94 | } -------------------------------------------------------------------------------- /src/axes/axes3D.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 30/1/21. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_AXES3D_H 6 | #define OPENGLPLOTLIVE_PROJ_AXES3D_H 7 | 8 | // Project Includes 9 | #include "axes.h" 10 | 11 | 12 | namespace GLPL { 13 | 14 | 15 | class Axes3D : public Axes { 16 | public: 17 | // Constructor 18 | Axes3D(float x, float y, float width, float height, std::shared_ptr parentDimensions); 19 | 20 | // Functions 21 | // Text 22 | void addText(const char* textString, float x, float y, float fontSize, AttachLocation attachLocation=BOTTOM_LEFT); 23 | std::shared_ptr getText(unsigned int textStringId); 24 | void removeTextString(unsigned int textStringId); 25 | // Line 26 | std::shared_ptr addLine(std::vector *dataPtX, std::vector *dataPtY, LineType lineType = SINGLE_LINE, 27 | glm::vec3 colour = LC_WHITE, float opacityRatio=1.0, std::string label = ""); 28 | // Scatter Plots 29 | std::shared_ptr addScatterPlot(std::vector *dataPtX, std::vector *dataPtY, 30 | glm::vec3 colour = LC_WHITE, float opacityRatio=1.0, MarkerType markerType=MARKER_CIRCLE, std::string label = ""); 31 | 32 | // Labels 33 | void setTitle(std::string newTitle); 34 | void setXLabel(std::string newXLabel); 35 | void setYLabel(std::string newYLabel); 36 | void setXLabelRotation(TextRotation newTextRotation); 37 | void setYLabelRotation(TextRotation newTextRotation); 38 | 39 | private: 40 | // Functions 41 | void createAxesLines(); 42 | 43 | // Data 44 | // Text String 45 | unsigned int textStringCount = 0; 46 | std::unordered_map> textStringMap; 47 | 48 | }; 49 | 50 | } 51 | 52 | 53 | #endif //OPENGLPLOTLIVE_PROJ_AXES3D_H 54 | -------------------------------------------------------------------------------- /src/dataTypes/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Add sources 2 | file(GLOB CPP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) 3 | file(GLOB H_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h) 4 | target_sources(${PROJECT_NAME} PRIVATE ${CPP_FILES}) 5 | target_sources(${PROJECT_NAME} PUBLIC "${H_FILES}") 6 | 7 | # Setup include directories 8 | target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/dataTypes) -------------------------------------------------------------------------------- /src/dataTypes/dataTypes.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 29/3/20. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_DATATYPES_H 6 | #define OPENGLPLOTLIVE_DATATYPES_H 7 | 8 | // GLAD - Multi Language GL Loader-Generator 9 | #include 10 | 11 | 12 | namespace GLPL { 13 | 14 | struct pt2D { 15 | GLfloat x; 16 | GLfloat y; 17 | }; 18 | 19 | } 20 | 21 | #endif //OPENGLPLOTLIVE_DATATYPES_H 22 | -------------------------------------------------------------------------------- /src/interaction/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Add sources 2 | file(GLOB CPP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) 3 | file(GLOB H_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h) 4 | target_sources(${PROJECT_NAME} PRIVATE ${CPP_FILES}) 5 | target_sources(${PROJECT_NAME} PUBLIC "${H_FILES}") 6 | 7 | # Setup include directories 8 | target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/interaction) -------------------------------------------------------------------------------- /src/interaction/IClickable.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-laptop-dell on 12/12/20. 3 | // 4 | 5 | #include "IClickable.h" 6 | 7 | 8 | namespace GLPL { 9 | 10 | IClickable::IClickable() { 11 | 12 | } 13 | 14 | void IClickable::setActive(bool activeState) { 15 | activated = activeState; 16 | } 17 | 18 | bool IClickable::isActive() { 19 | return activated; 20 | } 21 | 22 | void IClickable::toggleActive() { 23 | activated = !activated; 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /src/interaction/IClickable.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-laptop-dell on 12/12/20. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_ICLICKABLE_H 6 | #define OPENGLPLOTLIVE_PROJ_ICLICKABLE_H 7 | 8 | namespace GLPL { 9 | 10 | class IClickable { 11 | public: 12 | // Constructor 13 | IClickable(); 14 | 15 | // Functions 16 | virtual void onLeftClick() = 0; 17 | void setActive(bool activeState); 18 | bool isActive(); 19 | void toggleActive(); 20 | 21 | protected: 22 | bool activated = false; 23 | 24 | }; 25 | 26 | } 27 | 28 | #endif //OPENGLPLOTLIVE_PROJ_ICLICKABLE_H 29 | -------------------------------------------------------------------------------- /src/interaction/PressButton.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-laptop-dell on 12/12/20. 3 | // 4 | 5 | #include "PressButton.h" 6 | 7 | #include 8 | 9 | namespace GLPL { 10 | 11 | PressButton::PressButton(std::string newButtonName, float x, float y, float width, float height, 12 | std::shared_ptr parentDimensions, 13 | std::string tooltipText) : 14 | ConstantXYDrawable(x, y, width, height, CONSTANT_SCALE, CONSTANT_SCALE, std::move(parentDimensions)) { 15 | // Set button name 16 | buttonName = std::move(newButtonName); 17 | 18 | // Set Bounding Box Color 19 | boundingBoxColor = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); 20 | 21 | // Setup Shading Buffers 22 | PressButton::setupShadingBuffers(); 23 | 24 | // Create tooltip 25 | std::shared_ptr buttonParentDimensions = createParentDimensions(); 26 | tooltipPt = std::make_shared(tooltipText, 0.5f, -0.2f, 10.0f, buttonParentDimensions); 27 | tooltipPt->setAttachLocation(CENTRE_TOP); 28 | tooltipPt->setFontSize(8.0); 29 | tooltipPt->setTextColor(glm::vec3(0.0f, 0.0f, 0.0f)); 30 | PressButton::registerChild(tooltipPt); 31 | } 32 | 33 | void PressButton::Draw() { 34 | // Draw button shading 35 | PressButton::drawButtonShading(); 36 | 37 | // Draw button outline 38 | PressButton::drawButtonOutline(); 39 | 40 | // Draw tooltip 41 | PressButton::drawTooltip(); 42 | } 43 | 44 | void PressButton::onLeftClick() { 45 | toggleActive(); 46 | } 47 | 48 | std::string PressButton::getID() { 49 | return "PressButton:" + buttonName + ":" + std::to_string(x) + ":" + std::to_string(y); 50 | } 51 | 52 | void PressButton::setHovered(bool newHovered) { 53 | IDrawable::setHovered(newHovered); 54 | 55 | if (newHovered) { 56 | hoverBeginTime = (float)glfwGetTime(); 57 | } else { 58 | hoverBeginTime = -1; 59 | } 60 | } 61 | 62 | void PressButton::setupShadingBuffers() { 63 | unsigned int indicesDataSizeBytes = internalIndices.size()*sizeof(internalIndices[0]); 64 | 65 | glGenBuffers(1, &EBO); 66 | 67 | // Setup Buffers 68 | // Bind to existing VAO 69 | glBindVertexArray(VAO); 70 | // EBO - Send Indices 71 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); 72 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesDataSizeBytes, &internalIndices[0], GL_STATIC_DRAW); 73 | 74 | glBindVertexArray(0); // Unbind VAO 75 | } 76 | 77 | void PressButton::drawButtonShading() { 78 | // Draws the data currently stored in the shaded line corresponding to the given VAO 79 | // The VAO is bound to the EBO from earlier 80 | // Select colour 81 | glm::vec4 inColor; 82 | if (selected && !isActive()) { 83 | inColor = buttonInactiveShadingHoverColor; 84 | } else if (!selected && !isActive()) { 85 | inColor = buttonInactiveShadingColor; 86 | } else if (selected && isActive()) { 87 | inColor = buttonActiveShadingHoverColor; 88 | } else if (!selected && isActive()) { 89 | inColor = buttonActiveShadingColor; 90 | } 91 | 92 | // Select Shader 93 | std::shared_ptr shader = shaderSetPt->getPlot2dShader(); 94 | shader->Use(); 95 | 96 | glUniformMatrix4fv(glGetUniformLocation(shader->Program, "transformViewport"), 1, GL_FALSE, glm::value_ptr(overallTransform)); 97 | GLfloat zDepthVal = getZDepthValue(); 98 | glUniform4fv(glGetUniformLocation(shader->Program, "inColor"), 1, glm::value_ptr(inColor)); 99 | glUniform1f(glGetUniformLocation(shader->Program, "z"), zDepthVal); 100 | glBindVertexArray(VAO); 101 | glDrawElements(GL_TRIANGLES, internalIndices.size(), GL_UNSIGNED_INT, nullptr); 102 | glBindVertexArray(0); 103 | 104 | } 105 | 106 | void PressButton::drawButtonOutline() { 107 | // Select colour 108 | glm::vec4 inColor; 109 | if (isHovered() && !isActive()) { 110 | inColor = buttonInactiveOutlineHoverColor; 111 | } else if (!isHovered() && !isActive()) { 112 | inColor = buttonInactiveOutlineColor; 113 | } else if (isHovered() && isActive()) { 114 | inColor = buttonActiveOutlineHoverColor; 115 | } else if (!isHovered() && isActive()) { 116 | inColor = buttonActiveOutlineColor; 117 | } 118 | 119 | // Select shader 120 | std::shared_ptr shader = shaderSetPt->getPlot2dShader(); 121 | shader->Use(); 122 | 123 | glUniformMatrix4fv(glGetUniformLocation(shader->Program,"transformViewport"), 1, GL_FALSE, glm::value_ptr(overallTransform)); 124 | glUniform4fv(glGetUniformLocation(shader->Program,"inColor"),1,glm::value_ptr(inColor)); 125 | glBindVertexArray(VAO); 126 | glDrawArrays(GL_LINE_LOOP,0,4); 127 | glBindVertexArray(0); 128 | } 129 | 130 | void PressButton::drawTooltip() { 131 | auto currTime = (float)glfwGetTime(); 132 | if (tooltipPt->getTextString().size() > 0) { 133 | if (hoverBeginTime > 0 && currTime - hoverBeginTime > tooltipHoverTimeS) { 134 | tooltipPt->Draw(); 135 | } 136 | } 137 | } 138 | 139 | } -------------------------------------------------------------------------------- /src/interaction/PressButton.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-laptop-dell on 12/12/20. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_PRESSBUTTON_H 6 | #define OPENGLPLOTLIVE_PROJ_PRESSBUTTON_H 7 | 8 | #include "../rendering/IDrawable.h" 9 | #include "../rendering/ConstantXYDrawable.h" 10 | #include "IClickable.h" 11 | #include "Tooltip.h" 12 | 13 | 14 | namespace GLPL { 15 | 16 | class PressButton : public ConstantXYDrawable { 17 | public: 18 | // Constructor 19 | PressButton(std::string newButtonName, float x, float y, float width, float height, 20 | std::shared_ptr parentDimensions, 21 | std::string tooltipText = ""); 22 | 23 | // Functions 24 | void Draw(); 25 | void onLeftClick() override; 26 | std::string getID(); 27 | void setHovered(bool newHovered); 28 | 29 | 30 | private: 31 | std::string buttonName; 32 | 33 | // Shading 34 | GLuint EBO; 35 | std::vector internalIndices = {0, 1, 3, 2, 3, 1}; 36 | 37 | // Functions 38 | void setupShadingBuffers(); 39 | void drawButtonShading(); 40 | void drawButtonOutline(); 41 | void drawTooltip(); 42 | 43 | // PressButton Appearance 44 | glm::vec4 buttonInactiveOutlineColor = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); 45 | glm::vec4 buttonInactiveOutlineHoverColor = glm::vec4(0.0f, 1.0f, 1.0f, 1.0f); 46 | glm::vec4 buttonInactiveShadingColor = glm::vec4(0.6f, 0.6f, 0.6f, 1.0f); 47 | glm::vec4 buttonInactiveShadingHoverColor = glm::vec4(0.8f, 0.8f, 0.8f, 1.0f); 48 | glm::vec4 buttonActiveOutlineColor = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); 49 | glm::vec4 buttonActiveOutlineHoverColor = glm::vec4(0.0f, 1.0f, 1.0f, 1.0f); 50 | glm::vec4 buttonActiveShadingColor = glm::vec4(0.3f, 0.3f, 0.3f, 1.0f); 51 | glm::vec4 buttonActiveShadingHoverColor = glm::vec4(0.4f, 0.4f, 0.4f, 1.0f); 52 | 53 | // Tooltip 54 | float tooltipHoverTimeS = 0.5; // The hover time until the tooltip is shown, in seconds 55 | float hoverBeginTime = -1; // The time at which the button was first hovered for the current hover period 56 | std::shared_ptr tooltipPt = nullptr; 57 | 58 | }; 59 | 60 | } 61 | 62 | 63 | #endif //OPENGLPLOTLIVE_PROJ_PRESSBUTTON_H 64 | -------------------------------------------------------------------------------- /src/interaction/PressButtonWithImage.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-laptop-dell on 23/12/20. 3 | // 4 | 5 | #include "PressButtonWithImage.h" 6 | 7 | #include 8 | 9 | 10 | namespace GLPL { 11 | 12 | 13 | PressButtonWithImage::PressButtonWithImage(std::string newButtonName, float x, float y, float width, float height, 14 | std::string newTextureName, 15 | std::shared_ptr parentDimensions, 16 | std::string tooltipText) : PressButton( 17 | std::move(newButtonName), x, y, width, height, std::move(parentDimensions), std::move(tooltipText)) { 18 | 19 | textureName = std::move(newTextureName); 20 | textureManager = shaderSetPt->getTextureManager(); 21 | 22 | createAndSetupLogoBuffers(); 23 | } 24 | 25 | void PressButtonWithImage::Draw() { 26 | PressButton::Draw(); 27 | 28 | // Bind Texture 29 | glBindTexture(GL_TEXTURE_2D, textureManager->getTextureId(textureName)); 30 | 31 | // Use texture shader 32 | std::shared_ptr shader = shaderSetPt->getTextureShader(); 33 | shader->Use(); 34 | 35 | // Setup uniforms 36 | glUniformMatrix4fv(glGetUniformLocation(shader->Program,"transformViewport"), 1, GL_FALSE, glm::value_ptr(overallTransform)); 37 | glActiveTexture(GL_TEXTURE0); 38 | glBindVertexArray(logoVAO); 39 | 40 | // Draw logo 41 | glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); 42 | 43 | // Unbind Arrays 44 | glBindVertexArray(0); 45 | glBindTexture(GL_TEXTURE_2D, 0); 46 | } 47 | 48 | std::string PressButtonWithImage::getID() { 49 | return PressButton::getID(); 50 | } 51 | 52 | void PressButtonWithImage::createAndSetupLogoBuffers() { 53 | // Create Buffers 54 | glGenVertexArrays(1, &logoVAO); 55 | glGenBuffers(1, &logoVBO); 56 | glGenBuffers(1, &logoEBO); 57 | 58 | // Setup Buffers 59 | glBindVertexArray(logoVAO); 60 | glBindBuffer(GL_ARRAY_BUFFER, logoVBO); 61 | glBufferData(GL_ARRAY_BUFFER, logoVerts.size()*sizeof(logoVerts[0]), &logoVerts[0], GL_STATIC_DRAW); 62 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, logoEBO); 63 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, logoIndices.size()*sizeof(logoIndices[0]), &logoIndices[0], GL_STATIC_DRAW); 64 | 65 | // Position Attributes 66 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4*sizeof(float), (void*)0); 67 | glEnableVertexAttribArray(0); 68 | // Texture Coord Attribute 69 | glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4*sizeof(float), (void*)(2*sizeof(float))); 70 | glEnableVertexAttribArray(1); 71 | } 72 | } -------------------------------------------------------------------------------- /src/interaction/PressButtonWithImage.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-laptop-dell on 23/12/20. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_PRESSBUTTONWITHIMAGE_H 6 | #define OPENGLPLOTLIVE_PROJ_PRESSBUTTONWITHIMAGE_H 7 | 8 | // Project Includes 9 | #include "PressButton.h" 10 | #include "../textures/TextureManager.h" 11 | 12 | 13 | namespace GLPL { 14 | 15 | class PressButtonWithImage : public PressButton { 16 | public: 17 | // Constructor 18 | PressButtonWithImage(std::string newButtonName, float x, float y, float width, float height, 19 | std::string textureName, 20 | std::shared_ptr parentDimensions, 21 | std::string tooltipText = ""); 22 | 23 | // Functions 24 | void Draw() override; 25 | std::string getID() override; 26 | 27 | private: 28 | // Buffers 29 | unsigned int logoVAO, logoVBO, logoEBO; 30 | 31 | // Image // Positions // Texture Coords 32 | std::vector logoVerts = { -1.0f, -1.0f, 0.0f, 0.0f, // bottom left 33 | 1.0f, -1.0f, 1.0f, 0.0f, // bottom right 34 | 1.0f, 1.0f, 1.0f, 1.0f, // top right 35 | -1.0f, 1.0f, 0.0f, 1.0f}; // top left 36 | std::vector logoIndices = {0, 1, 3, // First triangle 37 | 1, 2, 3}; // Second triangle 38 | std::string textureName; 39 | 40 | // Texture Manager 41 | std::shared_ptr textureManager; 42 | 43 | // Functions 44 | void createAndSetupLogoBuffers(); 45 | 46 | }; 47 | 48 | } 49 | 50 | 51 | #endif //OPENGLPLOTLIVE_PROJ_PRESSBUTTONWITHIMAGE_H 52 | -------------------------------------------------------------------------------- /src/interaction/Tooltip.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 3/1/21. 3 | // 4 | 5 | #include "Tooltip.h" 6 | 7 | 8 | namespace GLPL { 9 | 10 | 11 | Tooltip::Tooltip(const std::string &textString, float x, float y, float fontSize, 12 | std::shared_ptr parentDimensions) : TextString(textString, x, y, fontSize, 13 | std::move(parentDimensions)) { 14 | 15 | // Setup background buffers 16 | Tooltip::setupBackgroundBuffers(); 17 | 18 | // Setup not hoverable or mouse overable 19 | setCanMouseOver(false); 20 | setHoverable(false); 21 | } 22 | 23 | void Tooltip::Draw() { 24 | // Draw background first 25 | Tooltip::drawBackground(); 26 | 27 | // Draw text 28 | TextString::Draw(); 29 | 30 | } 31 | 32 | void Tooltip::setupBackgroundBuffers() { 33 | unsigned int indicesDataSizeBytes = internalIndices.size()*sizeof(internalIndices[0]); 34 | 35 | glGenBuffers(1, &EBO); 36 | 37 | // Setup Buffers 38 | // Bind to existing VAO 39 | glBindVertexArray(VAO); 40 | // EBO - Send Indices 41 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); 42 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesDataSizeBytes, &internalIndices[0], GL_STATIC_DRAW); 43 | 44 | glBindVertexArray(0); // Unbind VAO 45 | } 46 | 47 | void Tooltip::drawBackground() { 48 | // Draws the data currently stored in the shaded line corresponding to the given VAO 49 | // The VAO is bound to the EBO from earlier 50 | // Select Shader 51 | std::shared_ptr shader = shaderSetPt->getPlot2dShader(); 52 | shader->Use(); 53 | 54 | glUniformMatrix4fv(glGetUniformLocation(shader->Program, "transformViewport"), 1, GL_FALSE, glm::value_ptr(overallTransform)); 55 | GLfloat zDepthVal = getZDepthValue(); 56 | glUniform4fv(glGetUniformLocation(shader->Program, "inColor"), 1, glm::value_ptr(tooltipBackgroundColor)); 57 | glUniform1f(glGetUniformLocation(shader->Program, "z"), zDepthVal); 58 | glBindVertexArray(VAO); 59 | glDrawElements(GL_TRIANGLES, internalIndices.size(), GL_UNSIGNED_INT, nullptr); 60 | glBindVertexArray(0); 61 | } 62 | } -------------------------------------------------------------------------------- /src/interaction/Tooltip.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 3/1/21. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_TOOLTIP_H 6 | #define OPENGLPLOTLIVE_PROJ_TOOLTIP_H 7 | 8 | 9 | // Project Includes 10 | #include "../texts/TextString.h" 11 | 12 | 13 | namespace GLPL { 14 | 15 | 16 | class Tooltip : public TextString { 17 | public: 18 | // Constructor 19 | Tooltip(const std::string& textString, float x, float y, float fontSize, std::shared_ptr parentDimensions); 20 | 21 | // Functions 22 | void Draw(); 23 | 24 | private: 25 | // Shading 26 | GLuint EBO; 27 | std::vector internalIndices = {0, 1, 3, 2, 3, 1}; 28 | glm::vec4 tooltipBackgroundColor = glm::vec4(0.8f, 0.8f, 0.8f, 1.0f); 29 | 30 | // Functions 31 | void setupBackgroundBuffers(); 32 | void drawBackground(); 33 | 34 | }; 35 | } 36 | 37 | 38 | #endif //OPENGLPLOTLIVE_PROJ_TOOLTIP_H 39 | -------------------------------------------------------------------------------- /src/lines/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Add sources 2 | file(GLOB CPP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) 3 | file(GLOB H_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h) 4 | target_sources(${PROJECT_NAME} PRIVATE ${CPP_FILES}) 5 | target_sources(${PROJECT_NAME} PUBLIC "${H_FILES}") 6 | 7 | # Setup include directories 8 | target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/lines) -------------------------------------------------------------------------------- /src/lines/GLTypes.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by tbatt on 18/04/2020. 3 | // 4 | 5 | #ifndef IRACINGTRACEOVERLAY_PROJ_GLTYPES_H 6 | #define IRACINGTRACEOVERLAY_PROJ_GLTYPES_H 7 | 8 | // GLAD - Multi Language GL Loader-Generator 9 | #include 10 | 11 | // GLFW (Multi-platform library for OpenGL) 12 | #include 13 | 14 | 15 | namespace GLPL { 16 | // Template the vector type 17 | // Set mappings from Type T to GL Types 18 | template 19 | constexpr int getGLType(); 20 | 21 | template<> 22 | constexpr int getGLType() { return GL_INT; } 23 | 24 | template<> 25 | constexpr int getGLType() { return GL_FLOAT; } 26 | 27 | template<> 28 | constexpr int getGLType() { return GL_DOUBLE; } 29 | 30 | } 31 | 32 | #endif //IRACINGTRACEOVERLAY_PROJ_GLTYPES_H 33 | -------------------------------------------------------------------------------- /src/lines/ILine2D.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 30/6/20. 3 | // 4 | 5 | #include "ILine2D.h" 6 | 7 | 8 | namespace GLPL { 9 | 10 | ILine2D::ILine2D(std::shared_ptr parentDimensions) : Plotable(std::move(parentDimensions)) {}; 11 | 12 | void ILine2D::setLineColour(glm::vec3 lineColor) { 13 | this->colour = lineColor; 14 | } 15 | 16 | void ILine2D::setMode(GLenum newMode) { 17 | this->mode = newMode; 18 | } 19 | 20 | void ILine2D::setLineWidth(unsigned int newLineWidth) { 21 | this->lineWidth = newLineWidth; 22 | } 23 | 24 | glm::vec3 ILine2D::getColour() { 25 | return this->colour; 26 | } 27 | 28 | GLenum ILine2D::getMode() { 29 | return this->mode; 30 | } 31 | 32 | void ILine2D::setOpacityRatio(float newOpacityRatio) { 33 | this->opacityRatio = newOpacityRatio; 34 | } 35 | 36 | int GLPL::ILine2D::getHoverCursor() { 37 | return 0; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/lines/ILine2D.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 30/6/20. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_ILINE2D_H 6 | #define OPENGLPLOTLIVE_PROJ_ILINE2D_H 7 | 8 | // Project Includes 9 | #include "../axes/Plotable.h" 10 | #include "lineColours.h" 11 | #include "../util/util.h" 12 | 13 | 14 | namespace GLPL { 15 | class ILine2D : public Plotable { 16 | public: 17 | ILine2D(std::shared_ptr parentDimensions); 18 | 19 | void setLineColour(glm::vec3 lineColor); 20 | void setMode(GLenum newMode); 21 | void setLineWidth(unsigned int newLineWidth); 22 | glm::vec3 getColour(); 23 | GLenum getMode(); 24 | void setOpacityRatio(float newOpacityRatio); 25 | int getHoverCursor() override; 26 | 27 | virtual std::vector getMinMax(bool onlyPositiveX, bool onlyPositiveY) = 0; 28 | virtual void drawLegendEntry(glm::mat4 rectOverallTransform) = 0; 29 | 30 | 31 | protected: 32 | // Data 33 | unsigned int lineWidth = 1; 34 | glm::vec3 colour = LC_WHITE; 35 | GLenum mode; // Mode, line or points 36 | float opacityRatio = 1.0; 37 | }; 38 | } 39 | 40 | 41 | #endif //OPENGLPLOTLIVE_PROJ_ILINE2D_H 42 | -------------------------------------------------------------------------------- /src/lines/ILine2D_OLD.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 27/3/20. 3 | // 4 | 5 | #include "ILine2D_OLD.h" 6 | 7 | 8 | 9 | namespace GLPL { 10 | 11 | ILine2D_OLD::ILine2D_OLD() { 12 | 13 | } 14 | 15 | void ILine2D_OLD::createAndSetupBuffers(GLuint *VAOPt, GLuint *VBOPt, int dataSizeBytes, const void *dataAddress, 16 | int strideBytes, int glType) { 17 | /* Create Buffers */ 18 | glGenVertexArrays(1, VAOPt); 19 | glGenBuffers(1, VBOPt); 20 | 21 | /* Setup Buffers */ 22 | glBindVertexArray(*VAOPt); 23 | glBindBuffer(GL_ARRAY_BUFFER, *VBOPt); 24 | 25 | /* Copy data into buffer */ 26 | glBufferData(GL_ARRAY_BUFFER, dataSizeBytes, dataAddress, GL_DYNAMIC_DRAW); 27 | 28 | /* Position Attributes */ 29 | glEnableVertexAttribArray(0); 30 | glVertexAttribPointer(0, 2, glType, GL_FALSE, strideBytes, (GLvoid *) 0); 31 | 32 | glBindVertexArray(0); // Unbind VAO 33 | 34 | } 35 | 36 | void 37 | ILine2D_OLD::drawData(Shader shader, glm::mat4 axesLimitViewportTrans, GLuint *VAOPt, glm::vec3 colour, int nPts, 38 | GLenum mode) { 39 | // Draws the data currently stored in the line corresponding to the given VAO 40 | shader.Use(); 41 | glLineWidth(lineWidth); 42 | glUniformMatrix4fv(glGetUniformLocation(shader.Program, "transformViewport"), 1, GL_FALSE, 43 | glm::value_ptr(axesLimitViewportTrans)); 44 | glm::vec4 inColor = glm::vec4(colour, 1.0); 45 | glUniform4fv(glGetUniformLocation(shader.Program, "inColor"), 1, glm::value_ptr(inColor)); 46 | glBindVertexArray(*VAOPt); 47 | glDrawArrays(mode, 0, nPts); 48 | glBindVertexArray(0); 49 | glLineWidth(1); 50 | } 51 | 52 | void ILine2D_OLD::setLineColour(glm::vec3 lineColor) { 53 | this->colour = lineColor; 54 | } 55 | 56 | void ILine2D_OLD::setMode(GLenum newMode) { 57 | this->mode = newMode; 58 | } 59 | 60 | void ILine2D_OLD::setLineWidth(unsigned int newLineWidth) { 61 | this->lineWidth = newLineWidth; 62 | } 63 | 64 | glm::vec3 ILine2D_OLD::getColour() { 65 | return this->colour; 66 | } 67 | 68 | GLenum ILine2D_OLD::getMode() { 69 | return this->mode; 70 | } 71 | 72 | 73 | } -------------------------------------------------------------------------------- /src/lines/ILine2D_OLD.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 27/3/20. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_ILINE2D_H 6 | #define OPENGLPLOTLIVE_ILINE2D_H 7 | 8 | // GLM Mathematics 9 | #include 10 | #include 11 | #include 12 | 13 | // GLFW (Multi-platform library for OpenGL) 14 | #include 15 | 16 | // Project Includes 17 | #include "../rendering/shader.h" 18 | #include "lineColours.h" 19 | 20 | // Standard Includes 21 | #include 22 | 23 | 24 | namespace GLPL { 25 | class ILine2D_OLD { 26 | public: 27 | ILine2D_OLD(); 28 | 29 | void createAndSetupBuffers(GLuint *VAOPt, GLuint *VBOPt, int dataSizeBytes, const void *dataAddress, 30 | int strideBytes, int glType=GL_FLOAT); 31 | 32 | void drawData(Shader shader, glm::mat4 axesLimitViewportTrans, GLuint *VAOPt, glm::vec3 colour, int nPts, 33 | GLenum mode); 34 | void setLineColour(glm::vec3 lineColor); 35 | void setMode(GLenum newMode); 36 | void setLineWidth(unsigned int newLineWidth); 37 | glm::vec3 getColour(); 38 | GLenum getMode(); 39 | 40 | virtual void Draw(Shader shader, glm::mat4 axesLimitViewportTrans) = 0; 41 | 42 | virtual std::vector getMinMax() = 0; 43 | 44 | protected: 45 | /* Attributes */ 46 | unsigned int lineWidth = 1; 47 | glm::vec3 colour = LC_WHITE; 48 | GLenum mode; // Mode, line or points 49 | }; 50 | } 51 | 52 | 53 | #endif //OPENGLPLOTLIVE_ILINE2D_H 54 | -------------------------------------------------------------------------------- /src/lines/ISingleLine2D.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 27/3/20. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_ILINE2D2_H 6 | #define OPENGLPLOTLIVE_ILINE2D2_H 7 | 8 | // GLM Mathematics 9 | #include 10 | #include 11 | #include 12 | 13 | // GLFW (Multi-platform library for OpenGL) 14 | #include 15 | 16 | // Project Includes 17 | #include "../rendering/shader.h" 18 | #include "lineColours.h" 19 | #include "../axes/Plotable.h" 20 | #include "ILine2D.h" 21 | 22 | // Standard Includes 23 | #include 24 | 25 | 26 | namespace GLPL { 27 | class ISingleLine2D : public ILine2D { 28 | public: 29 | ISingleLine2D(std::shared_ptr parentDimensions); 30 | 31 | void createAndSetupBuffers(int dataSizeBytes, const void *dataAddress, 32 | int strideBytes, int glType=GL_FLOAT); 33 | void createAndSetupBuffers(int vertDataSizeBytes, int indicesDataSizeBytes, 34 | const void *vertDataAddress, const void *indicesDataAddress, 35 | int strideBytes, int glType=GL_FLOAT); 36 | 37 | void createAndSetupLegendBuffers(int dataSizeBytes, const void *dataAddress, 38 | int strideBytes, int glType=GL_FLOAT); 39 | 40 | void drawData(int nPts, bool selected); 41 | 42 | void drawLegendEntry(glm::mat4 rectOverallTransform); 43 | 44 | protected: 45 | // Line Buffers 46 | GLuint lineVAO, lineVBO, lineEBO; 47 | GLuint legendLineVAO, legendLineVBO; 48 | 49 | std::vector legendLineData = {-1.0f, 0.0f, 1.0f, 0.0f}; 50 | 51 | // Functions 52 | std::shared_ptr selectShader(); 53 | 54 | void drawLegendLine(glm::mat4 rectOverallTransform, bool selected); 55 | 56 | }; 57 | } 58 | 59 | 60 | #endif //OPENGLPLOTLIVE_ILINE2D2_H 61 | -------------------------------------------------------------------------------- /src/lines/Line2D2CircularVecs.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by tbatt on 11/04/2020. 3 | // 4 | 5 | #include "Line2D2CircularVecs.h" 6 | 7 | namespace GLPL { 8 | Line2D2CircularVecs::Line2D2CircularVecs(std::vector *dataPtX, std::vector *dataPtY, GLenum mode) { 9 | this->dataPtX = dataPtX; 10 | this->dataPtY = dataPtY; 11 | this->setMode(mode); 12 | 13 | /* Setup Buffers */ 14 | updateInternalData(0); 15 | int dataSizeBytes = internalData.size()*sizeof(internalData[0]); 16 | createAndSetupBuffers(&VAO, &VBO, dataSizeBytes, &internalData[0], 2*sizeof(internalData[0])); 17 | 18 | /* Set number of Points */ 19 | nPts = internalData.size()/2.0; 20 | } 21 | 22 | Line2D2CircularVecs::~Line2D2CircularVecs() { 23 | 24 | } 25 | 26 | void Line2D2CircularVecs::updateInternalData(unsigned int currIndex) { 27 | /* Creates an internal data store from the current dataVecPt */ 28 | // Get minimum length of both vectors 29 | unsigned int totLen = std::min(this->dataPtX->size(), this->dataPtY->size()); 30 | // Resize vector to data 31 | internalData.resize(2*totLen); 32 | // Update with new data 33 | // First slice 34 | unsigned int len1 = totLen - currIndex; 35 | for(unsigned int i=0; i Line2D2CircularVecs::getMinMax() { 64 | // Gets the minimum and maximum values of both x and y for the data 65 | float maxFloat = std::numeric_limits::max(); 66 | float xmin = maxFloat; 67 | float xmax = -maxFloat; 68 | float ymin = maxFloat; 69 | float ymax = -maxFloat; 70 | for (unsigned int i = 0; i xmax) { 74 | xmax = xval; 75 | } 76 | if (xval < xmin) { 77 | xmin = xval; 78 | } 79 | if (yval > ymax) { 80 | ymax = yval; 81 | } 82 | if (yval < ymin) { 83 | ymin = yval; 84 | } 85 | } 86 | 87 | return std::vector {xmin,xmax,ymin,ymax}; 88 | } 89 | } -------------------------------------------------------------------------------- /src/lines/Line2D2CircularVecs.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by tbatt on 11/04/2020. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_LINE2D2CIRCULARVECS_H 6 | #define OPENGLPLOTLIVE_PROJ_LINE2D2CIRCULARVECS_H 7 | 8 | #include "ILine2D_OLD.h" 9 | 10 | 11 | namespace GLPL { 12 | class Line2D2CircularVecs : public ILine2D_OLD { 13 | // Two vectors corresponding to an x vector and a y vector 14 | // An index specifies the 'start' of the vector 15 | // The resultant vector is from the index to the end of the vector, plus 16 | // the start to the index. 17 | // This operates similar to a circular buffer. 18 | public: 19 | /* Constructor */ 20 | Line2D2CircularVecs(std::vector* dataPtX, std::vector* dataPtY, GLenum mode = GL_LINE_STRIP); 21 | 22 | /* Destructor */ 23 | ~Line2D2CircularVecs(); 24 | 25 | /* Functions */ 26 | void updateInternalData(unsigned int currIndex); 27 | void Draw(GLPL::Shader shader, glm::mat4 axesLimitViewportTrans); 28 | std::vector getMinMax(); 29 | 30 | protected: 31 | /* Buffers */ 32 | GLuint VAO, VBO; 33 | int nPts = 0; 34 | 35 | /* Data */ 36 | bool updated = false; 37 | std::vector* dataPtX; 38 | std::vector* dataPtY; 39 | std::vector internalData; 40 | 41 | }; 42 | 43 | } 44 | 45 | 46 | #endif //OPENGLPLOTLIVE_PROJ_LINE2D2CIRCULARVECS_H 47 | -------------------------------------------------------------------------------- /src/lines/Line2D2CircularVecsPosNeg.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by tbatt on 11/04/2020. 3 | // 4 | 5 | #include "Line2D2CircularVecsPosNeg.h" 6 | 7 | namespace GLPL { 8 | Line2D2CircularVecsPosNeg::Line2D2CircularVecsPosNeg(std::vector* dataPtX, std::vector* dataPtY, 9 | glm::vec4 posColor, glm::vec4 negColor, GLenum mode) : 10 | Line2D2CircularVecs(dataPtX, dataPtY, mode) { 11 | this->colPos = posColor; 12 | this->colNeg = negColor; 13 | } 14 | 15 | Line2D2CircularVecsPosNeg::~Line2D2CircularVecsPosNeg() { 16 | 17 | } 18 | 19 | void Line2D2CircularVecsPosNeg::Draw(GLPL::Shader shader, glm::mat4 axesLimitViewportTrans) { 20 | // Check if the number of points changed 21 | if (updated) { 22 | int newPts = (internalData).size()/2; 23 | nPts = newPts; 24 | // Update buffer and attributes 25 | glBindBuffer(GL_ARRAY_BUFFER, VBO); 26 | glBufferData(GL_ARRAY_BUFFER, internalData.size()*sizeof(internalData[0]), &internalData[0], GL_DYNAMIC_DRAW); 27 | updated = false; 28 | } 29 | 30 | // Draw plot 31 | // Draws the data currently stored in the line corresponding to the given VAO 32 | shader.Use(); 33 | glLineWidth(lineWidth); 34 | glUniformMatrix4fv(glGetUniformLocation(shader.Program, "transformViewport"), 1, GL_FALSE, 35 | glm::value_ptr(axesLimitViewportTrans)); 36 | glUniform4fv(glGetUniformLocation(shader.Program, "colPos"), 1, glm::value_ptr(colPos)); 37 | glUniform4fv(glGetUniformLocation(shader.Program, "colNeg"), 1, glm::value_ptr(colNeg)); 38 | glBindVertexArray(VAO); 39 | glDrawArrays(mode, 0, nPts); 40 | glBindVertexArray(0); 41 | glLineWidth(1); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /src/lines/Line2D2CircularVecsPosNeg.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by tbatt on 11/04/2020. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_LINE2D2CIRCULARVECSPOSNEG_H 6 | #define OPENGLPLOTLIVE_PROJ_LINE2D2CIRCULARVECSPOSNEG_H 7 | 8 | #include "Line2D2CircularVecs.h" 9 | 10 | 11 | namespace GLPL { 12 | class Line2D2CircularVecsPosNeg : public Line2D2CircularVecs { 13 | // Alters Line2D2CircularVecs to plot parts of the line that are above and below the line in different colours 14 | public: 15 | /* Constructor */ 16 | Line2D2CircularVecsPosNeg(std::vector* dataPtX, std::vector* dataPtY, 17 | glm::vec4 posColor, glm::vec4 negColor, GLenum mode = GL_LINE_STRIP); 18 | 19 | /* Destructor */ 20 | ~Line2D2CircularVecsPosNeg(); 21 | 22 | /* Functions */ 23 | void Draw(GLPL::Shader shader, glm::mat4 axesLimitViewportTrans); 24 | 25 | private: 26 | // Data 27 | glm::vec4 colPos; 28 | glm::vec4 colNeg; 29 | }; 30 | 31 | } 32 | 33 | 34 | #endif //OPENGLPLOTLIVE_PROJ_LINE2D2CIRCULARVECSPOSNEG_H 35 | -------------------------------------------------------------------------------- /src/lines/Line2D2Vecs.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by tbatt on 11/04/2020. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_LINE2D2VECS_H 6 | #define OPENGLPLOTLIVE_PROJ_LINE2D2VECS_H 7 | 8 | #include "ISingleLine2D.h" 9 | 10 | 11 | namespace GLPL { 12 | 13 | class Line2D2Vecs : public ISingleLine2D { 14 | // Two vectors corresponding to an x vector and a y vector 15 | public: 16 | /* Constructor */ 17 | Line2D2Vecs(std::vector* dataPtX, std::vector* dataPtY, 18 | std::shared_ptr parentDimensions, GLenum mode = GL_LINE_STRIP); 19 | 20 | /* Destructor */ 21 | ~Line2D2Vecs(); 22 | 23 | /* Functions */ 24 | void updateInternalData(); 25 | void updateIncrementalInternalData(); 26 | void Draw(); 27 | std::string getID(); 28 | void clearData(); 29 | std::vector getMinMax(bool onlyPositiveX, bool onlyPositiveY); 30 | std::tuple getClosestPoint(float xVal); 31 | std::tuple getClosestPoint(float xVal, float xmin, float xmax, float ymin, float ymax); 32 | 33 | 34 | std::vector getInternalData(); 35 | std::vector getInternalIndices(); 36 | 37 | std::vector* dataPtX; 38 | std::vector* dataPtY; 39 | 40 | protected: 41 | /* Data */ 42 | int nPts = 0; 43 | 44 | std::vector internalData; // This is sorted by x values 45 | std::vector internalIndices; // This keeps track of the indices in their original order, for plotting 46 | 47 | 48 | }; 49 | 50 | } 51 | 52 | 53 | #endif //OPENGLPLOTLIVE_PROJ_LINE2D2VECS_H 54 | -------------------------------------------------------------------------------- /src/lines/Line2DPts.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 27/3/20. 3 | // 4 | 5 | #include "Line2DPts.h" 6 | 7 | 8 | namespace GLPL { 9 | Line2DPts::Line2DPts(std::vector* dataPtPt, GLenum mode) : ILine2D_OLD() { 10 | this->dataPtPt = dataPtPt; 11 | this->setMode(mode); 12 | 13 | /* Setup Buffers */ 14 | int dataSizeBytes = dataPtPt->size() * 2 * sizeof(GLfloat); 15 | createAndSetupBuffers(&VAO, &VBO, dataSizeBytes, dataPtPt->data(), 16 | sizeof(GLPL::pt2D)); // dataPtPt->data() gives the address of the first element of the vector 17 | 18 | /* Set Number of Points */ 19 | nPts = dataPtPt->size(); 20 | } 21 | 22 | Line2DPts::~Line2DPts() { 23 | std::cout << "Destructed Line2DPts." << std::endl; 24 | } 25 | 26 | void Line2DPts::Draw(GLPL::Shader shader, glm::mat4 axesLimitViewportTrans) { 27 | // Check if number of points changed 28 | int newPts = dataPtPt->size(); 29 | if (newPts != nPts) { 30 | nPts = newPts; 31 | // Update buffer and attributes 32 | glBindBuffer(GL_ARRAY_BUFFER, VBO); 33 | glBufferData(GL_ARRAY_BUFFER, dataPtPt->size() * 2 * sizeof(GLfloat), dataPtPt->data(), GL_DYNAMIC_DRAW); 34 | } 35 | 36 | // Draw Plot 37 | drawData(shader, axesLimitViewportTrans, &VAO, getColour(), nPts, getMode()); 38 | } 39 | 40 | 41 | std::vector Line2DPts::getMinMax() { 42 | // Gets the minimum and maximum values of both x and y for the data 43 | float xmin = 0; 44 | float xmax = 0; 45 | float ymin = 0; 46 | float ymax = 0; 47 | for (unsigned int i = 0; i < dataPtPt->size(); i++) { 48 | float xval = (*dataPtPt)[i].x; 49 | float yval = (*dataPtPt)[i].y; 50 | if (xval > xmax) { 51 | xmax = xval; 52 | } 53 | if (xval < xmin) { 54 | xmin = xval; 55 | } 56 | if (yval > ymax) { 57 | ymax = yval; 58 | } 59 | if (yval < ymin) { 60 | ymin = yval; 61 | } 62 | } 63 | 64 | return std::vector{xmin, xmax, ymin, ymax}; 65 | } 66 | } -------------------------------------------------------------------------------- /src/lines/Line2DPts.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 27/3/20. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_LINE2DPTS_H 6 | #define OPENGLPLOTLIVE_LINE2DPTS_H 7 | 8 | 9 | #include "../dataTypes/dataTypes.h" 10 | #include "ILine2D_OLD.h" 11 | #include "lineColours.h" 12 | 13 | 14 | namespace GLPL { 15 | class Line2DPts : public ILine2D_OLD { 16 | // Line of pt2D Structures 17 | public: 18 | /* Constructor */ 19 | Line2DPts(std::vector* dataPtPt, GLenum mode = GL_LINE_STRIP); 20 | 21 | /* Destructor */ 22 | ~Line2DPts(); 23 | 24 | /* Functions */ 25 | void Draw(GLPL::Shader shader, glm::mat4 axesLimitViewportTrans); 26 | std::vector getMinMax(); 27 | 28 | 29 | private: 30 | /* Buffers */ 31 | GLuint VAO, VBO; 32 | int nPts = 0; 33 | 34 | /* Data */ 35 | std::vector *dataPtPt; 36 | 37 | }; 38 | } 39 | 40 | #endif //OPENGLPLOTLIVE_LINE2DPTS_H 41 | -------------------------------------------------------------------------------- /src/lines/Line2DVec.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 29/3/20. 3 | // 4 | 5 | #include "Line2DVec.h" 6 | 7 | 8 | namespace GLPL { 9 | 10 | template 11 | Line2DVec::Line2DVec(std::vector* dataVecPt, GLenum mode) { 12 | this->dataVecPt = dataVecPt; 13 | this->setMode(mode); 14 | 15 | /* Setup Buffers */ 16 | int dataSizeBytes = dataVecPt->size()*sizeof((*dataVecPt)[0]); 17 | int glType = getGLType(); 18 | createAndSetupBuffers(&VAO, &VBO, dataSizeBytes, dataVecPt->data(), 2*sizeof((*dataVecPt)[0]), glType); // dataVecPt->data() gives the address of the first element of the vector 19 | 20 | /* Set Number of Points */ 21 | nPts = dataVecPt->size()/2; 22 | 23 | } 24 | 25 | template 26 | void Line2DVec::Draw(Shader shader, glm::mat4 axesLimitViewportTrans) { 27 | // Check if number of points changed 28 | int newPts = dataVecPt->size()/2; 29 | if (newPts != nPts) { 30 | nPts = newPts; 31 | // Update buffer and attributes 32 | glBindBuffer(GL_ARRAY_BUFFER,VBO); 33 | glBufferData(GL_ARRAY_BUFFER, dataVecPt->size()*sizeof((*dataVecPt)[0]),dataVecPt->data(),GL_DYNAMIC_DRAW); 34 | } 35 | 36 | // Draw Plot 37 | drawData(shader, axesLimitViewportTrans, &VAO, getColour(), nPts, getMode()); 38 | } 39 | 40 | template 41 | void Line2DVec::appendVec(T x, T y) { 42 | // Appends a point to the current data 43 | this->dataVecPt->push_back(x); 44 | this->dataVecPt->push_back(y); 45 | } 46 | 47 | template 48 | std::vector Line2DVec::getMinMax() { 49 | // Gets the minimum and maximum values of both x and y for the data 50 | float xmin = 0; 51 | float xmax = 0; 52 | float ymin = 0; 53 | float ymax = 0; 54 | for (unsigned int i = 0; isize()/2.0; i++) { 55 | T xval = (*dataVecPt)[2*i]; 56 | T yval = (*dataVecPt)[2*i+1]; 57 | if (xval > xmax) { 58 | xmax = (float)xval; 59 | } 60 | if (xval < xmin) { 61 | xmin = (float)xval; 62 | } 63 | if (yval > ymax) { 64 | ymax = (float)yval; 65 | } 66 | if (yval < ymin) { 67 | ymin = (float)yval; 68 | } 69 | } 70 | 71 | return std::vector {xmin,xmax,ymin,ymax}; 72 | } 73 | 74 | // Force the compiler to generate templates of these types 75 | template class Line2DVec; 76 | template class Line2DVec; 77 | template class Line2DVec; 78 | 79 | } 80 | 81 | -------------------------------------------------------------------------------- /src/lines/Line2DVec.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 29/3/20. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_LINE2DVEC_H 6 | #define OPENGLPLOTLIVE_LINE2DVEC_H 7 | 8 | 9 | #include "../dataTypes/dataTypes.h" 10 | #include "ILine2D_OLD.h" 11 | 12 | 13 | 14 | namespace GLPL { 15 | // Template the vector type 16 | // Set mappings from Type T to GL Types 17 | template constexpr int getGLType(); 18 | 19 | template <> constexpr int getGLType() { return GL_INT; } 20 | template <> constexpr int getGLType() { return GL_FLOAT; } 21 | template <> constexpr int getGLType() { return GL_DOUBLE; } 22 | 23 | // Class template 24 | template 25 | class Line2DVec : public ILine2D_OLD { 26 | // Line of 2-length vectors 27 | public: 28 | /* Constructor */ 29 | Line2DVec(std::vector* dataVecPt, GLenum mode = GL_LINE_STRIP); 30 | 31 | /* Functions */ 32 | void Draw(Shader shader, glm::mat4 axesLimitViewportTrans); 33 | void appendVec(T x, T y); 34 | std::vector getMinMax(); 35 | 36 | private: 37 | /* Buffers */ 38 | GLuint VAO, VBO; 39 | int nPts = 0; 40 | 41 | /* Data */ 42 | std::vector* dataVecPt; 43 | }; 44 | } 45 | 46 | 47 | #endif //OPENGLPLOTLIVE_LINE2DVEC_H 48 | -------------------------------------------------------------------------------- /src/lines/Line2DVecGLMV3.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 29/3/20. 3 | // 4 | 5 | #include "Line2DVecGLMV3.h" 6 | 7 | 8 | namespace GLPL { 9 | Line2DVecGLMV3::Line2DVecGLMV3(std::vector* dataVecPt, int indexX, int indexY, GLenum mode) { 10 | this->dataVecPt = dataVecPt; 11 | this->setMode(mode); 12 | this->indexX = indexX; 13 | this->indexY = indexY; 14 | 15 | /* Setup Buffers */ 16 | updateInternalData(); 17 | int dataSizeBytes = internalData.size()*sizeof(internalData[0]); 18 | createAndSetupBuffers(&VAO, &VBO, dataSizeBytes, &internalData[0], 2*sizeof(internalData[0])); 19 | 20 | /* Set Number of Points */ 21 | nPts = dataVecPt->size()/2.0; 22 | 23 | } 24 | 25 | void Line2DVecGLMV3::updateInternalData() { 26 | /* Creates an internal data store from the current dataVecPt */ 27 | // Resize vector to data 28 | internalData.resize(2*dataVecPt->size()); 29 | // Update With New Data 30 | for(unsigned int i=0; isize(); i++) { 31 | internalData[2*i] = (*dataVecPt)[i][indexX]; 32 | internalData[2*i + 1] = (*dataVecPt)[i][indexY]; 33 | } 34 | } 35 | 36 | void Line2DVecGLMV3::Draw(Shader shader, glm::mat4 axesLimitViewportTrans) { 37 | // Check if number of points changed 38 | int newPts = (internalData).size()/2; 39 | if (newPts != nPts) { 40 | nPts = newPts; 41 | // Update buffer and attributes 42 | glBindBuffer(GL_ARRAY_BUFFER,VBO); 43 | glBufferData(GL_ARRAY_BUFFER, internalData.size()*sizeof(internalData[0]),&internalData[0],GL_DYNAMIC_DRAW); 44 | } 45 | 46 | // Draw Plot 47 | drawData(shader, axesLimitViewportTrans, &VAO, getColour(), nPts, getMode()); 48 | } 49 | 50 | std::vector Line2DVecGLMV3::getMinMax() { 51 | // Gets the minimum and maximum values of both x and y for the data 52 | float maxFloat = std::numeric_limits::max(); 53 | float xmin = maxFloat; 54 | float xmax = -maxFloat; 55 | float ymin = maxFloat; 56 | float ymax = -maxFloat; 57 | for (unsigned int i = 0; i xmax) { 61 | xmax = xval; 62 | } 63 | if (xval < xmin) { 64 | xmin = xval; 65 | } 66 | if (yval > ymax) { 67 | ymax = yval; 68 | } 69 | if (yval < ymin) { 70 | ymin = yval; 71 | } 72 | } 73 | 74 | return std::vector {xmin,xmax,ymin,ymax}; 75 | } 76 | 77 | }; 78 | 79 | -------------------------------------------------------------------------------- /src/lines/Line2DVecGLMV3.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 29/3/20. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_LINE2DVECGLMV3_H 6 | #define OPENGLPLOTLIVE_LINE2DVECGLMV3_H 7 | 8 | #include "ILine2D_OLD.h" 9 | 10 | namespace GLPL { 11 | class Line2DVecGLMV3 : public ILine2D_OLD { 12 | // Line of vector of glm::dvec3s 13 | public: 14 | /* Constructor */ 15 | Line2DVecGLMV3(std::vector* dataVecPt, int indexX = 0, int indexY = 1, GLenum mode = GL_LINE_STRIP); 16 | 17 | /* Functions */ 18 | void updateInternalData(); 19 | void Draw(Shader shader, glm::mat4 axesLimitViewportTrans); 20 | std::vector getMinMax(); 21 | 22 | private: 23 | /* Buffers */ 24 | GLuint VAO, VBO; 25 | int nPts = 0; 26 | 27 | /* Data */ 28 | std::vector* dataVecPt; 29 | std::vector internalData; 30 | 31 | /* Selection */ 32 | int indexX; 33 | int indexY; 34 | 35 | }; 36 | 37 | } 38 | 39 | 40 | #endif //OPENGLPLOTLIVE_LINE2DVECGLMV3_H 41 | -------------------------------------------------------------------------------- /src/lines/Line2DVecVec.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 29/3/20. 3 | // 4 | 5 | #include "Line2DVecVec.h" 6 | 7 | namespace GLPL { 8 | Line2DVecVec::Line2DVecVec(std::vector>* dataVecPt, int indexX, int indexY, GLenum mode) { 9 | this->dataVecPt = dataVecPt; 10 | this->setMode(mode); 11 | this->indexX = indexX; 12 | this->indexY = indexY; 13 | 14 | /* Setup Buffers */ 15 | updateInternalData(); 16 | int dataSizeBytes = internalData.size()*sizeof(internalData[0]); 17 | createAndSetupBuffers(&VAO, &VBO, dataSizeBytes, &internalData[0], 2*sizeof(internalData[0])); 18 | 19 | /* Set Number of Points */ 20 | nPts = dataVecPt->size()/2.0; 21 | 22 | } 23 | 24 | void Line2DVecVec::updateInternalData() { 25 | /* Creates an internal data store from the current dataVecPt */ 26 | // Resize vector to data 27 | internalData.resize(2*dataVecPt->size()); 28 | // Update With New Data 29 | for(unsigned int i=0; isize(); i++) { 30 | internalData[2*i] = (*dataVecPt)[i][indexX]; 31 | internalData[2*i + 1] = (*dataVecPt)[i][indexY]; 32 | } 33 | } 34 | 35 | void Line2DVecVec::Draw(Shader shader, glm::mat4 axesLimitViewportTrans) { 36 | // Check if number of points changed 37 | int newPts = (internalData).size()/2; 38 | if (newPts != nPts) { 39 | nPts = newPts; 40 | // Update buffer and attributes 41 | glBindBuffer(GL_ARRAY_BUFFER,VBO); 42 | glBufferData(GL_ARRAY_BUFFER, internalData.size()*sizeof(internalData[0]),&internalData[0],GL_DYNAMIC_DRAW); 43 | } 44 | 45 | // Draw Plot 46 | drawData(shader, axesLimitViewportTrans, &VAO, getColour(), nPts, getMode()); 47 | } 48 | 49 | std::vector Line2DVecVec::getMinMax(bool onlyPositiveX, bool onlyPositiveY) { 50 | // Gets the minimum and maximum values of both x and y for the data 51 | float xmin = 0; 52 | float xmax = 0; 53 | float ymin = 0; 54 | float ymax = 0; 55 | for (unsigned int i = 0; i xmax && (!onlyPositiveX || xval > 0)) { 59 | xmax = xval; 60 | } 61 | if (xval < xmin && (!onlyPositiveX || xval > 0)) { 62 | xmin = xval; 63 | } 64 | if (yval > ymax && (!onlyPositiveY || yval > 0)) { 65 | ymax = yval; 66 | } 67 | if (yval < ymin && (!onlyPositiveY || yval > 0)) { 68 | ymin = yval; 69 | } 70 | } 71 | 72 | return std::vector {xmin,xmax,ymin,ymax}; 73 | } 74 | 75 | 76 | }; -------------------------------------------------------------------------------- /src/lines/Line2DVecVec.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 29/3/20. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_LINE2DVECVEC_H 6 | #define OPENGLPLOTLIVE_LINE2DVECVEC_H 7 | 8 | 9 | #include "../dataTypes/dataTypes.h" 10 | #include "ILine2D_OLD.h" 11 | 12 | 13 | namespace GLPL { 14 | class Line2DVecVec : public ILine2D_OLD { 15 | // Line of vectors of vectors 16 | public: 17 | /* Constructor */ 18 | Line2DVecVec(std::vector>* dataVecPt, int indexX = 0, int indexY = 1, GLenum mode = GL_LINE_STRIP); 19 | 20 | /* Functions */ 21 | void updateInternalData(); 22 | void Draw(Shader shader, glm::mat4 axesLimitViewportTrans); 23 | std::vector getMinMax(bool onlyPositiveX = false, bool onlyPositiveY = false); 24 | 25 | private: 26 | /* Buffers */ 27 | GLuint VAO, VBO; 28 | int nPts = 0; 29 | 30 | /* Data */ 31 | std::vector>* dataVecPt; 32 | std::vector internalData; 33 | 34 | /* Selection */ 35 | int indexX; 36 | int indexY; 37 | 38 | }; 39 | } 40 | 41 | 42 | #endif //OPENGLPLOTLIVE_LINE2DVECVEC_H 43 | -------------------------------------------------------------------------------- /src/lines/Line2DVecfVecGLMV3.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 29/3/20. 3 | // 4 | 5 | #include "Line2DVecfVecGLMV3.h" 6 | 7 | 8 | namespace GLPL { 9 | Line2DVecfVecGLMV3::Line2DVecfVecGLMV3(std::vector* dataVecfPt, std::vector* dataVecGLMV3Pt, int indexGLM, GLenum mode) { 10 | this->dataVecfPt = dataVecfPt; 11 | this->setMode(mode); 12 | this->dataVecGLMV3Pt = dataVecGLMV3Pt; 13 | this->indexGLM = indexGLM; 14 | 15 | /* Setup Buffers */ 16 | updateInternalData(); 17 | int dataSizeBytes = internalData.size()*sizeof(internalData[0]); 18 | createAndSetupBuffers(&VAO, &VBO, dataSizeBytes, &internalData[0], 2*sizeof(internalData[0])); 19 | 20 | /* Set Number of Points */ 21 | nPts = internalData.size()/2.0; 22 | 23 | } 24 | 25 | void Line2DVecfVecGLMV3::updateInternalData() { 26 | /* Creates an internal data store from the current dataVecPt */ 27 | // Get minimum length of both vectors 28 | int len = std::min(dataVecfPt->size(),dataVecGLMV3Pt->size()); 29 | // Resize vector to data 30 | internalData.resize(2*len); 31 | // Update With New Data 32 | for(int i=0; i Line2DVecfVecGLMV3::getMinMax() { 53 | // Gets the minimum and maximum values of both x and y for the data 54 | float maxFloat = std::numeric_limits::max(); 55 | float xmin = maxFloat; 56 | float xmax = -maxFloat; 57 | float ymin = maxFloat; 58 | float ymax = -maxFloat; 59 | for (unsigned int i = 0; i xmax) { 63 | xmax = xval; 64 | } 65 | if (xval < xmin) { 66 | xmin = xval; 67 | } 68 | if (yval > ymax) { 69 | ymax = yval; 70 | } 71 | if (yval < ymin) { 72 | ymin = yval; 73 | } 74 | } 75 | 76 | return std::vector {xmin,xmax,ymin,ymax}; 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /src/lines/Line2DVecfVecGLMV3.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 29/3/20. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_LINE2DVECFVECGLMV3_H 6 | #define OPENGLPLOTLIVE_LINE2DVECFVECGLMV3_H 7 | 8 | #include "../dataTypes/dataTypes.h" 9 | #include "ILine2D_OLD.h" 10 | 11 | 12 | namespace GLPL { 13 | class Line2DVecfVecGLMV3 : public ILine2D_OLD { 14 | // Line of vector vs vector of glm::dvec3s 15 | // For plotting a vector of floats against an index selected form a vector of glm::dvec3s 16 | // For example plotting a vector of time data against a vector of glm::dvec3. 17 | 18 | public: 19 | /* Constructor */ 20 | Line2DVecfVecGLMV3(std::vector* dataVecfPt, std::vector* dataVecGLMV3Pt, int indexGLM = 0, GLenum mode = GL_LINE_STRIP); 21 | 22 | /* Functions */ 23 | void updateInternalData(); 24 | void Draw(Shader shader, glm::mat4 axesLimitViewportTrans); 25 | std::vector getMinMax(); 26 | 27 | private: 28 | /* Buffers */ 29 | GLuint VAO, VBO; 30 | int nPts = 0; 31 | 32 | /* Data */ 33 | std::vector* dataVecfPt; 34 | std::vector* dataVecGLMV3Pt; 35 | std::vector internalData; 36 | 37 | /* Selection */ 38 | int indexGLM; 39 | 40 | }; 41 | } 42 | 43 | 44 | #endif //OPENGLPLOTLIVE_LINE2DVECFVECGLMV3_H 45 | -------------------------------------------------------------------------------- /src/lines/LineType.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 29/6/20. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_LINETYPE_H 6 | #define OPENGLPLOTLIVE_PROJ_LINETYPE_H 7 | 8 | namespace GLPL { 9 | enum LineType { 10 | SINGLE_LINE, 11 | SHADED_LINE 12 | }; 13 | } 14 | 15 | #endif //OPENGLPLOTLIVE_PROJ_LINETYPE_H 16 | -------------------------------------------------------------------------------- /src/lines/lineColours.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lineColours.h 3 | * 4 | * Created on: 8Apr.,2017 5 | * Author: bcub3d-desktop 6 | */ 7 | 8 | #ifndef LINECOLOURS_H_ 9 | #define LINECOLOURS_H_ 10 | 11 | namespace GLPL{ 12 | // Line Colours 13 | #define LC_WHITE glm::vec3(1.0, 1.0, 1.0) 14 | #define LC_BLACK glm::vec3(0.0, 0.0, 0.0) 15 | #define LC_RED glm::vec3(1.0, 0.0, 0.0) 16 | #define LC_GREEN glm::vec3(0.0, 1.0, 0.0) 17 | #define LC_BLUE glm::vec3(0.0, 0.0, 1.0) 18 | #define LC_YELLOW glm::vec3(1.0, 1.0, 0.0) 19 | #define LC_CYAN glm::vec3(0.0, 1.0, 1.0) 20 | #define LC_MAGENTA glm::vec3(1.0, 0.0, 1.0) 21 | #define LC_SILVER glm::vec3(0.7529, 0.7529, 0.7529) 22 | #define LC_GRAY glm::vec3(0.5020, 0.5020, 0.5020) 23 | #define LC_MAROON glm::vec3(0.5020, 0.0, 0.0) 24 | #define LC_OLIVE glm::vec3(0.5020, 0.5020, 0.0) 25 | #define LC_DARKGREEN glm::vec3(0.0, 0.5020, 0.0) 26 | #define LC_PURPLE glm::vec3(0.5020, 0.0, 0.5020) 27 | #define LC_TEAL glm::vec3(0.0, 0.5020, 0.5020) 28 | #define LC_NAVY glm::vec3(0.0, 0.0, 0.5020) 29 | } 30 | 31 | 32 | 33 | #endif /* LINECOLOURS_H_ */ 34 | -------------------------------------------------------------------------------- /src/plot/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Add sources 2 | file(GLOB CPP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) 3 | file(GLOB H_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h) 4 | target_sources(${PROJECT_NAME} PRIVATE ${CPP_FILES}) 5 | target_sources(${PROJECT_NAME} PUBLIC "${H_FILES}") 6 | 7 | # Setup include directories 8 | target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/plot) -------------------------------------------------------------------------------- /src/plot/plot.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by tbatt on 19/04/2020. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_PLOT_H 6 | #define OPENGLPLOTLIVE_PROJ_PLOT_H 7 | 8 | // Standard Includese 9 | #include 10 | 11 | // Project Includes 12 | #include "../axes/axes.h" 13 | #include "../rendering/ConstantXYDrawable.h" 14 | #include "../axes/axes2D.h" 15 | #include "../axes/axes3D.h" 16 | 17 | 18 | namespace GLPL { 19 | 20 | class Plot : public ConstantXYDrawable { 21 | // Plot contains sets of axes, labels and titles 22 | public: 23 | // Constructor 24 | Plot(float x, float y, float width, float height, std::shared_ptr parentDimensions, 25 | unsigned int numHorizontal = 1, unsigned int numVertical = 1); 26 | 27 | // Functions 28 | void setPlotLayout(unsigned int newNumHorizontal, unsigned int newNumVertical); 29 | void updatePlotLayout(); 30 | std::shared_ptr add2DAxes(); 31 | std::shared_ptr add3DAxes(); 32 | std::shared_ptr addAxes(AxesType axesType); 33 | std::shared_ptr add2DAxes(float x, float y, float width, float height); 34 | std::shared_ptr add3DAxes(float x, float y, float width, float height); 35 | std::shared_ptr addAxes(float x, float y, float width, float height, AxesType axesType); 36 | std::shared_ptr getAxes(unsigned int axesId); 37 | void removeAxes(unsigned int axesId); 38 | void Draw(); 39 | std::string getID(); 40 | 41 | private: 42 | // Plot layout 43 | unsigned int numVertical = 1; 44 | unsigned int numHorizontal = 1; 45 | 46 | // Axes 47 | unsigned int axesCount = 0; 48 | std::unordered_map> axesMap; 49 | 50 | }; 51 | 52 | } 53 | 54 | 55 | #endif //OPENGLPLOTLIVE_PROJ_PLOT_H 56 | -------------------------------------------------------------------------------- /src/rendering/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Add sources 2 | file(GLOB CPP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) 3 | file(GLOB H_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h) 4 | target_sources(${PROJECT_NAME} PRIVATE ${CPP_FILES}) 5 | target_sources(${PROJECT_NAME} PUBLIC "${H_FILES}") 6 | 7 | # Setup include directories 8 | target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/rendering) -------------------------------------------------------------------------------- /src/rendering/ConstantXYDrawable.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 1/8/20. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_CONSTANTXYDRAWABLE_H 6 | #define OPENGLPLOTLIVE_PROJ_CONSTANTXYDRAWABLE_H 7 | 8 | #include "IDrawable.h" 9 | 10 | 11 | namespace GLPL { 12 | 13 | enum XYScale { 14 | CONSTANT_SCALE, 15 | CONSTANT_SIZE 16 | }; 17 | 18 | 19 | class ConstantXYDrawable : public IDrawable { 20 | public: 21 | // Constructor 22 | ConstantXYDrawable(float x, float y, float width, float height, 23 | XYScale xScale, XYScale yScale, 24 | std::shared_ptr parentDimensions, 25 | AttachLocation newAttachLocation = BOTTOM_LEFT); 26 | 27 | // Functions 28 | void setPosition(float newX, float newY); 29 | void setSize(float newWidth, float newHeight); 30 | void updateSizePx(); 31 | void setParentDimensions(glm::mat4 newParentTransform, 32 | int newParentXPx, 33 | int newParentYPx, 34 | int newParentWidthPx, 35 | int newParentHeightPx); 36 | void setParentDimensions(std::shared_ptr parentDimensions); 37 | 38 | void setXScale(XYScale newXScale); 39 | void setYScale(XYScale newYScale); 40 | void setXYScale(XYScale newXScale, XYScale newYScale); 41 | 42 | 43 | // Data 44 | XYScale xScale = CONSTANT_SCALE; 45 | XYScale yScale = CONSTANT_SCALE; 46 | 47 | }; 48 | 49 | } 50 | 51 | 52 | #endif //OPENGLPLOTLIVE_PROJ_CONSTANTXYDRAWABLE_H 53 | -------------------------------------------------------------------------------- /src/rendering/ShaderSet.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by tbatt on 19/04/2020. 3 | // 4 | 5 | #include "ShaderSet.h" 6 | 7 | namespace GLPL { 8 | 9 | GLPL::ShaderSet::ShaderSet() { 10 | // Setup character loader using the correct fonts 11 | const GLchar* fontPath = getFontPath(); 12 | characterLoaderPt = std::make_shared(fontPath); 13 | 14 | // Get DPI Scaling 15 | GLFWmonitor* monitor = glfwGetPrimaryMonitor(); 16 | glfwGetMonitorContentScale(monitor, &xScaleDpi, &yScaleDpi); 17 | 18 | // Make shared_ptrs 19 | textShaderPt = std::make_shared(textShader); 20 | plot2dShaderPt = std::make_shared(plot2dShader); 21 | plot2dLogxShaderPt = std::make_shared(plot2dShaderLogx); 22 | plot2dLogyShaderPt = std::make_shared(plot2dShaderLogy); 23 | plot2dLogxLogyShaderPt = std::make_shared(plot2dShaderLogxLogy); 24 | scatter2dShaderPt = std::make_shared(scatter2dShader); 25 | scatter2dLogxShaderPt = std::make_shared(scatter2dLogxShader); 26 | scatter2dLogyShaderPt = std::make_shared(scatter2dLogyShader); 27 | scatter2dLogxLogyShaderPt = std::make_shared(scatter2dLogxLogyShader); 28 | textureShaderPt = std::make_shared(textureShader); 29 | plotPosNeg2DShaderPt = std::make_shared(plotPosNeg2DShader); 30 | plotTransparent2dShaderPt = std::make_shared(plotTransparent2dShader); 31 | textureMangerPt = std::make_shared(textureManager); 32 | } 33 | 34 | 35 | const GLchar* GLPL::ShaderSet::getFontPath() { 36 | // Determine font paths 37 | // Check for fonts in Ubuntu 38 | const GLchar* ubuntuFontPath = "/usr/share/fonts/truetype/ubuntu/Ubuntu-R.ttf"; 39 | std::ifstream f(ubuntuFontPath); 40 | if (f.good()) { 41 | return ubuntuFontPath; 42 | } 43 | // Check for fonts in Fedora 44 | const GLchar* fedoraFontPath = "/usr/share/fonts/liberation-mono/LiberationMono-Regular.ttf"; 45 | std::ifstream g(fedoraFontPath); 46 | if (g.good()) { 47 | return fedoraFontPath; 48 | } 49 | // Check for fonts in Windows 50 | const GLchar* windowsFontPath = "C:/Windows/Fonts/Arial.ttf"; 51 | std::ifstream h(windowsFontPath); 52 | if (h.good()) { 53 | return windowsFontPath; 54 | } 55 | 56 | std::cout << "No Fonts Found! Try adding a path to determineFontPath in ShaderSet.h." << std::endl; 57 | 58 | return nullptr; 59 | } 60 | 61 | 62 | float ShaderSet::getXDpiScaling() { 63 | return xScaleDpi; 64 | } 65 | 66 | 67 | float ShaderSet::getYDpiScaling() { 68 | return yScaleDpi; 69 | } 70 | 71 | std::shared_ptr GLPL::ShaderSet::getTextShader() { 72 | return textShaderPt; 73 | } 74 | 75 | std::shared_ptr GLPL::ShaderSet::getPlot2dShader() { 76 | return plot2dShaderPt; 77 | } 78 | 79 | std::shared_ptr GLPL::ShaderSet::getPlot2dLogxShader() { 80 | return plot2dLogxShaderPt; 81 | } 82 | 83 | std::shared_ptr GLPL::ShaderSet::getPlot2dLogyShader() { 84 | return plot2dLogyShaderPt; 85 | } 86 | 87 | std::shared_ptr GLPL::ShaderSet::getPlot2dLogxLogyShader() { 88 | return plot2dLogxLogyShaderPt; 89 | } 90 | 91 | std::shared_ptr GLPL::ShaderSet::getScatter2dShader() { 92 | return scatter2dShaderPt; 93 | } 94 | 95 | std::shared_ptr GLPL::ShaderSet::getScatter2dLogxShader() { 96 | return scatter2dLogxShaderPt; 97 | } 98 | 99 | std::shared_ptr GLPL::ShaderSet::getScatter2dLogyShader() { 100 | return scatter2dLogyShaderPt; 101 | } 102 | 103 | std::shared_ptr GLPL::ShaderSet::getScatter2dLogxLogyShader() { 104 | return scatter2dLogxLogyShaderPt; 105 | } 106 | 107 | std::shared_ptr GLPL::ShaderSet::getTextureShader() { 108 | return textureShaderPt; 109 | } 110 | 111 | std::shared_ptr GLPL::ShaderSet::getPlotPosNeg2DShader() { 112 | return plotPosNeg2DShaderPt; 113 | } 114 | 115 | std::shared_ptr GLPL::ShaderSet::getPlotTransparent2dShader() { 116 | return plotTransparent2dShaderPt; 117 | } 118 | 119 | std::shared_ptr ShaderSet::getCharacterLoader() { 120 | return characterLoaderPt; 121 | } 122 | 123 | std::shared_ptr ShaderSet::getTextureManager() { 124 | return textureMangerPt; 125 | } 126 | 127 | } -------------------------------------------------------------------------------- /src/rendering/ShaderSet.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by tbatt on 19/04/2020. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_SHADERSET_H 6 | #define OPENGLPLOTLIVE_PROJ_SHADERSET_H 7 | 8 | // Standard Includes 9 | #include 10 | 11 | // Project Includes 12 | #include "shader.h" 13 | #include "../texts/CharacterLoader.h" 14 | #include "../textures/TextureManager.h" 15 | 16 | 17 | namespace GLPL { 18 | 19 | // Contains the shaders for plotting 20 | class ShaderSet { 21 | public: 22 | // Constructor 23 | ShaderSet(); 24 | 25 | // Functions 26 | const GLchar* getFontPath(); 27 | float getXDpiScaling(); 28 | float getYDpiScaling(); 29 | std::shared_ptr getTextShader(); 30 | std::shared_ptr getPlot2dShader(); 31 | std::shared_ptr getPlot2dLogxShader(); 32 | std::shared_ptr getPlot2dLogyShader(); 33 | std::shared_ptr getPlot2dLogxLogyShader(); 34 | std::shared_ptr getScatter2dShader(); 35 | std::shared_ptr getScatter2dLogxShader(); 36 | std::shared_ptr getScatter2dLogyShader(); 37 | std::shared_ptr getScatter2dLogxLogyShader(); 38 | std::shared_ptr getTextureShader(); 39 | std::shared_ptr getPlotPosNeg2DShader(); 40 | std::shared_ptr getPlotTransparent2dShader(); 41 | std::shared_ptr getCharacterLoader(); 42 | std::shared_ptr getTextureManager(); 43 | 44 | private: 45 | // DPI Scaling 46 | float xScaleDpi = 1; 47 | float yScaleDpi = 1; 48 | 49 | // Shaders 50 | Shader textShader = Shader("Shaders/font.vs", "Shaders/font.frag"); 51 | Shader plot2dShader = Shader("Shaders/plot2d.vs","Shaders/plot2d.frag"); 52 | Shader plot2dShaderLogx = Shader("Shaders/plot2dLogx.vs","Shaders/plot2d.frag"); 53 | Shader plot2dShaderLogy = Shader("Shaders/plot2dLogy.vs","Shaders/plot2d.frag"); 54 | Shader plot2dShaderLogxLogy = Shader("Shaders/plot2dLogxLogy.vs","Shaders/plot2d.frag"); 55 | Shader scatter2dShader = Shader("Shaders/scatter2d.vs","Shaders/scatter2d.frag"); 56 | Shader scatter2dLogxShader = Shader("Shaders/scatter2dLogx.vs","Shaders/scatter2d.frag"); 57 | Shader scatter2dLogyShader = Shader("Shaders/scatter2dLogy.vs","Shaders/scatter2d.frag"); 58 | Shader scatter2dLogxLogyShader = Shader("Shaders/scatter2dLogxLogy.vs","Shaders/scatter2d.frag"); 59 | Shader textureShader = Shader("Shaders/texture.vs", "Shaders/texture.frag"); 60 | Shader plotPosNeg2DShader = Shader("Shaders/plotPosNeg2d.vs", "Shaders/plotPosNeg2d.frag"); 61 | Shader plotTransparent2dShader = Shader("Shaders/plotTransparent2d.vs", "Shaders/plotTransparent2d.frag"); 62 | 63 | // shared_ptr 64 | std::shared_ptr textShaderPt; 65 | std::shared_ptr plot2dShaderPt; 66 | std::shared_ptr plot2dLogxShaderPt; 67 | std::shared_ptr plot2dLogyShaderPt; 68 | std::shared_ptr plot2dLogxLogyShaderPt; 69 | std::shared_ptr scatter2dShaderPt; 70 | std::shared_ptr scatter2dLogxShaderPt; 71 | std::shared_ptr scatter2dLogyShaderPt; 72 | std::shared_ptr scatter2dLogxLogyShaderPt; 73 | std::shared_ptr textureShaderPt; 74 | std::shared_ptr plotPosNeg2DShaderPt; 75 | std::shared_ptr plotTransparent2dShaderPt; 76 | std::shared_ptr textureMangerPt; 77 | 78 | 79 | // Text 80 | std::shared_ptr characterLoaderPt; 81 | // Textures 82 | TextureManager textureManager = TextureManager(); 83 | 84 | }; 85 | 86 | } 87 | 88 | 89 | #endif //OPENGLPLOTLIVE_PROJ_SHADERSET_H 90 | -------------------------------------------------------------------------------- /src/rendering/TopLevelDrawable.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by tbatt on 17/06/2020. 3 | // 4 | 5 | #include "TopLevelDrawable.h" 6 | 7 | 8 | GLPL::TopLevelDrawable::TopLevelDrawable(float x, float y, int widthPx, int heightPx) : IDrawable() { 9 | // Set 1-to-1 transform for top level 10 | parentTransform = glm::mat4(1.0f); 11 | 12 | // Initialise data 13 | TopLevelDrawable::setPosition(x, y); 14 | TopLevelDrawable::setSize((float)widthPx, (float)heightPx); 15 | } 16 | 17 | void GLPL::TopLevelDrawable::setPosition(float newX, float newY) { 18 | this->x = newX; 19 | this->y = newY; 20 | // Update Transforms 21 | IDrawable::updateTransforms(); 22 | // Update Children 23 | updateChildren(); 24 | } 25 | 26 | void GLPL::TopLevelDrawable::setSize(float newWidth, float newHeight) { 27 | // Overwrite width with max ratio 28 | this->width = 1.0f; 29 | this->height = 1.0f; 30 | // Set size in pixels 31 | this->widthPx = (int)newWidth; 32 | this->heightPx = (int)newHeight; 33 | // Update Transforms; 34 | IDrawable::updateTransforms(); 35 | // Update Children 36 | updateChildren(); 37 | } 38 | 39 | std::pair GLPL::TopLevelDrawable::getSizePx() { 40 | return {this->widthPx, this->heightPx}; 41 | } 42 | 43 | void GLPL::TopLevelDrawable::setParentDimensions(glm::mat4 newParentTransform, 44 | int newParentXPx, 45 | int newParentYPx, 46 | int newParentWidthPx, 47 | int newParentHeightPx) { 48 | // This is already the top level 49 | parentTransform = glm::mat4(1.0f); 50 | parentXPx = 0.0; // Always zero as this is the top level 51 | parentYPx = 0.0; // Always zero as this is the top level 52 | parentWidthPx = getWidthPx(); 53 | parentHeightPx = getHeightPx(); 54 | updateTransforms(); 55 | // Update Children 56 | updateChildren(); 57 | } 58 | 59 | void GLPL::TopLevelDrawable::setParentDimensions(std::shared_ptr parentDimensions) { 60 | // This is already the top level 61 | parentTransform = glm::mat4(1.0f); 62 | parentWidthPx = getWidthPx(); 63 | parentHeightPx = getHeightPx(); 64 | updateTransforms(); 65 | } -------------------------------------------------------------------------------- /src/rendering/TopLevelDrawable.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by tbatt on 17/06/2020. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_TOPLEVELDRAWABLE_H 6 | #define OPENGLPLOTLIVE_PROJ_TOPLEVELDRAWABLE_H 7 | 8 | #include "IDrawable.h" 9 | 10 | 11 | namespace GLPL { 12 | class TopLevelDrawable : public IDrawable { 13 | public: 14 | // Constructor 15 | TopLevelDrawable(float x, float y, int widthPx, int heightPx); 16 | 17 | // Functions 18 | void setPosition(float newX, float newY); 19 | void setSize(float newWidth, float newHeight); 20 | std::pair getSizePx(); 21 | void setParentDimensions(glm::mat4 newParentTransform, 22 | int newParentXPx, 23 | int newParentYPx, 24 | int newParentWidthPx, 25 | int newParentHeightPx); 26 | void setParentDimensions(std::shared_ptr parentDimensions); 27 | 28 | 29 | }; 30 | } 31 | 32 | 33 | #endif //OPENGLPLOTLIVE_PROJ_TOPLEVELDRAWABLE_H 34 | -------------------------------------------------------------------------------- /src/rendering/shader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * shader.h 3 | * 4 | * Created on: 27Dec.,2016 5 | * Author: bcub3d-desktop 6 | */ 7 | 8 | #ifndef P_SHADER_H_ 9 | #define P_SHADER_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | // GLAD - Multi Language GL Loader-Generator 17 | #include 18 | 19 | 20 | namespace GLPL { 21 | class Shader { 22 | public: 23 | // Program ID 24 | GLuint Program; 25 | /* Constructor to build the shader */ 26 | Shader(const GLchar* vertexPath, const GLchar* fragmentPath) { 27 | // Get vertex/fragment source from file path 28 | std::string vertexCode; 29 | std::string fragmentCode; 30 | std::ifstream vShaderFile; 31 | std::ifstream fShaderFile; 32 | // Handle file exceptions 33 | vShaderFile.exceptions(std::ifstream::badbit); 34 | fShaderFile.exceptions(std::ifstream::badbit); 35 | try { 36 | // Open Files 37 | vShaderFile.open(vertexPath); 38 | fShaderFile.open(fragmentPath); 39 | std::stringstream vShaderStream, fShaderStream; 40 | // Read buffer into stream 41 | vShaderStream << vShaderFile.rdbuf(); 42 | fShaderStream << fShaderFile.rdbuf(); 43 | // Close Files 44 | vShaderFile.close(); 45 | fShaderFile.close(); 46 | // Convert stream to GLchar array 47 | vertexCode = vShaderStream.str(); 48 | fragmentCode = fShaderStream.str(); 49 | } catch(std::ifstream::failure & e) { 50 | std::cout << "ERROR::SHADER::FILE_NOT_SUCCESFULLY_READ:\n" << vertexPath << ", " << fragmentPath << '\n'; 51 | } 52 | const GLchar* vShaderCode = vertexCode.c_str(); 53 | const GLchar* fShaderCode = fragmentCode.c_str(); 54 | 55 | /* Compile Shaders */ 56 | GLuint vertex, fragment; 57 | GLint success; 58 | GLchar infoLog[512]; 59 | 60 | // Vertex Shader 61 | vertex = glCreateShader(GL_VERTEX_SHADER); 62 | glShaderSource(vertex,1,&vShaderCode,NULL); 63 | glCompileShader(vertex); 64 | // Check for errors 65 | glGetShaderiv(vertex,GL_COMPILE_STATUS,&success); 66 | if(!success) { 67 | glGetShaderInfoLog(vertex,512,NULL,infoLog); 68 | std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << vertexPath << ", " << fragmentPath << "\n" << infoLog << '\n'; 69 | } 70 | 71 | // Fragment Shader 72 | fragment = glCreateShader(GL_FRAGMENT_SHADER); 73 | glShaderSource(fragment,1,&fShaderCode,NULL); 74 | glCompileShader(fragment); 75 | // Check for errors 76 | glGetShaderiv(fragment,GL_COMPILE_STATUS,&success); 77 | if(!success) { 78 | glGetShaderInfoLog(fragment,512,NULL,infoLog); 79 | std::cout << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << vertexPath << ", " << fragmentPath << "\n" << infoLog << '\n'; 80 | } 81 | 82 | // Shader Program 83 | this->Program = glCreateProgram(); 84 | glAttachShader(this->Program,vertex); 85 | glAttachShader(this->Program,fragment); 86 | glLinkProgram(this->Program); 87 | // Check for linking errors 88 | glGetProgramiv(this->Program,GL_LINK_STATUS,&success); 89 | if(!success) { 90 | glGetProgramInfoLog(this->Program,512,NULL,infoLog); 91 | std::cout << "ERROR::SHADER::PROGRAM::LINKING_FAILED\n" << vertexPath << ", " << fragmentPath << "\n" << infoLog << '\n'; 92 | } 93 | 94 | // Delete Shaders (no longer needed) 95 | glDeleteShader(vertex); 96 | glDeleteShader(fragment); 97 | } 98 | 99 | // Use the program 100 | void Use() { 101 | glUseProgram(this->Program); 102 | } 103 | }; 104 | } 105 | 106 | #endif /* P_SHADER_H_ */ 107 | -------------------------------------------------------------------------------- /src/rendering/transforms.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 8/4/20. 3 | // 4 | 5 | #include "transforms.h" 6 | 7 | namespace GLPL { 8 | // Transform to custom viewports 9 | glm::mat4 Transforms::viewportTransform(float x, float y, float width, float height) { 10 | // Creates transform matrix for a custom sized viewport 11 | // x: The bottom left corner x coordinate (in 0 to 1) 12 | // y: The bottom left corner y coordinate (in 0 to 1) 13 | // width: The width of the new viewport (in 0 to 1) 14 | // height: The height of the new viewport (in 0 to 1) 15 | // Output is in [-1 to 1] 16 | 17 | 18 | // Calculate Center 19 | float xc = x + width/2.0; // 0 to 1 20 | float yc = y + height/2.0; // 0 to 1 21 | 22 | // Convert from [0,1] to [-1,1] 23 | float xn = 2*xc - 1; 24 | float yn = 2*yc - 1; 25 | 26 | // Translate by offset 27 | glm::mat4 trans = glm::translate(glm::mat4(1), glm::vec3(xn, yn, 0)); 28 | 29 | // Scale new viewport 30 | float scaleX = width; 31 | float scaleY = height; 32 | glm::mat4 scale = glm::scale(trans, glm::vec3(scaleX, scaleY, 1)); 33 | 34 | return scale; 35 | }; 36 | } -------------------------------------------------------------------------------- /src/rendering/transforms.h: -------------------------------------------------------------------------------- 1 | /* 2 | * tranforms.h 3 | * 4 | * Created on: 25Feb.,2017 5 | * Author: bcub3d-desktop 6 | */ 7 | 8 | #ifndef P_TRANSFORMS_H_ 9 | #define P_TRANSFORMS_H_ 10 | 11 | // GLM Mathematics 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | namespace GLPL { 18 | 19 | class Transforms { 20 | public: 21 | static glm::mat4 viewportTransform(float x, float y, float width, float height); 22 | }; 23 | 24 | } 25 | 26 | 27 | 28 | #endif /* P_TRANSFORMS_H_ */ 29 | -------------------------------------------------------------------------------- /src/scatterPlot/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Add sources 2 | file(GLOB CPP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) 3 | file(GLOB H_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h) 4 | target_sources(${PROJECT_NAME} PRIVATE ${CPP_FILES}) 5 | target_sources(${PROJECT_NAME} PUBLIC "${H_FILES}") 6 | 7 | # Setup include directories 8 | target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/scatterPlot) -------------------------------------------------------------------------------- /src/scatterPlot/IScatterPlot.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 26/12/20. 3 | // 4 | 5 | #include "IScatterPlot.h" 6 | 7 | 8 | namespace GLPL { 9 | 10 | IScatterPlot::IScatterPlot(std::shared_ptr parentDimensions) : 11 | Plotable(std::move(parentDimensions)) {}; 12 | 13 | void IScatterPlot::setMarkerColour(glm::vec3 newMarkerColour) { 14 | markerColour = newMarkerColour; 15 | } 16 | 17 | void IScatterPlot::setOpacityRatio(float newOpacityRatio) { 18 | opacityRatio = newOpacityRatio; 19 | } 20 | 21 | void IScatterPlot::setMarkerOutlineColour(glm::vec3 newMarkerColour) { 22 | markerOutlineColour = newMarkerColour; 23 | } 24 | 25 | void IScatterPlot::setMarkerSizePx(float newMarkerSizePx) { 26 | markerSizePx = newMarkerSizePx; 27 | 28 | generateAllMarkerVerts(); 29 | } 30 | 31 | void IScatterPlot::setOutlineOpacityRatio(float newOpacityRatio) { 32 | outlineOpacityRatio = newOpacityRatio; 33 | } 34 | 35 | void IScatterPlot::setMarkerType(MarkerType newMarkerType) { 36 | markerType = newMarkerType; 37 | 38 | generateAllMarkerVerts(); 39 | } 40 | 41 | glm::vec3 IScatterPlot::getColour() { 42 | return markerColour; 43 | } 44 | 45 | int IScatterPlot::getHoverCursor() { 46 | return 0; 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /src/scatterPlot/IScatterPlot.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 26/12/20. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_ISCATTERPLOT_H 6 | #define OPENGLPLOTLIVE_PROJ_ISCATTERPLOT_H 7 | 8 | 9 | // Standard Includes 10 | #include 11 | 12 | // Project Includes 13 | #include "../axes/Plotable.h" 14 | #include "../lines/lineColours.h" 15 | 16 | 17 | namespace GLPL { 18 | 19 | enum MarkerType { 20 | MARKER_SQUARE, 21 | MARKER_CIRCLE, 22 | MARKER_DIAMOND, 23 | MARKER_TRIANGLE_DOWN, 24 | MARKER_TRIANGLE_UP, 25 | MARKER_TRIANGLE_LEFT, 26 | MARKER_TRIANGLE_RIGHT 27 | }; 28 | 29 | class IScatterPlot : public Plotable { 30 | public: 31 | 32 | IScatterPlot(std::shared_ptr parentDimensions); 33 | 34 | void setMarkerColour(glm::vec3 newMarkerColour); 35 | void setOpacityRatio(float newOpacityRatio); 36 | void setMarkerOutlineColour(glm::vec3 newMarkerOutlineColour); 37 | void setOutlineOpacityRatio(float newOpacityRatio); 38 | void setMarkerSizePx(float newMarkerSizePx); 39 | void setMarkerType(MarkerType newMarkerType); 40 | glm::vec3 getColour(); 41 | int getHoverCursor() override; 42 | 43 | virtual std::vector getMinMax(bool onlyPositiveX, bool onlyPositiveY) = 0; 44 | virtual void generateAllMarkerVerts() = 0; 45 | 46 | protected: 47 | // Marker Properties 48 | glm::vec3 markerColour = LC_WHITE; 49 | glm::vec3 markerOutlineColour = LC_WHITE; 50 | float opacityRatio = 0.7; 51 | float outlineOpacityRatio = 1.0; 52 | float markerSizePx = 15; // Width/Height of the marker in pixels 53 | MarkerType markerType = MARKER_SQUARE; 54 | 55 | }; 56 | 57 | } 58 | 59 | 60 | #endif //OPENGLPLOTLIVE_PROJ_ISCATTERPLOT_H 61 | -------------------------------------------------------------------------------- /src/scatterPlot/IScatterPlot2D.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 26/12/20. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_ISCATTERPLOT2D_H 6 | #define OPENGLPLOTLIVE_PROJ_ISCATTERPLOT2D_H 7 | 8 | 9 | // Project Includes 10 | #include "IScatterPlot.h" 11 | 12 | 13 | namespace GLPL { 14 | 15 | 16 | class IScatterPlot2D : public IScatterPlot { 17 | public: 18 | IScatterPlot2D(std::shared_ptr parentDimensions); 19 | 20 | void createAndSetupBuffers(int dataSizeBytes, const void *dataAddress, 21 | int markerVertSizeBytes, const void *markerVertsAddress, 22 | int markerOutlineIndicesDataSizeBytes, const void *markerOutlineIndicesDataAddress); 23 | void createAndSetupBuffersMarkerPolygons(int dataSizeBytes, const void *dataAddress, 24 | int markerVertSizeBytes, const void *markerVertsAddress); 25 | void createAndSetupBuffersMarkerOutline(int dataSizeBytes, const void *dataAddress, 26 | int markerOutlineIndicesDataSizeBytes, const void *markerOutlineIndicesDataAddress); 27 | 28 | void createAndSetupLegendBuffers(int dataSizeBytes, const void *dataAddress, 29 | int markerVertSizeBytes, const void *markerVertsAddress, 30 | int markerOutlineIndicesDataSizeBytes, const void *markerOutlineIndicesDataAddress); 31 | void createAndSetupLegendBuffersMarkerPolygons(int dataSizeBytes, const void *dataAddress, 32 | int markerVertSizeBytes, const void *markerVertsAddress); 33 | void createAndSetupLegendBuffersMarkerOutline(int dataSizeBytes, const void *dataAddress, 34 | int markerOutlineIndicesDataSizeBytes, const void *markerOutlineIndicesDataAddress); 35 | 36 | void drawData(int nPts, bool selected); 37 | 38 | void drawLegendEntry(glm::mat4 rectOverallTransform); 39 | 40 | protected: 41 | // Line Buffers 42 | GLuint scatterVAO, scatterVBO; 43 | GLuint markerVBO; 44 | GLuint scatterOutlineVAO, scatterOutlineVBO; 45 | GLuint markerOutlineVBO; 46 | 47 | GLuint legendScatterVAO, legendScatterVBO; 48 | GLuint legendMarkerVBO; 49 | GLuint legendScatterOutlineVAO, legendScatterOutlineVBO; 50 | GLuint legendMarkerOutlineVBO; 51 | 52 | // Marker Vertices 53 | std::vector markerVerts = {}; // positions (2) 54 | std::vector markerOutlineVerts = {}; 55 | 56 | std::vector legendMarkerData = {0.0f, 0.0f}; 57 | 58 | // Functions 59 | std::shared_ptr selectShader(); 60 | void generateAllMarkerVerts(); 61 | void generateMarkerEquallySpaced(unsigned int nCirclePoints, float thetaRadStart, float xHalfWidth, float yHalfHeight); 62 | void generateMarkerSquareVerts(float xHalfWidth, float yHalfHeight); 63 | void generateMarkerCircleVerts(float xHalfWidth, float yHalfHeight); 64 | 65 | void drawLegendMarker(glm::mat4 rectOverallTransform, bool selected); 66 | 67 | 68 | }; 69 | 70 | } 71 | 72 | 73 | #endif //OPENGLPLOTLIVE_PROJ_ISCATTERPLOT2D_H 74 | -------------------------------------------------------------------------------- /src/scatterPlot/Scatter2D2Vecs.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 26/12/20. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_SCATTER2D2VECS_H 6 | #define OPENGLPLOTLIVE_PROJ_SCATTER2D2VECS_H 7 | 8 | 9 | #include "IScatterPlot2D.h" 10 | 11 | namespace GLPL { 12 | 13 | 14 | class Scatter2D2Vecs : public IScatterPlot2D { 15 | // Two vectors corresponding to an x vector and a y vector 16 | public: 17 | // Constructor 18 | Scatter2D2Vecs(std::vector* dataPtX, std::vector* dataPtY, 19 | std::shared_ptr parentDimensions); 20 | 21 | 22 | // Functions 23 | void updateInternalData(); 24 | void updateIncrementalInternalData(); 25 | void Draw(); 26 | std::string getID(); 27 | void clearData(); 28 | std::vector getMinMax(bool onlyPositiveX, bool onlyPositiveY); 29 | std::tuple getClosestPoint(float xVal); 30 | std::tuple getClosestPoint(float xVal, float xmin, float xmax, float ymin, float ymax); 31 | 32 | 33 | std::vector* dataPtX; 34 | std::vector* dataPtY; 35 | 36 | private: 37 | // Data 38 | int nPts = 0; 39 | 40 | std::vector internalData; 41 | 42 | }; 43 | 44 | } 45 | 46 | 47 | #endif //OPENGLPLOTLIVE_PROJ_SCATTER2D2VECS_H 48 | -------------------------------------------------------------------------------- /src/shadedLines/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Add sources 2 | file(GLOB CPP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) 3 | file(GLOB H_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h) 4 | target_sources(${PROJECT_NAME} PRIVATE ${CPP_FILES}) 5 | target_sources(${PROJECT_NAME} PUBLIC "${H_FILES}") 6 | 7 | # Setup include directories 8 | target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/shadedLines) -------------------------------------------------------------------------------- /src/shadedLines/IShadedLine2D.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by tbatt on 12/04/2020. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_ISHADEDLINE2D_H 6 | #define OPENGLPLOTLIVE_PROJ_ISHADEDLINE2D_H 7 | 8 | // GLFW (Multi-platform library for OpenGL) 9 | #include 10 | 11 | // GLM Mathematics 12 | #include 13 | #include 14 | #include 15 | 16 | // Project Includes 17 | #include "../rendering/shader.h" 18 | #include "../lines/lineColours.h" 19 | #include "../axes/Plotable.h" 20 | #include "../lines/ILine2D.h" 21 | 22 | // Standard Includes 23 | #include 24 | 25 | 26 | namespace GLPL { 27 | class IShadedLine2D : public ILine2D { 28 | public: 29 | IShadedLine2D(std::shared_ptr parentDimensions); 30 | 31 | void createAndSetupBuffers(int vertDataSizeBytes, int indicesDataSizeBytes, 32 | const void *vertDataAddress, const void *indicesDataAddress, 33 | int strideBytes, int glType=GL_FLOAT); 34 | void createAndSetupLegendBuffers(int vertDataSizeBytes, int indicesDataSizeBytes, 35 | const void *vertDataAddress, const void *indicesDataAddress, 36 | int strideBytes, int glType=GL_FLOAT); 37 | void drawData(int numIndices, bool selected); 38 | int getHoverCursor(); 39 | 40 | void drawLegendEntry(glm::mat4 rectOverallTransform); 41 | 42 | protected: 43 | // Line Buffers 44 | GLuint lineVAO, lineVBO, lineEBO; 45 | GLuint legendLineVAO, legendLineVBO, legendLineEBO; 46 | 47 | std::vector legendData = {0.0f, 0.0f, 48 | -1.0f, 0.0f, 49 | -1.0f, -1.0f, 50 | 1.0f, 0.0f, 51 | 1.0f, 1.0f}; 52 | std::vector legendIndices = {0, 1, 2, 53 | 0, 3, 4}; 54 | 55 | // Functions 56 | std::shared_ptr selectShader(); 57 | 58 | void drawLegendArea(glm::mat4 rectOverallTransform, bool selected); 59 | 60 | }; 61 | } 62 | 63 | #endif //OPENGLPLOTLIVE_PROJ_ISHADEDLINE2D_H 64 | -------------------------------------------------------------------------------- /src/shadedLines/ShadedLine2D2CircularVecs.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by tbatt on 12/04/2020. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_SHADEDLINE2D2CIRCULARVECS_H 6 | #define OPENGLPLOTLIVE_PROJ_SHADEDLINE2D2CIRCULARVECS_H 7 | 8 | #include "IShadedLine2D.h" 9 | 10 | 11 | namespace GLPL { 12 | class ShadedLine2D2CircularVecs : public IShadedLine2D { 13 | // Two vectors corresponding to an x vector and a y vector 14 | // An index specifies the 'start' of the vector 15 | // The resultant vector is from the index to the end of the vector, plus 16 | // the start to the index. 17 | // This operates similar to a circular buffer. 18 | public: 19 | /* Constructor */ 20 | ShadedLine2D2CircularVecs(std::vector *dataPtX, std::vector *dataPtY, 21 | std::shared_ptr parentDimensions, GLenum mode = GL_TRIANGLES); 22 | 23 | /* Destructor */ 24 | ~ShadedLine2D2CircularVecs(); 25 | 26 | /* Functions */ 27 | void updateInternalData(unsigned int currIndex); 28 | void updateIncrementalInternalData(); 29 | void Draw(); 30 | std::string getID(); 31 | std::vector getMinMax(bool onlyPositiveX, bool onlyPositiveY); 32 | std::tuple getClosestPoint(float xVal); 33 | std::tuple getClosestPoint(float xVal, float xmin, float xmax, float ymin, float ymax); 34 | 35 | std::vector* dataPtX; 36 | std::vector* dataPtY; 37 | 38 | private: 39 | /* Data */ 40 | bool updated = false; 41 | int nIndices = 0; 42 | std::vector internalData; 43 | std::vector internalIndices; 44 | // Sorted data for interactor 45 | std::vector sortedInternalData; 46 | 47 | }; 48 | 49 | 50 | } 51 | 52 | #endif //OPENGLPLOTLIVE_PROJ_SHADEDLINE2D2CIRCULARVECS_H 53 | -------------------------------------------------------------------------------- /src/shapes/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Add sources 2 | file(GLOB CPP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) 3 | file(GLOB H_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h) 4 | target_sources(${PROJECT_NAME} PRIVATE ${CPP_FILES}) 5 | target_sources(${PROJECT_NAME} PUBLIC "${H_FILES}") 6 | 7 | # Setup include directories 8 | target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/shapes) -------------------------------------------------------------------------------- /src/shapes/Rectangle.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 20/11/22. 3 | // 4 | 5 | #include "Rectangle.h" 6 | 7 | 8 | namespace GLPL { 9 | 10 | Rectangle::Rectangle(float x, float y, float width, float height, 11 | std::shared_ptr parentDimensions) : 12 | ConstantXYDrawable(x, y, width, height, 13 | CONSTANT_SCALE, CONSTANT_SCALE, 14 | std::move(parentDimensions)) { 15 | 16 | // Set bounding box color 17 | boundingBoxColor = glm::vec4(0.6f, 0.6f, 1.0f, 1.0f); 18 | 19 | 20 | // Setup Buffers 21 | createAndSetupRectBuffers(); 22 | 23 | 24 | } 25 | 26 | 27 | 28 | void Rectangle::Draw() { 29 | // Draw rectangle box 30 | std::shared_ptr shader = shaderSetPt->getPlot2dShader(); 31 | shader->Use(); 32 | 33 | // Draw background 34 | glUniformMatrix4fv(glGetUniformLocation(shader->Program,"transformViewport"), 1, GL_FALSE, glm::value_ptr(overallTransform)); 35 | glUniform4fv(glGetUniformLocation(shader->Program,"inColor"),1,glm::value_ptr(backgroundColor)); 36 | glBindVertexArray(rectSolidVAO); 37 | glDrawArrays(GL_TRIANGLES,0,6); 38 | glBindVertexArray(0); 39 | 40 | // Draw outline 41 | glUniformMatrix4fv(glGetUniformLocation(shader->Program,"transformViewport"), 1, GL_FALSE, glm::value_ptr(overallTransform)); 42 | glUniform4fv(glGetUniformLocation(shader->Program,"inColor"),1,glm::value_ptr(outlineColor)); 43 | glBindVertexArray(rectOutlineVAO); 44 | glDrawArrays(GL_LINE_LOOP,0,4); 45 | glBindVertexArray(0); 46 | 47 | 48 | // Draw bounding box of children 49 | for(auto & i : children) { 50 | i->drawBoundingBox(); 51 | } 52 | 53 | } 54 | 55 | std::string Rectangle::getID() { 56 | return std::string(); 57 | } 58 | 59 | void Rectangle::createAndSetupRectBuffers() { 60 | // Background shape 61 | // Create Buffers 62 | glGenVertexArrays(1,&rectSolidVAO); 63 | glGenBuffers(1,&rectSolidVBO); 64 | 65 | // Setup Buffers 66 | glBindVertexArray(rectSolidVAO); 67 | glBindBuffer(GL_ARRAY_BUFFER,rectSolidVBO); 68 | glBufferData(GL_ARRAY_BUFFER, rectSolidVerts.size()*sizeof(GLfloat),&rectSolidVerts[0],GL_STATIC_DRAW); 69 | 70 | // Position Attributes 71 | glEnableVertexAttribArray(0); 72 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid*)0); 73 | 74 | glBindVertexArray(0); 75 | 76 | // Outline shape 77 | // Create Buffers 78 | glGenVertexArrays(1,&rectOutlineVAO); 79 | glGenBuffers(1,&rectOutlineVBO); 80 | 81 | // Setup Buffers 82 | glBindVertexArray(rectOutlineVAO); 83 | glBindBuffer(GL_ARRAY_BUFFER,rectOutlineVBO); 84 | glBufferData(GL_ARRAY_BUFFER, rectOutlineVerts.size()*sizeof(GLfloat),&rectOutlineVerts[0],GL_STATIC_DRAW); 85 | 86 | // Position Attributes 87 | glEnableVertexAttribArray(0); 88 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid*)0); 89 | 90 | glBindVertexArray(0); 91 | 92 | } 93 | 94 | void Rectangle::setOutlineColor(glm::vec4 newColor) { 95 | outlineColor = newColor; 96 | } 97 | 98 | void Rectangle::setBackgroundColor(glm::vec4 newColor) { 99 | backgroundColor = newColor; 100 | } 101 | 102 | 103 | } 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /src/shapes/Rectangle.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 20/11/22. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_RECTANGLE_H 6 | #define OPENGLPLOTLIVE_PROJ_RECTANGLE_H 7 | 8 | 9 | #include "../rendering/ConstantXYDrawable.h" 10 | 11 | 12 | 13 | namespace GLPL { 14 | 15 | class Rectangle : public ConstantXYDrawable { 16 | public: 17 | // Constructor 18 | Rectangle(float x, float y, float width, float height, 19 | std::shared_ptr parentDimensions); 20 | 21 | // Functions 22 | void Draw(); 23 | std::string getID(); 24 | void setBackgroundColor(glm::vec4 newColor); 25 | void setOutlineColor(glm::vec4 newColor); 26 | 27 | 28 | private: 29 | // Functions 30 | void createAndSetupRectBuffers(); 31 | 32 | // Data 33 | int nPts = 0; 34 | glm::vec4 backgroundColor = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); 35 | glm::vec4 outlineColor = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); 36 | 37 | // Line Buffers 38 | GLuint rectSolidVAO, rectSolidVBO; 39 | GLuint rectOutlineVAO, rectOutlineVBO; 40 | 41 | // Vertices 42 | std::vector rectSolidVerts = {-1.0f, -1.0f, 43 | -1.0f, 1.0f, 44 | 1.0f, 1.0f, 45 | -1.0f, -1.0f, 46 | 1.0f, 1.0f, 47 | 1.0f, -1.0f}; 48 | std::vector rectOutlineVerts = {-1.0f, -1.0f, 49 | -1.0f, 1.0f, 50 | 1.0f, 1.0f, 51 | 1.0f, -1.0f}; 52 | 53 | 54 | }; 55 | 56 | 57 | } 58 | 59 | #endif //OPENGLPLOTLIVE_PROJ_RECTANGLE_H 60 | -------------------------------------------------------------------------------- /src/texts/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Add sources 2 | file(GLOB CPP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) 3 | file(GLOB H_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h) 4 | target_sources(${PROJECT_NAME} PRIVATE ${CPP_FILES}) 5 | target_sources(${PROJECT_NAME} PUBLIC "${H_FILES}") 6 | 7 | # Setup include directories 8 | target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/texts) -------------------------------------------------------------------------------- /src/texts/CharacterLoader.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by tbatt on 19/04/2020. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_CHARACTERLOADER_H 6 | #define OPENGLPLOTLIVE_PROJ_CHARACTERLOADER_H 7 | 8 | // Standard Includes 9 | #include 10 | #include 11 | 12 | // GLAD - Multi Language GL Loader-Generator 13 | #include 14 | 15 | // GLFW (Multi-platform library for OpenGL) 16 | #include 17 | 18 | // GLM Mathematics 19 | #include 20 | #include 21 | #include 22 | 23 | // Free Type Library 24 | #include 25 | #include FT_FREETYPE_H 26 | 27 | 28 | namespace GLPL { 29 | // Character Structure 30 | struct Character { 31 | GLuint TextureID; // ID handle of the glyph texture 32 | glm::ivec2 Size; // Size of glyph 33 | glm::ivec2 Bearing; // Offset from baseline to left/top of glyph 34 | GLuint Advance; // Offset to advance to next glyph 35 | }; 36 | 37 | struct Character3 { 38 | // See https://www.freetype.org/freetype2/docs/glyphs/glyphs-3.html 39 | GLuint TextureID; // ID handle of the glyph texture 40 | int width; // Width of glyph 41 | int height; // Height of glyph 42 | int bearingX; // Horizontal distance to the left of the glyph from the origin 43 | int bearingY; // Vertical distance to the top of the glyph from the origin 44 | int advance; // Distance from the origin to the right edge of the area surrounding the glyph 45 | }; 46 | 47 | struct TextFontDimensions { 48 | int width; // Total width 49 | int height; // Total height 50 | int yOffset; // The offset from the origin line to the bottom left hand corner 51 | }; 52 | 53 | struct TextPixelDimensions { 54 | float width; // Total width 55 | float height; // Total height 56 | float yOffset; // The offset from the origin line to the bottom left hand corner 57 | }; 58 | 59 | 60 | struct StringFontDimensions { 61 | int width; // Total width in font space 62 | int height; // Total height in font space 63 | int yOffset; // Vertical offset from top edge to the origin line, in font space 64 | }; 65 | 66 | struct StringPixelDimensions { 67 | float width; // Total width in pixels 68 | float height; // Total height in pixels 69 | float yOffset; // Vertical offset in pixel space 70 | }; 71 | 72 | struct StringDimensions { 73 | StringFontDimensions fontDims; 74 | StringPixelDimensions pixelDims; 75 | }; 76 | 77 | 78 | class CharacterLoader { 79 | public: 80 | // Constructor 81 | CharacterLoader(const GLchar* fontPath); 82 | std::shared_ptr getCharacter(const char reqCharacter); 83 | glm::vec2 calcPixelsPerEmSquare(int fontSize); 84 | TextFontDimensions getStringFontDimensions(std::string newString); 85 | 86 | 87 | int getEmSquareSize(); 88 | 89 | private: 90 | // Data 91 | std::map> Characters; 92 | GLuint VAO, VBO; 93 | // Freetype 94 | FT_Library ft; 95 | FT_Face face; 96 | // Font Size 97 | float ptInPixels = 1; 98 | float ptInPerHeight = 1; 99 | float unitsPerEm = 1; 100 | float dpiX = 1; 101 | float dpiY = 1; 102 | float inch2Mm = 25.4; 103 | int emSquareSize = 2048; 104 | 105 | // Functions 106 | void loadFont(const GLchar* fontPath); 107 | void loadGlyphs(); 108 | void createAndSetupBuffers(); 109 | void determineScaling(); 110 | }; 111 | } 112 | 113 | #endif //OPENGLPLOTLIVE_PROJ_CHARACTERLOADER_H 114 | -------------------------------------------------------------------------------- /src/texts/TextString.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by tbatt on 19/04/2020. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_TEXTSTRING_H 6 | #define OPENGLPLOTLIVE_PROJ_TEXTSTRING_H 7 | 8 | // Project Includes 9 | #include "../rendering/ConstantXYDrawable.h" 10 | 11 | 12 | namespace GLPL {; 13 | 14 | enum TextRotation { 15 | HORIZONTAL, 16 | SIDEWAYS_RIGHT, 17 | UPSIDE_DOWN, 18 | SIDEWAYS_LEFT 19 | }; 20 | 21 | class TextString : public ConstantXYDrawable { 22 | public: 23 | // Constructor 24 | TextString(const std::string& textString, float x, float y, float fontSize, std::shared_ptr parentDimensions); 25 | 26 | // Functions 27 | void Draw(); 28 | std::string getID(); 29 | void setTextString(std::string newTextString); 30 | std::string getTextString(); 31 | void setTextColor(glm::vec3 textColor); 32 | void setFontSize(float fontSize); 33 | void setTextRotation(TextRotation newTextRotation); 34 | 35 | 36 | private: 37 | // Functions 38 | void createAndSetupFontBuffers(); 39 | void updateTextDimensions(); 40 | void generateVertices(); 41 | void generateVerticesHorizontal(); 42 | void generateVerticesUpsideDown(); 43 | void generateVerticesSidewaysRight(); 44 | void generateVerticesSidewaysLeft(); 45 | void drawText(); 46 | 47 | // Buffers 48 | GLuint textVAO, textVBO; 49 | 50 | // Data 51 | std::shared_ptr characterLoader; 52 | // Text Attributes 53 | std::string textString = ""; 54 | float fontSize = 12; 55 | glm::vec3 textColor = glm::vec3(1.0f); 56 | // Text Dimensions 57 | TextFontDimensions textFontDimensions; 58 | glm::vec2 fontPixelFactor = glm::vec2(1.0f); // Font space to pixel space conversion factors 59 | glm::vec2 pixelRelativeFactor = glm::vec2(1.0f); // Pixel space to axes relative space conversion factors, without origin translate 60 | // Font Polygon Vertices List 61 | std::vector, 6>> verticesList; // In Axes relative space 62 | // Rotation 63 | TextRotation textRotation = HORIZONTAL; 64 | 65 | }; 66 | } 67 | 68 | #endif //OPENGLPLOTLIVE_PROJ_TEXTSTRING_H 69 | -------------------------------------------------------------------------------- /src/textures/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Add sources 2 | file(GLOB CPP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) 3 | file(GLOB H_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h) 4 | target_sources(${PROJECT_NAME} PRIVATE ${CPP_FILES}) 5 | target_sources(${PROJECT_NAME} PUBLIC "${H_FILES}") 6 | 7 | # Setup include directories 8 | target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/textures) -------------------------------------------------------------------------------- /src/textures/TextureManager.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-laptop-dell on 23/12/20. 3 | // 4 | 5 | // Opengl Includes 6 | #include 7 | 8 | // Texture Loading Includes 9 | #define STB_IMAGE_IMPLEMENTATION 10 | #include "stb_image.h" 11 | 12 | // Standard Includes 13 | #include 14 | 15 | // Project Includes 16 | #include "TextureManager.h" 17 | 18 | #include 19 | #include 20 | 21 | 22 | namespace GLPL { 23 | 24 | 25 | GLPL::TextureManager::TextureManager() { 26 | TextureManager::loadPngTextures(); 27 | 28 | } 29 | 30 | void TextureManager::loadTexture(const std::string& textureName, const char* texturePath) { 31 | // Bind to new texture 32 | unsigned int texture; 33 | glGenTextures(1, &texture); 34 | glBindTexture(GL_TEXTURE_2D, texture); 35 | 36 | // Set wrapping/filtering options 37 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 38 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 39 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 40 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 41 | 42 | // Load the texture 43 | int width, height, nrChannels; 44 | unsigned char *data = stbi_load(texturePath, &width, &height, &nrChannels, 0); 45 | 46 | // Cheek Result 47 | if (data) { 48 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); 49 | glGenerateMipmap(GL_TEXTURE_2D); 50 | } else { 51 | std::cout << "Failed to load texture! - " << texturePath << std::endl; 52 | } 53 | 54 | // Free the data 55 | stbi_image_free(data); 56 | 57 | // Store in map 58 | textureMap.insert(std::pair(textureName, texture)); 59 | 60 | } 61 | 62 | unsigned int TextureManager::getTextureId(std::string textureName) { 63 | if (textureMap.count(textureName) > 0) { 64 | return textureMap.at(textureName); 65 | } else { 66 | std::cout << "Texture " << textureName << " not found in texture map!" << std::endl; 67 | return 0; 68 | } 69 | } 70 | 71 | std::vector TextureManager::getFilesInDir() { 72 | std::vector files; 73 | DIR *dir = opendir("textures"); 74 | if (!dir) { 75 | std::cout << "Texture directory does not exist!" << std::endl; 76 | } else { 77 | dirent *entry; 78 | while ((entry = readdir(dir)) != nullptr) { 79 | files.emplace_back(entry->d_name); 80 | } 81 | } 82 | closedir(dir); 83 | 84 | return files; 85 | } 86 | 87 | bool TextureManager::hasExt(const std::string &str, const std::string &suffix) { 88 | return str.size() >= suffix.size() && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; 89 | } 90 | 91 | void TextureManager::loadPngTextures() { 92 | std::vector files = TextureManager::getFilesInDir(); 93 | 94 | for(const auto& file : files) { 95 | if (TextureManager::hasExt(file, ".png")) { 96 | std::string noExt = file.substr(0, file.size()-4); 97 | std::string path = "textures/" + file; 98 | TextureManager::loadTexture(noExt, path.c_str()); 99 | } 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/textures/TextureManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-laptop-dell on 23/12/20. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_TEXTUREMANAGER_H 6 | #define OPENGLPLOTLIVE_PROJ_TEXTUREMANAGER_H 7 | 8 | // Standard Includes 9 | #include 10 | #include 11 | 12 | 13 | namespace GLPL { 14 | 15 | class TextureManager { 16 | public: 17 | // Constructor 18 | TextureManager(); 19 | 20 | // Functions 21 | void loadTexture(const std::string& textureName, const char* texturePath); 22 | unsigned int getTextureId(std::string textureName); 23 | 24 | private: 25 | // Data 26 | std::unordered_map textureMap; 27 | 28 | // Functions 29 | std::vector getFilesInDir(); 30 | bool hasExt(const std::string &str, const std::string &suffix); 31 | void loadPngTextures(); 32 | }; 33 | 34 | } 35 | 36 | #endif //OPENGLPLOTLIVE_PROJ_TEXTUREMANAGER_H 37 | -------------------------------------------------------------------------------- /src/util/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Add sources 2 | file(GLOB CPP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) 3 | file(GLOB H_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h) 4 | target_sources(${PROJECT_NAME} PRIVATE ${CPP_FILES}) 5 | target_sources(${PROJECT_NAME} PUBLIC "${H_FILES}") 6 | 7 | # Setup include directories 8 | target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/util) -------------------------------------------------------------------------------- /src/util/util.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-laptop-dell on 11/12/20. 3 | // 4 | 5 | #include "util.h" 6 | 7 | namespace GLPL { 8 | 9 | 10 | int binarySearch(std::vector data, unsigned int leftInd, unsigned int rightInd, 11 | float inVal, unsigned int dataLen) { 12 | // Format is [x1, y1, ..., n1, x2, y2, ..., n2, ...] 13 | // Take every second first index 14 | // dataLen is the distance between successive x values 15 | int m = 0; 16 | while (leftInd <= rightInd) { 17 | m = (int)floor((double)(leftInd + rightInd) / 2.0f); 18 | if (leftInd == rightInd - 1 || leftInd == rightInd) { 19 | return leftInd; 20 | } else if (data[dataLen*m] < inVal) { 21 | leftInd = m ; 22 | } else if (data[dataLen*m] > inVal) { 23 | rightInd = m; 24 | } else { 25 | return m; 26 | } 27 | 28 | } 29 | return -1; 30 | } 31 | 32 | float clip(float inVal, float minVal, float maxVal) { 33 | return std::max(minVal, std::min(inVal, maxVal)); 34 | } 35 | 36 | float logWithBase(float value2Log, float logBase) { 37 | return std::log(value2Log) / std::log(logBase); 38 | } 39 | 40 | float logWithBase(float value2Log, unsigned int logBase) { 41 | return std::log(value2Log) / (float)std::log(logBase); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/util/util.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-laptop-dell on 11/12/20. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_UTIL_H 6 | #define OPENGLPLOTLIVE_PROJ_UTIL_H 7 | 8 | // Standard Includes 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | # define M_PI 3.14159265358979323846 /* pi */ 15 | 16 | 17 | namespace GLPL { 18 | 19 | int binarySearch(std::vector data, unsigned int leftInd, unsigned int rightInd, float inVal, unsigned int dataLen=2); 20 | float clip(float inVal, float minVal, float maxVal); 21 | float logWithBase(float value2Log, float logBase); 22 | float logWithBase(float value2Log, unsigned int logBase); 23 | 24 | } 25 | 26 | 27 | #endif //OPENGLPLOTLIVE_PROJ_UTIL_H 28 | -------------------------------------------------------------------------------- /src/window/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Add sources 2 | file(GLOB CPP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) 3 | file(GLOB H_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h) 4 | target_sources(${PROJECT_NAME} PRIVATE ${CPP_FILES}) 5 | target_sources(${PROJECT_NAME} PUBLIC ${H_FILES}) 6 | 7 | # Setup include directories 8 | target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/window) -------------------------------------------------------------------------------- /src/window/FramelessDraggableWindow.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by tbatt on 13/04/2020. 3 | // 4 | 5 | #include "FramelessDraggableWindow.h" 6 | 7 | namespace GLPL { 8 | 9 | FramelessDraggableWindow::FramelessDraggableWindow(int windowWidth, int windowHeight, bool transparentBackground, 10 | bool alwaysOnTop) : 11 | GLPL::Window(windowWidth, windowHeight, transparentBackground, false) { 12 | // Set background color 13 | this->setFrameless(true); 14 | this->setAlwaysOnTop(alwaysOnTop); 15 | 16 | // Setup input callbacks 17 | glfwSetMouseButtonCallback(this->getWindow(), mouse_button_callback); 18 | glfwSetCursorPosCallback(this->getWindow(), cursor_position_callback); 19 | 20 | } 21 | 22 | void FramelessDraggableWindow::showWindow() { 23 | glfwShowWindow(this->getWindow()); 24 | } 25 | 26 | void FramelessDraggableWindow::hideWindow() { 27 | glfwHideWindow(this->getWindow()); 28 | } 29 | 30 | void FramelessDraggableWindow::mouse_button_callback(GLFWwindow* window, int button, int action, int mods) { 31 | // Get Window class 32 | GLPL::FramelessDraggableWindow* windowPt = (GLPL::FramelessDraggableWindow*) glfwGetWindowUserPointer(window); 33 | if (button == GLFW_MOUSE_BUTTON_LEFT) { 34 | if (action == GLFW_PRESS) { 35 | windowPt->mouseHeld = true; 36 | // Update stored cursor position 37 | double x, y; 38 | glfwGetCursorPos(window, &x, &y); 39 | windowPt->cursorX = floor(x); 40 | windowPt->cursorY = floor(y); 41 | } else if (action == GLFW_RELEASE) { 42 | windowPt->mouseHeld = false; 43 | windowPt->cursorX = 0; 44 | windowPt->cursorY = 0; 45 | } 46 | } 47 | } 48 | 49 | void FramelessDraggableWindow::cursor_position_callback(GLFWwindow *window, double x, double y) { 50 | // Get Window class 51 | GLPL::FramelessDraggableWindow* windowPt = (GLPL::FramelessDraggableWindow*) glfwGetWindowUserPointer(window); 52 | if (windowPt->mouseHeld) { 53 | windowPt->xOffset = (int)x - windowPt->cursorX; 54 | windowPt->yOffset = (int)y - windowPt->cursorY; 55 | 56 | int winPosX, winPosY; 57 | glfwGetWindowPos(window, &winPosX, &winPosY); 58 | glfwSetWindowPos(window, winPosX + windowPt->xOffset, winPosY + windowPt->yOffset); 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /src/window/FramelessDraggableWindow.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by tbatt on 13/04/2020. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_PROJ_FRAMELESSDRAGGABLEWINDOW_H 6 | #define OPENGLPLOTLIVE_PROJ_FRAMELESSDRAGGABLEWINDOW_H 7 | 8 | // GLM Mathematics 9 | #include 10 | 11 | // Project Includes 12 | #include "window.h" 13 | 14 | 15 | namespace GLPL { 16 | class FramelessDraggableWindow : public GLPL::Window { 17 | public: 18 | // Constructor 19 | FramelessDraggableWindow(int windowWidth, int windowHeight, bool transparentBackground, 20 | bool alwaysOnTop); 21 | 22 | // Functions 23 | void showWindow(); 24 | void hideWindow(); 25 | 26 | private: 27 | // Functions 28 | static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods); 29 | static void cursor_position_callback(GLFWwindow* window, double x, double y); 30 | 31 | // Data 32 | bool mouseHeld = false; 33 | int cursorX = 0; 34 | int cursorY = 0; 35 | int xOffset = 0; 36 | int yOffset = 0; 37 | }; 38 | 39 | } 40 | 41 | 42 | #endif //OPENGLPLOTLIVE_PROJ_FRAMELESSDRAGGABLEWINDOW_H 43 | -------------------------------------------------------------------------------- /src/window/IWindow.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 28/3/20. 3 | // 4 | 5 | #include "IWindow.h" 6 | 7 | 8 | namespace GLPL { 9 | IWindow::IWindow() { 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/window/IWindow.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 28/3/20. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_IWINDOW_H 6 | #define OPENGLPLOTLIVE_IWINDOW_H 7 | 8 | // GLFW (Multi-platform library for OpenGL) 9 | #include 10 | #include "../rendering/IDrawable.h" 11 | 12 | 13 | namespace GLPL { 14 | 15 | class IWindow { 16 | public: 17 | IWindow(); 18 | 19 | virtual GLFWwindow *getWindow() = 0; 20 | virtual void Draw() = 0; 21 | }; 22 | 23 | } 24 | 25 | 26 | #endif //OPENGLPLOTLIVE_IWINDOW_H 27 | -------------------------------------------------------------------------------- /src/window/inputCallbacks.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by bcub3d-desktop on 28/3/20. 3 | // 4 | 5 | #ifndef OPENGLPLOTLIVE_INPUTCALLBACKS_H 6 | #define OPENGLPLOTLIVE_INPUTCALLBACKS_H 7 | 8 | // GLFW (Multi-platform library for OpenGL) 9 | #include 10 | 11 | // Project Includes 12 | #include "window.h" 13 | 14 | namespace GLPL { 15 | 16 | static void key_callback(GLFWwindow *window, int key, int scancode, int action, int mode) { 17 | // Get Window class 18 | GLPL::Window *windowPt = (GLPL::Window *) glfwGetWindowUserPointer(window); 19 | // ESC to close window 20 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) { 21 | glfwSetWindowShouldClose(window, GL_TRUE); 22 | } 23 | // Set key states 24 | if (action == GLFW_PRESS) { 25 | windowPt->setKeysByIndex(key, true, mode); 26 | // Set toggle states 27 | windowPt->setToggleKeysByIndex(key, !windowPt->getToggleKeyStateByIndex(key, mode), mode); 28 | } else if (action == GLFW_RELEASE) { 29 | windowPt->setKeysByIndex(key, false, mode); 30 | } 31 | 32 | // Handle selection 33 | windowPt->updateSelection(); 34 | } 35 | 36 | static void reDraw(GLFWwindow *window, int width, int height) { 37 | // Get Window class 38 | auto *windowPt = (GLPL::Window *) glfwGetWindowUserPointer(window); 39 | // Redraw window on resize 40 | windowPt->updateStoredSize(width, height); 41 | 42 | } 43 | 44 | static void mouseCallback(GLFWwindow *window, int button, int action, int mods) { 45 | // Get Window class 46 | auto *windowPt = (GLPL::Window *) glfwGetWindowUserPointer(window); 47 | // Handle mouse click 48 | windowPt->handleMouseClick(button, action, mods); 49 | 50 | } 51 | 52 | static void cursorMoved(GLFWwindow *window, double xpos, double ypos) { 53 | // Get Window class 54 | auto *windowPt = (GLPL::Window *) glfwGetWindowUserPointer(window); 55 | // Handle mouse movement 56 | windowPt->handleMouseMovement(xpos, ypos); 57 | } 58 | 59 | static void mouseScrolled(GLFWwindow* window, double xoffset, double yoffset) { 60 | // Get Window class 61 | auto *windowPt = (GLPL::Window *) glfwGetWindowUserPointer(window); 62 | // Handle scrolling 63 | windowPt->handleMouseScroll(xoffset, yoffset); 64 | } 65 | } 66 | 67 | 68 | #endif //OPENGLPLOTLIVE_INPUTCALLBACKS_H 69 | -------------------------------------------------------------------------------- /src/window/window.h: -------------------------------------------------------------------------------- 1 | /* 2 | * window.h 3 | * 4 | * Created on: 29Mar.,2017 5 | * Author: bcub3d-desktop 6 | */ 7 | 8 | #ifndef P_WINDOW_H_ 9 | #define P_WINDOW_H_ 10 | 11 | // GLAD - Multi Language GL Loader-Generator 12 | #include 13 | 14 | // GLFW (Multi-platform library for OpenGL) 15 | #include 16 | 17 | // Standard Includes 18 | #include 19 | #include 20 | 21 | // Project Includes 22 | #include "IWindow.h" 23 | #include "../rendering/IDrawable.h" 24 | #include "../plot/plot.h" 25 | #include "../rendering/TopLevelDrawable.h" 26 | 27 | 28 | namespace GLPL { 29 | 30 | enum CurrentAction { 31 | NO_ACTION, 32 | LEFT_MOUSE_PRESSED, 33 | LEFT_MOUSE_DRAG, 34 | LEFT_MOUSE_SHIFT_PRESSED, 35 | LEFT_MOUSE_SHIFT_DRAG, 36 | MIDDLE_MOUSE_PRESSED, 37 | MIDDLE_MOUSE_DRAG, 38 | RIGHT_MOUSE_PRESSED, 39 | RIGHT_MOUSE_DRAG, 40 | RIGHT_MOUSE_SHIFT_PRESSED, 41 | RIGHT_MOUSE_SHIFT_DRAG 42 | }; 43 | 44 | class Window : public IWindow, TopLevelDrawable { 45 | public: 46 | // Constructor 47 | Window(int windowWidth, int windowHeight, bool printSelected = false, bool transparentBackground = GLFW_FALSE, bool focusOnShow = GLFW_FALSE); 48 | ~Window(); 49 | // Functions 50 | void setKeysByIndex(int index, bool boolean, int mode); 51 | void setToggleKeysByIndex(int index, bool boolean, int mode); 52 | bool getToggleKeyStateByIndex(int index, int mode); 53 | GLFWwindow* getWindow(); 54 | void preLoopDraw(bool clearBuffer); 55 | void postLoopDraw(); 56 | void setFrameless(bool framelessOn); 57 | void setAlwaysOnTop(bool alwaysOnTop); 58 | void setBackgroundColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); 59 | std::shared_ptr getShaderSet(); 60 | std::shared_ptr getParentDimensions(); 61 | void updateStoredSize(int newWidth, int newHeight); 62 | void handleMouseClick(int button, int action, int mods); 63 | void handleMouseMovement(double xpos, double ypos); 64 | void handleMouseScroll(double xoffset, double yoffset); 65 | void updateSelection(); 66 | void handleRightMouseHeld(bool buttonHeld); 67 | void handleMiddleMouseHeld(bool buttonHeld); 68 | void handleLeftMouseHeld(bool buttonHeld); 69 | void handleLeftShiftMouseHeld(bool buttonHeld); 70 | void handleRightShiftMouseHeld(bool buttonHeld); 71 | void updateSizePx(); 72 | void Draw(); 73 | std::string getID(); 74 | 75 | void addPlot(const std::shared_ptr& plotPt); 76 | 77 | private: 78 | // Functions 79 | void initGLFW(); 80 | void updateStoredSize(); 81 | void initGLAD(); 82 | 83 | bool updateMouseOverStates(double xpos, double ypos); 84 | void updateHoverableStates(double xpos, double ypos); 85 | void updateDragActionStates(); 86 | void updateDraggingItems(); 87 | void printSelection(); 88 | 89 | // Data 90 | // Base Window 91 | GLFWwindow* window; 92 | std::array backgroundColor = {0.0f, 0.0f, 0.0f, 1.0f}; 93 | bool transparentBackground; 94 | bool focusOnShow; 95 | glm::mat4 transform = glm::mat4(1.0f); 96 | std::shared_ptr shaderSetPt; 97 | 98 | // Selection 99 | std::shared_ptr>> mousedOverObjs = std::make_shared>>(); 100 | std::shared_ptr>> hoverableObjs = std::make_shared>>(); 101 | std::shared_ptr>> draggingObjs = std::make_shared>>(); 102 | std::shared_ptr selected = {}; 103 | bool printSelected = true; 104 | 105 | // Cursor 106 | int lastCursorType = 0; 107 | GLFWcursor* lastCursor = NULL; 108 | 109 | // Mouse Click 110 | CurrentAction currentAction = NO_ACTION; 111 | double xPressed, yPressed; 112 | 113 | // Keys 114 | bool keys[1024]; 115 | bool toggleKeys[1024]; 116 | bool shiftKeys[1024]; 117 | bool shiftToggleKeys[1024]; 118 | }; 119 | 120 | } 121 | 122 | 123 | #endif /* P_WINDOW_H_ */ 124 | -------------------------------------------------------------------------------- /tests/AxesLineTicks-test.cpp: -------------------------------------------------------------------------------- 1 | #include "gtest/gtest.h" 2 | #include "../src/util/util.h" 3 | #include "../src/lines/Line2D2Vecs.h" 4 | #include "../src/window/window.h" 5 | 6 | 7 | 8 | 9 | namespace GLPL { 10 | 11 | class AxesLineTickMultipleParamTests :public ::testing::TestWithParam> { 12 | public: 13 | static void SetUpTestSuite() { 14 | // Window Size 15 | int windowWidth = 1600; 16 | int windowHeight = 800; 17 | 18 | // Init GLFW 19 | std::shared_ptr window = std::shared_ptr( 20 | new GLPL::Window(windowWidth, windowHeight, false, false)); 21 | std::shared_ptr window2 = std::dynamic_pointer_cast(window); 22 | 23 | // Get shader set 24 | std::shared_ptr shaderSetPt = window2->getShaderSet(); 25 | 26 | // Create Empty Parent Dimensions 27 | ParentDimensions parentDimensions = ParentDimensions{glm::mat4(0.0f), 1, 1, 1, 1, shaderSetPt}; 28 | std::shared_ptr newParentPointers = std::make_shared(parentDimensions); 29 | 30 | // Create Axes Line Ticks 31 | AxesDirection axesDirection = X_AXES_CENTRE; 32 | std::shared_ptr newAxes = std::make_shared(axesDirection, newParentPointers); 33 | } 34 | 35 | static std::shared_ptr newAxes; 36 | 37 | }; 38 | 39 | std::shared_ptr AxesLineTickMultipleParamTests::newAxes = nullptr; 40 | 41 | 42 | TEST_P(AxesLineTickMultipleParamTests, value2NeatStrTests) { 43 | double inValue = std::get<0>(GetParam()); 44 | const std::string& expectedStr = std::get<1>(GetParam()); 45 | unsigned int maxCharSuggestion = std::get<2>(GetParam()); 46 | double expSwapover = std::get<3>(GetParam()); 47 | unsigned int minDecimal = std::get<4>(GetParam()); 48 | 49 | std::string outString = newAxes->value2NeatStr(inValue, maxCharSuggestion, expSwapover, minDecimal); 50 | EXPECT_EQ(outString, expectedStr); 51 | } 52 | 53 | INSTANTIATE_TEST_CASE_P( 54 | AxesLineTicksTextTests, 55 | AxesLineTickMultipleParamTests, 56 | ::testing::Values( 57 | std::make_tuple(1.00, "1.000", 4, 1000, 1), 58 | std::make_tuple(10.00, "10.00", 4, 1000, 1), 59 | std::make_tuple(100.0, "100.0", 4, 1000, 1), 60 | std::make_tuple(220.5454, "220.5", 4, 1000, 1), 61 | std::make_tuple(0.1, "0.10", 4, 1000, 1), 62 | std::make_tuple(0.01, "0.01", 4, 1000, 1), 63 | std::make_tuple(0.001, "1.0e-3", 4, 1000, 1), 64 | std::make_tuple(1000.0, "1.0e+3", 4, 1000, 1), 65 | std::make_tuple(0.0001, "1.0e-4", 4, 1000, 1), 66 | std::make_tuple(1e11, "1.0e+11", 4, 1000, 1), 67 | std::make_tuple(-1.00, "-1.0", 4, 1000, 1), 68 | std::make_tuple(-10.00, "-10.0", 4, 1000, 1), 69 | std::make_tuple(-100.0, "-100.0", 4, 1000, 1), 70 | std::make_tuple(-0.1, "-0.10", 4, 1000, 1), 71 | std::make_tuple(-0.01, "-0.01", 4, 1000, 1), 72 | std::make_tuple(-0.001, "-1.0e-3", 4, 1000, 1), 73 | std::make_tuple(-1000.0, "-1.0e+3", 4, 1000, 1), 74 | std::make_tuple(-0.0001, "-1.0e-4", 4, 1000, 1), 75 | std::make_tuple(-1e11, "-1.0e+11", 4, 1000, 1), 76 | std::make_tuple(-2.17e-3, "-2.2e-3", 4, 1000, 1) 77 | ) 78 | ); 79 | 80 | TEST(AxesLineTicksTests, LogTicksFromMaxMin) { 81 | // Window Size 82 | int windowWidth = 1600; 83 | int windowHeight = 800; 84 | 85 | // Init GLFW 86 | std::shared_ptr window = std::shared_ptr( 87 | new GLPL::Window(windowWidth, windowHeight, false, false)); 88 | std::shared_ptr window2 = std::dynamic_pointer_cast(window); 89 | 90 | // Get shader set 91 | std::shared_ptr shaderSetPt = window2->getShaderSet(); 92 | 93 | // Create Empty Parent Dimensions 94 | ParentDimensions parentDimensions = ParentDimensions{glm::mat4(0.0f), 1, 1, 1, 1, shaderSetPt}; 95 | std::shared_ptr newParentPointers = std::make_shared(parentDimensions); 96 | 97 | // Create Axes Line Ticks 98 | AxesDirection axesDirection = X_AXES_CENTRE; 99 | std::shared_ptr newAxes = std::make_shared(axesDirection, newParentPointers); 100 | 101 | // Set Log 102 | newAxes->setLogScale(true, 10.0f); 103 | 104 | // Set min/max 105 | newAxes->setMinMax(0.001, 100, -5, 5); 106 | 107 | // Check axes position 108 | std::vector axesPos = newAxes->getAxesTickPos(); 109 | 110 | 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Define test executable name 2 | set(BINARY ${CMAKE_PROJECT_NAME}_tests) 3 | 4 | # Find source files 5 | file(GLOB TEST_SOURCES LIST_DIRECTORIES true *.h *.cpp) 6 | set(SOURCES ${TEST_SOURCES}) 7 | 8 | # Add an executable target 9 | add_executable(${BINARY} ${TEST_SOURCES} ${CMAKE_SOURCE_DIR}/include/glad.c) 10 | 11 | # Specify libraries to be linked 12 | target_link_libraries(${BINARY} PUBLIC gtest openGLPlotLive ${LIBS}) 13 | 14 | # Add tests to be run 15 | add_test(NAME ${BINARY} COMMAND ${BINARY}) 16 | 17 | # Copy Shader files to build directory 18 | add_custom_command(TARGET openGLPlotLive-proj_tests PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/Shaders $/../tests/Shaders) 19 | add_custom_command(TARGET openGLPlotLive-proj_tests PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/textures $/../tests/../textures) 20 | 21 | # Add test target 22 | add_custom_target(tests) 23 | add_dependencies(tests openGLPlotLive-proj_tests) 24 | 25 | -------------------------------------------------------------------------------- /tests/Line2D2Vecs-test.cpp: -------------------------------------------------------------------------------- 1 | #include "gtest/gtest.h" 2 | #include "../src/util/util.h" 3 | #include "../src/lines/Line2D2Vecs.h" 4 | #include "../src/window/window.h" 5 | 6 | 7 | 8 | namespace GLPL { 9 | 10 | TEST(Line2D2VecsTests, SortingWithSameXValuesTest) { 11 | // Create initial data 12 | std::vector xVec; 13 | std::vector yVec; 14 | // Square TL, TR, BR, BL, TL 15 | float xL = 1.0f; 16 | float xR = 2.0f; 17 | float yB = 3.0f; 18 | float yT = 4.0f; 19 | // Top Left 20 | xVec.push_back(xL); 21 | yVec.push_back(yT); 22 | // Top Right 23 | xVec.push_back(xR); 24 | yVec.push_back(yT); 25 | // Bottom Right 26 | xVec.push_back(xR); 27 | yVec.push_back(yB); 28 | // Bottom Left 29 | xVec.push_back(xL); 30 | yVec.push_back(yB); 31 | // Top Left 32 | xVec.push_back(xL); 33 | yVec.push_back(yT); 34 | 35 | // Window Size 36 | int windowWidth = 1600; 37 | int windowHeight = 800; 38 | 39 | // Init GLFW 40 | std::shared_ptr window = std::shared_ptr(new GLPL::Window(windowWidth, windowHeight, false, false)); 41 | std::shared_ptr window2 = std::dynamic_pointer_cast(window); 42 | 43 | // Get shader set 44 | std::shared_ptr shaderSetPt = window2->getShaderSet(); 45 | 46 | // Create Empty Parent Dimensions 47 | ParentDimensions parentDimensions = ParentDimensions{glm::mat4(0.0f), 1, 1, 1, 1, shaderSetPt}; 48 | std::shared_ptr newParentPointers = std::make_shared(parentDimensions); 49 | 50 | // Create Line Object 51 | std::shared_ptr lineObj = std::make_shared(&xVec, &yVec, newParentPointers); 52 | 53 | // Check that the internal data and indices are sorted correctly 54 | std::vector actualIndices = lineObj->getInternalIndices(); 55 | std::vector actualData = lineObj->getInternalData(); 56 | for(unsigned int i=0; i xVec; 70 | std::vector yVec; 71 | // Square TR, TL, BL, BR, TR 72 | float xL = 1.0f; 73 | float xR = 2.0f; 74 | float yB = 3.0f; 75 | float yT = 4.0f; 76 | // Top Right 77 | xVec.push_back(xR); 78 | yVec.push_back(yT); 79 | // Top Left 80 | xVec.push_back(xL); 81 | yVec.push_back(yT); 82 | // Bottom Left 83 | xVec.push_back(xL); 84 | yVec.push_back(yB); 85 | // Bottom Right 86 | xVec.push_back(xR); 87 | yVec.push_back(yB); 88 | // Top Right 89 | xVec.push_back(xR); 90 | yVec.push_back(yT); 91 | 92 | // Window Size 93 | int windowWidth = 1600; 94 | int windowHeight = 800; 95 | 96 | // Init GLFW 97 | std::shared_ptr window = std::shared_ptr(new GLPL::Window(windowWidth, windowHeight, false, false)); 98 | std::shared_ptr window2 = std::dynamic_pointer_cast(window); 99 | 100 | // Get shader set 101 | std::shared_ptr shaderSetPt = window2->getShaderSet(); 102 | 103 | // Create Empty Parent Dimensions 104 | ParentDimensions parentDimensions = ParentDimensions{glm::mat4(0.0f), 1, 1, 1, 1, shaderSetPt}; 105 | std::shared_ptr newParentPointers = std::make_shared(parentDimensions); 106 | 107 | // Create Line Object 108 | std::shared_ptr lineObj = std::make_shared(&xVec, &yVec, newParentPointers); 109 | 110 | // Check that the internal data and indices are sorted correctly 111 | std::vector actualIndices = lineObj->getInternalIndices(); 112 | std::vector actualData = lineObj->getInternalData(); 113 | for(unsigned int i=0; i