### Install Project Targets Source: https://github.com/stevenlovegrove/pangolin/blob/master/tools/VideoJson/CMakeLists.txt Specify installation paths for the generated executables and libraries. ```cmake install(TARGETS VideoJsonPrint VideoJsonTransform RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib ) ``` -------------------------------- ### Install Executable Target Source: https://github.com/stevenlovegrove/pangolin/blob/master/tools/VideoConvert/CMakeLists.txt Define installation paths for the generated executable using standard CMake install commands. ```cmake install(TARGETS VideoConvert RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib ) ``` -------------------------------- ### Install Pangolin using vcpkg Source: https://github.com/stevenlovegrove/pangolin/blob/master/README.md Install the Pangolin library using the vcpkg dependency manager. This involves cloning the vcpkg repository, bootstrapping it, integrating it with your system, and then installing Pangolin. ```bash git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ./vcpkg integrate install ./vcpkg install pangolin ``` -------------------------------- ### Set Include Directories and Install Source: https://github.com/stevenlovegrove/pangolin/blob/master/components/pango_image/CMakeLists.txt Configures include directories for build and installation, and installs the include directory. This makes the Pangolin headers available during build and after installation. ```cmake target_include_directories(${COMPONENT} PUBLIC $ $ ) install(DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/include" DESTINATION ${CMAKE_INSTALL_PREFIX} ) ``` -------------------------------- ### Install Project Targets and Configs Source: https://github.com/stevenlovegrove/pangolin/blob/master/CMakeLists.txt Defines installation paths and rules for project targets, headers, and CMake configuration files to ensure relocatability. ```cmake include(GNUInstallDirs) # This relative path allows installed files to be relocatable. set( CMAKECONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ) file( RELATIVE_PATH REL_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKECONFIG_INSTALL_DIR}" "${CMAKE_INSTALL_PREFIX}/include" ) install( TARGETS ${component_list} EXPORT ${PROJECT_NAME}Targets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) install( FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) install( EXPORT ${PROJECT_NAME}Targets DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) ``` -------------------------------- ### Conditionally Build Tools and Examples Source: https://github.com/stevenlovegrove/pangolin/blob/master/CMakeLists.txt Adds subdirectories for examples and tools based on project build configuration flags. ```cmake set(Pangolin_DIR ${CMAKE_CURRENT_BINARY_DIR}) if(BUILD_EXAMPLES) add_subdirectory(examples) endif() if(BUILD_TOOLS) add_subdirectory(tools) endif() ``` -------------------------------- ### Install VideoViewer Executable and Libraries Source: https://github.com/stevenlovegrove/pangolin/blob/master/tools/VideoViewer/CMakeLists.txt Installs the VideoViewer executable and its associated libraries to the specified runtime and library destinations. This is part of the standard CMake installation process. ```cmake install(TARGETS VideoViewer RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib ) ``` -------------------------------- ### Set Target Properties and Installation Source: https://github.com/stevenlovegrove/pangolin/blob/master/components/pango_windowing/CMakeLists.txt Finalizes target properties, links core dependencies, and defines installation rules for headers. ```cmake set_target_properties( ${COMPONENT} PROPERTIES VERSION ${PANGOLIN_VERSION} SOVERSION ${PANGOLIN_VERSION_MAJOR} ) target_sources(${COMPONENT} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/src/window.cpp) target_link_libraries(${COMPONENT} PUBLIC pango_core pango_opengl ) target_include_directories(${COMPONENT} PUBLIC $ $ $ ) install(DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/include" DESTINATION ${CMAKE_INSTALL_PREFIX}) install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include" DESTINATION ${CMAKE_INSTALL_PREFIX}) ``` -------------------------------- ### Install Directory Source: https://github.com/stevenlovegrove/pangolin/blob/master/components/pango_display/CMakeLists.txt Installs a directory to the specified destination during the CMake installation process. Ensure the destination path is correctly configured. ```cmake install(DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/include" DESTINATION ${CMAKE_INSTALL_PREFIX} ) ``` -------------------------------- ### Basic PyPangolin Usage Source: https://context7.com/stevenlovegrove/pangolin/llms.txt Demonstrates basic window creation, camera setup, UI panel, 3D view, variable creation, and keyboard callbacks in Python. ```python #!/usr/bin/env python3 import pypangolin as pango from OpenGL.GL import * import math def main(): # Create window win = pango.CreateWindowAndBind("Python Demo", 640, 480) glEnable(GL_DEPTH_TEST) # Setup camera pm = pango.ProjectionMatrix(640, 480, 420, 420, 320, 240, 0.1, 1000) mv = pango.ModelViewLookAt(-2, 2, -2, 0, 0, 0, pango.AxisY) s_cam = pango.OpenGlRenderState(pm, mv) # Create UI panel ui_width = 180 pango.CreatePanel("ui").SetBounds( pango.Attach(0), pango.Attach(1), pango.Attach(0), pango.Attach.Pix(ui_width) ) # Create 3D view handler = pango.Handler3D(s_cam) d_cam = ( pango.CreateDisplay() .SetBounds( pango.Attach(0), pango.Attach(1), pango.Attach.Pix(ui_width), pango.Attach(1), -640.0 / 480.0 ) .SetHandler(handler) ) # Create variables using Var object var_ui = pango.Var("ui") var_ui.a_Button = False var_ui.a_Toggle = (False, pango.VarMeta(toggle=True)) var_ui.a_double = (1.0, pango.VarMeta(0, 5)) var_ui.an_int = (2, pango.VarMeta(0, 10)) var_ui.a_string = "Hello" # Keyboard callback def on_key_a(): print("'a' key pressed!") pango.RegisterKeyPressCallback(ord('a'), on_key_a) while not pango.ShouldQuit(): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # Check for GUI changes if var_ui.GuiChanged('a_double'): print(f"Slider changed to: {var_ui.a_double}") d_cam.Activate(s_cam) pango.glDrawColouredCube() pango.glDrawAxis(1.5) pango.FinishFrame() if __name__ == "__main__": main() ``` -------------------------------- ### Build and Install Pangolin Source: https://github.com/stevenlovegrove/pangolin/blob/master/README.md Standard commands to configure, build, and test the Pangolin library using CMake. ```bash # Get Pangolin cd ~/your_fav_code_directory git clone --recursive https://github.com/stevenlovegrove/Pangolin.git cd Pangolin # Install dependencies (as described above, or your preferred method) ./scripts/install_prerequisites.sh recommended # Configure and build cmake -B build cmake --build build # with Ninja for faster builds (sudo apt install ninja-build) cmake -B build -GNinja cmake --build build # GIVEME THE PYTHON STUFF!!!! (Check the output to verify selected python version) cmake --build build -t pypangolin_pip_install # Run me some tests! (Requires Catch2 which must be manually installed on Ubuntu.) cmake -B build -G Ninja -D BUILD_TESTS=ON cmake --build build cd build ctest ``` -------------------------------- ### Pangolin Main Window and View Setup Source: https://context7.com/stevenlovegrove/pangolin/llms.txt Initializes a Pangolin window and sets up render states and views. Includes a 3D camera view and an image overlay view, demonstrating SetBounds for layout management. ```cpp #include #include #include int main() { pangolin::CreateWindowAndBind("Layout Demo", 800, 600); glEnable(GL_DEPTH_TEST); pangolin::OpenGlRenderState s_cam( pangolin::ProjectionMatrix(640, 480, 420, 420, 320, 240, 0.1, 1000), pangolin::ModelViewLookAt(-1, 1, -1, 0, 0, 0, pangolin::AxisY) ); const int UI_WIDTH = 180; // Main 3D view: fills remaining space after UI panel // SetBounds(bottom, top, left, right, aspect_ratio) pangolin::View& d_cam = pangolin::Display("cam") .SetBounds(0.0, 1.0, // Full height pangolin::Attach::Pix(UI_WIDTH), // Left: 180px from edge 1.0, // Right: full width -640.0f/480.0f) // Negative aspect = grow to fit .SetHandler(new pangolin::Handler3D(s_cam)); // Image overlay: top-left corner, max 1/3 of window pangolin::View& d_image = pangolin::Display("image") .SetBounds(2/3.0f, 1.0f, // Top third vertically 0.0f, 1/3.0f, // Left third horizontally 640.0/480.0) // Positive aspect = shrink to fit .SetLock(pangolin::LockLeft, pangolin::LockTop); // Anchor to top-left // Create texture for image display pangolin::GlTexture tex(64, 48, GL_RGB, false, 0, GL_RGB, GL_UNSIGNED_BYTE); while (!pangolin::ShouldQuit()) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Render 3D view d_cam.Activate(s_cam); pangolin::glDrawColouredCube(); // Render image overlay d_image.Activate(); glColor3f(1.0, 1.0, 1.0); tex.RenderToViewport(); pangolin::FinishFrame(); } return 0; } ``` -------------------------------- ### Install Emscripten SDK Source: https://github.com/stevenlovegrove/pangolin/blob/master/README.md Commands to clone and activate the Emscripten SDK for web compilation. ```bash mkdir ~/tools && cd ~/tools git clone https://github.com/emscripten-core/emsdk.git cd emsdk && ./emsdk install latest && ./emsdk activate latest ``` -------------------------------- ### Install Plotter Executable and Libraries Source: https://github.com/stevenlovegrove/pangolin/blob/master/tools/Plotter/CMakeLists.txt Installs the Plotter executable and associated libraries to specified destinations in the installation prefix. This is part of the build and deployment process. ```cmake install(TARGETS Plotter RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib ) ``` -------------------------------- ### Manage Dependencies Source: https://github.com/stevenlovegrove/pangolin/blob/master/README.md Use the provided script to identify or install required system packages for Pangolin. ```bash # See what package manager and packages are recommended ./scripts/install_prerequisites.sh --dry-run recommended # Override the package manager choice and install all packages ./scripts/install_prerequisites.sh -m brew all ``` -------------------------------- ### Install Sigslot using CMake Build Source: https://github.com/stevenlovegrove/pangolin/blob/master/components/pango_core/include/sigslot/README.md Build and install Sigslot from its root directory using CMake. Options like `SIGSLOT_REDUCE_COMPILE_TIME` can be set during configuration. ```sh mkdir build && cd build cmake .. -DSIGSLOT_REDUCE_COMPILE_TIME=ON -DCMAKE_INSTALL_PREFIX=~/local cmake --build . --target install # If you want to compile examples: cmake --build . --target sigslot-examples # And compile/execute unit tests: cmake --build . --target sigslot-tests ``` -------------------------------- ### Real-time Data Plotter with Data Logging Source: https://context7.com/stevenlovegrove/pangolin/llms.txt Creates a real-time plot of time-series data using DataLog and Plotter. Includes setup for window, data logger, plotter bounds, markers, and frame updates. Requires pangolin/display/display.h and pangolin/plot/plotter.h. ```cpp #include #include #include int main() { pangolin::CreateWindowAndBind("Plotter Demo", 800, 600); // Create data logger pangolin::DataLog log; // Add named labels for each data series std::vector labels; labels.push_back("sin(t)"); labels.push_back("cos(t)"); labels.push_back("sin(t)+cos(t)"); log.SetLabels(labels); const float tinc = 0.01f; // Create plotter view // Plotter(log, x_min, x_max, y_min, y_max, x_tick, y_tick) pangolin::Plotter plotter(&log, 0.0f, 4.0f * (float)M_PI / tinc, // X range (samples) -2.0f, 2.0f, // Y range (float)M_PI / (4.0f * tinc), // X tick spacing 0.5f // Y tick spacing ); plotter.SetBounds(0.0, 1.0, 0.0, 1.0); // Track most recent data point plotter.Track("$i"); // $i = sample index // Add visual markers/annotations plotter.AddMarker( pangolin::Marker::Vertical, -1000, pangolin::Marker::LessThan, pangolin::Colour::Blue().WithAlpha(0.2f) ); plotter.AddMarker( pangolin::Marker::Horizontal, 1.0, pangolin::Marker::GreaterThan, pangolin::Colour::Red().WithAlpha(0.2f) ); plotter.AddMarker( pangolin::Marker::Horizontal, 0.0, pangolin::Marker::Equal, pangolin::Colour::Green().WithAlpha(0.2f) ); // Add plotter to display pangolin::DisplayBase().AddDisplay(plotter); float t = 0.0f; while (!pangolin::ShouldQuit()) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Log new data point each frame log.Log(sin(t), cos(t), sin(t) + cos(t)); t += tinc; pangolin::FinishFrame(); } return 0; } ``` -------------------------------- ### Find and Include Pangolin Library Source: https://github.com/stevenlovegrove/pangolin/blob/master/examples/HelloPangolinOffscreen/CMakeLists.txt Use this CMake command to find the Pangolin library and include its directories. Ensure Pangolin 0.5 or later is installed. ```cmake find_package(Pangolin 0.5 REQUIRED) include_directories(${Pangolin_INCLUDE_DIRS}) ``` -------------------------------- ### 3D View Transformations with Pangolin Source: https://github.com/stevenlovegrove/pangolin/blob/master/examples/BasicOpenGL/README.md Introduces 3D transformations in OpenGL, including mapping from normalized device coordinates to clip coordinates using linear transforms and homogeneous coordinates. This example focuses on the concepts rather than specific Pangolin API for transforms. ```cpp #include int main() { // Initialise Pangolin pangolin::CreateWindowAndBind("Pangolin 3D Transforms", 640, 480); glEnable(GL_DEPTH_TEST); // Define camera parameters (example values) pangolin::OpenGlRenderState camera; camera.gl.modelView.SetIdentity(); camera.gl.projection.SetPerspective(60.0f, (float)640/480, 0.1f, 100.0f); // Define a triangle in 3D space const Vertex vertices[] = { {{-1.0f, -1.0f, 0.0f}}, {{ 1.0f, -1.0f, 0.0f}}, {{ 0.0f, 1.0f, 0.0f}} }; // Main Loop while (!pangolin::ShouldQuit()) { // Clear screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Apply camera transformations pangolin:: dalam_gl(camera.gl); // Apply model transformations (e.g., rotation, translation) // Example: Rotate the triangle glRotatef(pangolin::Now().Time * 50.0f, 0.0f, 1.0f, 0.0f); // Draw the triangle glBegin(GL_TRIANGLES); glColor3f(1.0f, 0.0f, 0.0f); glVertex3fv(vertices[0].data()); glColor3f(0.0f, 1.0f, 0.0f); glVertex3fv(vertices[1].data()); glColor3f(0.0f, 0.0f, 1.0f); glVertex3fv(vertices[2].data()); glEnd(); // Swap frames and process events pangolin::FinishFrame(); } return 0; } ``` -------------------------------- ### Create OpenGL Window and Bind Context Source: https://context7.com/stevenlovegrove/pangolin/llms.txt Initializes a window and sets up the main rendering loop. This is the standard entry point for Pangolin applications. ```cpp #include #include #include int main() { // Create a 640x480 window with title "MyApp" pangolin::CreateWindowAndBind("MyApp", 640, 480); // Enable depth testing for 3D rendering glEnable(GL_DEPTH_TEST); // Main rendering loop while (!pangolin::ShouldQuit()) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Render content here... pangolin::glDrawColouredCube(); // Swap buffers and process events pangolin::FinishFrame(); } return 0; } ``` -------------------------------- ### Create GUI Controls with Var System Source: https://context7.com/stevenlovegrove/pangolin/llms.txt Demonstrates how to initialize a panel and bind various widget types like sliders, checkboxes, and buttons to variables. ```cpp #include #include #include #include #include #include #include #include #include #include int main() { pangolin::CreateWindowAndBind("GUI Demo", 640, 480); glEnable(GL_DEPTH_TEST); // Calculate UI width based on font const int UI_WIDTH = 20 * pangolin::default_font().MaxWidth(); pangolin::OpenGlRenderState s_cam( pangolin::ProjectionMatrix(640, 480, 420, 420, 320, 240, 0.1, 1000), pangolin::ModelViewLookAt(-0, 0.5, -3, 0, 0, 0, pangolin::AxisY) ); // Create 3D view pangolin::View& d_cam = pangolin::CreateDisplay() .SetBounds(0.0, 1.0, pangolin::Attach::Pix(UI_WIDTH), 1.0, 640.0f/480.0f) .SetHandler(new pangolin::Handler3D(s_cam)); // Create panel for GUI widgets (auto-registers variables with "ui." prefix) pangolin::CreatePanel("ui") .SetBounds(0.0, 1.0, 0.0, pangolin::Attach::Pix(UI_WIDTH)); // Define tweak variables with different widget types pangolin::Var a_button("ui.A_Button", false, false); // Push button pangolin::Var a_checkbox("ui.A_Checkbox", false, true); // Checkbox (toggle=true) pangolin::Var a_double("ui.A_Double", 3.0, 0.0, 5.0); // Slider with range pangolin::Var an_int("ui.An_Int", 2, 0, 5); // Integer slider pangolin::Var a_log("ui.Log_Scale", 3.0, 1.0, 1e4, true); // Log-scale slider pangolin::Var a_string("ui.A_String", "Edit ME!"); // Text input pangolin::Var display_only("ui.Display_Only", 42); // Read-only display // Function button - calls lambda when clicked pangolin::Var> save_window("ui.Save_Window", [](){ pangolin::SaveWindowOnRender("screenshot"); std::cout << "Screenshot saved!" << std::endl; }); // Keyboard shortcut to modify variable pangolin::RegisterKeyPressCallback(pangolin::PANGO_CTRL + 'r', [&](){ a_double = 0.0; // Reset slider }); while (!pangolin::ShouldQuit()) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Check if button was pushed this frame if (pangolin::Pushed(a_button)) { std::cout << "Button pressed!" << std::endl; } // Variables work like their wrapped types if (a_checkbox) { an_int = static_cast(a_double); } // Update display-only variable display_only = an_int * 2; // Render 3D view if visible if (d_cam.IsShown()) { d_cam.Activate(s_cam); glColor3f(1.0, 1.0, 1.0); pangolin::glDrawColouredCube(); } pangolin::FinishFrame(); } return 0; } ``` -------------------------------- ### Create Multi-Display Layout with Shared Cameras Source: https://context7.com/stevenlovegrove/pangolin/llms.txt Sets up a window with four synchronized viewports, demonstrating how to manage independent and shared camera states. Requires OpenGL and Pangolin libraries. ```cpp #include #include #include #include int main() { pangolin::CreateWindowAndBind("Multi-Display", 800, 600); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); pangolin::OpenGlMatrix proj = pangolin::ProjectionMatrix(640, 480, 420, 420, 320, 240, 0.1, 1000); // Two independent camera states pangolin::OpenGlRenderState s_cam1(proj, pangolin::ModelViewLookAt(1, 0.5, -2, 0, 0, 0, pangolin::AxisY)); pangolin::OpenGlRenderState s_cam2(proj, pangolin::ModelViewLookAt(0, 0, -2, 0, 0, 0, pangolin::AxisY)); // Create individual displays with aspect ratio pangolin::View& d_cam1 = pangolin::Display("cam1") .SetAspect(640.0f/480.0f) .SetHandler(new pangolin::Handler3D(s_cam1)); pangolin::View& d_cam2 = pangolin::Display("cam2") .SetAspect(640.0f/480.0f) .SetHandler(new pangolin::Handler3D(s_cam2)); pangolin::View& d_cam3 = pangolin::Display("cam3") .SetAspect(640.0f/480.0f) .SetHandler(new pangolin::Handler3D(s_cam1)); // Shares cam1 state pangolin::View& d_cam4 = pangolin::Display("cam4") .SetAspect(640.0f/480.0f) .SetHandler(new pangolin::Handler3D(s_cam2)); // Shares cam2 state // Container with automatic equal layout pangolin::Display("multi") .SetBounds(0.0, 1.0, 0.0, 1.0) .SetLayout(pangolin::LayoutEqual) // Automatically arrange in grid .AddDisplay(d_cam1) .AddDisplay(d_cam2) .AddDisplay(d_cam3) .AddDisplay(d_cam4); while (!pangolin::ShouldQuit()) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Render each viewport d_cam1.Activate(s_cam1); pangolin::glDrawColouredCube(); d_cam2.Activate(s_cam2); pangolin::glDrawColouredCube(); d_cam3.Activate(s_cam1); pangolin::glDrawColouredCube(); d_cam4.Activate(s_cam2); pangolin::glDrawColouredCube(); pangolin::FinishFrame(); } return 0; } ``` -------------------------------- ### Build and Install Python Wheel Source: https://github.com/stevenlovegrove/pangolin/blob/master/README.md Build a Python wheel for the pypangolin module using the 'pypangolin_wheel' target. Install or uninstall the wheel using 'pypangolin_pip_install' and 'pypangolin_pip_uninstall' targets. Note: These targets are currently only supported on MacOS and Linux. ```bash cmake --build . --target pypangolin_wheel ``` ```bash cmake --build . --target pypangolin_pip_install ``` ```bash cmake --build . --target pypangolin_pip_uninstall ``` -------------------------------- ### Configure Pangolin CMake Target Source: https://github.com/stevenlovegrove/pangolin/blob/master/components/pango_tools/CMakeLists.txt Defines a target component, sets its properties, links dependencies, and configures installation paths. ```cmake get_filename_component(COMPONENT ${CMAKE_CURRENT_LIST_DIR} NAME) target_sources( ${COMPONENT} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/src/video_viewer.cpp ) set_target_properties( ${COMPONENT} PROPERTIES VERSION ${PANGOLIN_VERSION} SOVERSION ${PANGOLIN_VERSION_MAJOR} ) target_link_libraries(${COMPONENT} PUBLIC pango_display pango_video) target_include_directories(${COMPONENT} PUBLIC $ $ ) install(DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/include" DESTINATION ${CMAKE_INSTALL_PREFIX} ) ``` -------------------------------- ### Configure Camera State with Projection and ModelView Source: https://context7.com/stevenlovegrove/pangolin/llms.txt Sets up an OpenGL render state with a projection matrix and a model-view matrix using LookAt. The model-view matrix defines the camera's position and orientation. ```cpp // Usage with OpenGlRenderState pangolin::OpenGlRenderState cam_state(proj_standard); cam_state.SetModelViewMatrix( pangolin::ModelViewLookAt(0, 5, -5, 0, 0, 0, pangolin::AxisY) ); ``` -------------------------------- ### Configure Pangolin CMake Target Source: https://github.com/stevenlovegrove/pangolin/blob/master/components/pango_packetstream/CMakeLists.txt Defines source files, properties, and installation rules for a CMake target within the Pangolin project. ```cmake get_filename_component(COMPONENT ${CMAKE_CURRENT_LIST_DIR} NAME) target_sources( ${COMPONENT} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/src/packet.cpp ${CMAKE_CURRENT_LIST_DIR}/src/packetstream.cpp ${CMAKE_CURRENT_LIST_DIR}/src/packetstream_reader.cpp ${CMAKE_CURRENT_LIST_DIR}/src/packetstream_writer.cpp ${CMAKE_CURRENT_LIST_DIR}/src/playback_session.cpp ) set_target_properties( ${COMPONENT} PROPERTIES VERSION ${PANGOLIN_VERSION} SOVERSION ${PANGOLIN_VERSION_MAJOR} ) target_compile_definitions(${COMPONENT} PRIVATE "PANGOLIN_VERSION_STRING=\"${PANGOLIN_VERSION}\"") target_link_libraries(${COMPONENT} PUBLIC pango_core) target_include_directories(${COMPONENT} PUBLIC $ $ ) install(DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/include" DESTINATION ${CMAKE_INSTALL_PREFIX} ) ``` -------------------------------- ### Build Pangolin with Emscripten Source: https://github.com/stevenlovegrove/pangolin/blob/master/README.md Use emcmake to configure the build system for web output. ```bash cd ~/code/Pangolin mkdir build-em && cd build-em source ~/tools/emsdk/emsdk_env.sh emcmake cmake .. ``` -------------------------------- ### Integrate Sigslot with CMake Source: https://github.com/stevenlovegrove/pangolin/blob/master/components/pango_core/include/sigslot/README.md Use Sigslot as an imported CMake target. This is the preferred installation method and automatically applies necessary linker flags. ```cmake find_package(PalSigslot) add_executable(MyExe main.cpp) target_link_libraries(MyExe PRIVATE Pal::Sigslot) ``` -------------------------------- ### Capture Video with VideoInput Source: https://context7.com/stevenlovegrove/pangolin/llms.txt Demonstrates capturing video from a specified URI (e.g., test pattern, webcam, file) and displaying it in a Pangolin window. Supports various video sources and formats. ```cpp #include #include #include #include #include int main(int argc, char* argv[]) { // Video URI examples: // "test:[size=640x480,n=1,fmt=RGB24]//" - Test pattern // "v4l:///dev/video0" - Linux webcam // "convert:[fmt=RGB24]//v4l:///dev/video0" - With format conversion // "dc1394:[fps=30,size=640x480]//0" - FireWire camera // "openni:[img1=rgb]//" - OpenNI (Kinect) // "file:///path/to/video.avi" - Video file // "files:///path/to/sequence/img%03d.png" - Image sequence std::string uri = (argc > 1) ? argv[1] : "test:[size=640x480,fmt=RGB24]//"; // Open video source pangolin::VideoInput video(uri); const unsigned int w = video.Width(); const unsigned int h = video.Height(); const pangolin::PixelFormat fmt = video.PixFormat(); std::cout << "Video: " << w << "x" << h << " format: " << fmt.format << std::endl; // Create window matching video dimensions pangolin::CreateWindowAndBind("Video Viewer", w, h); // Create viewport with correct aspect ratio pangolin::View& vVideo = pangolin::Display("Video") .SetAspect((float)w / h); // Determine OpenGL format from pixel format GLint glformat = (fmt.channels == 1) ? GL_LUMINANCE : (fmt.channels == 3) ? GL_RGB : GL_RGBA; GLenum gltype = (fmt.channel_bits[0] == 8) ? GL_UNSIGNED_BYTE : (fmt.channel_bits[0] == 16) ? GL_UNSIGNED_SHORT : GL_FLOAT; // Create texture for display pangolin::GlTexture texVideo(w, h, glformat, false, 0, glformat, gltype); // Allocate image buffer std::vector img(video.SizeBytes()); while (!pangolin::ShouldQuit()) { glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); // Grab next frame if (video.GrabNext(img.data(), true)) { texVideo.Upload(img.data(), glformat, gltype); } // Display video vVideo.Activate(); texVideo.RenderToViewportFlipY(); pangolin::FinishFrame(); } return 0; } ``` -------------------------------- ### Organize Sub-views with Pangolin Viewport Source: https://github.com/stevenlovegrove/pangolin/blob/master/examples/BasicOpenGL/README.md Demonstrates using Pangolin to manage and resize sub-views within the main window, simplifying manual layout adjustments. ```cpp #include int main() { // Initialise Pangolin pangolin::CreateWindowAndBind("Pangolin Viewport Example", 640, 480); glEnable(GL_DEPTH_TEST); // Define layout and views pangolin::View& main_view = pangolin::CreateDisplay("main").SetBounds(0.0, 1.0, 0.0, 1.0); pangolin::View& sub_view1 = pangolin::CreateDisplay("sub1").SetBounds(0.0, 0.5, 0.0, 0.5); pangolin::View& sub_view2 = pangolin::CreateDisplay("sub2").SetBounds(0.5, 1.0, 0.0, 0.5); pangolin::View& sub_view3 = pangolin::CreateDisplay("sub3").SetBounds(0.0, 0.5, 0.5, 1.0); pangolin::View& sub_view4 = pangolin::CreateDisplay("sub4").SetBounds(0.5, 1.0, 0.5, 1.0); // Set display hierarchy main_view.AddChildren(&sub_view1); main_view.AddChildren(&sub_view2); main_view.AddChildren(&sub_view3); main_view.AddChildren(&sub_view4); // Main Loop while (!pangolin::ShouldQuit()) { // Clear screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Render content for each sub-view (example: draw a colored quad) sub_view1.Activate(); glColor3f(1.0f, 0.0f, 0.0f); // Red pangolin::DrawBox(-0.5, -0.5, 0.5, 0.5); sub_view2.Activate(); glColor3f(0.0f, 1.0f, 0.0f); // Green pangolin::DrawBox(-0.5, -0.5, 0.5, 0.5); sub_view3.Activate(); glColor3f(0.0f, 0.0f, 1.0f); // Blue pangolin::DrawBox(-0.5, -0.5, 0.5, 0.5); sub_view4.Activate(); glColor3f(1.0f, 1.0f, 0.0f); // Yellow pangolin::DrawBox(-0.5, -0.5, 0.5, 0.5); // Swap frames and process events pangolin::FinishFrame(); } return 0; } ``` -------------------------------- ### Configure Pangolin Component Build Source: https://github.com/stevenlovegrove/pangolin/blob/master/components/pango_vars/CMakeLists.txt Defines target sources, properties, and installation paths for a CMake component. Requires the PANGOLIN_VERSION and PANGOLIN_VERSION_MAJOR variables to be defined. ```cmake get_filename_component(COMPONENT ${CMAKE_CURRENT_LIST_DIR} NAME) target_sources( ${COMPONENT} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/src/vars.cpp ${CMAKE_CURRENT_LIST_DIR}/src/varstate.cpp ) set_target_properties( ${COMPONENT} PROPERTIES VERSION ${PANGOLIN_VERSION} SOVERSION ${PANGOLIN_VERSION_MAJOR} ) target_link_libraries(${COMPONENT} PUBLIC pango_core) target_include_directories(${COMPONENT} PUBLIC $ $ ) install(DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/include" DESTINATION ${CMAKE_INSTALL_PREFIX} ) if(BUILD_TESTS) add_executable(test_vars ${CMAKE_CURRENT_LIST_DIR}/tests/test_all.cpp) target_link_libraries(test_vars PRIVATE Catch2::Catch2WithMain ${COMPONENT}) catch_discover_tests(test_vars) endif() ``` -------------------------------- ### Draw Triangle with VBO and Shaders (Pangolin) Source: https://github.com/stevenlovegrove/pangolin/blob/master/examples/BasicOpenGL/README.md Demonstrates using Pangolin's C++ wrappers for VBOs and shaders, improving readability. Includes Pangolin's preprocessor features for shader management. ```cpp #include int main() { // Define vertices of the triangle const Vertex vertices[] = { {{-0.5f, -0.5f, 0.0f}}, {{ 0.5f, -0.5f, 0.0f}}, {{ 0.0f, 0.5f, 0.0f}} }; // Initialise Pangolin pangolin::CreateWindowAndBind("Pangolin Quick-start guide", 640, 480); glEnable(GL_DEPTH_TEST); // Load shaders using Pangolin's utility // Assumes shader code is in a file named "shader.glsl" with @start annotations // Example shader.glsl: // #start vertex // #version 330 core // layout (location = 0) in vec3 aPos; // void main() // { // gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0); // } // #end // #start fragment // #version 330 core // out vec4 FragColor; // void main() // { // FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f); // } // #end pangolin::GlSlProgram shader_program; shader_program.AttachShader( "#version 330 core\n" "layout (location = 0) in vec3 aPos;\n" "void main()\n" "{\n" " gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n" "}\n" "#end\n" "#start fragment\n" "#version 330 core\n" "out vec4 FragColor;\n" "void main()\n" "{\n" " FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n" "}\n" ); shader_program.LinkProgram(); // Create and manage VBO with Pangolin wrapper pangolin::GlBuffer vbo_triangle(GL_ARRAY_BUFFER); vbo_triangle.BufferData(sizeof(vertices), vertices); // Main Loop while (!pangolin::ShouldQuit()) { // Clear screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Use shader program shader_program.Use(); // Upload perspective and define camera pangolin::OpenGlRenderState s_cam; s_cam.gl.modelView.SetIdentity(); pangolin:: dalam_gl(s_cam.gl); // Enable vertex attribute array and set pointer glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); // Draw the triangle glDrawArrays(GL_TRIANGLES, 0, 3); // Disable vertex attribute array glDisableVertexAttribArray(0); // Swap frames and process events pangolin::FinishFrame(); } return 0; } ``` -------------------------------- ### Find Pangolin Library and Link Executable Source: https://github.com/stevenlovegrove/pangolin/blob/master/tools/VideoViewer/CMakeLists.txt Configures CMake to find the Pangolin library and link it to the VideoViewer executable. Ensure Pangolin is installed and discoverable by CMake. ```cmake find_package(Pangolin 0.8 REQUIRED) include_directories(${Pangolin_INCLUDE_DIRS}) add_executable(VideoViewer main.cpp) target_link_libraries(VideoViewer ${Pangolin_LIBRARIES}) ``` -------------------------------- ### Configure Pangolin Component in CMake Source: https://github.com/stevenlovegrove/pangolin/blob/master/components/pango_scene/CMakeLists.txt Defines a target, sets versioning properties, links OpenGL dependencies, and configures include directories for build and install interfaces. ```cmake get_filename_component(COMPONENT ${CMAKE_CURRENT_LIST_DIR} NAME) target_sources( ${COMPONENT} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/src/renderable.cpp ) set_target_properties( ${COMPONENT} PROPERTIES VERSION ${PANGOLIN_VERSION} SOVERSION ${PANGOLIN_VERSION_MAJOR} ) target_link_libraries(${COMPONENT} PUBLIC pango_opengl) target_include_directories(${COMPONENT} PUBLIC $ $ ) install(DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/include" DESTINATION ${CMAKE_INSTALL_PREFIX} ) ``` -------------------------------- ### Record Video with VideoOutput Source: https://context7.com/stevenlovegrove/pangolin/llms.txt Shows how to record a video stream from a VideoInput source to a file using VideoOutput with a specified encoder (e.g., FFmpeg). The stream is also displayed in real-time. ```cpp #include #include #include #include int main() { // Open video source with recording capability std::string input_uri = "test:[size=640x480,fmt=RGB24]//"; std::string record_uri = "ffmpeg:[fps=30,bps=8388608]//output.avi"; pangolin::VideoInput video(input_uri); const unsigned int w = video.Width(); const unsigned int h = video.Height(); // Create video recorder pangolin::VideoOutput recorder(record_uri); recorder.SetStreams(video.Streams()); pangolin::CreateWindowAndBind("Recording", w, h); pangolin::View vVideo((float)w / h); pangolin::GlTexture texVideo(w, h, GL_RGB); std::vector img(video.SizeBytes()); int frame_count = 0; const int max_frames = 300; // Record ~10 seconds at 30fps while (!pangolin::ShouldQuit() && frame_count < max_frames) { glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); if (video.GrabNext(img.data(), true)) { // Upload for display texVideo.Upload(img.data(), GL_RGB, GL_UNSIGNED_BYTE); // Write frame to video file recorder.WriteStreams(img.data()); frame_count++; } vVideo.Activate(); texVideo.RenderToViewportFlipY(); pangolin::FinishFrame(); } // Recorder automatically closes when destroyed return 0; } ``` -------------------------------- ### Find and Link Pangolin Library Source: https://github.com/stevenlovegrove/pangolin/blob/master/examples/HelloPangolin/CMakeLists.txt Use these CMake commands to find the Pangolin library, include its headers, and link your executable against it. Ensure Pangolin is installed and discoverable by CMake. ```cmake find_package(Pangolin 0.8 REQUIRED) include_directories(${Pangolin_INCLUDE_DIRS}) ``` ```cmake add_executable(HelloPangolin main.cpp) target_link_libraries(HelloPangolin pango_display pango_python) ``` -------------------------------- ### Find Eigen3 and Set Compile Definition Source: https://github.com/stevenlovegrove/pangolin/blob/master/components/pango_image/CMakeLists.txt Finds the Eigen3 library and sets a compile definition for its usage. Ensure Eigen3 is installed or available in the CMake search path. ```cmake find_package(Eigen3 REQUIRED NO_MODULE) target_compile_definitions(${COMPONENT} PUBLIC HAVE_EIGEN) ```