00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- 00002 00003 this file is part of rcssserver3D 00004 Fri May 9 2003 00005 Copyright (C) 2002,2003 Koblenz University 00006 Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group 00007 $Id: material2dtexture.cpp,v 1.2 2004/04/18 16:32:36 rollmark Exp $ 00008 00009 This program is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation; version 2 of the License. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program; if not, write to the Free Software 00020 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00021 */ 00022 #include "material2dtexture.h" 00023 #include <kerosin/textureserver/textureserver.h> 00024 #include <kerosin/textureserver/texture.h> 00025 #include <kerosin/openglserver/openglserver.h> 00026 #include <zeitgeist/logserver/logserver.h> 00027 #include <zeitgeist/scriptserver/scriptserver.h> 00028 00029 using namespace zeitgeist; 00030 using namespace kerosin; 00031 using namespace boost; 00032 using namespace std; 00033 00034 Material2DTexture::Material2DTexture() : MaterialSolid() 00035 { 00036 } 00037 00038 Material2DTexture::~Material2DTexture() 00039 { 00040 } 00041 00042 bool Material2DTexture::LoadTexture(const std::string& texName, shared_ptr<Texture>& store) 00043 { 00044 shared_ptr<ScriptServer> scriptServer = GetCore()->GetScriptServer(); 00045 shared_ptr<TextureServer> textureServer = shared_dynamic_cast<TextureServer> 00046 (GetCore()->Get("/sys/server/texture")); 00047 00048 store.reset(); 00049 00050 if (textureServer.get() == 0) 00051 { 00052 GetLog()->Error() 00053 << "(Material2DTexture) ERROR: cannot find TextureServer\n"; 00054 return false; 00055 } 00056 00057 store = textureServer->GetTexture(texName); 00058 return (store.get() != 0); 00059 } 00060 00061 bool Material2DTexture::SetDiffuseTexture(const std::string& texName) 00062 { 00063 return LoadTexture(texName,mTexDiffuse); 00064 } 00065 00066 bool Material2DTexture::SetNormalTexture(const std::string& texName) 00067 { 00068 return LoadTexture(texName,mTexNormal); 00069 } 00070 00071 bool Material2DTexture::SetSpecularTexture(const std::string& texName) 00072 { 00073 return LoadTexture(texName,mTexSpecular); 00074 } 00075 00076 void Material2DTexture::Bind() 00077 { 00078 SetupMaterial(); 00079 00080 if (mTexDiffuse.get() != 0) 00081 { 00082 glActiveTextureARB(GL_TEXTURE0_ARB); 00083 glEnable(GL_TEXTURE_2D); 00084 mTexDiffuse->Bind(); 00085 } 00086 00087 if (mTexNormal.get() != 0) 00088 { 00089 glActiveTextureARB(GL_TEXTURE1_ARB); 00090 glEnable(GL_TEXTURE_2D); 00091 mTexNormal->Bind(); 00092 } 00093 00094 if (mTexSpecular.get() != 0) 00095 { 00096 glActiveTextureARB(GL_TEXTURE2_ARB); 00097 glEnable(GL_TEXTURE_2D); 00098 mTexSpecular->Bind(); 00099 } 00100 }