CodeSnippets
From Ogre Wiki
(Redirected from CodeSnippits)
|
HOWTO's and Code SnippetsThis is a cookbook of code recipies for implementing a wide variety of tasks. The mini articles below on this page are for articles of a significant size. See The Big HOWTO and The Big HOWTO (II) for a large collection of miscellaneous, smaller samples. Samples from external sites go on the External Resources page. |
Contents |
HOWTO
HOWTO - Collection of miscellaneous, smaller samples
HOWTO (II) - Part 2
Geometry
Vertex and Index Buffers
- Sharing buffers - Sharing vertex and index buffers across multiple meshes
- Generating a Mesh - Example of creating a mesh in memory using a index and vertex buffer
- Retrieving vertex data from a mesh
- Dynamically growing vertex buffers
- Creating a sphere mesh manually with nice texture coordinates and normals
- Using super ellipsoid for creating simple 3d primitives
- Creating various geometric/geodesic shapes
- Creates a set of tubes along a path
- Changing Coordinate Handedness - One way of using DirectX data
Manual Object
- ManualObject - A minimal example
- ManualObject 2D - A minimal example (Eihort only)
- ManualObject AxisObject - A simple Axis using box's.
- EditorGridSystem - A dynamically changing grid system for editors and such
- Create Tetrahedron with MOGRE (easy to port for Ogre)
General
- Setting a vector's length
- Nearest point on a line - Find the nearest point on a line between two points
- 2D line intersection - do 2 lines described by 4 vertices in a plane intersect?
- Find Spline index - from global interpolation value
- Raycasting to the polygon level - how to see if a line intersects with a mesh's geometry
- Get Screenspace Coordinates - Get the screenspace (2D) coordinates of a MovableObject.
- Projecting 3D position and size to 2D
- Equal Length Spline - Generating new spline (based on SimpleSpline) which has equal distance between points.
- Nearest point on a Spline - From "Robust and Efficient Computation of the Closest Point on a Spline Curve"
- Get XZ coordinates - Retrieve XZ coordinates by a mouse ray
Rendering
- 2D Sprite Manager: A class for rendering 2D sprites, ie: the DirectDraw way.
- Drawing Lines in 3D
- Drawing lines in 3D revisited: Example of dynamic buffers code.
- Drawing Circles in 3D
- Displaying 2D Backgrounds
- Displaying a Lens Flare Effect
- HDR Effects Without Using Full Floating Point Textures
- Billboard-style Text in 3D: MovableText
Non-Photorealistic Rendering
Materials & Textures
- Loading resources from a URL - an Archive class for external resources.
- Merging and transforming archives - an Archive implementations that provide various transforms (resource overrides, file name prefixes).
- Creating dynamic textures - and materials using them.
- Saving dynamic textures
- Per renderable transparency - Utility classes to allow single renderables (Entities and SubEntities so far) to change their transparency without changing others that use the same material through a MaterialInstance utility class. See [this forum thread]
- Exporting 3D Textures - The (programmatic) generation of .dds and .raw 3D textures for use in Ogre.
- Material script examples - some example materials
- Rotating a texture using the getYaw() function - How to rotate a texture 360 degrees with the quaternion.getYaw() function
- Displaying 3D Object Text in 2D Without Using Billboards -- How to use the view transform to obtain 2D screen-space coordinates to draw overlay text above or near an object in the 3D scene.
- Displaying non-overlapping Text Overlays above Ogre MovableObjects -- Some enhancements to the Xavier's ObjectTextDisplay class resulted in 3 classes that do all the work for you. Enjoy!
- ObjectTitle - Display a title (text overlay) above a MovableObject
- Loading PGF Images -- Source code for loading PGF images using libPGF in Ogre
- Terrain Selection using a Mesh Decal -- using a mesh decal to show a marker on the terrain for terrain selection
- Light mapping -- A class used to do lightmapping in ogre.
- Reloading materials and parsing material scripts -- Ogre helper methods to reload all the materials found in a material script.
- Extending the Ogre GUI demo to reload textures on the fly -- A small extension to add a reload button to the Ogre GUI demo that makes customizing TaharezLook.tga faster.
- ColoredTextAreaOverlayElement -- A class to allow Quake 3 style color codes to be inserted into text overlay elements.
- Fade In/Out Effect Overlay -- Create an overlay that lets you create fade in/out effects in your scene.
- Crop Image -- Crop an Image into a smaller image.
- Creating transparency based on a key colour in code
- Merge exe with a media zip -- Embed a zip file of media within an ogre application executable.
Particles
- Sun Effect - An Example Particle Script
- Moving Space Dust Effect - A Space Dust Effect
- Interpolation Affector - A particle affector to vary size, rotation and velocity of particles.
- Iterated Fractals - Using ManualObjects as Point Sprites to create a Pickover attractor (updates in real-time with a million or more points!)
Shaders
- Introduction - How to submit a shader
- Getting Started With Ogre CG Materials
- How to compile CG code - How to check for errors in .cg code
- Orange Shader - A simple shader
- Fading Object Shader - A fade-to-dark effect
- Holographe Shader - An hologram effect
- PerPixel Lighting - Basic per-pixel, rather slow, texturing included
- PerPixel Lighting II
- The Monster - Tuneable parameters, feature-full, 1-pass, max 3 lights
- Shadows - How to start on Shadows
- Depth Shadow Mapping - How to implement depth shadow mapping in your own project as seen in the Shadows demo
- Custom Shadow Mapping - How to implement a custom shadow technique
- Parallel Split Shadow Mapping (PSSM) - A method for high-detail shadows
- Offset Bump Ambient Lightmap - Offset/Bump with added ambient and optional lightmap
- Ocean Fog - Basic underwater "depth" effect using the Ocean Shader
- Normal Mapping with Hardware Skinning and Specular - Combined normal mapping and hardware skinning
- Smoke Trails - Adding some turbulence to your ribbon trails
- Terrain Alpha Splatting - Basic terrain shader with up to 8 splat textures.
Animation & Movement
- Rotating yaw while ignoring pitch and roll
- Manually Controlling Bones
- 3rd person camera system tutorial - How to create a basic, flexible camera system
- Integrating Physics and OGRE from XML - Creating and loading physical structures from XML and automatically linking them to Ogre models.
- How to limit the pitch of a camera
- Creating a simple first-person camera system
- Generic Manual Pose Loading
- Make a character look at the camera Using quaternions and SLERP to make a character look at a camera(or any other object for that matter) naturally, with constraints on head movement
- Euler Angle Class - An Ogre compatible class for euler angles.
- How to drive a car - You have a car, you have a point (i.e. waypoint), but you don't know how to determine side car should turn to drive to point(left or right).
- Controlling car on twisted track - Controlling car on crazy, twisted tracks using physics engine.
Input
- Head Tracking using the WiiMote
- 3D Object Picking - cTh (bad camel screen to 3D coord translation)
- Translate from english keyboard layout to any other, for instance german
- Using OGRE with GII Using OGRE with the GII input library
- Using OIS Using the Object-orientated Input System Library with OGRE
- Pick Drag Drop - How to make drag&drop objects
- Simple keyboard string editing - A small class to take key presses and edit a string.
- Auto Repeat Key Input - A small class to take key presses and auto repeat keyboard input for GUI.
GUI
- UOgreBrowser - Embedding uBrowser in an Ogre application
- Using Ogre with FLTK FLUID - Tutorial
CEGUI
- CEGUI Common File Dialog - CEGUI Common file dialog
- Initial Mouse Position With OIS and CEGUI - How to initialize the mouse cursor to a starting position
- CEGUI Build Dialog - CEGUI dialog which displays rotating 3D meshes on multiple buttons
- How To Show The Mouse Cursor - Showing the mouse using CEGUI
- Creating a good looking Confirm Dialog with CEGUI
- Update Ogre source code with latest Cegui source code
Other GUI Systems
- Comparison of GUIs - This page contains a comparison of the various GUI systems available
- Integrating OpenGUI - How to integrate OpenGUI in Ogre projects
- MyGUI quickstart - How to add a GUI with button
General
- Creating Overlays via Code
- PieSlice Overlay - Useful for pie charts, sniper scopes, rev counters and other such circular GUI elements.
- How to show the Mouse Cursor W/O CEGUI
- Simple Text Output - Simple text output using overlays.
- Scrolling Message - Scrolling messages which is based on the Simple Text Output above.
- OgreFontHelper utils for rendering text if Ogre::TextAreaOverlayElement is not enough
- Reading a Unicode Multi Language Translation Table - A How To with code for creating, reading, and using a Unicode translation table
- ColoredTextAreaOverlayElement - Extension for the TextAreaOverlayElement
Embedding OGRE in mainstream GUI libraries
- Using Ogre with FLTK - Here presented a way to embed Ogre into FLTK gui toolkit window
- wxOgre - A simple rendering widget for wxWindows (OGRE V1.0.1)
- wxOgre for OGRE v1.2 - A simple rendering widget for wxWindows (OGRE V1.2)
- wxOgre for OGRE v1.4 - A simple rendering widget for wxWindows 2.8 <- Most Recent.
- GtkOgre - A GtkWidget for embedding Ogre render windows in GTK.
- GtkmmOgre - A GtkmmOgreWidget for embedding Ogre render windows in Gtkmm.
- qtOgre - Embedding Ogre into a qt application.
Sound & multimedia
- FMOD SoundManager - SoundManager using FMOD
- OpenAL SoundManager - SoundManager using OpenAl
- DirectShow video on a texture - how to play video with Direct Show in Ogre textures
Physics
- Mesh strider for bullet - Subclass from btStridingMeshInterface for sharing graphics and collision meshes
- Debug drawer for bullet - Subclass from btIDebugDraw that allows you to visualize collision shapes, contact points and more.
System
Minimal Ogre projects
- Basic Ogre Framework A fully featured, yet clean base application.
- Project base - A blank project to use as the base of your own. Get all the messy initial details out of the way with this 1000+ line boilerplate.
- Minimal Application a minimal app without using exampleApplication.h
- Hello World with minimal Ogre init: Hello World without using ExampleApplication.h or resource scripts
- Minimal Practical Application a minimal application using it's own main loop and plugin loading
- One Function Ogre: Exploring how to start Ogre without using ExampleApplication.h or the built in Config Dialog
Timer
- TimerManager - Wrapping Ogre::Timer to issue callbacks
- Assaf Muller's Timer Manager - A timer manager to help you access timers from anywhere
Logging
Console
OS tricks
- Change of a icon and caption of the Application Simple way.
- Find path to executable to locate data files
- How to make your project paths cross platform
- Installing Video Drivers On Linux
- Solve *.material scripts parsing problems on Linux
- Detect AC power status on Windows
Scene manager
Render system
- How to safely load rendersystems without a crash (as in, fail gracefully on systems that lack DirectX or GL)
- How to flush the GPU command buffer regularly
Script compilers (Shoggoth)
Misc
- Controlling Particle Systems
- How to load a mesh without initialising the Ogre renderer
- Parsing XML Files
- A simple camcorder class for recording & playing back camera paths
- A short example on how to create a plugin DLL that is loaded by Ogre at startup.
- How to load a mesh not under the predefined resource path.
Miscellaneous
- Easy debug text - uses the default ogre debug overlay text on the OgreDebugPanel overlay
- High resolution screenshots - how to make screenshots of unlimited size
- Printf with ogre - a simple class that lets you use printf with ogre.
- DotScene Loader with User Data - code for loading .scene files
- DotScene Loader with User Data Class - code for loading .scene files too
- Frustum Culling In Object Space - frustum culling using a custom SimpleFrustum class.
- Writing text on texture - how to write text onto a texture.
- All-purpose script parser - allows you to load your own custom data from Ogre-style scripts
- Query Ogre Version - a shell extension which allows to know the version of Ogre I'm working on
- MovableTextOverlay - display a text above an object (HUD / heads up display)
- Ogre Compatible HeightMap - get height of terrain at (x,z) positions
- Set icon of Window (Mogre)
- TinyXMLResource - use TinyXML documents via Ogres resource system
- AI Agent Control - AI Agent control code snippets
Useful Code Articles (w/code)
- std::map<> versus core::tree<> - Gamedev.net
- Soft Edge Shadows - Gamedev.net
- Callbacks - CodeGuru
- Function Pointers - Newty.DE
- Function Pointers - Eskimo.com
- Pointers to Member Functions - Parashift
- Fast Delegates - The Code Project


