### Install Ogre using vcpkg Source: https://github.com/ogrecave/ogre/blob/master/BuildingOgre.md This sequence of commands demonstrates how to install Ogre using the vcpkg dependency manager. It includes cloning vcpkg, bootstrapping, integrating, and finally installing Ogre. ```bash git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ./vcpkg integrate install vcpkg install ogre ``` -------------------------------- ### Start OgreBites Application Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/tutorials/setup.md Create an instance of your application class and call the run method to start the Ogre rendering loop. ```cpp int main() { // NOTE: The sample object (MyGame) must be created on the heap, // otherwise it will not be possible to call the destructor // when the application exits. auto myGame = std::make_unique(); myGame->initApp(); // content of setup is next myGame->exec(); } ``` -------------------------------- ### Install Plugin Headers Source: https://github.com/ogrecave/ogre/blob/master/PlugIns/GLSLang/CMakeLists.txt Installs the header files for the GLSLang plugin. ```cmake install(FILES ${HEADER_FILES} DESTINATION include/OGRE/Plugins/GLSLang) ``` -------------------------------- ### Install Ogre using Makefiles Source: https://github.com/ogrecave/ogre/blob/master/BuildingOgre.md For Makefile-based generators, use 'make install' to install Ogre. You may need root privileges depending on the installation location. ```bash make install # (or sudo make install, if root privileges are required) ``` -------------------------------- ### Create WiX Installer for Demos Source: https://github.com/ogrecave/ogre/blob/master/Samples/CMakeLists.txt Generates a WiX installer for Ogre demos on Windows if WiX is found and samples are being built. It configures necessary files and creates a custom target for building the MSI package. ```cmake if (MSVC AND OGRE_BUILD_SAMPLES) find_package(Wix) if (Wix_FOUND) # Create WiX setup for demo build configure_file(${OGRE_TEMPLATES_DIR}/demos.wxs.in ${CMAKE_CURRENT_BINARY_DIR}/demos.wxs @ONLY) configure_file(${OGRE_TEMPLATES_DIR}/demomedia.wxi.in ${CMAKE_CURRENT_BINARY_DIR}/demomedia.wxi @ONLY) configure_file(${OGRE_TEMPLATES_DIR}/DemoLicense.rtf ${CMAKE_CURRENT_BINARY_DIR}/DemoLicense.rtf COPYONLY) # Configure files, set media dir temporarily set(OGRE_MEDIA_DIR_TMP ${OGRE_MEDIA_DIR_REL}) set(OGRE_MEDIA_DIR_REL "Media") configure_file(${OGRE_TEMPLATES_DIR}/resources.cfg.in ${CMAKE_CURRENT_BINARY_DIR}/resources.cfg @ONLY) # restore set(OGRE_MEDIA_DIR_REL ${OGRE_MEDIA_DIR_TMP}) add_custom_target(demo_installer COMMAND ${Wix_BINARY_DIR}/candle demos.wxs COMMAND ${Wix_BINARY_DIR}/light -ext WixUIExtension -cultures:en-us -out OgreDemos_v${OGRE_VERSION_DASH_SEPARATED}.msi demos.wixobj WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "Building demo installer" VERBATIM ) # Make sure we build samples first add_dependencies(demo_installer SampleBrowser) endif() endif() ``` -------------------------------- ### Install Header Files for OgreDotScenePlugin Source: https://github.com/ogrecave/ogre/blob/master/PlugIns/DotScene/CMakeLists.txt This command installs the header files collected earlier into the 'include/OGRE/Plugins/DotScene' directory of the installation prefix. This ensures that users can include the plugin's headers when using it in their projects. ```cmake install(FILES ${HEADER_FILES} DESTINATION include/OGRE/Plugins/DotScene) ``` -------------------------------- ### OGRE Script Format Example Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/scripts.md This example demonstrates the basic structure of an OGRE script, including comments, object definitions, attributes, and nested objects. Ensure object names are globally unique. ```cpp // This is a comment object_keyword Example/ObjectName { attribute_name "some value" object_keyword2 "Nested Object" { other_attribute 1 2 3 // and so on.. } } ``` -------------------------------- ### Install Ogre using CMake Source: https://github.com/ogrecave/ogre/blob/master/BuildingOgre.md After building, use this command to install Ogre to the specified CMAKE_INSTALL_PREFIX. This is necessary for referencing Ogre in other projects with CMake. ```bash cmake --build . --config Release --target install ``` -------------------------------- ### Create Scene with OgreBites Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/tutorials/setup.md Implement the setup method to create the scene, including loading resources and setting up the scene manager. ```cpp void MyGame::setup() { // do something before initApp ApplicationContext::initApp(); // create the scene Ogre::SceneManager* sceneManager = mRoot->createSceneManager(); // register our custom scene Ogre::RTShader::ShaderGenerator::getSingletonPtr()->addSceneManager(sceneManager); // next we will be introducing the camera Ogre::Camera* camera = sceneManager->createCamera("myCamera"); camera->setNearClipDistance(10); camera->setAutoAspectRatio(true); Ogre::SceneNode* camNode = sceneManager->getRootSceneNode()->createChildSceneNode(); camNode->attachObject(camera); // also need to tell where the sample media will be mRoot->getRenderSystem()->getConfigurationManager()->setMediaDirectory("../media"); } ``` -------------------------------- ### Initialize the Ogre Profiler Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/tutorials/profiler.md Enable the profiler singleton at the start of your application. This sets up the necessary media for profiling. ```cpp Ogre::Profiler::getSingleton().setEnabled(true); ``` -------------------------------- ### Camera Information Setup Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/tutorials/basictutorials/basictutorial3.md Sets up camera information, likely for rendering or scene management purposes. ```cpp // Setup camera info cam->setFrustumOffset(0.0f); cam->setWindow); cam->setProjectionType(PT_PERSPECTIVE); cam->setFOVy(Degree(75)); cam->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight())); ``` -------------------------------- ### GLSL Shader Example Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/high-level-programs.md A basic GLSL vertex shader example. ```cpp #version 120 uniform mat4 worldMatrix; attribute vec4 vertex; void main() { gl_Position = worldMatrix * vertex; } ``` -------------------------------- ### Install Overlay Component Source: https://github.com/ogrecave/ogre/blob/master/Components/Overlay/CMakeLists.txt Installs the OgreOverlay component, including its header files and a profiler zip file, to the appropriate destinations within the OGRE installation directory. ```cmake # install ogre_config_framework(OgreOverlay) ogre_config_component(OgreOverlay) install(FILES ${HEADER_FILES} DESTINATION include/OGRE/Overlay ) install(FILES "${PROJECT_SOURCE_DIR}/Media/packs/profiler.zip" DESTINATION "${OGRE_MEDIA_PATH}/packs/" ) ``` -------------------------------- ### Setup OgreOverlay Target Source: https://github.com/ogrecave/ogre/blob/master/Components/Overlay/CMakeLists.txt Configures the OgreOverlay target library, linking it with OgreMain and setting include directories for build and installation. It also conditionally links FreeType libraries and includes directories if FreeType is found. ```cmake # setup target add_library(OgreOverlay ${OGRE_COMP_LIB_TYPE} ${HEADER_FILES} ${SOURCE_FILES}) set_target_properties(OgreOverlay PROPERTIES VERSION ${OGRE_SOVERSION} SOVERSION ${OGRE_SOVERSION}) target_link_libraries(OgreOverlay PUBLIC OgreMain) target_include_directories(OgreOverlay PUBLIC "$" $) if(FREETYPE_FOUND) target_compile_definitions(OgreOverlay PRIVATE HAVE_FREETYPE) target_link_libraries(OgreOverlay PRIVATE ${FREETYPE_LIBRARIES}) target_include_directories(OgreOverlay PRIVATE ${FREETYPE_INCLUDE_DIRS}) if(ZLIB_FOUND) target_link_libraries(OgreOverlay PRIVATE ZLIB::ZLIB) endif() elseif(UNIX) set_source_files_properties(src/OgreFont.cpp PROPERTIES COMPILE_FLAGS "-Wno-cast-qual -Wno-unused-function") endif() ``` -------------------------------- ### Install OgreBullet Header Files Source: https://github.com/ogrecave/ogre/blob/master/Components/Bullet/CMakeLists.txt Installs the header files for the OgreBullet component to the appropriate destination directory. ```cmake install(FILES ${HEADER_FILES} DESTINATION include/OGRE/Bullet) ``` -------------------------------- ### Install Ubuntu Dependencies for OGRE Source: https://github.com/ogrecave/ogre/blob/master/BuildingOgre.md Installs necessary system headers and libraries for building OGRE on Ubuntu, including optional dependencies for Wayland, input handling, and documentation generation. ```bash sudo apt-get install libgles2-mesa-dev libvulkan-dev glslang-dev # with OGRE_USE_WAYLAND=OFF sudo apt-get install libxrandr-dev # with OGRE_USE_WAYLAND=ON sudo apt-get install libwayland-dev libwayland-egl1 libegl-dev # Optional dependencies sudo apt-get install libsdl2-dev doxygen ``` -------------------------------- ### Deferred Shading Example Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/tutorials/deferred.md This snippet demonstrates the integration of deferred shading logic within the Ogre framework. ```cpp #include void DeferredShading::execute(Ogre::SceneManager* sm, Ogre::SceneManager::LightList* lightList) { sm->prepareShadowTextures(lightList); } ``` -------------------------------- ### Basic DotScene XML Structure Source: https://github.com/ogrecave/ogre/blob/master/PlugIns/DotScene/README.md A simple example of a .scene file defining nodes, positions, scales, entities, and lights. ```xml ``` -------------------------------- ### Install OgreMain Library and Headers with CMake Source: https://github.com/ogrecave/ogre/blob/master/OgreMain/CMakeLists.txt Installs the OgreMain library and its associated header files to the appropriate destinations. This is typically used in the build process to make the library available for use. ```cmake ogre_config_lib(OgreMain TRUE) install(FILES ${HEADER_FILES} DESTINATION include/OGRE ) install(FILES ${PLATFORM_HEADERS} DESTINATION include/OGRE/${PLATFORM_HEADER_INSTALL} ) install(FILES ${THREAD_HEADER_FILES} DESTINATION include/OGRE/Threading ) ``` -------------------------------- ### Enable LiSPSM Shadow Camera Setup Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/ogre-shadows.md Applies the Light Space Perspective Shadow Mapping (LiSPSM) algorithm to the scene's shadow camera setup. This is a global setting for the SceneManager. ```cpp mSceneMgr->setShadowCameraSetup(Ogre::LiSPSMShadowCameraSetup::create()); ``` -------------------------------- ### HW Basic Vertex Shader Input Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/instancing.md Example of vertex shader input for HW Basic instancing, including the world matrix. ```cpp ... float3x4 worldMatrix : TEXCOORD1, ... ``` -------------------------------- ### DotScene XML for Instanced Entities Source: https://github.com/ogrecave/ogre/blob/master/PlugIns/DotScene/README.md Example of an entity definition in a .scene file that specifies it should be managed by an Instance Manager. ```xml ``` -------------------------------- ### Material Definition With Unified Programs Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/high-level-programs.md This example demonstrates using unified program definitions to support multiple languages (HLSL and GLSL) within a single material definition, reducing redundancy. ```cpp vertex_program myVertexProgramHLSL hlsl { source prog.hlsl entry_point main_vp target vs_2_0 } fragment_program myFragmentProgramHLSL hlsl { source prog.hlsl entry_point main_fp target ps_2_0 } vertex_program myVertexProgramGLSL glsl { source prog.vert } fragment_program myFragmentProgramGLSL glsl { source prog.frag default_params { param_named tex int 0 } } // Unified definition vertex_program myVertexProgram unified { delegate myVertexProgramGLSL delegate myVertexProgramHLSL } fragment_program myFragmentProgram unified { delegate myFragmentProgramGLSL delegate myFragmentProgramHLSL } material SupportHLSLandGLSLwithUnified { // HLSL technique technique { pass { vertex_program_ref myVertexProgram { param_named_auto worldViewProj worldviewproj_matrix param_named_auto lightColour light_diffuse_colour 0 param_named_auto lightSpecular light_specular_colour 0 param_named_auto lightAtten light_attenuation 0 } fragment_program_ref myFragmentProgram { } } } } ``` -------------------------------- ### Material Definition Without Unified Programs Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/high-level-programs.md This example shows how to define a programmable material supporting both HLSL and GLSL by duplicating techniques for each language. This can lead to bloated material definitions. ```cpp vertex_program myVertexProgramHLSL hlsl { source prog.hlsl entry_point main_vp target vs_2_0 } fragment_program myFragmentProgramHLSL hlsl { source prog.hlsl entry_point main_fp target ps_2_0 } vertex_program myVertexProgramGLSL glsl { source prog.vert } fragment_program myFragmentProgramGLSL glsl { source prog.frag default_params { param_named tex int 0 } } material SupportHLSLandGLSLwithoutUnified { // HLSL technique technique { pass { vertex_program_ref myVertexProgramHLSL { param_named_auto worldViewProj worldviewproj_matrix param_named_auto lightColour light_diffuse_colour 0 param_named_auto lightSpecular light_specular_colour 0 param_named_auto lightAtten light_attenuation 0 } fragment_program_ref myFragmentProgramHLSL { } } } // GLSL technique technique { pass { vertex_program_ref myVertexProgramGLSL { param_named_auto worldViewProj worldviewproj_matrix param_named_auto lightColour light_diffuse_colour 0 param_named_auto lightSpecular light_specular_colour 0 param_named_auto lightAtten light_attenuation 0 } fragment_program_ref myFragmentProgramGLSL { } } } } ``` -------------------------------- ### Shader Script Equivalent for Programmatic Creation Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/high-level-programs.md This is the shader script syntax that the programmatic C++ example replicates. It defines a vertex program with specific source, preprocessor defines, and automatic parameters. ```cpp vertex_program glTF2/PBR_vs glsl { source pbr-vert.glsl preprocessor_defines HAS_NORMALS,HAS_TANGENTS default_params { param_named_auto u_MVPMatrix worldviewproj_matrix } } ``` -------------------------------- ### Initialize OgreBites Application Context Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/tutorials/setup.md Set up the application name and initialize Ogre components and the window using OgreBites::ApplicationContext. ```cpp class MyGame : public OgreBites::ApplicationContext { public: MyGame() : ApplicationContext("MyGame") {} void setup() override; }; void MyGame::setup() { // do something before initApp ApplicationContext::initApp(); // do something after initApp } ``` -------------------------------- ### Get Custom Translator Instance Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/scripts.md Implement the getTranslator function to return an instance of your custom translator. This example reuses a single instance for efficiency. ```cpp #define font_get_translator Ogre::ScriptTranslator* FontTranslatorManager::getTranslator(const Ogre::String& type) { if (type == "font") { return &mFontTranslator; } return 0; } ``` -------------------------------- ### Compile Ogre Java Sample Source: https://github.com/ogrecave/ogre/blob/master/Samples/Java/README.md Use this command to compile the Example.java file. Ensure Ogre-*.jar is in your classpath. ```bash javac Example.java -classpath Ogre-*.jar ``` -------------------------------- ### Run Ogre Java Sample Source: https://github.com/ogrecave/ogre/blob/master/Samples/Java/README.md Execute the compiled Java sample. The -Djava.library.path argument is crucial for loading native libraries. ```bash java -classpath .:Ogre-1.12.12.jar -Djava.library.path=. Example ``` -------------------------------- ### Install TestContext on Windows Source: https://github.com/ogrecave/ogre/blob/master/Tests/VisualTests/Context/CMakeLists.txt Ensures TestContext is installed when building on Windows, as it cannot be run directly from the build directory. ```cmake if (WIN32) ogre_install_target(TestContext "" FALSE) endif() ``` -------------------------------- ### Set Up Camera for Terrain Tutorial Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/tutorials/basictutorials/basictutorial3.md Configures the camera, including setting the far clip distance to zero for no far clipping. ```cpp void setupContent(SceneManager* sm, SceneManager* sm2, Light* light) { // Setup the camera Camera* cam = sm->createCamera("Cam1"); cam->setPosition(Vector3(0, 1000, 0)); cam->lookAt(Vector3(0, 0, 0)); cam->setNearClipDistance(1); cam->setFarClipDistance(0); // No far clipping // Setup the second camera Camera* cam2 = sm2->createCamera("Cam2"); cam2->setPosition(Vector3(0, 1000, 0)); cam2->lookAt(Vector3(0, 0, 0)); cam2->setNearClipDistance(1); cam2->setFarClipDistance(0); // No far clipping } ``` -------------------------------- ### Initialize OverlaySystem with OgreBites Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/manual.md If using OgreBites, fetch the pre-existing OverlaySystem from the application context and add it as a render queue listener to the SceneManager. ```cpp Ogre::OverlaySystem* pOverlaySystem = myApplicationContext.getOverlaySystem(); mSceneMgr->addRenderQueueListener(pOverlaySystem); ``` -------------------------------- ### Instantiate Elements Using Templates Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/scripts.md Demonstrates creating a panel and buttons within an overlay, inheriting properties from defined templates. ```cpp overlay MyOverlays/AnotherOverlay { zorder 490 overlay_element MyElements/BackPanel BorderPanel : MyTemplates/BasicBorderPanel { left 0 top 0 width 1 height 1 overlay_element MyElements/HostButton Button : MyTemplates/BasicButton { left 0.82 top 0.45 caption MyTemplates/BasicText HOST } overlay_element MyElements/JoinButton Button : MyTemplates/BasicButton { left 0.82 top 0.60 caption MyTemplates/BasicText JOIN } } } ``` -------------------------------- ### Install Fedora Dependencies for OGRE Source: https://github.com/ogrecave/ogre/blob/master/BuildingOgre.md Installs required system headers and libraries for building OGRE on Fedora, including optional dependencies for Wayland, input handling, and documentation generation. ```bash sudo dnf install mesa-libGL-devel mesa-libEGL-devel mesa-vulkan-devel glslang-devel # with OGRE_USE_WAYLAND=OFF sudo dnf install libXrandr-devel # with OGRE_USE_WAYLAND=ON sudo dnf install pkgconfig wayland-devel egl-wayland # Optional dependencies sudo dnf install SDL2-devel doxygen ``` -------------------------------- ### Create Instance Manager with HW VTF LUT Flags Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/instancing.md Demonstrates creating an Instance Manager with flags for HW Instancing VTF and Bone Matrix LookUp Table, suitable for animating large crowds. ```cpp mSceneMgr->createInstanceManager("InstanceMgr","MyMesh.mesh", ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, InstanceManager::HWInstancingVTF, numInstancesPerBatch,IM_USEALL|IM_VTFBONEMATRIXLOOKUP ); ``` -------------------------------- ### Initialize Ogre Application Context Source: https://github.com/ogrecave/ogre/blob/master/Samples/Python/numpy_sample.ipynb Sets up the Ogre application context and initializes the rendering subsystem. This is necessary for environments without a direct display, requiring an offscreen render target. ```python !pip install ogre-python import matplotlib.pyplot as plt import numpy as np import Ogre import Ogre.Bites import Ogre.RTShader class Application(Ogre.Bites.ApplicationContextBase): def __init__(self): Ogre.Bites.ApplicationContextBase.__init__(self, "OgreColab") def oneTimeConfig(self): rs = self.getRoot().getRenderSystemByName("OpenGL 3+ Rendering Subsystem") self.getRoot().setRenderSystem(rs) return True def pollEvents(self): pass ctx = Application() ctx.initApp() root = ctx.getRoot() scn_mgr = root.createSceneManager() shadergen = Ogre.RTShader.ShaderGenerator.getSingleton() shadergen.addSceneManager(scn_mgr) # no RenderWindows are available here, so create an offscreen rendertarget and use that w, h = 640, 480 tex = Ogre.TextureManager.getSingleton().createManual( "target", Ogre.RGN_DEFAULT, Ogre.TEX_TYPE_2D, w, h, 0, Ogre.PF_BYTE_RGB, Ogre.TU_RENDERTARGET, None) win = tex.getBuffer().getRenderTarget() ``` -------------------------------- ### Set Install Path for macOS Plugins Source: https://github.com/ogrecave/ogre/blob/master/Tests/VisualTests/VTests/CMakeLists.txt Configures the installation path for the VTests library on macOS to ensure that plugins are correctly located within the application bundle. This is specific to Apple platforms and not iOS. ```cmake if (APPLE AND NOT APPLE_IOS) # Set the INSTALL_PATH so that Samples can be installed in the application package set_target_properties(VTests PROPERTIES BUILD_WITH_INSTALL_RPATH 1 INSTALL_NAME_DIR "@executable_path/../Plugins" ) endif() ``` -------------------------------- ### Copy SDK and Create Android Project Source: https://github.com/ogrecave/ogre/blob/master/Samples/AndroidJNI/CMakeLists.txt Uses a custom command to copy the SDK directory before building the dummy JNI library and then calls `create_android_proj` to finalize the Android project setup. ```cmake add_custom_command(TARGET OgreJNIDummy PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_BINARY_DIR}/java" "${NDKOUT}") create_android_proj(OgreJNIDummy) ``` -------------------------------- ### Task-Based WorkQueue API Example Source: https://github.com/ogrecave/ogre/blob/master/Docs/14-Notes.md The WorkQueue API has transitioned from a request/response model to a task-based model. This example demonstrates sending work as a callback, eliminating the need for explicit request/response handlers and the WorkQueue-channel concept. ```cpp Root::getSingleton().getWorkQueue()->addRequest(mWorkQueueChannel, WORKQUEUE_DERIVED_DATA_REQUEST, data); ``` ```cpp Root::getSingleton().getWorkQueue()->addTask( [this, req]() { auto req = new WorkQueue::Request(0, 0, data, 0, 0); auto res = handleRequest(r, NULL); Root::getSingleton().getWorkQueue()->addMainThreadTask([this, res]() { handleResponse(res, NULL); delete res; }); }); ``` -------------------------------- ### Run C# Sample with Mono Source: https://github.com/ogrecave/ogre/blob/master/Samples/Csharp/README.md Execute a compiled C# sample using the Mono runtime on Linux. ```bash mono example.exe ``` -------------------------------- ### Instantiate Dummy Profiler for Release Builds Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/tutorials/profiler.md Creates a dummy profiler instance and enables it for use in release builds when OGRE_PROFILING is OFF. This allows manual use of beginProfile() and endProfile() but disables the OgreProfile macros. ```cpp // Create dummy profile to set singleton pointer new Ogre::Profiler(); // Give it a timer and enable it Ogre::Profiler::getSingleton().setTimer(Root::getSingleton().getTimer()); Ogre::Profiler::getSingleton().setEnabled(true); ``` -------------------------------- ### Programmatic GPU Program Creation Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/high-level-programs.md This example demonstrates how to create a vertex program programmatically using the Ogre API, mirroring the functionality of a shader script definition. It shows setting the source, preprocessor defines, and auto-updating parameters. ```cpp using namespace Ogre; GpuProgramManager& mgr = GpuProgramManager::getSingleton(); GpuProgramPtr vertex_program = mgr.createProgram("glTF2/PBR_vs", RGN_DEFAULT, "glsl", GPT_VERTEX_PROGRAM); vertex_program->setSource("pbr-vert.glsl"); vertex_program->setParameter("preprocessor_defines", "HAS_NORMALS,HAS_TANGENTS"); GpuProgramParametersPtr params = vertex_program->getDefaultParameters(); params->setNamedAutoConstant("u_MVPMatrix", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX); ``` -------------------------------- ### Add Android JNI Binding Example Source: https://github.com/ogrecave/ogre/blob/master/Samples/CMakeLists.txt Conditionally adds the Android JNI sample subdirectory if OGRE_BUILD_ANDROID_JNI_SAMPLE is enabled. ```cmake if(OGRE_BUILD_ANDROID_JNI_SAMPLE) add_subdirectory(AndroidJNI) endif() ``` -------------------------------- ### Configure and Generate LOD Levels Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/tutorials/meshlod.md Programmatically configure LOD generation using LodConfig. This example demonstrates setting up proportional reduction based on distance and adding manually created LOD levels. Ensure background queue is enabled for threaded generation. ```cpp Ogre::LodConfig config(mesh); config.createGeneratedLodLevel(5, 0.5); // At 5 ogre worldspace units use 50% reduced mesh config.createGeneratedLodLevel(10, 0.75); // By default, it is using DistanceLodStrategy and proportional reduction. config.createManualLodLevel(15, "mesh_LOD3.mesh"); // Manual level created in blender, maya or 3ds max. config.advanced.useBackgroundQueue = true; // Generate in background thread, later inject with framelistener. Ogre::MeshLodGenerator::getSingleton().generateLodLevels(config); // Or you can use autoconfigured LOD: Ogre::MeshLodGenerator::getSingleton().generateAutoconfiguredLodLevels(mesh); ``` -------------------------------- ### Material Definition for Uber Shader Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/high-level-programs.md Example of instantiating an uber shader in a material file using preprocessor defines. ```material vertex_program TextureAndSkinning glsl { source UberShader_vp.glsl preprocessor_defines USE_UV,USE_SKINNING default_params { ... } } ``` -------------------------------- ### Instantiate Particle System from Script Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/particle-scripts.md Demonstrates how to create a particle system instance from a script template using Ogre::SceneManager. The method takes the name for the new system and the name of the template defined in the script. ```cpp Ogre::ParticleSystem* ps = mSceneMgr->createParticleSystem("MyParticleSystem", "Examples/Manual/Smoke"); ``` -------------------------------- ### Set Global Volume Material Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/tutorials/volume.md Sets the global material for the volume chunk, for example, using a 'triplanarReference' material. ```cpp volumeRoot->setMaterial("triplanarReference"); ``` -------------------------------- ### Define and Load Terrains Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/tutorials/basictutorials/basictutorial3.md Iterates through terrain definitions and asks the TerrainGroup to load them. This example uses a single terrain. ```cpp mTerrainGroup->defineTerrain(0, 0, 0.0f, 0.0f, "Terrain", "", false); // Set up the blend maps for (int i = 0; i < mTerrainGroup->getTerrainCount(); ++i) { Terrain* terrain = mTerrainGroup->getTerrain(i % mTerrainGroup->getTerrainSize(), i / mTerrainGroup->getTerrainSize()); initBlendMaps(terrain); } ``` -------------------------------- ### DotScene XML for Static Geometry Source: https://github.com/ogrecave/ogre/blob/master/PlugIns/DotScene/README.md Example of an entity definition in a .scene file that specifies it should be part of a static geometry group. ```xml ``` -------------------------------- ### Create TrayManager Instance Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/tutorials/trays.md Instantiate a TrayManager, providing a unique name for the interface and the Ogre::RenderWindow. Optionally, a TrayListener can be provided for event notifications. Remember to load 'Trays.zip' and initialize the Overlays component beforehand. ```cpp OgreBites::TrayManager* mTrayMgr = new OgreBites::TrayManager("InterfaceName", mWindow); ``` -------------------------------- ### Initialize OverlaySystem Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/manual.md Manually initialize the OverlaySystem by creating an instance and adding it as a render queue listener to the SceneManager. This is required for overlays to function. ```cpp Ogre::OverlaySystem* pOverlaySystem = new Ogre::OverlaySystem(); mSceneMgr->addRenderQueueListener(pOverlaySystem); ``` -------------------------------- ### Set pass to iterate once per light type Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/material-scripts.md The pass is executed once for each specified light type. For example, 'point' lights. ```materialscript iteration once_per_light point ``` -------------------------------- ### Create a Spotlight Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/tutorials/basictutorials/basictutorial2.md Use Ogre::SceneManager::createLight to add a spotlight to the scene. This is typically done after creating other scene elements. ```cpp Ogre::Light* light = mSceneMgr->createLight("SpotLight"); ``` -------------------------------- ### Spacing Around Operators Source: https://github.com/ogrecave/ogre/blob/master/Docs/CodingStandards.md Insert spaces around operators for better readability. For example, use 'x + y' instead of 'x+y'. ```cpp int result = x + y; ``` -------------------------------- ### Using Instance Manager with DotScene in Ogre C++ Source: https://github.com/ogrecave/ogre/blob/master/PlugIns/DotScene/README.md Code demonstrating the creation of an InstanceManager and loading a scene that uses instanced entities. ```cpp // Create the InstanceManager Ogre::InstanceManager* im = mSceneMgr->createInstanceManager("Foliage", "Cube.mesh", "MyGroup", Ogre::InstanceManager::ShaderBased, 80, Ogre::IM_USEALL); attachmentNode->loadChildren("myScene.scene"); ``` -------------------------------- ### Configure Test Environment Source: https://github.com/ogrecave/ogre/blob/master/Tests/CMakeLists.txt Sets up the test environment by creating necessary directories and linking framework resources. This is typically used during the build process to prepare the testing infrastructure. ```cmake add_custom_command(TARGET Test_Ogre POST_BUILD COMMAND mkdir ARGS -p ${OGRE_TEST_CONTENTS_PATH}/Plugins) set(FRAMEWORKS OgreOverlay OgreBites OgrePaging OgreProperty OgreRTShaderSystem OgreTerrain OgreVolume OgreMeshLodGenerator Plugin_BSPSceneManager Plugin_CgProgramManager Plugin_OctreeSceneManager Plugin_OctreeZone Plugin_ParticleFX Plugin_PCZSceneManager Plugin_DotScene Codec_STBI Codec_FreeImage RenderSystem_GL RenderSystem_GL3Plus RenderSystem_Metal ) foreach(FWK ${FRAMEWORKS}) add_custom_command(TARGET Test_Ogre POST_BUILD COMMAND ARGS if [ -d ${PROJECT_BINARY_DIR}/lib/${OGRE_BUILT_FRAMEWORK}/${FWK}.framework ]\; then ln -s -f ${PROJECT_BINARY_DIR}/lib/${OGRE_BUILT_FRAMEWORK}/${FWK}.framework ${OGRE_TEST_CONTENTS_PATH}/Frameworks/${FWK}.framework\; fi ) endforeach() endif (OGRE_BUILD_TESTS) ``` -------------------------------- ### Adding User Data to Entities in DotScene Source: https://github.com/ogrecave/ogre/blob/master/PlugIns/DotScene/README.md Example of how to attach custom user data properties to an entity within a .scene file. ```xml ``` -------------------------------- ### VTF Instancing Texture Unit Setup Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/instancing.md Configuration for the texture unit used in VTF (Software) instancing. Filtering is set to none. ```plaintext texture_unit InstancingVTF { filtering none } ``` -------------------------------- ### Python: Rapid Prototyping with HighPy Source: https://github.com/ogrecave/ogre/blob/master/README.md Use this snippet to quickly set up a PBR scene with OGRE using its Python bindings. Ensure you have installed the 'ogre-python' package. The loop exits when the ESC key is pressed. ```python # pip install ogre-python import Ogre.HighPy as ohi # Create a window ohi.window_create("Ogre", window_size=(1280, 720)) # Load a mesh (glTF 2.0, OBJ, or Ogre Mesh) ohi.mesh_show("Ogre", "DamagedHelmet.glb", position=(0, 0, -3)) ohi.point_light("Ogre", position=(0, 10, 0)) # Main Loop while ohi.window_draw("Ogre") != 27: # Press ESC to exit pass ``` -------------------------------- ### Generate Ogre API Documentation Source: https://github.com/ogrecave/ogre/blob/master/BuildingOgre.md If doxygen is installed and detected by CMake, this command can be used to generate the API documentation. This is an optional build target. ```bash make OgreDoc ``` -------------------------------- ### Set Entity Scale Source: https://github.com/ogrecave/ogre/blob/master/Docs/src/tutorials/basictutorials/basictutorial1.md Scales an entity by providing a scale factor for each dimension. This example adds a new Ogre head with a different scale. ```cpp @snippet Samples/Tutorials/BasicTutorial1.cpp entity3 ``` -------------------------------- ### Link Sample Libraries for Static Builds Source: https://github.com/ogrecave/ogre/blob/master/Samples/Browser/CMakeLists.txt Conditionally links all OGRE sample libraries when building a static SampleBrowser. ```cmake if (OGRE_STATIC) # Link to samples too target_link_libraries(SampleBrowser ${OGRE_SAMPLES_LIST}) endif() ``` -------------------------------- ### Configure XAW Library for Linux Source: https://github.com/ogrecave/ogre/blob/master/Components/Bites/CMakeLists.txt Appends C++ source files and dependencies for the XAW library on Linux, excluding Wayland, and installs a resource file. ```cmake list(APPEND SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/OgreGLXConfigDialog.cpp") list(APPEND DEPENDENCIES ${X11_Xt_LIB} ${XAW_LIBRARY}) install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/misc/GLX_backdrop.png" DESTINATION "${OGRE_MEDIA_PATH}/../") ``` -------------------------------- ### Configure OgreBullet Library Source: https://github.com/ogrecave/ogre/blob/master/Components/Bullet/CMakeLists.txt Defines the OgreBullet library, links necessary components like OgreMain and OgreTerrain, and sets up include directories for build and installation. ```cmake set(HEADER_FILES include/OgreBullet.h ${PROJECT_BINARY_DIR}/include/OgreBulletExports.h) add_library(OgreBullet ${OGRE_COMP_LIB_TYPE} ${HEADER_FILES} src/OgreBullet.cpp) if (OGRE_BUILD_COMPONENT_TERRAIN) target_link_libraries(OgreBullet PUBLIC OgreTerrain) endif() target_link_libraries(OgreBullet PUBLIC OgreMain) target_include_directories(OgreBullet PUBLIC "$" $) target_include_directories(OgreBullet SYSTEM PUBLIC "$") if(OGRE_BUILD_DEPENDENCIES) target_include_directories(OgreBullet PUBLIC "$") target_link_libraries(OgreBullet PUBLIC "$") else() target_link_libraries(OgreBullet PUBLIC ${BULLET_LIBRARIES}) endif() ```