Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
3be471f750 | ||
![]() |
8be25bcebc | ||
![]() |
8f02ca1df2 | ||
![]() |
4e8b9c2fa3 | ||
![]() |
189e89ae21 | ||
![]() |
a4248ddef7 | ||
![]() |
97a65f92d1 |
@ -2,40 +2,43 @@
|
||||
// by James Turk (james.p.turk@gmail.com)
|
||||
// Based on work by Marijn Haverbeke (http://marijn.haverbeke.nl)
|
||||
//
|
||||
// Version 0.2.2 - Released 28 February 2011 - Fixed linux compilation.
|
||||
// Version 0.2.1 - Released 2 March 2008 - Updated contact information.
|
||||
// Version 0.2.0 - Released 18 July 2005 - Added beginDraw/endDraw,
|
||||
// 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
|
||||
//
|
||||
// Copyright (c) 2005-2008, James Turk
|
||||
// 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
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// * 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
|
||||
// * 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
|
||||
// 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
|
||||
// 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.
|
||||
|
||||
|
||||
#include "GLFT_Font.hpp"
|
||||
#include <cstring>
|
||||
|
||||
|
||||
// static members
|
||||
FT_Library FTLibraryContainer::library_;
|
||||
@ -91,7 +94,7 @@ GLFT_Font::~GLFT_Font()
|
||||
void GLFT_Font::open(const std::string& filename, unsigned int size)
|
||||
{
|
||||
const size_t MARGIN = 3;
|
||||
|
||||
|
||||
// release the font if it already exists
|
||||
if(isValid())
|
||||
{
|
||||
@ -143,8 +146,8 @@ void GLFT_Font::open(const std::string& filename, unsigned int size)
|
||||
lineSpace -= widths_[ch];
|
||||
|
||||
maxAscent = std::max(face->glyph->bitmap_top, maxAscent);
|
||||
maxDescent = std::max(face->glyph->bitmap.rows -
|
||||
face->glyph->bitmap_top, maxDescent);
|
||||
maxDescent = std::max((int)face->glyph->bitmap.rows -
|
||||
(int)face->glyph->bitmap_top, maxDescent);
|
||||
}
|
||||
|
||||
height_ = maxAscent + maxDescent; // calculate height_ for text
|
||||
@ -162,7 +165,7 @@ void GLFT_Font::open(const std::string& filename, unsigned int size)
|
||||
|
||||
// create and zero the memory
|
||||
unsigned char* image = new unsigned char[imageHeight * imageWidth];
|
||||
std::memset(image, 0, imageHeight * imageWidth);
|
||||
memset(image, 0, imageHeight * imageWidth);
|
||||
|
||||
// These are the position at which to draw the next glyph
|
||||
size_t x = MARGIN;
|
||||
@ -267,13 +270,13 @@ void GLFT_Font::drawText(float x, float y, const char *str, ...) const
|
||||
char buf[1024];
|
||||
|
||||
va_start(args,str);
|
||||
std::vsnprintf(buf, 1024, str, args); // avoid buffer overflow
|
||||
vsnprintf(buf, 1024, str, args); // avoid buffer overflow
|
||||
va_end(args);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texID_);
|
||||
glPushMatrix();
|
||||
glTranslated(x,y,0);
|
||||
for(unsigned int i=0; i < std::strlen(buf); ++i)
|
||||
for(unsigned int i=0; i < strlen(buf); ++i)
|
||||
{
|
||||
unsigned char ch( buf[i] - SPACE ); // ch-SPACE = DisplayList offset
|
||||
// replace characters outside the valid range with undrawable
|
||||
@ -328,7 +331,7 @@ std::ostream& GLFT_Font::beginDraw(float x, float y)
|
||||
return ss_;
|
||||
}
|
||||
|
||||
StreamFlusher GLFT_Font::endDraw()
|
||||
StreamFlusher GLFT_Font::endDraw()
|
||||
{
|
||||
drawText(drawX_, drawY_, ss_.str()); // draw the string
|
||||
ss_.str(""); // clear the buffer
|
||||
|
@ -2,6 +2,7 @@
|
||||
// by James Turk (james.p.turk@gmail.com)
|
||||
// Based on work by Marijn Haverbeke (http://marijn.haverbeke.nl)
|
||||
//
|
||||
// Version 0.2.2 - Released 28 February 2011 - Fixed linux compilation.
|
||||
// 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
|
||||
@ -38,7 +39,11 @@
|
||||
#ifndef GLFT_FONT_HPP
|
||||
#define GLFT_FONT_HPP
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <OpenGL/gl.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
23
LICENSE
Normal file
23
LICENSE
Normal file
@ -0,0 +1,23 @@
|
||||
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.
|
10
Makefile
10
Makefile
@ -1,5 +1,13 @@
|
||||
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 -lGL -lfreetype -pthread `freetype-config --cflags`
|
||||
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
|
||||
|
44
README
44
README
@ -1,35 +1,9 @@
|
||||
// GLFT_Font (http://polimath.com/blog/code/glft_font/)
|
||||
// by James Turk (james.p.turk@gmail.com)
|
||||
// Based on work by Marijn Haverbeke (http://marijn.haverbeke.nl)
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// Copyright (c) 2005-2008, 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.
|
||||
GLFT_Font
|
||||
by James Turk (james.p.turk@gmail.com)
|
||||
Based on work by Marijn Haverbeke (http://marijn.haverbeke.nl)
|
||||
|
||||
Version 0.2.2 - Released 28 February 2011 - Fixed linux compilation.
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user