Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2961 was 1625, checked in by rgrieder, 16 years ago

merged hud branch back to trunk

  • Property svn:eol-style set to native
File size: 2.9 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 "OrxonoxStableHeaders.h"
35#include "TextureGenerator.h"
36#include <OgreMaterialManager.h>
37#include <OgreTechnique.h>
38#include "util/Convert.h"
39
40namespace std
41{
42    template <>
43    bool less<orxonox::ColourValue>::operator()(const orxonox::ColourValue& __x, const orxonox::ColourValue& __y) const
44    {
45        if (__x.r == __y.r)
46        {
47            if (__x.g == __y.g)
48            {
49                if (__x.b == __y.b)
50                {
51                    return __x.a < __y.a;
52                }
53                return __x.b < __y.b;
54            }
55            return __x.g < __y.g;
56        }
57        return __x.r < __y.r;
58    }
59}
60
61namespace orxonox
62{
63    std::map<std::string, std::map<ColourValue, std::string> > TextureGenerator::materials_s;
64    unsigned int TextureGenerator::materialCount_s = 0;
65
66    /*static*/ const std::string& TextureGenerator::getMaterialName(std::string textureName, const ColourValue& colour)
67    {
68        std::map<ColourValue, std::string>& colourMap = materials_s[textureName];
69        std::map<ColourValue, std::string>::const_iterator it = colourMap.find(colour);
70
71        if (it == colourMap.end())
72        {
73            std::string materialName = textureName + "_Material_" + convertToString(materialCount_s++);
74            Ogre::MaterialPtr material = (Ogre::MaterialPtr)Ogre::MaterialManager::getSingleton().create(materialName, "General");
75            material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
76            Ogre::TextureUnitState* textureUnitState = material->getTechnique(0)->getPass(0)->createTextureUnitState();
77            textureUnitState->setTextureName(textureName);
78            textureUnitState->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, colour);
79            return (colourMap[colour] = materialName);
80        }
81        else
82        {
83            return (*it).second;
84        }
85    }
86}
Note: See TracBrowser for help on using the repository browser.