Delta-Works TreeLib (c) 2007-2008 Stefan Elsen Q/A What is TreeLib? TreeLib is a shared library for Linux and Windows to handle trees. The library handles generation, automated detail approximation and rendering in OpenGL. An existing OpenGL context is required for rendering. The library may however be used to simply extract the geometries of the generated trees in order to render them via other methods. A valid OpenGL context is not needed in this case. Are there any restrictions on how to create the used OpenGL context (if any)? No. Any context will do. With whatever foundation or method created. In general You should be able to use whatever language as long as it can create an OpenGL context and open DLLs/SOs. The provided headers are for C/C++ only so far though. You may have to improvise. Is there a version of TreeLib for Direct3d? Not at this point. If you wish to use this library to render trees using Direct3d, You will have to extract and render the trees manually. What extensions does TreeLib use/require? TreeLib does not require extensions but does look and perform better if certain key extensions are available. Bump-mapping depends on OpenGL Shader Objects (using GLSL, the OpenGL shading lanaguage) being available and will be disabled if those are not supported. Imposters will require the OpenGL Frame Buffer extension. If this extension is not available then imposter rendering will be disabled and all trees will be rendered in geometry. Also imposters may be normal-mapped and thus look better if shader objects are available. Is TreeLib free? Yes. You may use TreeLib for any purpose, commercial or not, as long as the original behavior and the content of this file remain unchanged. However, charging money for the library or any of its generated geometries as a stand-alone product is prohibited. If you payed money to acquire this library then you were probably swindled. You may distribute this library as pleased. A link to http://www.Delta-Works.org is appreciated but not required. Is TreeLib open source? Not for the time being. TreeLib does depend on a closed-source library of considerable size and cannot be compiled by itself. Can generated trees be exported? Yes. The tree geometry may be exported as separate vertex and triangular index data. The leaves may be exported as an array of positions. How many trees can i use simultaniously? As many as you like/have memory for. You may also reuse the same tree as often as you wish throughout the scenery. Is TreeLib multi thread safe? Mostly. For the sake of memory and speed efficiency i avoided the use of mutexes per tree. To see what functions are thread safe in what manner check the function specifications below. May I reuse the provided textures? The textures are derivative works of free photos. They may be reused or modified as seen fit. TreeLib contents: The core consists of the shared library treelib.dll (treelib.so for linux/unix) and a separate 'textures' folder containing three textures: bark.png, bump.png, and leaves.png Make sure this folder is located in the same folder as the library itself when rendering or loading textures through the dll. Additionally the files treelib.h and interface.h/.cpp help simplifying the linking process for C++ applications. To get You started with a simple example application a file 'example.zip' contains a simple GLUT application that renders a single tree to a window. Should You encounter troubles with the example or need further instruction then feel free to contact me. Linking TreeLib: You should start by putting all files into a sub-folder of the project that will access the library. For easier linking it's useful to include the files interface.h and interface.cpp into your project. The function TreeLib::load(filename) handles all necessary linking and returns true on success. Alternatively you can link the library and extract the pointers manually. Generating and rendering trees: There are currently two ways of creating a tree: void*tree = TreeLib::createTree() will create a pure random tree and void*tree = TreeLib::createTreeFromSeed(int) will (re)create a tree from a seed. When a new tree is created, it receives a copy of the global configuration as its own. By default generated trees are about the size of real trees with 1.0f being 1 meter. This can be altered using the respective settings. To render a tree it must first be put into Your scenery using the TreeLib::putTree(tree,position,up,right); where [tree] is Your tree, [position] is a pointer to a 3-float array containing the position, [up] a pointer to a 3-float array containing the up axis, and [right] a pointer to a 3-float array containing the right axis ([up] and [right] are required to be of length 1 and orthogonal to each other). Example: float right[3] = {1,0,0}, up[3] = {0,1,0}, position[3] = {0,0,0}; TreeLib::putTree(my_tree,position,up,right); Once all trees have been put into the scenery, a simple call to TreeLib::renderComposition() will render all put trees. Alternatively You can invoke (or not invoke) the individual tasks using the following methods: TreeGen::renderCompositionImposters(), TreeGen::renderCompositionBranches(), TreeGen::renderCompositionShadows(), and TreeGen::renderCompositionLeaves() These functions may be invoked in any order. However, once You're done it's crucial that You invoke the TreeGen::flushComposition() function. Otherwise the trees of each frame will stack causing a render time explosion. Textures: TreeLib requires two (optionally also a third bump-map) textures, one for the leaves and one for the branches. There are two ways of specifying those: * By string: By default textures are defined as filenames and loaded the first time they are needed. Supported file types are Bitmap, JPEG, PNG, and TGA. Unlike most other tree attributes, changing the filename of a tree's texture's path does not require a tree rebuild. * By integer: You can specify textures directly as OpenGL texture integers, effectivly overriding any specified texture file path. Likewise You may also retrieve the OpenGL texture handle of a loaded texture. Examples: Linking, creating and rendering: if (!TreeLib::load("treelib/treelib.dll")) { cout << "Error while linking:\n"<