Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
5c8fe7bb9c |
@ -1,14 +1,14 @@
|
|||||||
// GLFT_Font (http://polimath.com/blog/code/glft_font/)
|
// GLFT_Font (http://www.cs.rit.edu/~jpt2433/glftfont/)
|
||||||
// by James Turk (james.p.turk@gmail.com)
|
// by James Turk (jpt2433@rit.edu)
|
||||||
// Based on work by Marijn Haverbeke (http://marijn.haverbeke.nl)
|
// Based on work by Marijn Haverbeke (http://marijn.haverbeke.nl)
|
||||||
//
|
//
|
||||||
// Version 0.2.2 - Released 28 February 2011 - Fixed linux compilation.
|
// Version 0.1 - Released 1 July 2005 - Initial Release
|
||||||
// Version 0.2.1 - Released 2 March 2008 - Updated contact information.
|
// Version 0.2 - Released 18 July 2005 - Added beginDraw/endDraw,
|
||||||
// Version 0.2.0 - Released 18 July 2005 - Added beginDraw/endDraw,
|
|
||||||
// Changed vsprintf to vsnprintf
|
// Changed vsprintf to vsnprintf
|
||||||
// Version 0.1.0 - Released 1 July 2005 - Initial Release
|
|
||||||
//
|
//
|
||||||
// Copyright (c) 2005-2008, James Turk
|
// $Id: GLFT_Font.cpp,v 1.1.1.1 2005/07/18 22:19:16 cozman Exp $
|
||||||
|
//
|
||||||
|
// Copyright (c) 2005, James Turk
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// Redistribution and use in source and binary forms, with or without
|
// Redistribution and use in source and binary forms, with or without
|
||||||
@ -37,8 +37,6 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "GLFT_Font.hpp"
|
#include "GLFT_Font.hpp"
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
|
|
||||||
// static members
|
// static members
|
||||||
FT_Library FTLibraryContainer::library_;
|
FT_Library FTLibraryContainer::library_;
|
||||||
@ -146,8 +144,8 @@ void GLFT_Font::open(const std::string& filename, unsigned int size)
|
|||||||
lineSpace -= widths_[ch];
|
lineSpace -= widths_[ch];
|
||||||
|
|
||||||
maxAscent = std::max(face->glyph->bitmap_top, maxAscent);
|
maxAscent = std::max(face->glyph->bitmap_top, maxAscent);
|
||||||
maxDescent = std::max((int)face->glyph->bitmap.rows -
|
maxDescent = std::max(face->glyph->bitmap.rows -
|
||||||
(int)face->glyph->bitmap_top, maxDescent);
|
face->glyph->bitmap_top, maxDescent);
|
||||||
}
|
}
|
||||||
|
|
||||||
height_ = maxAscent + maxDescent; // calculate height_ for text
|
height_ = maxAscent + maxDescent; // calculate height_ for text
|
||||||
@ -165,7 +163,7 @@ void GLFT_Font::open(const std::string& filename, unsigned int size)
|
|||||||
|
|
||||||
// create and zero the memory
|
// create and zero the memory
|
||||||
unsigned char* image = new unsigned char[imageHeight * imageWidth];
|
unsigned char* image = new unsigned char[imageHeight * imageWidth];
|
||||||
memset(image, 0, imageHeight * imageWidth);
|
std::memset(image, 0, imageHeight * imageWidth);
|
||||||
|
|
||||||
// These are the position at which to draw the next glyph
|
// These are the position at which to draw the next glyph
|
||||||
size_t x = MARGIN;
|
size_t x = MARGIN;
|
||||||
@ -270,13 +268,13 @@ void GLFT_Font::drawText(float x, float y, const char *str, ...) const
|
|||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
va_start(args,str);
|
va_start(args,str);
|
||||||
vsnprintf(buf, 1024, str, args); // avoid buffer overflow
|
std::vsnprintf(buf, 1024, str, args); // avoid buffer overflow
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, texID_);
|
glBindTexture(GL_TEXTURE_2D, texID_);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslated(x,y,0);
|
glTranslated(x,y,0);
|
||||||
for(unsigned int i=0; i < strlen(buf); ++i)
|
for(unsigned int i=0; i < std::strlen(buf); ++i)
|
||||||
{
|
{
|
||||||
unsigned char ch( buf[i] - SPACE ); // ch-SPACE = DisplayList offset
|
unsigned char ch( buf[i] - SPACE ); // ch-SPACE = DisplayList offset
|
||||||
// replace characters outside the valid range with undrawable
|
// replace characters outside the valid range with undrawable
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
// GLFT_Font (http://polimath.com/blog/code/glft_font/)
|
// GLFT_Font (http://www.cs.rit.edu/~jpt2433/glftfont/)
|
||||||
// by James Turk (james.p.turk@gmail.com)
|
// by James Turk (jpt2433@rit.edu)
|
||||||
// Based on work by Marijn Haverbeke (http://marijn.haverbeke.nl)
|
// Based on work by Marijn Haverbeke (http://marijn.haverbeke.nl)
|
||||||
//
|
//
|
||||||
// Version 0.2.2 - Released 28 February 2011 - Fixed linux compilation.
|
// Version 0.1 - Released 1 July 2005 - Initial Release
|
||||||
// Version 0.2.1 - Released 2 March 2008 - Updated contact information.
|
// Version 0.2 - Released 18 July 2005 - Added beginDraw/endDraw,
|
||||||
// Version 0.2.0 - Released 18 July 2005 - Added beginDraw/endDraw,
|
|
||||||
// Changed vsprintf to vsnprintf
|
// Changed vsprintf to vsnprintf
|
||||||
// Version 0.1.0 - Released 1 July 2005 - Initial Release
|
|
||||||
//
|
//
|
||||||
// Copyright (c) 2005-2008, James Turk
|
// $Id: GLFT_Font.hpp,v 1.1.1.1 2005/07/18 22:19:16 cozman Exp $
|
||||||
|
//
|
||||||
|
// Copyright (c) 2005, James Turk
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// Redistribution and use in source and binary forms, with or without
|
// Redistribution and use in source and binary forms, with or without
|
||||||
@ -39,11 +39,7 @@
|
|||||||
#ifndef GLFT_FONT_HPP
|
#ifndef GLFT_FONT_HPP
|
||||||
#define GLFT_FONT_HPP
|
#define GLFT_FONT_HPP
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
#include <OpenGL/gl.h>
|
|
||||||
#else
|
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <ft2build.h>
|
#include <ft2build.h>
|
||||||
#include FT_FREETYPE_H
|
#include FT_FREETYPE_H
|
||||||
|
23
LICENSE
23
LICENSE
@ -1,23 +0,0 @@
|
|||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions are met:
|
|
||||||
|
|
||||||
* Redistributions of source code must retain the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimer.
|
|
||||||
* Redistributions in binary form must reproduce the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer in the
|
|
||||||
documentation and/or other materials provided with the distribution.
|
|
||||||
* Neither the name of the GLFT_Font nor the names of its contributors
|
|
||||||
may be used to endorse or promote products derived from this software
|
|
||||||
without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
||||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
POSSIBILITY OF SUCH DAMAGE.
|
|
13
Makefile
13
Makefile
@ -1,13 +0,0 @@
|
|||||||
UNAME := $(shell uname)
|
|
||||||
|
|
||||||
ifeq ($(UNAME), Darwin)
|
|
||||||
GL := -framework OpenGL
|
|
||||||
else
|
|
||||||
GL := -lGL -lXrandr
|
|
||||||
endif
|
|
||||||
|
|
||||||
test: test.cpp GLFT_Font.cpp
|
|
||||||
g++ GLFT_Font.cpp test.cpp -o test -Wall -pedantic -lglfw $(GL) -lfreetype -pthread `freetype-config --cflags`
|
|
||||||
|
|
||||||
glftfont.tar.gz:
|
|
||||||
tar -czf glftfont.tar.gz GLFT_Font.cpp GLFT_Font.hpp index.html README test.cpp Makefile
|
|
41
README
41
README
@ -1,9 +1,34 @@
|
|||||||
GLFT_Font
|
// GLFT_Font (http://www.cs.rit.edu/~jpt2433/glftfont/)
|
||||||
by James Turk (james.p.turk@gmail.com)
|
// by James Turk (jpt2433@rit.edu)
|
||||||
Based on work by Marijn Haverbeke (http://marijn.haverbeke.nl)
|
// Based on work by Marijn Haverbeke (http://marijn.haverbeke.nl)
|
||||||
|
//
|
||||||
|
// Version 0.1 - Released 1 July 2005
|
||||||
|
//
|
||||||
|
// Copyright (c) 2005, James Turk
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// * Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// * Redistributions in binary form must reproduce the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer in the
|
||||||
|
// documentation and/or other materials provided with the distribution.
|
||||||
|
// * Neither the name of the GLFT_Font nor the names of its contributors
|
||||||
|
// may be used to endorse or promote products derived from this software
|
||||||
|
// without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||||
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
Version 0.2.2 - Released 28 February 2011 - Fixed linux compilation.
|
$Id: README,v 1.1.1.1 2005/07/18 22:19:16 cozman Exp $
|
||||||
Version 0.2.1 - Released 2 March 2008 - Updated contact information.
|
|
||||||
Version 0.2.0 - Released 18 July 2005 - Added beginDraw/endDraw,
|
|
||||||
Changed vsprintf to vsnprintf
|
|
||||||
Version 0.1.0 - Released 1 July 2005 - Initial Release
|
|
||||||
|
55
index.html
Normal file
55
index.html
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<html>
|
||||||
|
<head><title>GLFT_Font</title></head>
|
||||||
|
<body>
|
||||||
|
<h1>GLFT_Font</h1>
|
||||||
|
|
||||||
|
<h2>About GLFT_Font</h2>
|
||||||
|
<p>
|
||||||
|
GLFT_Font is originally by <a href="mailto:jpt2433@rit.edu">James Turk</a>
|
||||||
|
although it is based on the work of
|
||||||
|
<a href="http://marijn.haverbeke.nl">Marijn Haverbeke</a>. GLFT_Font allows
|
||||||
|
programmers to use fonts in their OpenGL applications with great ease on any
|
||||||
|
platform for which both <a href="http://freetype.org">FreeType2</a> and
|
||||||
|
<a href="http://opengl.org">OpenGL</a> are available.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Obtaining GLFT_Font</h2>
|
||||||
|
<p>
|
||||||
|
The latest copy of GLFT_Font will be available via this website.
|
||||||
|
At the moment the latest version is <a href="glftfont-0.1.tar.gz">0.1</a>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Using GLFT_Font</h2>
|
||||||
|
<p>
|
||||||
|
Using GLFT_Font is designed to be extremely simple. The simplest use is:
|
||||||
|
<hr />
|
||||||
|
<pre>
|
||||||
|
#include "GLFT_Font.h"
|
||||||
|
|
||||||
|
...
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
...
|
||||||
|
Font fnt("somefont.ttf", size);
|
||||||
|
...
|
||||||
|
fnt.drawText(x, y, "Hello World");
|
||||||
|
</pre>
|
||||||
|
<hr />
|
||||||
|
GLFT_Font also includes support for finding the width/height of a string and
|
||||||
|
drawText supports printf-style argument formatting.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Changelog</h2>
|
||||||
|
<p>
|
||||||
|
<ul>
|
||||||
|
<li> <a href="glftfont-0.1.tar.gz">Version 0.1</a> - 1 July 2005 - Initial Release </li>
|
||||||
|
</ul>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<hr />
|
||||||
|
<p><em>$Id: index.html,v 1.1.1.1 2005/07/18 22:19:16 cozman Exp $</em></p>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
3
test.cpp
3
test.cpp
@ -1,7 +1,8 @@
|
|||||||
// This file is distributed along with GLFT_Font and is in the public domain.
|
// This file is distributed along with GLFT_Font and is in the public domain.
|
||||||
// Compiled with g++ GLFT_Font.cpp test.cpp -o test -Wall -pedantic
|
// Compiled with g++ GLFT_Font.cpp test.cpp -o test -Wall -pedantic
|
||||||
// -lglfw -lGL -pthread -lfreetype `freetype-config --cflags`
|
// -lglfw -lGL -lfreetype
|
||||||
//
|
//
|
||||||
|
// $Id: test.cpp,v 1.1.1.1 2005/07/18 22:19:16 cozman Exp $
|
||||||
|
|
||||||
#include <GL/glfw.h>
|
#include <GL/glfw.h>
|
||||||
#include "GLFT_Font.hpp"
|
#include "GLFT_Font.hpp"
|
||||||
|
Loading…
Reference in New Issue
Block a user