1 ////////////////////////////////////////////////////////////////////////////////
2 //    Scorched3D (c) 2000-2011
3 //
4 //    This file is part of Scorched3D.
5 //
6 //    Scorched3D is free software; you can redistribute it and/or modify
7 //    it under the terms of the GNU General Public License as published by
8 //    the Free Software Foundation; either version 2 of the License, or
9 //    (at your option) any later version.
10 //
11 //    Scorched3D is distributed in the hope that it will be useful,
12 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //    GNU General Public License for more details.
15 //
16 //    You should have received a copy of the GNU General Public License along
17 //    with this program; if not, write to the Free Software Foundation, Inc.,
18 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ////////////////////////////////////////////////////////////////////////////////
20 
21 #include <sprites/TextActionRenderer.h>
22 #include <GLW/GLWFont.h>
23 #include <GLEXT/GLCameraFrustum.h>
24 #include <GLEXT/GLState.h>
25 
TextActionRenderer(Vector & position,Vector & color,const std::string & text)26 TextActionRenderer::TextActionRenderer(
27 		Vector &position,
28 		Vector &color,
29 		const std::string &text) :
30 	position_(position),
31 	color_(color),
32 	text_(text),
33 	frameTime_(0.0f)
34 {
35 }
36 
~TextActionRenderer()37 TextActionRenderer::~TextActionRenderer()
38 {
39 }
40 
simulate(Action * action,float timepassed,bool & remove)41 void TextActionRenderer::simulate(Action *action, float timepassed, bool &remove)
42 {
43 	position_[2] += timepassed;
44 	frameTime_ += timepassed;
45 	remove = (frameTime_ > 6.0f);
46 }
47 
draw(Action * action)48 void TextActionRenderer::draw(Action *action)
49 {
50 	if (!GLCameraFrustum::instance()->sphereInFrustum(position_))
51 	{
52 		return;
53 	}
54 
55 	GLState currentState(GLState::DEPTH_ON | GLState::TEXTURE_ON);
56 	glDepthMask(GL_FALSE);
57 	GLWFont::instance()->getGameFont()->drawBilboard(color_, 1.0f - (frameTime_ / 6.0f), 1.0f,
58 		position_[0], position_[1], position_[2],
59 		text_.c_str());
60 
61 	glDepthMask(GL_TRUE);
62 }
63