00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- 00002 this file is part of rcssserver3D 00003 Fri May 9 2003 00004 Copyright (C) 2002,2003 Koblenz University 00005 Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group 00006 $Id: soccerrender.cpp,v 1.2 2004/12/30 15:57:40 rollmark Exp $ 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; version 2 of the License. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00020 00021 SoccerRender 00022 */ 00023 #include <sstream> 00024 #include "soccerrender.h" 00025 #include "soccermonitor.h" 00026 #include <zeitgeist/logserver/logserver.h> 00027 #include <kerosin/openglserver/openglserver.h> 00028 #include <kerosin/fontserver/fontserver.h> 00029 #include <kerosin/fontserver/font.h> 00030 00031 using namespace kerosin; 00032 using namespace boost; 00033 using namespace std; 00034 00035 SoccerRender::SoccerRender() : kerosin::CustomRender() 00036 { 00037 } 00038 00039 SoccerRender::~SoccerRender() 00040 { 00041 } 00042 00043 void SoccerRender::OnLink() 00044 { 00045 // get the FontServer 00046 mFontServer = 00047 shared_static_cast<FontServer>(GetCore()->Get("/sys/server/font")); 00048 if (mFontServer.get() == 0) 00049 { 00050 GetLog()->Error() << "ERROR: (SoccerRender) Unable to get FontServer\n"; 00051 } else 00052 { 00053 string font = "VeraMono.ttf"; 00054 int fontSize = 24; 00055 mFont = mFontServer->GetFont(font, fontSize); 00056 00057 if (mFont.get() == 0) 00058 { 00059 GetLog()->Error() << "(SoccerRender) Unable to get font " 00060 << font << " " << fontSize << "\n"; 00061 } 00062 } 00063 00064 // get the SoccerMonitor 00065 mMonitor = shared_static_cast<SoccerMonitor> 00066 (GetCore()->Get("/sys/server/simulation/SparkMonitorClient/SoccerMonitor")); 00067 00068 if (mMonitor.get() == 0) 00069 { 00070 GetLog()->Error() << "ERROR: (SoccerRender) Unable to get SoccerMonitor\n"; 00071 } 00072 } 00073 00074 void SoccerRender::OnUnlink() 00075 { 00076 mFont.reset(); 00077 mFontServer.reset(); 00078 mMonitor.reset(); 00079 } 00080 00081 00082 void SoccerRender::Render() 00083 { 00084 if ( 00085 (mFontServer.get() == 0) || 00086 (mFont.get() == 0) || 00087 (mMonitor.get() == 0) 00088 ) 00089 { 00090 return; 00091 } 00092 00093 stringstream ss; 00094 ss << "(" << mMonitor->GetGameHalfString() << ") "; 00095 ss << mMonitor->GetPlayModeString(); 00096 ss << " t=" << mMonitor->GetTime(); 00097 00098 mFontServer->Begin(); 00099 mFont->Bind(); 00100 glColor3f(1,1,1); 00101 mFont->DrawString(0, 0, ss.str().c_str()); 00102 mFontServer->End(); 00103 }