Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/tools/TextureGenerator.cc @ 3126

Last change on this file since 3126 was 3110, checked in by rgrieder, 16 years ago

Removed old msvc specific support for precompiled header files.

  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file
31    @brief Implementation of the TextureGenerator.
32*/
33
34#include "TextureGenerator.h"
35#include <OgreMaterialManager.h>
36#include <OgreTechnique.h>
37#include "util/Convert.h"
38
39namespace std
40{
41    template <>
42    bool less<orxonox::ColourValue>::operator()(const orxonox::ColourValue& __x, const orxonox::ColourValue& __y) const
43    {
44        if (__x.r == __y.r)
45        {
46            if (__x.g == __y.g)
47            {
48                if (__x.b == __y.b)
49                {
50                    return __x.a < __y.a;
51                }
52                return __x.b < __y.b;
53            }
54            return __x.g < __y.g;
55        }
56        return __x.r < __y.r;
57    }
58}
59
60namespace orxonox
61{
62    std::map<std::string, std::map<ColourValue, std::string> > TextureGenerator::materials_s;
63    unsigned int TextureGenerator::materialCount_s = 0;
64
65    /*static*/ const std::string& TextureGenerator::getMaterialName(std::string textureName, const ColourValue& colour)
66    {
67        std::map<ColourValue, std::string>& colourMap = materials_s[textureName];
68        std::map<ColourValue, std::string>::const_iterator it = colourMap.find(colour);
69
70        if (it == colourMap.end())
71        {
72            std::string materialName = textureName + "_Material_" + convertToString(materialCount_s++);
73            Ogre::MaterialPtr material = (Ogre::MaterialPtr)Ogre::MaterialManager::getSingleton().create(materialName, "General");
74            material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
75            Ogre::TextureUnitState* textureUnitState = material->getTechnique(0)->getPass(0)->createTextureUnitState();
76            textureUnitState->setTextureName(textureName);
77            textureUnitState->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, colour);
78            return (colourMap[colour] = materialName);
79        }
80        else
81        {
82            return (*it).second;
83        }
84    }
85}
Note: See TracBrowser for help on using the repository browser.