Click here to Skip to main content
15,892,161 members
Articles / Mobile Apps / iPhone

FreeType on OpenGL ES (iPhone)

Rate me:
Please Sign up or sign in to vote.
4.75/5 (10 votes)
24 Nov 2010CPOL4 min read 86.8K   3K   27  
Faster, smarter and better looking fonts rendered with OpenGL ES
#include "PreCompile.h"
#include "Game.h"
#include "Util.h"
#include "FTBitmapFont.h"
#include "FontAtlas.h"
#include "ResManager.h"
#include "FTBitmapChar.h"


Game::Game() 
{
}

Game::~Game()
{
	g_resManager.Release();
}

void Game::Init(const string& dirResources, const string& dirUser, int screenWidth, int screenHeight)
{
#ifndef APPSTORE_BUILD
	int timeNow = GetMilliSeconds();
#endif	
	try
	{
		g_resManager.Init(dirResources, dirUser, screenWidth, screenHeight);
	}
	catch(RacException ex)
	{
		m_strErr = ex.GetStrErr();
		cout << ex.GetStrErr() << endl;
		return;
	}
	m_timeLast = GetMilliSeconds();
#ifndef APPSTORE_BUILD
	int timeElapsed = abs(m_timeLast-timeNow);
	cout << "startup time:" << timeElapsed << "ms" << endl;
#endif
}	// Init




void Game::Render()
{
	glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT);
	FTBitmapFont* pArialFont = g_resManager.GetFTFont(0);
	pArialFont->DrawString(5, 0, "AV Arial font 12 point", BLACK);
	FTBitmapFont* pTimesFont = g_resManager.GetFTFont(1);
	pTimesFont->DrawString(5, pArialFont->GetLineHeight(), "AV Times New Roman font 18 point", BLACK);
	FTBitmapFont* pTimesFont2 = g_resManager.GetFTFont(2);
	pTimesFont2->DrawString(5, pArialFont->GetLineHeight()+pTimesFont->GetLineHeight(), 
							"AV Times New Roman font 16 point", BLACK);
	g_resManager.GetFontAtlas()->RenderAtlas(5, 300);
	g_resManager.GetBatcher().RenderCurr();
}




By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Astronautz
Spain Spain
After working in the software industry for many years, I've started my own games company that specialises in strategy games for mobile platforms.

Comments and Discussions