void OptionsState::DrawMusicVolume()
{
	BitmapFont* font = Game::GetInstance()->GetFont();
	std::string tempString = std::to_string(Game::GetInstance()->GetMusicVolume());
	const char* vol = tempString.c_str();
	font->Draw(vol, SGD::Point{ 450, 340 }, 0.7f);
}
 inline void reset(const BitmapFont& mBF)
 {
     xMin = xMax = yMin = yMax = 0;
     iX = iY = chCount = 0;
     width = mBF.getCellWidth();
     height = mBF.getCellHeight();
 }
Esempio n. 3
0
//---------------------------------------------------------------------------
STATIC BitmapFont* BitmapFont::CreateAndGetFont( const std::string& metaDataFilePath )
{
	BitmapFont* result = new BitmapFont();
	bool didLoad = result->LoadMetaDataWithTinyXML( metaDataFilePath );
	if ( !didLoad )
	{
		delete result;
		result = nullptr;
	}

	return result;
}
Esempio n. 4
0
//---------------------------------------------------------------------------
STATIC BitmapFont* BitmapFont::CreateAndGetFont( ZipFile* zipFile, const char* metaDataFilePath )
{
	BitmapFont* result = new BitmapFont();
	bool didLoad = result->LoadMetaDataWithTinyXML( zipFile, metaDataFilePath );
	if ( !didLoad )
	{
		delete result;
		result = nullptr;
	}
	
	return result;
}
Esempio n. 5
0
                inline void reset(const BitmapFont& mBF) noexcept
                {
                    rDatas.clear();

                    xMin = xMax = yMin = yMax = nextHChunkSpacing = 0.f;

                    width = mBF.getCellWidth();
                    height = mBF.getCellHeight();
                    iX = 0;

                    nl = htab = vtab = 0;
                }
//-----------------------------------------------------------------------------------
void TheGame::RenderMainMenu()
{
    if (m_mainMenuText == nullptr)
    {
        MeshBuilder builder;
        BitmapFont* bmFont = BitmapFont::CreateOrGetFontFromGlyphSheet("Runescape");
        builder.AddText2D(Vector2(450, 600), "Picougelike", 7.0f, RGBA::VAPORWAVE, true, bmFont);
        builder.AddText2D(Vector2(450, 300), "New Game (N)", 5.0f, RGBA::CYAN, true, bmFont);
        builder.AddText2D(Vector2(450, 150), "Quit (Q)", 5.0f, RGBA::CYAN, true, bmFont);
        m_mainMenuText = new MeshRenderer(new Mesh(), bmFont->GetMaterial());
        builder.CopyToMesh(m_mainMenuText->m_mesh, &Vertex_TextPCT::Copy, sizeof(Vertex_TextPCT), &Vertex_TextPCT::BindMeshToVAO);
    }
    m_mainMenuText->Render();
}
//This function is called at the beginning of the game.
void load_world(){
    //Generate the font.
    font.build_font("data/images/bitmap_font.png");

    //Load the textures.
    sprite_sheet_brush=load_texture("data/images/sprite_sheet_brush.png");
    sprite_sheet_items=load_texture("data/images/sprite_sheet_items.png");
    sprite_sheet_level_items=load_texture("data/images/sprite_sheet_level_items.png");
    sprite_sheet_npcs=load_texture("data/images/sprite_sheet_npcs.png");
    tiles=load_texture("data/images/tiles.png");
    tiles_background=load_texture("data/images/tiles_background.png");
    worldmap_tiles=load_texture("data/images/worldmap_tiles.png");
    water_tiles=load_texture("data/images/water_tiles.png");
    background_static=load_texture("data/images/background_static.png");
    grid=load_texture("data/images/grid.png");
    grid_items=load_texture("data/images/grid_items.png");
    overlays=load_texture("data/images/overlays.png");
    sprite_sheet_moving_platform=load_texture("data/images/sprite_sheet_moving_platform.png");
    sprite_sheet_doors=load_texture("data/images/sprite_sheet_doors.png");
    sprite_sheet_door_standard=load_texture("data/images/sprite_sheet_door_standard.png");
    sprite_sheet_triggers=load_texture("data/images/sprite_sheet_triggers.png");
    sprite_sheet_traps=load_texture("data/images/sprite_sheet_traps.png");
    sprite_sheet_signs=load_texture("data/images/sprite_sheet_sign.png");
    sprite_sheet_spring=load_texture("data/images/sprite_sheet_spring.png");
    sprite_sheet_booster=load_texture("data/images/sprite_sheet_booster.png");

    //Load the sound effects.
    sound_camera_unlock=Mix_LoadWAV("data/sounds/camera_unlock.wav");
    sound_camera_lock=Mix_LoadWAV("data/sounds/camera_lock.wav");
    sound_camera_move=Mix_LoadWAV("data/sounds/camera_move.wav");
}
Esempio n. 8
0
void LoadResource() {
	GGlobalVarManager->Init();

	GFileSys->SetRootPath("../../resource/", true);
	
	GShaderManager.LoadFromFile(ShaderDiffuse, "../../assets/shader330.glsl");
	GShaderManager.LoadFromFile(ShaderUI, "../../assets/ShaderUI.glsl");
	checkGlError("GShaderManager.LoadFromFile");

	bitmapFont.LoadFromFile("consolas.bitmapfont");
	spriteBatch.Init(128);

	ModelInstance* model = NULL;
	model = CreateModel("build_tower003.mesh", "2.png");
	model->transform_ = Matrix4f::Transform(Quaternionf::IDENTITY, Vector3f(-1.0f, 10.0f, 0.0f));
	Models.push_back(model);

	//model = CreateModel("build_house008.mesh", "1.png");
	//model->transform_ = Matrix4f::Transform(Quaternionf::IDENTITY, Vector3f(1.5f, 10.0f, 0.0f));
	//Models.push_back(model);


	//model = CreateModel("Box001.mesh", "2.png");
	//MatrixTransform(model->transform_, Quaternionf::IDENTITY, Vector3f(0.0f, 0.0f, 0.0f));
	//Models.push_back(model);

}
Esempio n. 9
0
bool GUIButton::Load(File* f, GUIElement* parent)
{
	GUIElement::Load(f, parent);

	BitmapFont* b = new BitmapFont;
	if(!b->Load(f, this))
	{
		ReportError("GUI Button load fail, could not load bitmap font!");
		return false;
	}

	m_pButtonText = b;
	return true;
	/*
	std::string font;
	std::string message;
	UInt xCells, yCells = 0;
	if(!f->GetString(&font))
	{
		ReportError("GUI Button load fail. Could not find button font texture");
		return false;
	}
	if(!f->GetString(&message))
	{
		ReportError("GUI Button load fail. Could not find button text!");
		return false;
	}
	if(!f->GetUInt(&xCells))
	{
		ReportError("GUI Button load fail. Could not find xCells number!");
		return false;
	}
	if(!f->GetUInt(&yCells))
	{
		ReportError("GUI Button load fail. Could not find yCells number!");
		return false;
	}
	m_pButtonText = new BitmapFont(font, message, xCells, yCells);
	
	m_pButtonText->SetPosOffset(m_posOffset);
	m_pButtonText->SetDimensions(m_dimensions);
	m_pButtonText->SetParent(this);

	return true;
	*/

}
Esempio n. 10
0
BitmapText::BitmapText(const std::string& string, const BitmapFont &font) {
	m_font = &font;
	m_vertices = sf::VertexArray(sf::Quads);
	m_string = transform(string);
	m_color = sf::Color::White;
	m_characterSize = font.getGlyphSize().y;
	m_lineSpacing = 0.5f;
	init();
}
Esempio n. 11
0
BitmapFont *BitmapFont::FromLua(LuaManager* Lua, std::string TableName)
{
    BitmapFont* Ret = new BitmapFont();

    Lua->UseArray(TableName);
    Directory Locat = Lua->GetFieldS("Location", GameState::GetInstance().GetSkinPrefix() + "font.tga");
    int CharWidth = Lua->GetFieldI("CharWidth");
    int CharHeight = Lua->GetFieldI("CharHeight");
    int CellWidth = Lua->GetFieldI("CellWidth");
    int CellHeight = Lua->GetFieldI("CellHeight");
    int RenderWidth = Lua->GetFieldI("RenderWidth");
    int RenderHeight = Lua->GetFieldI("RenderHeight");
    int FontStart = Lua->GetFieldI("FontStart");
    Lua->Pop();

    Ret->LoadFontImage(Locat.c_path(), Vec2(CharWidth, CharHeight), Vec2(CellWidth, CellHeight), Vec2(RenderWidth, RenderHeight), FontStart);

    return Ret;
}
Esempio n. 12
0
BitmapFont* ResourceManager::LoadFont(const char* a_ccFont)
{
	if(m_pFontMap.find(a_ccFont) == m_pFontMap.end())
	{		
		BitmapFont* pFont = new BitmapFont();

		if (!(pFont->LoadFont(a_ccFont)))
		{
			printf("Failed to load file: %s \n", a_ccFont);
			return nullptr;
		}

		m_pFontMap.insert(std::pair<const char*, BitmapFont*>(a_ccFont, pFont));

		return pFont;
	}
	else
	{
		return m_pFontMap[a_ccFont];
	}
}
Esempio n. 13
0
bool TextManager::addFont(std::string key, char* fileName) {
	if(key == "\0" && key == "\n") {
		Log::get()->err("Font Create Fail: invalid key");
		return false;
	}

	BitmapFont* font = new BitmapFont(m_pRender);
	if(!font) {
		Log::get()->err("BitmapFont Allocation Failed");
		return false;
	}

	if(!font->init(fileName)) {
		Log::get()->err("font->init(%s) Failed", fileName);
		return false;
	}

	fontMap[key] = font;

	return true;
}
Esempio n. 14
0
//---------------------------------------------------------------------------
STATIC BitmapFont* BitmapFont::CreateOrGetFont( const char* metaDataFilePath )
{
	BitmapFont* result = nullptr;
	if ( s_bitmapFontRegistry.find( metaDataFilePath ) == s_bitmapFontRegistry.end() )
	{
		result = new BitmapFont();
		if ( !result->LoadMetaDataWithTinyXML( metaDataFilePath ) )
		{
			delete result;
			result = nullptr;
		}
		else
		{
			s_bitmapFontRegistry.insert( std::make_pair( metaDataFilePath, result ) );
		}
	}
	else
	{
		return s_bitmapFontRegistry[ metaDataFilePath ];
	}

	return result;
}
Esempio n. 15
0
void MessageSystem::drawMessages(Window& window, BitmapFont& font,
                                 const std::vector<Message>& messages, int currentTurn)
{
    font.setArea(GUI::getMessageArea(window));
    for (int end = int(messages.size()), i = std::max(0, end - maxMessagesToPrint); i < end; ++i)
    {
        bool isNewMessage = messages[i].turn >= currentTurn - 1;
        auto color = isNewMessage ? White : Gray;
        font.print(window, "- ", color);
        std::string text = messages[i].text;

        if (messages[i].count > 1)
            text += " (x" + std::to_string(messages[i].count) + ")";

        font.printLine(window, text, color, Color::none, true, SplitLines);
    }

#ifdef DEBUG
    font.setArea(GUI::getDebugMessageArea(window));
    for (const DebugMessage& message : debugMessages)
        font.printLine(window, message.content, messageColors[message.type]);
#endif
}
void BitmapString::SetFont(const BitmapFont& font)
{
	if (&font != font_)
	{
		font_ = &font;
		char_width_ = font.GetCharWidth();
		for (size_t i = 0; i < bitmaps_.size(); ++i)
		{
			sf::Sprite& sprite = bitmaps_[i];
			sprite.SetX(i * char_width_);
			sprite.SetSubRect(font_->GetCharRect(chars_[i]));
			sprite.SetImage(font_->GetImage());
		}
	}
}
Esempio n. 17
0
	friend void BitmapGlyphInitializeLayoutData(
		BitmapGlyphRenderingBase& that,
		BitmapGlyphLayoutData& layout_data,
		BitmapFont& font,
		const CodePoint* cps,
		GLsizei length
	)
	{
		OGLPLUS_FAKE_USE(that);
		assert(layout_data._storage);
		BitmapGlyphLayoutStorage& _storage = *layout_data._storage;
		std::vector<GLfloat> x_offsets;
		GLfloat width = font.QueryXOffsets(cps, length, x_offsets);
		_storage.Initialize(
			layout_data,
			width,
			x_offsets,
			cps,
			length
		);
	}
Esempio n. 18
0
void OptionsState::Render(float elapsedTime)
{
	SGD::GraphicsManager::GetInstance()->DrawTexture(Game::GetInstance()->GetMenuBackground(), SGD::Point{ 0, 0 });
	BitmapFont* font = Game::GetInstance()->GetFont();
	font->Draw("Options", SGD::Point{ 335, 100 }, 1.5f);
	font->Draw("Music Volume", SGD::Point{ 350, 300 }, 0.7f, SGD::Color{ 235, 255, 0 });
	//font->Draw((char*)(GetMusicVolume()), SGD::Point{ 500, 300 }, 1.0f, SGD::Color{ 255, 255, 0 });
	// no numbers? WAII?!
	font->Draw("Sound Effects Volume", SGD::Point{ 350, 380 }, 0.7f, SGD::Color{ 235, 255, 0 });
	font->Draw("Exit", SGD::Point{ 350, 460 }, 0.7f, SGD::Color{ 235, 255, 0 });

	font->Draw("0", SGD::Point{ 310, 300.0f + 80 * m_iCursor }, 0.7f, SGD::Color{ 235, 255, 255 });

	DrawMusicVolume();
	DrawSfxVolume();
	DrawSoundBars();
}
Esempio n. 19
0
void StatTracker::Render(float y)
{
	BitmapFont* pFont = Game::GetInstance()->GetFont();

	SGD::Point pos;
	pos.x = 200;
	pos.y = y;

	

	std::stringstream display;

	// Total Time Played
	int timePlayed = (int)m_fTimePlayed;
	display << "Total Time Played:";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display);
	int days = timePlayed / 86400;
	timePlayed -= days * 86400;
	display << "\t\t";
	display <<  days;
	display << " Days";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display);
	int hours = timePlayed / 3600;
	timePlayed -= hours * 3600;
	display << "\t\t";
	display << hours;
	display << " Hours";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );
	
	Increment(pos, display);
	int minutes = timePlayed / 60;
	timePlayed -= minutes * 60;
	display << "\t\t";
	display << minutes;
	display << " Minutes";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );
	
	Increment(pos, display);
	display << "\t\t";
	display << timePlayed;
	display << " Seconds";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );
	
	Increment(pos, display, 3);

	// Build Phase Time
	Increment(pos, display);
	display << "Build Phase Time:";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );
	
	timePlayed = (int)m_fBuildPhaseTime;

	Increment(pos, display);
	days = timePlayed / 86400;
	timePlayed -= days * 86400;
	display << "\t\t";
	display <<  days;
	display << " Days";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display);
	hours = timePlayed / 3600;
	timePlayed -= hours * 3600;
	display << "\t\t";
	display << hours;
	display << " Hours";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );
	
	Increment(pos, display);
	minutes = timePlayed / 60;
	timePlayed -= minutes * 60;
	display << "\t\t";
	display << minutes;
	display << " Minutes";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );
	
	Increment(pos, display);
	display << "\t\t";
	display << timePlayed;
	display << " Seconds";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );
	
	Increment(pos, display, 3);

	// Survival Phase Time
	Increment(pos, display);
	display << "Survival Phase Time:";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );
	
	timePlayed = (int)m_fSurvivalTime;

	Increment(pos, display);
	days = timePlayed / 86400;
	timePlayed -= days * 86400;
	display << "\t\t";
	display <<  days;
	display << " Days";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display);
	hours = timePlayed / 3600;
	timePlayed -= hours * 3600;
	display << "\t\t";
	display << hours;
	display << " Hours";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );
	
	Increment(pos, display);
	minutes = timePlayed / 60;
	timePlayed -= minutes * 60;
	display << "\t\t";
	display << minutes;
	display << " Minutes";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );
	
	Increment(pos, display);
	display << "\t\t";
	display << timePlayed;
	display << " Seconds";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );
	
	Increment(pos, display, 3);

	// Distance Walked
	Increment(pos, display);
	display << "Distance Walked:";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );
	
	int distance = (int)m_fDistanceWalked;

	Increment(pos, display);
	int kilo = distance/1000;
	distance -= kilo * 1000;
	display << "\t\t";
	display << kilo;
	display << ".";
	display << distance;
	display << "Kilometers";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display, 6);

	// Total Rounds Survived
	Increment(pos, display);
	display << "Total Rounds Survived: ";
	display << m_uRoundsSurvived;
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display, 7);

	// Survival Streak
	Increment(pos, display);
	display << "Highest Round Reached: ";
	display << m_uConsecutiveRoundsSurvived;
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display, 7);

	// Total Kills
	Increment(pos, display);
	display << "Total Kills: ";
	display << m_uTotalKills;
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display, 7);

	// Blood Spilled
	Increment(pos, display);
	display << "Blood Spilled:";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display);
	float blood = m_fBloodSpilled;
	float gallon = blood / 4.54f;
	display << "\t\t";
	display << gallon;
	display << " Imperial Gallons";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );
	
	Increment(pos, display, 6);

	// Grenades Thrown
	Increment(pos, display);
	display << "Weight of Grenades Thrown:";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	float weight = (float)((m_uGrenadesThrown * 400.0f)/1000.0f);
	
	Increment(pos, display);
	if ( weight > 1.0f )
	{
		display << weight;
		display << " Kilograms";
	}
	else
	{
		display << weight * 1000.0f;
		display << " Grams";
	}
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display, 6);

	// Shots Fired
	Increment(pos, display);
	display << "Total Shots Fired: ";
	display << m_uTotalShotsFired;
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display, 7);

	// Machine Gun
	Increment(pos, display);
	display << "Weight in Machine Gun Shells Fired:";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	weight = (float)((m_uMachineGunBullets * 11.8f)/1000.0f);
	
	Increment(pos, display);
	if ( weight > 1.0f )
	{
		display << weight;
		display << " Kilograms";
	}
	else
	{
		display << weight * 1000.0f;
		display << " Grams";
	}
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display, 6);

	// Shotgun
	Increment(pos, display);
	display << "Weight in Shotgun Shells Fired:";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	weight = (float)((m_uShotgunShells *  7.795f)/1000.0f);
	
	Increment(pos, display);
	if ( weight > 1.0f )
	{
		display << weight;
		display << " Kilograms";
	}
	else
	{
		display << weight * 1000.0f;
		display << " Grams";
	}
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display, 6);

	// RPG
	Increment(pos, display);
	display << "Weight in RPG's Fired:";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	weight = (float)((m_uRPGRounds *  2200.0f)/1000.0f);
	
	Increment(pos, display);
	if ( weight > 1.0f )
	{
		display << weight;
		display << " Kilograms";
	}
	else
	{
		display << weight * 1000.0f;
		display << " Grams";
	}
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display, 6);

	// HatTrick
	Increment(pos, display);
	display << "Weight in Hat Trick Pucks Fired:";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );
	
	weight = (float)((m_uHatTrickShots *  185.0f)/1000.0f);
	
	Increment(pos, display);
	if ( weight > 1.0f )
	{
		display << weight;
		display << " Kilograms";
	}
	else
	{
		display << weight * 1000.0f;
		display << " Grams";
	}
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display, 6);

	// Walls
	Increment(pos, display);
	display << "Walls:";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display);
	display << m_uWallsPlaced;
	display << " Placed";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display);
	display << m_uWallsPickedUp;
	display << " Picked Up";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display, 5);

	// Windows
	Increment(pos, display);
	display << "Windows:";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display);
	display << m_uWindowsPlaced;
	display << " Placed";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display);
	display << m_uWindowsPickedUp;
	display << " Picked Up";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display, 5);

	// Towers
	Increment(pos, display);
	display << "Towers:";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display);
	display << m_uTowersBought;
	display << " Bought";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display);
	display << m_uTowersSold;
	display << " Sold";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display, 5);

	// Traps
	Increment(pos, display);
	display << "Traps:";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display);
	display << m_uTrapsBought;
	display << " Bought";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display);
	display << m_uTrapsSold;
	display << " Sold";
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );

	Increment(pos, display, 5);

	// Money
	Increment(pos, display);
	display << "Loonies Spent: ";
	display << m_uMoneySpent;
	pFont->Draw ( display.str ().c_str () , (int)pos.x , (int)pos.y , 0.5f , { 0 , 0 , 0 } );


}
Esempio n. 20
0
void RenderManager::DrawTextPrivate()
{
	if(enqueuedTextData.size() == 0)
		return;

	gRenderAPI->BeginPerfEvent("RenderText");

	for(int fnt=0; fnt<FONT_MaxSupported; fnt++)
	{
		// Calculate number of quads to render
		int numQuads = 0;
		for(vector<TextRenderData>::const_iterator it=enqueuedTextData.begin(); it != enqueuedTextData.end(); it++)
		{
			if(it->useFont == fnt)
				numQuads += it->text.length();
		}

		if(numQuads == 0)
			continue;

		// Create vertex buffer
		VertexBuffer* textVB = gRenderAPI->CreateVertexBuffer(VFMT_P3C3U2, numQuads*4, NULL, true);
		VertexContainer_P3C3U2* pData = (VertexContainer_P3C3U2*)textVB->Lock();

		float fontHeightNDC, fontWidthNDC;
		for(vector<TextRenderData>::const_iterator it=enqueuedTextData.begin(); it != enqueuedTextData.end(); it++)
		{
			const TextRenderData& data = *it;

			if(data.useFont == fnt)
			{
				// Convert font height from pixel units to NDC units
				fontHeightNDC = 2*data.size/fullScreenBufferSizeY;

				// The current position of the render cursor
				float renderCursorX = data.posX;

				// Font used
				BitmapFont* font = engineFonts[data.useFont];

				// Font color
				ColorVector color = data.color;

				// Text to render
				const string& renderText = data.text;

				for(unsigned int i=0; i<renderText.length(); i++)
				{
					BitmapFont::CharDescriptor charData = font->GetData(renderText.at(i), data.bBold);

					fontWidthNDC = charData.aspectRatio * fontHeightNDC; 

					pData->px = renderCursorX;
					pData->py = data.posY;
					pData->pz = 0.f;
					pData->cx = color.r;
					pData->cy = color.g;
					pData->cz = color.b;
					pData->u = charData.u1;
					pData->v = charData.v1;

					pData++;

					pData->px = renderCursorX + fontWidthNDC;
					pData->py = data.posY;
					pData->pz = 0.f;
					pData->cx = color.r;
					pData->cy = color.g;
					pData->cz = color.b;
					pData->u = charData.u2;
					pData->v = charData.v1;

					pData++;

					pData->px = renderCursorX + fontWidthNDC;
					pData->py = data.posY - fontHeightNDC;
					pData->pz = 0.f;
					pData->cx = color.r;
					pData->cy = color.g;
					pData->cz = color.b;
					pData->u = charData.u2;
					pData->v = charData.v2;

					pData++;

					pData->px = renderCursorX;
					pData->py = data.posY - fontHeightNDC;
					pData->pz = 0.f;
					pData->cx = color.r;
					pData->cy = color.g;
					pData->cz = color.b;
					pData->u = charData.u1;
					pData->v = charData.v2;

					pData++;

					renderCursorX += fontWidthNDC;
				}
			}
		}

		textVB->Unlock();

		// Create index buffer
		IndexBuffer* textIB = gRenderAPI->CreateIndexBuffer(IFMT_16Bit, numQuads*6, NULL, true);
		short* iData = (short*)textIB->Lock();

		int offset = 0;
		for(unsigned int i=0; i<enqueuedTextData.size(); i++)
		{
			if(enqueuedTextData.at(i).useFont == fnt)
			{
				for(unsigned int j=0; j<enqueuedTextData.at(i).text.length(); j++)
				{
					*iData = offset + 4*j + 0; iData++;
					*iData = offset + 4*j + 1; iData++;
					*iData = offset + 4*j + 3; iData++;

					*iData = offset + 4*j + 2; iData++;
					*iData = offset + 4*j + 3; iData++;
					*iData = offset + 4*j + 1; iData++;
				}

				offset += 4*enqueuedTextData.at(i).text.length();
			}
		}

		textIB->Unlock();

		// Vertex shader
		VertexShader* vShader = gRenderManager.GetPassthroughShader(VFMT_P3C3U2, INTERPOLANT_MeshUV | INTERPOLANT_MeshColor);
		vShader->Bind();

		// Pixel shader
		simpleFontPixelShader->SetValues(engineFonts[fnt]->GetTexture(), SamplerState::TrilinearWrap);
		simpleFontPixelShader->Bind();

		gRenderAPI->SetVertexBuffer(0, textVB);
		gRenderAPI->SetIndexBuffer(textIB);
		gRenderAPI->DrawIndexed(TOPOLOGY_TriangleList, numQuads*2);

		// Clean up the buffers
		gRenderAPI->DestroyVertexBuffer(textVB);
		gRenderAPI->DestroyIndexBuffer(textIB);
	}

	gRenderAPI->EndPerfEvent();
}
//==============================
// OvrTextFade_Component::CalcIconFadeOffset
Vector3f OvrTextFade_Component::CalcIconFadeOffset( char const * text, BitmapFont const & font, Vector3f const & axis, float const iconWidth )
{
    float textWidth = font.CalcTextWidth( text );
    float const fullWidth = textWidth + iconWidth;
    return axis * ( ( fullWidth * 0.5f ) - ( iconWidth * 0.5f ) );  // this is a bit odd, but that's because the icon's origin is its center
}
    // static
    bool BitmapFontLoader::load(const char * const filepath, BitmapFont &font)
    {
        uint32_t largest_id = 0;
        std::vector<BmfCharBlock> character_blocks;
        BmfCommonBlock common_block;

        std::ifstream file(filepath, std::ifstream::in | std::ifstream::binary);

        if (!file.is_open())
        {
            log::error("BitmapFontLoader: Count not open file %", filepath);
            return false;
        }

        try
        {
            if (! (read_uint8(file) == 'B'
                && read_uint8(file) == 'M'
                && read_uint8(file) == 'F'))
            {
                throw ParseError("Invalid file header.");
            }

            uint8_t version = read_uint8(file);
            if (version != BmfVersion)
            {
                throw ParseError("Wrong version. Expected " + to_string(BmfVersion) + ", found " + to_string(static_cast<unsigned int>(version)));
            }

            while (file.peek() != std::istream::traits_type::eof())
            {
                uint8_t block_type = read_uint8(file);
                uint32_t block_size = read_uint32(file);

                switch (block_type)
                {
                case BmfInfoBlock::TYPE:
                    {
                        BmfInfoBlock block;
                        block.font_size = read_int16(file);
                        block.bit_field = read_uint8(file);
                        block.char_set = read_uint8(file);
                        block.stretch_h = read_uint16(file);
                        block.anti_aliasing = read_uint8(file);
                        block.padding_up = read_uint8(file);
                        block.padding_right = read_uint8(file);
                        block.padding_down = read_uint8(file);
                        block.padding_left = read_uint8(file);
                        block.spacing_horizontal = read_uint8(file);
                        block.spacing_vertical = read_uint8(file);
                        block.outline = read_uint8(file);
                        read_string(file);
                    }
                    break;

                case BmfCommonBlock::TYPE:
                    common_block.line_height = read_uint16(file);
                    common_block.base = read_uint16(file);
                    common_block.scale_w = read_uint16(file);
                    common_block.scale_h = read_uint16(file);
                    common_block.pages = read_uint16(file);
                    common_block.bit_field = read_uint8(file);
                    common_block.alpha_channel = read_uint8(file);
                    common_block.red_channel = read_uint8(file);
                    common_block.green_channel = read_uint8(file);
                    common_block.blue_channel = read_uint8(file);
                    break;

                case BmfPageBlock::TYPE:
                    read_string(file);
                    break;

                case BmfCharBlock::TYPE:
                    {
                        int number_of_characters = block_size / 20;
                        log::debug("BitmapFontLoader: number of characters in font file: %", number_of_characters);

                        for (int i=0; i<number_of_characters; i++)
                        {
                            BmfCharBlock block;
                            block.id = read_uint32(file);
                            block.x = read_uint16(file);
                            block.y = read_uint16(file);
                            block.width = read_uint16(file);
                            block.height = read_uint16(file);
                            block.offset_x = read_int16(file);
                            block.offset_y = read_int16(file);
                            block.advance_x = read_uint16(file);
                            block.page = read_uint8(file);
                            block.channel = read_uint8(file);
                            //log::debug("BitmapFontLoader: char id: % (%)", block.id, (char)block.id);
                            character_blocks.push_back(block);
                            if (block.id > largest_id)
                                largest_id = block.id;
                        }
                    }
                    break;

                case BmfKerningPairBlock::TYPE:
                    {
                        int number_of_kerning_pairs = block_size / 10;
                        for (int i=0; i<number_of_kerning_pairs; i++)
                        {
                            BmfKerningPairBlock block;
                            block.first = read_uint32(file);
                            block.second = read_uint32(file);
                            block.amount = read_int16(file);
                        }
                    }
                    break;

                default:
                    throw ParseError("Invalid block type " + to_string(static_cast<unsigned int>(block_type)));
                }
            }
        }
        catch (EndOfFile &eof)
        {
            log::error("BitmapFontLoader: Encountered end of file unexpectedly.");
            log::debug("File position: %", file.tellg());
            file.close();
            return false;
        }
        catch (ParseError &err)
        {
            log::error("BitmapFontLoader: Failed to parse font definition. Position: %\n       Reason: %", file.tellg(), err.what());
            file.close();
            return false;
        }

        file.close();

        font.m_base = common_block.base;
        font.m_line_height = common_block.line_height;
        font.reserve(largest_id+1);
        for (BmfCharBlock &cblock : character_blocks)
        {
            BitmapFontCharacter c;
            c.id = cblock.id;
            c.x = cblock.x;
            c.y = cblock.y;
            c.width = cblock.width;
            c.height = cblock.height;
            c.offset_x = cblock.offset_x;
            c.offset_y = cblock.offset_y;
            c.advance_x = cblock.advance_x;
            font.add_character(c);
        }

        return true;
    }