FTGL crap

This commit is contained in:
James Turk 2005-06-29 04:30:40 +00:00
parent 03691c11ab
commit fc6ce7335c
8 changed files with 336 additions and 5 deletions

View File

@ -5,7 +5,7 @@
# James Turk (jpt2433@rit.edu) # James Turk (jpt2433@rit.edu)
# #
# Version: # Version:
# $Id: SConstruct,v 1.12 2005/06/11 05:28:41 cozman Exp $ # $Id: SConstruct,v 1.13 2005/06/29 04:30:40 cozman Exp $
import os,os.path import os,os.path
import glob import glob
@ -74,7 +74,7 @@ header.close()
BuildDir('build', 'src', duplicate=0) BuildDir('build', 'src', duplicate=0)
lib = env.Library(os.path.join('lib',LIBRARY), source=SRC_FILES, lib = env.Library(os.path.join('lib',LIBRARY), source=SRC_FILES,
CPPPATH = 'include', CPPFLAGS = '-Wall -pedantic') CPPPATH = ['include', '/usr/include/freetype2/'], CPPFLAGS = '-Wall -pedantic')
env.Alias(LIBRARY,lib) env.Alias(LIBRARY,lib)
env.Default(LIBRARY) env.Default(LIBRARY)
@ -89,8 +89,8 @@ test_srcs = glob.glob( os.path.join('test', '*_test.cpp') )
for test_src in test_srcs: for test_src in test_srcs:
test_name = test_src.replace('_test.cpp','') test_name = test_src.replace('_test.cpp','')
tests.append(env.Program(test_name, source=test_src, CPPPATH = INC_DIRS, tests.append(env.Program(test_name, source=test_src, CPPPATH = INC_DIRS+['/usr/include/freetype2/'],
LIBPATH='./lib', CPPFLAGS = '-Wall -pedantic', LIBPATH='./lib', CPPFLAGS = '-Wall -pedantic',
LIBS=['photon',OAL_LIB,'glfw',OGL_LIB,GLU_LIB,'physfs','corona'])) LIBS=['photon',OAL_LIB,'glfw',OGL_LIB,GLU_LIB,'physfs','corona','freetype','ftgl']))
env.Alias('test',tests) env.Alias('test',tests)

View File

@ -27,9 +27,11 @@
#include "util/filesys/filesys.hpp" #include "util/filesys/filesys.hpp"
#include "video/Pen.hpp" #include "video/Pen.hpp"
#include "video/Image.hpp" #include "video/Image.hpp"
#include "video/FontResourceManager.hpp"
#include "video/Texture.hpp" #include "video/Texture.hpp"
#include "video/Color.hpp" #include "video/Color.hpp"
#include "video/TextureResourceManager.hpp" #include "video/TextureResourceManager.hpp"
#include "video/VideoCore.hpp" #include "video/VideoCore.hpp"
#include "video/Font.hpp"
#endif // PHOTON_HPP #endif // PHOTON_HPP

86
include/video/Font.hpp Normal file
View File

@ -0,0 +1,86 @@
//This file is part of Photon (http://photon.sourceforge.net)
//Copyright (C) 2004-2005 James Turk
//
// Author:
// James Turk (jpt2433@rit.edu)
//
// Version:
// $Id: Font.hpp,v 1.1 2005/06/29 04:30:40 cozman Exp $
#ifndef PHOTON_VIDEO_FONT_HPP
#define PHOTON_VIDEO_FONT_HPP
#include "video/FontResourceManager.hpp"
#include "ResourceManaged.hpp"
namespace photon
{
namespace video
{
// Class: Font
// Simple OO wrapper around a TrueType font that can be drawn to textures and
// rendered via OpenGL.
//
// Since Font is a child of <ResourceManaged>, all memory management is
// taken care of.
//
// Operators:
// - Font = Font
// - bool : True if font is loaded, false if not.
// - ostream& << Font
class Font: public ResourceManaged<FontResourceManager>
{
// Group: (Con/De)structors
public:
// Function: Font
// Default constructor, initalizes internal state of Font.
Font();
// Function: Font
// Copy constructor, copies another Font.
//
// Parameters:
// rhs - Font to construct copy of.
Font(const Font &rhs);
// Function: Font
// Initializing constructor, loads Font via call to <open>.
//
// Parameters:
// name - Name of the Font <Resource> to open.
//
// See Also:
// <open>
Font(const std::string& name);
// Group: General
public:
// Function: open
// Opens an TrueType font.
//
// Loading is done via FTGL.
//
// Parameters:
// name - Name of the Font <Resource> to open.
void open(const std::string& name);
Font& operator=(const Font &rhs);
operator bool() const;
// Group: Writing
public:
void write(const std::string& str);
private:
FTFont* font_;
};
}
}
#endif //PHOTON_VIDEO_FONT_HPP

View File

@ -0,0 +1,42 @@
//This file is part of Photon (http://photon.sourceforge.net)
//Copyright (C) 2004-2005 James Turk
//
// Author:
// James Turk (jpt2433@rit.edu)
//
// Version:
// $Id: FontResourceManager.hpp,v 1.1 2005/06/29 04:30:40 cozman Exp $
#ifndef PHOTON_VIDEO_FONTRESOURCEMANAGER_HPP
#define PHOTON_VIDEO_FONTRESOURCEMANAGER_HPP
#include "ResourceManager.hpp"
#include "FTGL/FTGL.h"
#include "FTGL/FTFont.h"
namespace photon
{
namespace video
{
class FontResource : public Resource
{
public:
FTFont* font;
};
class FontResourceManager : public ResourceManager<FontResource>
{
public:
void getFontData(const std::string& name, FTFont*& font);
private:
virtual void loadResource(FontResource &res, const std::string& name);
virtual void freeResource(FontResource &res);
};
}
}
#endif //PHOTON_VIDEO_FONTRESOURCEMANAGER_HPP

59
src/video/Font.cpp Normal file
View File

@ -0,0 +1,59 @@
//This file is part of Photon (http://photon.sourceforge.net)
//Copyright (C) 2004-2005 James Turk
//
// Author:
// James Turk (jpt2433@rit.edu)
//
// Version:
// $Id: Font.cpp,v 1.1 2005/06/29 04:30:40 cozman Exp $
#include "video/Font.hpp"
namespace photon
{
namespace video
{
Font::Font()
{ }
Font::Font(const Font &rhs) :
ResourceManaged<FontResourceManager>(rhs)
{
resMgr_.getFontData(getName(), font_);
}
Font::Font(const std::string& name)
{
open(name);
}
void Font::open(const std::string& name)
{
ResourceManaged<FontResourceManager>::open(name);
resMgr_.getFontData(getName(), font_);
}
Font& Font::operator=(const Font &rhs)
{
if(&rhs != this)
{
ResourceManaged<FontResourceManager>::operator=(rhs);
resMgr_.getFontData(getName(), font_);
}
return *this;
}
Font::operator bool() const
{
return font_ != 0;
}
void Font::write(const std::string& str)
{
font_->Render(str.c_str());
}
}
}

View File

@ -0,0 +1,52 @@
//This file is part of Photon (http://photon.sourceforge.net)
//Copyright (C) 2004-2005 James Turk
//
// Author:
// James Turk (jpt2433@rit.edu)
//
// Version:
// $Id: FontResourceManager.cpp,v 1.1 2005/06/29 04:30:40 cozman Exp $
#include "video/FontResourceManager.hpp"
#include "util/FileBuffer.hpp"
#include "FTGL/FTGLTextureFont.h"
namespace photon
{
namespace video
{
void FontResourceManager::getFontData(const std::string& name, FTFont*& font)
{
FontResource resource( getResource(name) );
font = resource.font;
}
void FontResourceManager::loadResource(FontResource &res,
const std::string& path)
{
util::FileBuffer buf(path);
std::vector<ubyte> data = buf.getData();
//res.font = new FTGLTextureFont((ubyte*)&data[0],data.size());
res.font = new FTGLTextureFont("/usr/share/fonts/truetype/freefont/FreeMono.ttf");
if(!res.font || res.font->Error() != 0)
{
throw APIError("Failed to create FTGLTextureFont");
}
assert( res.font->FaceSize(6) );
}
void FontResourceManager::freeResource(FontResource &res)
{
delete res.font;
}
}
}

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: VideoCore.cpp,v 1.5 2005/06/27 04:24:16 cozman Exp $ // $Id: VideoCore.cpp,v 1.6 2005/06/29 04:30:40 cozman Exp $
#include "video/VideoCore.hpp" #include "video/VideoCore.hpp"
@ -13,6 +13,7 @@
#include "GL/gl.h" #include "GL/gl.h"
#include "GL/glu.h" #include "GL/glu.h"
#include "FTGL/FTLibrary.h"
namespace photon namespace photon
{ {
@ -24,6 +25,7 @@ VideoCore::VideoCore() :
viewportWidth_(0), viewportHeight_(0) viewportWidth_(0), viewportHeight_(0)
{ {
initOpenGL(); initOpenGL();
FTLibrary::Instance().Error(); // ignoring error, fix this
} }
VideoCore::~VideoCore() VideoCore::~VideoCore()

88
test/Font_test.cpp Normal file
View File

@ -0,0 +1,88 @@
//This file is part of Photon (http://photon.sourceforge.net)
//Copyright (C) 2004-2005 James Turk
//
// Author:
// James Turk (jpt2433@rit.edu)
//
// Version:
// $Id: Font_test.cpp,v 1.1 2005/06/29 04:30:40 cozman Exp $
#include "photon.hpp"
using namespace photon;
#include <boost/lexical_cast.hpp>
// This is a simple framework for writing extremely simple Photon applications
// it simply displays a blank window and the framerate in the titlebar of
// the created window. This is meant to show basic interaction between the
// user and the more common features of the AppCore and the Kernel.
class MainTask : public Task
{
public:
MainTask() :
Task("MainTask"),
app(AppCore::getInstance()),
video(video::VideoCore::getInstance())
{
LogSinkPtr csp( new ConsoleSink("console") );
log.addSink(csp);
video.setOrthoView(800,600);
video::Font::addResource("font","data/arial.ttf");
font.open("font");
}
void update()
{
static double t=0;
if(app.getTime() - t > 1.0)
{
app.setTitle("FPS: " +
boost::lexical_cast<std::string>(app.getFramerate()) );
t = app.getTime();
}
video.clear();
glColor4ub(255,0,0,255);
glEnable(GL_TEXTURE_2D);
glScaled(1.0/.75,1,1);
font.write("he");
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex2f(150,200);
glTexCoord2f(1,0); glVertex2f(300,350);
glTexCoord2f(1,1); glVertex2f(150,300);
glTexCoord2f(0,1); glVertex2f(200,350);
glEnd();
glColor4ub(255,255,255,255);
}
private:
video::Font font;
Log log;
AppCore& app;
video::VideoCore& video;
};
class ImageTest : public Application
{
public:
int main(const StrVec& args)
{
AppCore::getInstance().createDisplay(800,600,32,0,0,false);
Kernel::getInstance().addTask(TaskPtr(new MainTask()));
Kernel::getInstance().run();
return 0;
}
};
ENTRYPOINT(ImageTest)