mirror of
https://github.com/love2d/love.git
synced 2026-08-15 07:41:11 +02:00
merged in new font engine
--HG-- branch : minor
This commit is contained in:
@@ -26,8 +26,6 @@
|
||||
A93E6E5510420B57007D418B /* Lua.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A93E6E5310420B57007D418B /* Lua.framework */; };
|
||||
A93E6EED10420BA8007D418B /* love.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E6A3410420AC0007D418B /* love.cpp */; };
|
||||
A946CE821172BCD7005E1462 /* wrap_EncodedImageData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A946CE811172BCD7005E1462 /* wrap_EncodedImageData.cpp */; };
|
||||
A946D3BB117681BD005E1462 /* FontData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A946D3BA117681BC005E1462 /* FontData.cpp */; };
|
||||
A946D3C611768D69005E1462 /* wrap_FontData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A946D3C511768D69005E1462 /* wrap_FontData.cpp */; };
|
||||
A946D67F104248DA002BF36C /* Reference.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E69EA10420ABF007D418B /* Reference.cpp */; };
|
||||
A946D680104248DA002BF36C /* Matrix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E69E310420ABF007D418B /* Matrix.cpp */; };
|
||||
A946D681104248DA002BF36C /* Object.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E69E810420ABF007D418B /* Object.cpp */; };
|
||||
@@ -84,8 +82,6 @@
|
||||
A946D702104249A4002BF36C /* Graphics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E6A8D10420AC2007D418B /* Graphics.cpp */; };
|
||||
A946D703104249A4002BF36C /* Font.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E6A8710420AC2007D418B /* Font.cpp */; };
|
||||
A946D704104249A4002BF36C /* SpriteBatch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E6A9510420AC2007D418B /* SpriteBatch.cpp */; };
|
||||
A946D705104249A4002BF36C /* wrap_Glyph.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E6A9B10420AC2007D418B /* wrap_Glyph.cpp */; };
|
||||
A946D706104249A4002BF36C /* Glyph.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E6A8B10420AC2007D418B /* Glyph.cpp */; };
|
||||
A946D708104249A4002BF36C /* Drawable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E6A8210420AC2007D418B /* Drawable.cpp */; };
|
||||
A946D709104249A4002BF36C /* wrap_Graphics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E6A9D10420AC3007D418B /* wrap_Graphics.cpp */; };
|
||||
A946D70A104249A4002BF36C /* Image.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E6A8F10420AC2007D418B /* Image.cpp */; };
|
||||
@@ -362,8 +358,6 @@
|
||||
A93E6A8810420AC2007D418B /* Font.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Font.h; sourceTree = "<group>"; };
|
||||
A93E6A8910420AC2007D418B /* GLee.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = GLee.c; sourceTree = "<group>"; };
|
||||
A93E6A8A10420AC2007D418B /* GLee.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLee.h; sourceTree = "<group>"; };
|
||||
A93E6A8B10420AC2007D418B /* Glyph.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Glyph.cpp; sourceTree = "<group>"; };
|
||||
A93E6A8C10420AC2007D418B /* Glyph.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Glyph.h; sourceTree = "<group>"; };
|
||||
A93E6A8D10420AC2007D418B /* Graphics.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Graphics.cpp; sourceTree = "<group>"; };
|
||||
A93E6A8E10420AC2007D418B /* Graphics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Graphics.h; sourceTree = "<group>"; };
|
||||
A93E6A8F10420AC2007D418B /* Image.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Image.cpp; sourceTree = "<group>"; };
|
||||
@@ -374,8 +368,6 @@
|
||||
A93E6A9610420AC2007D418B /* SpriteBatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpriteBatch.h; sourceTree = "<group>"; };
|
||||
A93E6A9910420AC2007D418B /* wrap_Font.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_Font.cpp; sourceTree = "<group>"; };
|
||||
A93E6A9A10420AC2007D418B /* wrap_Font.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_Font.h; sourceTree = "<group>"; };
|
||||
A93E6A9B10420AC2007D418B /* wrap_Glyph.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_Glyph.cpp; sourceTree = "<group>"; };
|
||||
A93E6A9C10420AC2007D418B /* wrap_Glyph.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_Glyph.h; sourceTree = "<group>"; };
|
||||
A93E6A9D10420AC3007D418B /* wrap_Graphics.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_Graphics.cpp; sourceTree = "<group>"; };
|
||||
A93E6A9E10420AC3007D418B /* wrap_Graphics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_Graphics.h; sourceTree = "<group>"; };
|
||||
A93E6A9F10420AC3007D418B /* wrap_Image.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_Image.cpp; sourceTree = "<group>"; };
|
||||
@@ -572,10 +564,6 @@
|
||||
A93E6E5310420B57007D418B /* Lua.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Lua.framework; path = /Library/Frameworks/Lua.framework; sourceTree = "<absolute>"; };
|
||||
A946CE801172BCD6005E1462 /* wrap_EncodedImageData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_EncodedImageData.h; sourceTree = "<group>"; };
|
||||
A946CE811172BCD7005E1462 /* wrap_EncodedImageData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_EncodedImageData.cpp; sourceTree = "<group>"; };
|
||||
A946D3B9117681BC005E1462 /* FontData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FontData.h; sourceTree = "<group>"; };
|
||||
A946D3BA117681BC005E1462 /* FontData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontData.cpp; sourceTree = "<group>"; };
|
||||
A946D3C411768D69005E1462 /* wrap_FontData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_FontData.h; sourceTree = "<group>"; };
|
||||
A946D3C511768D69005E1462 /* wrap_FontData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_FontData.cpp; sourceTree = "<group>"; };
|
||||
A946D4421176AC42005E1462 /* Font.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Font.h; sourceTree = "<group>"; };
|
||||
A95684F5125D3555001B276B /* b64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b64.cpp; sourceTree = "<group>"; };
|
||||
A95684F6125D3555001B276B /* b64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b64.h; sourceTree = "<group>"; };
|
||||
@@ -939,8 +927,6 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A946D4421176AC42005E1462 /* Font.h */,
|
||||
A946D3BA117681BC005E1462 /* FontData.cpp */,
|
||||
A946D3B9117681BC005E1462 /* FontData.h */,
|
||||
A93E6A7010420AC1007D418B /* freetype */,
|
||||
A93E6A7710420AC2007D418B /* GlyphData.cpp */,
|
||||
A93E6A7810420AC2007D418B /* GlyphData.h */,
|
||||
@@ -948,8 +934,6 @@
|
||||
A93E6A7A10420AC2007D418B /* ImageRasterizer.h */,
|
||||
A93E6A7B10420AC2007D418B /* Rasterizer.cpp */,
|
||||
A93E6A7C10420AC2007D418B /* Rasterizer.h */,
|
||||
A946D3C511768D69005E1462 /* wrap_FontData.cpp */,
|
||||
A946D3C411768D69005E1462 /* wrap_FontData.h */,
|
||||
A93E6A7D10420AC2007D418B /* wrap_GlyphData.cpp */,
|
||||
A93E6A7E10420AC2007D418B /* wrap_GlyphData.h */,
|
||||
A93E6A7F10420AC2007D418B /* wrap_Rasterizer.cpp */,
|
||||
@@ -996,8 +980,6 @@
|
||||
A9BD60711226C988007DEC63 /* Framebuffer.h */,
|
||||
A93E6A8910420AC2007D418B /* GLee.c */,
|
||||
A93E6A8A10420AC2007D418B /* GLee.h */,
|
||||
A93E6A8B10420AC2007D418B /* Glyph.cpp */,
|
||||
A93E6A8C10420AC2007D418B /* Glyph.h */,
|
||||
A93E6A8D10420AC2007D418B /* Graphics.cpp */,
|
||||
A93E6A8E10420AC2007D418B /* Graphics.h */,
|
||||
A93E6A8F10420AC2007D418B /* Image.cpp */,
|
||||
@@ -1012,8 +994,6 @@
|
||||
A93E6A9A10420AC2007D418B /* wrap_Font.h */,
|
||||
A9BD60721226C988007DEC63 /* wrap_Framebuffer.cpp */,
|
||||
A9BD60731226C988007DEC63 /* wrap_Framebuffer.h */,
|
||||
A93E6A9B10420AC2007D418B /* wrap_Glyph.cpp */,
|
||||
A93E6A9C10420AC2007D418B /* wrap_Glyph.h */,
|
||||
A93E6A9D10420AC3007D418B /* wrap_Graphics.cpp */,
|
||||
A93E6A9E10420AC3007D418B /* wrap_Graphics.h */,
|
||||
A93E6A9F10420AC3007D418B /* wrap_Image.cpp */,
|
||||
@@ -1542,8 +1522,6 @@
|
||||
A946D702104249A4002BF36C /* Graphics.cpp in Sources */,
|
||||
A946D703104249A4002BF36C /* Font.cpp in Sources */,
|
||||
A946D704104249A4002BF36C /* SpriteBatch.cpp in Sources */,
|
||||
A946D705104249A4002BF36C /* wrap_Glyph.cpp in Sources */,
|
||||
A946D706104249A4002BF36C /* Glyph.cpp in Sources */,
|
||||
A946D708104249A4002BF36C /* Drawable.cpp in Sources */,
|
||||
A946D709104249A4002BF36C /* wrap_Graphics.cpp in Sources */,
|
||||
A946D70A104249A4002BF36C /* Image.cpp in Sources */,
|
||||
@@ -1648,8 +1626,6 @@
|
||||
A986DEB5113249A800810279 /* Thread.cpp in Sources */,
|
||||
A986DEB6113249A800810279 /* wrap_Thread.cpp in Sources */,
|
||||
A946CE821172BCD7005E1462 /* wrap_EncodedImageData.cpp in Sources */,
|
||||
A946D3BB117681BD005E1462 /* FontData.cpp in Sources */,
|
||||
A946D3C611768D69005E1462 /* wrap_FontData.cpp in Sources */,
|
||||
A9BD60741226C988007DEC63 /* Framebuffer.cpp in Sources */,
|
||||
A9BD60751226C988007DEC63 /* wrap_Framebuffer.cpp in Sources */,
|
||||
A95684F7125D3555001B276B /* b64.cpp in Sources */,
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#define LOVE_FONT_FONT_H
|
||||
|
||||
// LOVE
|
||||
#include "FontData.h"
|
||||
#include "Rasterizer.h"
|
||||
#include <image/ImageData.h>
|
||||
#include <common/Module.h>
|
||||
@@ -44,7 +43,6 @@ namespace font
|
||||
virtual Rasterizer * newRasterizer(love::image::ImageData * data, std::string glyphs) = 0;
|
||||
virtual Rasterizer * newRasterizer(love::image::ImageData * data, unsigned short * glyphs, int length) = 0;
|
||||
virtual GlyphData * newGlyphData(Rasterizer * r, unsigned short glyph) = 0;
|
||||
virtual FontData * newFontData(Rasterizer * r) = 0;
|
||||
|
||||
// Implement Module
|
||||
virtual const char * getName() const = 0;
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
|
||||
#include "FontData.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace font
|
||||
{
|
||||
|
||||
FontData::FontData(Rasterizer * raster)
|
||||
: raster(raster)
|
||||
{
|
||||
data = new GlyphData *[MAX_CHARS];
|
||||
for (unsigned int i = 0; i < MAX_CHARS; i++) {
|
||||
data[i] = raster->getGlyphData(i);
|
||||
}
|
||||
}
|
||||
|
||||
FontData::~FontData()
|
||||
{
|
||||
for (unsigned int i = 0; i < MAX_CHARS; i++) {
|
||||
data[i]->release();
|
||||
}
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
void * FontData::getData() const
|
||||
{
|
||||
return (void *)data;
|
||||
}
|
||||
|
||||
int FontData::getSize() const
|
||||
{
|
||||
return MAX_CHARS;
|
||||
}
|
||||
|
||||
GlyphData * FontData::getGlyphData(unsigned short glyph) const
|
||||
{
|
||||
return data[glyph];
|
||||
}
|
||||
|
||||
int FontData::getHeight() const
|
||||
{
|
||||
return raster->getHeight();
|
||||
}
|
||||
|
||||
} // font
|
||||
} // love
|
||||
@@ -1,56 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_FONT_FONT_DATA_H
|
||||
#define LOVE_FONT_FONT_DATA_H
|
||||
|
||||
// LOVE
|
||||
#include <common/Data.h>
|
||||
|
||||
#include "GlyphData.h"
|
||||
#include "Rasterizer.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace font
|
||||
{
|
||||
class FontData : public Data
|
||||
{
|
||||
public:
|
||||
FontData(Rasterizer * raster);
|
||||
virtual ~FontData();
|
||||
|
||||
// Implements Data.
|
||||
void * getData() const;
|
||||
int getSize() const;
|
||||
|
||||
GlyphData * getGlyphData(unsigned short glyph) const;
|
||||
int getHeight() const;
|
||||
|
||||
static const unsigned int MAX_CHARS = 256;
|
||||
|
||||
private:
|
||||
GlyphData ** data;
|
||||
Rasterizer * raster;
|
||||
};
|
||||
} // font
|
||||
} // love
|
||||
|
||||
#endif // LOVE_FONT_FONT_DATA_H
|
||||
@@ -28,7 +28,7 @@ namespace font
|
||||
{
|
||||
|
||||
GlyphData::GlyphData(unsigned short glyph, GlyphMetrics glyphMetrics, GlyphData::Format f)
|
||||
: glyph(glyph), metrics(glyphMetrics), data(0), format(f), padded(false)
|
||||
: glyph(glyph), metrics(glyphMetrics), data(0), format(f)
|
||||
{
|
||||
if (metrics.width && metrics.height) {
|
||||
switch (f) {
|
||||
@@ -69,12 +69,12 @@ namespace font
|
||||
|
||||
int GlyphData::getHeight() const
|
||||
{
|
||||
return (padded ? getPaddedHeight() : metrics.height);
|
||||
return metrics.height;
|
||||
}
|
||||
|
||||
int GlyphData::getWidth() const
|
||||
{
|
||||
return (padded ? getPaddedWidth() : metrics.width);
|
||||
return metrics.width;
|
||||
}
|
||||
|
||||
int GlyphData::getAdvance() const
|
||||
@@ -116,71 +116,6 @@ namespace font
|
||||
{
|
||||
return format;
|
||||
}
|
||||
|
||||
void GlyphData::pad()
|
||||
{
|
||||
if (data == 0)
|
||||
return;
|
||||
int w = getWidth();
|
||||
int h = getHeight();
|
||||
int pw = next_p2(w);
|
||||
int ph = next_p2(h);
|
||||
unsigned char * d = new unsigned char[pw * ph * (format == GlyphData::FORMAT_LUMINANCE_ALPHA ? 2 : 4)];
|
||||
for (int j = 0; j < ph; j++) {
|
||||
for (int i = 0; i < pw; i++) {
|
||||
int n = i+j*w;
|
||||
int p = i+j*pw;
|
||||
if (i < w && j < h) {
|
||||
if (format == GlyphData::FORMAT_LUMINANCE_ALPHA) {
|
||||
p *= 2;
|
||||
n *= 2;
|
||||
d[p] = data[n];
|
||||
d[p+1] = data[n+1];
|
||||
} else {
|
||||
p *= 4;
|
||||
n *= 4;
|
||||
d[p] = data[n];
|
||||
d[p+1] = data[n+1];
|
||||
d[p+2] = data[n+2];
|
||||
d[p+3] = data[n+3];
|
||||
}
|
||||
} else {
|
||||
if (format == GlyphData::FORMAT_LUMINANCE_ALPHA) {
|
||||
p *= 2;
|
||||
d[p] = d[p+1] = 0;
|
||||
} else {
|
||||
p *= 4;
|
||||
d[p] = d[p+1] = d[p+2] = d[p+3] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
delete[] data;
|
||||
data = d;
|
||||
padded = true;
|
||||
}
|
||||
|
||||
bool GlyphData::isPadded() const
|
||||
{
|
||||
return padded;
|
||||
}
|
||||
|
||||
int GlyphData::getPaddedWidth() const
|
||||
{
|
||||
return next_p2(metrics.width);
|
||||
}
|
||||
|
||||
int GlyphData::getPaddedHeight() const
|
||||
{
|
||||
return next_p2(metrics.height);
|
||||
}
|
||||
|
||||
inline int GlyphData::next_p2(int num) const
|
||||
{
|
||||
int powered = 2;
|
||||
while(powered < num) powered <<= 1;
|
||||
return powered;
|
||||
}
|
||||
|
||||
|
||||
} // font
|
||||
} // love
|
||||
|
||||
@@ -112,33 +112,6 @@ namespace font
|
||||
**/
|
||||
Format getFormat() const;
|
||||
|
||||
/**
|
||||
* Returns the closest number to num which is a power of two.
|
||||
*
|
||||
* @param num The number to be 2powered.
|
||||
**/
|
||||
inline int next_p2(int num) const;
|
||||
|
||||
/**
|
||||
* Pads the data to fit into a power-of-2 texture.
|
||||
**/
|
||||
void pad();
|
||||
|
||||
/**
|
||||
* Returns whether the data has been padded.
|
||||
**/
|
||||
bool isPadded() const;
|
||||
|
||||
/**
|
||||
* Returns the padded width.
|
||||
**/
|
||||
int getPaddedWidth() const;
|
||||
|
||||
/**
|
||||
* Returns the padded height.
|
||||
**/
|
||||
int getPaddedHeight() const;
|
||||
|
||||
private:
|
||||
// The glyph itself
|
||||
unsigned short glyph;
|
||||
@@ -151,9 +124,6 @@ namespace font
|
||||
|
||||
// The format the data's in
|
||||
Format format;
|
||||
|
||||
// Padded?
|
||||
bool padded;
|
||||
|
||||
}; // GlyphData
|
||||
|
||||
|
||||
@@ -79,7 +79,6 @@ namespace font
|
||||
gd[i*4+2] = p.b;
|
||||
gd[i*4+3] = p.a;
|
||||
}
|
||||
g->pad();
|
||||
return g;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,11 +66,6 @@ namespace freetype
|
||||
{
|
||||
return r->getGlyphData(glyph);
|
||||
}
|
||||
|
||||
FontData * Font::newFontData(Rasterizer * r)
|
||||
{
|
||||
return new FontData(r);
|
||||
}
|
||||
|
||||
const char * Font::getName() const
|
||||
{
|
||||
|
||||
@@ -63,7 +63,6 @@ namespace freetype
|
||||
Rasterizer * newRasterizer(love::image::ImageData * data, std::string glyphs);
|
||||
Rasterizer * newRasterizer(love::image::ImageData * data, unsigned short * glyphs, int length);
|
||||
GlyphData * newGlyphData(Rasterizer * r, unsigned short glyph);
|
||||
FontData * newFontData(Rasterizer * r);
|
||||
|
||||
// Implement Module
|
||||
const char * getName() const;
|
||||
|
||||
@@ -104,9 +104,6 @@ namespace freetype
|
||||
|
||||
// Having copied the data over, we can destroy the glyph
|
||||
FT_Done_Glyph(ftglyph);
|
||||
|
||||
// Pad the GlyphData for graphics cards that don't support npo2 textures
|
||||
glyphData->pad();
|
||||
|
||||
// Return data
|
||||
return glyphData;
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
|
||||
#include "Font.h"
|
||||
|
||||
#include <font/wrap_FontData.h>
|
||||
#include <font/wrap_GlyphData.h>
|
||||
#include <font/wrap_Rasterizer.h>
|
||||
|
||||
@@ -64,25 +63,15 @@ namespace freetype
|
||||
luax_newtype(L, "GlyphData", FONT_GLYPH_DATA_T, t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newFontData(lua_State * L)
|
||||
{
|
||||
Rasterizer * r = luax_checkrasterizer(L, 1);
|
||||
FontData * f = instance->newFontData(r);
|
||||
luax_newtype(L, "FontData", FONT_FONT_DATA_T, (void*)f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// List of functions to wrap.
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "newRasterizer", w_newRasterizer },
|
||||
{ "newGlyphData", w_newGlyphData },
|
||||
{ "newFontData", w_newFontData },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
static const lua_CFunction types[] = {
|
||||
luaopen_fontdata,
|
||||
luaopen_glyphdata,
|
||||
luaopen_rasterizer,
|
||||
0
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_FontData.h"
|
||||
|
||||
#include <common/wrap_Data.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace font
|
||||
{
|
||||
FontData * luax_checkfontdata(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<FontData>(L, idx, "FontData", FONT_FONT_DATA_T);
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "getPointer", w_Data_getPointer },
|
||||
{ "getSize", w_Data_getSize },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int luaopen_fontdata(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "FontData", functions);
|
||||
}
|
||||
|
||||
} // font
|
||||
} // love
|
||||
@@ -1,39 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_FONT_WRAP_FONT_DATA_H
|
||||
#define LOVE_FONT_WRAP_FONT_DATA_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
|
||||
#include "FontData.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace font
|
||||
{
|
||||
FontData * luax_checkfontdata(lua_State * L, int idx);
|
||||
int luaopen_fontdata(lua_State * L);
|
||||
|
||||
} // font
|
||||
} // love
|
||||
|
||||
#endif // LOVE_FONT_WRAP_FONT_DATA_H
|
||||
@@ -20,10 +20,13 @@
|
||||
|
||||
#include "Font.h"
|
||||
#include <font/GlyphData.h>
|
||||
#include "Quad.h"
|
||||
|
||||
#include <common/math.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <algorithm> // for max
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
@@ -31,33 +34,102 @@ namespace graphics
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Font::Font(love::font::FontData * data, const Image::Filter& filter)
|
||||
: height(data->getHeight()), lineHeight(1), mSpacing(1)
|
||||
Font::Font(love::font::Rasterizer * r, const Image::Filter& filter)
|
||||
: rasterizer(r), height(r->getHeight()), lineHeight(1), mSpacing(1), filter(filter)
|
||||
{
|
||||
glyphs = new Glyph*[MAX_CHARS];
|
||||
type = FONT_UNKNOWN;
|
||||
love::font::GlyphData * gd;
|
||||
|
||||
for(unsigned int i = 0; i < MAX_CHARS; i++)
|
||||
{
|
||||
gd = data->getGlyphData(i);
|
||||
glyphs[i] = new Glyph(gd, filter);
|
||||
glyphs[i]->load();
|
||||
widths[i] = gd->getWidth();
|
||||
spacing[i] = gd->getAdvance();
|
||||
bearingX[i] = gd->getBearingX();
|
||||
bearingY[i] = gd->getBearingY();
|
||||
if (type == FONT_UNKNOWN) type = (gd->getFormat() == love::font::GlyphData::FORMAT_LUMINANCE_ALPHA ? FONT_TRUETYPE : FONT_IMAGE);
|
||||
}
|
||||
love::font::GlyphData * gd = r->getGlyphData(32);
|
||||
type = (gd->getFormat() == love::font::GlyphData::FORMAT_LUMINANCE_ALPHA ? FONT_TRUETYPE : FONT_IMAGE);
|
||||
delete gd;
|
||||
createTexture();
|
||||
}
|
||||
|
||||
Font::~Font()
|
||||
{
|
||||
for(unsigned int i = 0; i < MAX_CHARS; i++)
|
||||
{
|
||||
glyphs[i]->release();
|
||||
unloadVolatile();
|
||||
}
|
||||
|
||||
void Font::createTexture()
|
||||
{
|
||||
texture_x = texture_y = rowHeight = 0;
|
||||
GLuint t;
|
||||
glGenTextures(1, &t);
|
||||
textures.push_back(t);
|
||||
glBindTexture(GL_TEXTURE_2D, t);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
|
||||
(filter.mag == Image::FILTER_LINEAR) ? GL_LINEAR : GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
||||
(filter.min == Image::FILTER_LINEAR) ? GL_LINEAR : GL_NEAREST);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
GLint format = (type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA);
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA,
|
||||
(GLsizei)TEXTURE_WIDTH,
|
||||
(GLsizei)TEXTURE_HEIGHT,
|
||||
0,
|
||||
format,
|
||||
GL_UNSIGNED_BYTE,
|
||||
NULL);
|
||||
}
|
||||
|
||||
Font::Glyph * Font::addGlyph(int glyph)
|
||||
{
|
||||
Glyph * g = new Glyph;
|
||||
g->list = glGenLists(1);
|
||||
if (g->list == 0) { // opengl failed to generate the list
|
||||
delete g;
|
||||
return NULL;
|
||||
}
|
||||
delete[] glyphs;
|
||||
love::font::GlyphData *gd = rasterizer->getGlyphData(glyph);
|
||||
g->spacing = gd->getAdvance();
|
||||
int w = gd->getWidth();
|
||||
int h = gd->getHeight();
|
||||
if (texture_x + w > TEXTURE_WIDTH) { // out of space - new row!
|
||||
texture_x = 0;
|
||||
texture_y += rowHeight;
|
||||
rowHeight = 0;
|
||||
}
|
||||
if (texture_y + h > TEXTURE_HEIGHT) { // totally out of space - new texture!
|
||||
createTexture();
|
||||
}
|
||||
GLuint t = textures.back();
|
||||
glBindTexture(GL_TEXTURE_2D, t);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, texture_x, texture_y, w, h, (type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA), GL_UNSIGNED_BYTE, gd->getData());
|
||||
|
||||
Quad::Viewport v;
|
||||
v.x = texture_x;
|
||||
v.y = texture_y;
|
||||
v.w = w;
|
||||
v.h = h;
|
||||
Quad * q = new Quad(v, TEXTURE_WIDTH, TEXTURE_HEIGHT);
|
||||
const vertex * verts = q->getVertices();
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&verts[0].x);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&verts[0].s);
|
||||
|
||||
glNewList(g->list, GL_COMPILE);
|
||||
glBindTexture(GL_TEXTURE_2D, t);
|
||||
glPushMatrix();
|
||||
glTranslatef(static_cast<float>(gd->getBearingX()), static_cast<float>(-gd->getBearingY()), 0.0f);
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
glPopMatrix();
|
||||
glEndList();
|
||||
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
delete q;
|
||||
delete gd;
|
||||
|
||||
texture_x += w;
|
||||
rowHeight = std::max(rowHeight, h);
|
||||
|
||||
glyphs[glyph] = g;
|
||||
return g;
|
||||
}
|
||||
|
||||
float Font::getHeight() const
|
||||
@@ -65,7 +137,7 @@ namespace opengl
|
||||
return static_cast<float>(height);
|
||||
}
|
||||
|
||||
void Font::print(std::string text, float x, float y, float angle, float sx, float sy) const
|
||||
void Font::print(std::string text, float x, float y, float angle, float sx, float sy)
|
||||
{
|
||||
float dx = 0.0f; // spacing counter for newline handling
|
||||
glPushMatrix();
|
||||
@@ -80,57 +152,66 @@ namespace opengl
|
||||
dx = 0.0f;
|
||||
continue;
|
||||
}
|
||||
if (!glyphs[g]) g = 32; // space
|
||||
Glyph * glyph = glyphs[g];
|
||||
if (!glyph) glyph = addGlyph(g);
|
||||
glPushMatrix();
|
||||
// 1.25 is magic line height for true type fonts
|
||||
if (type == FONT_TRUETYPE) glTranslatef(0, floor(getHeight() / 1.25f + 0.5f), 0);
|
||||
glyphs[g]->draw(0, 0, 0, 1, 1, 0, 0);
|
||||
glCallList(glyph->list);
|
||||
glPopMatrix();
|
||||
glTranslatef(static_cast<GLfloat>(spacing[g]), 0, 0);
|
||||
dx += spacing[g];
|
||||
glTranslatef(static_cast<GLfloat>(glyph->spacing), 0, 0);
|
||||
dx += glyph->spacing;
|
||||
}
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void Font::print(char character, float x, float y) const
|
||||
void Font::print(char character, float x, float y)
|
||||
{
|
||||
if (!glyphs[(int)character]) character = ' ';
|
||||
Glyph * glyph = glyphs[character];
|
||||
if (!glyph) glyph = addGlyph(character);
|
||||
glPushMatrix();
|
||||
glTranslatef(x, floor(y+getHeight() + 0.5f), 0.0f);
|
||||
glCallList(list+character);
|
||||
glCallList(glyph->list);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
int Font::getWidth(const std::string & line) const
|
||||
int Font::getWidth(const std::string & line)
|
||||
{
|
||||
if(line.size() == 0) return 0;
|
||||
int temp = 0;
|
||||
|
||||
Glyph * g;
|
||||
|
||||
for(unsigned int i = 0; i < line.size(); i++)
|
||||
{
|
||||
temp += static_cast<int>((spacing[(int)line[i]] * mSpacing));
|
||||
g = glyphs[line[i]];
|
||||
if (!g) g = addGlyph(line[i]);
|
||||
temp += static_cast<int>(g->spacing * mSpacing);
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
int Font::getWidth(const char * line) const
|
||||
int Font::getWidth(const char * line)
|
||||
{
|
||||
return this->getWidth(std::string(line));
|
||||
}
|
||||
|
||||
int Font::getWidth(const char character) const
|
||||
int Font::getWidth(const char character)
|
||||
{
|
||||
return spacing[(int)character];
|
||||
Glyph * g = glyphs[character];
|
||||
if (!g) g = addGlyph(character);
|
||||
return g->spacing;
|
||||
}
|
||||
|
||||
int Font::getWrap(const std::string & line, float wrap, int * lines) const
|
||||
int Font::getWrap(const std::string & line, float wrap, int * lines)
|
||||
{
|
||||
if(line.size() == 0) return 0;
|
||||
int maxw = 0;
|
||||
int linen = 1;
|
||||
int temp = 0;
|
||||
std::string text;
|
||||
Glyph * g;
|
||||
|
||||
for(unsigned int i = 0; i < line.size(); i++)
|
||||
{
|
||||
@@ -144,7 +225,9 @@ namespace opengl
|
||||
temp = getWidth(text);
|
||||
linen++;
|
||||
}
|
||||
temp += static_cast<int>((spacing[(int)line[i]] * mSpacing));
|
||||
g = glyphs[line[i]];
|
||||
if (!g) g = addGlyph(line[i]);
|
||||
temp += static_cast<int>(g->spacing * mSpacing);
|
||||
text += line[i];
|
||||
}
|
||||
|
||||
@@ -154,7 +237,7 @@ namespace opengl
|
||||
return maxw;
|
||||
}
|
||||
|
||||
int Font::getWrap(const char * line, float wrap, int * lines) const
|
||||
int Font::getWrap(const char * line, float wrap, int * lines)
|
||||
{
|
||||
return getWrap(std::string(line), wrap, lines);
|
||||
}
|
||||
@@ -181,21 +264,26 @@ namespace opengl
|
||||
|
||||
bool Font::loadVolatile()
|
||||
{
|
||||
// reload all glyphs
|
||||
for(unsigned int i = 0; i < MAX_CHARS; i++)
|
||||
{
|
||||
glyphs[i]->load();
|
||||
glNewList(list + i, GL_COMPILE);
|
||||
glyphs[i]->draw(0, 0, 0, 1, 1, 0, 0);
|
||||
glEndList();
|
||||
}
|
||||
return true;
|
||||
createTexture();
|
||||
}
|
||||
|
||||
void Font::unloadVolatile()
|
||||
{
|
||||
// delete the glyphs
|
||||
glDeleteLists(list, MAX_CHARS);
|
||||
// nuke everything from orbit
|
||||
std::map<int, Glyph *>::iterator it = glyphs.begin();
|
||||
Glyph * g;
|
||||
while (it != glyphs.end()) {
|
||||
g = it->second;
|
||||
glDeleteLists(g->list, 1);
|
||||
delete g;
|
||||
glyphs.erase(it++);
|
||||
}
|
||||
std::vector<GLuint>::iterator iter = textures.begin();
|
||||
while (iter != textures.end()) {
|
||||
glDeleteTextures(1, (GLuint*)&*iter);
|
||||
iter++;
|
||||
}
|
||||
textures.clear();
|
||||
}
|
||||
|
||||
} // opengl
|
||||
|
||||
@@ -22,13 +22,16 @@
|
||||
#define LOVE_GRAPHICS_OPENGL_FONT_H
|
||||
|
||||
// STD
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// LOVE
|
||||
#include <common/Object.h>
|
||||
#include <font/FontData.h>
|
||||
#include <font/Rasterizer.h>
|
||||
#include <graphics/Image.h>
|
||||
#include "Glyph.h"
|
||||
|
||||
#include "GLee.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -46,31 +49,40 @@ namespace opengl
|
||||
FONT_IMAGE,
|
||||
FONT_UNKNOWN
|
||||
};
|
||||
|
||||
struct Glyph
|
||||
{
|
||||
GLuint list;
|
||||
int spacing;
|
||||
};
|
||||
|
||||
love::font::Rasterizer * rasterizer;
|
||||
|
||||
int height;
|
||||
float lineHeight;
|
||||
float mSpacing; // modifies the spacing by multiplying it with this value
|
||||
Glyph ** glyphs;
|
||||
GLuint list; // the list of glyphs, for quicker drawing
|
||||
std::vector<GLuint> textures; // vector of packed textures
|
||||
std::map<int, Glyph *> glyphs; // maps glyphs to display lists
|
||||
FontType type;
|
||||
Image::Filter filter;
|
||||
|
||||
static const int TEXTURE_WIDTH = 512;
|
||||
static const int TEXTURE_HEIGHT = 512;
|
||||
|
||||
int texture_x, texture_y;
|
||||
int rowHeight;
|
||||
|
||||
void createTexture();
|
||||
Glyph * addGlyph(int glyph);
|
||||
|
||||
public:
|
||||
static const unsigned int MAX_CHARS = 256;
|
||||
// The widths of each character.
|
||||
int widths[MAX_CHARS];
|
||||
// The spacing of each character.
|
||||
int spacing[MAX_CHARS];
|
||||
// The X-bearing of each character.
|
||||
int bearingX[MAX_CHARS];
|
||||
// The Y-bearing of each character.
|
||||
int bearingY[MAX_CHARS];
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* @param data The font data to construct from.
|
||||
**/
|
||||
Font(love::font::FontData * data, const Image::Filter& filter = Image::Filter());
|
||||
Font(love::font::Rasterizer * r, const Image::Filter& filter = Image::Filter());
|
||||
|
||||
virtual ~Font();
|
||||
|
||||
@@ -82,7 +94,7 @@ namespace opengl
|
||||
* @param y The y-coordinate.
|
||||
* @param angle The amount of rotation.
|
||||
**/
|
||||
void print(std::string text, float x, float y, float angle = 0.0f, float sx = 1.0f, float sy = 1.0f) const;
|
||||
void print(std::string text, float x, float y, float angle = 0.0f, float sx = 1.0f, float sy = 1.0f);
|
||||
|
||||
/**
|
||||
* Prints the character at the designated position.
|
||||
@@ -91,7 +103,7 @@ namespace opengl
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
**/
|
||||
void print(char character, float x, float y) const;
|
||||
void print(char character, float x, float y);
|
||||
|
||||
/**
|
||||
* Returns the height of the font.
|
||||
@@ -103,15 +115,15 @@ namespace opengl
|
||||
*
|
||||
* @param line A line of text.
|
||||
**/
|
||||
int getWidth(const std::string & line) const;
|
||||
int getWidth(const char * line) const;
|
||||
int getWidth(const std::string & line);
|
||||
int getWidth(const char * line);
|
||||
|
||||
/**
|
||||
* Returns the width of the passed character.
|
||||
*
|
||||
* @param character A character.
|
||||
**/
|
||||
int getWidth(const char character) const;
|
||||
int getWidth(const char character);
|
||||
|
||||
/**
|
||||
* Returns the maximal width of a wrapped string
|
||||
@@ -121,8 +133,8 @@ namespace opengl
|
||||
* @param wrap The number of pixels to wrap at
|
||||
* @param lines Optional output of the number of lines needed
|
||||
**/
|
||||
int getWrap(const std::string & line, float wrap, int *lines = 0) const;
|
||||
int getWrap(const char * line, float wrap, int *lines = 0) const;
|
||||
int getWrap(const std::string & line, float wrap, int *lines = 0);
|
||||
int getWrap(const char * line, float wrap, int *lines = 0);
|
||||
|
||||
/**
|
||||
* Sets the line height (which should be a number to multiply the font size by,
|
||||
|
||||
@@ -1,147 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Glyph.h"
|
||||
|
||||
// STD
|
||||
#include <cstring> // For memcpy
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Glyph::Glyph(love::font::GlyphData * data, const Image::Filter& filter_)
|
||||
: data(data),
|
||||
width((float)data->getWidth()), height((float)data->getHeight()),
|
||||
texture(0), filter(filter_)
|
||||
{
|
||||
data->retain();
|
||||
|
||||
memset(vertices, 255, sizeof(vertex)*4);
|
||||
|
||||
vertices[0].x = 0; vertices[0].y = 0;
|
||||
vertices[1].x = 0; vertices[1].y = height;
|
||||
vertices[2].x = width; vertices[2].y = height;
|
||||
vertices[3].x = width; vertices[3].y = 0;
|
||||
|
||||
vertices[0].s = 0; vertices[0].t = 0;
|
||||
vertices[1].s = 0; vertices[1].t = 1;
|
||||
vertices[2].s = 1; vertices[2].t = 1;
|
||||
vertices[3].s = 1; vertices[3].t = 0;
|
||||
|
||||
}
|
||||
|
||||
Glyph::~Glyph()
|
||||
{
|
||||
if(data != 0)
|
||||
data->release();
|
||||
unload();
|
||||
}
|
||||
|
||||
void Glyph::draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const
|
||||
{
|
||||
static Matrix t;
|
||||
|
||||
t.setTransformation(x, y, angle, sx, sy, ox, oy);
|
||||
|
||||
if(texture != 0)
|
||||
glBindTexture(GL_TEXTURE_2D,texture);
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
glMultMatrixf((const GLfloat*)t.getElements());
|
||||
glTranslatef(static_cast<float>(data->getBearingX()), static_cast<float>(-data->getBearingY()), 0.0f);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&vertices[0].x);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&vertices[0].s);
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
}
|
||||
|
||||
bool Glyph::load()
|
||||
{
|
||||
return loadVolatile();
|
||||
}
|
||||
|
||||
void Glyph::unload()
|
||||
{
|
||||
unloadVolatile();
|
||||
}
|
||||
|
||||
bool Glyph::loadVolatile()
|
||||
{
|
||||
GLint format = GL_RGBA;
|
||||
if (data->getFormat() == love::font::GlyphData::FORMAT_LUMINANCE_ALPHA) format = GL_LUMINANCE_ALPHA;
|
||||
|
||||
glGenTextures(1,&texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
|
||||
(filter.mag == Image::FILTER_LINEAR) ? GL_LINEAR : GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
||||
(filter.min == Image::FILTER_LINEAR) ? GL_LINEAR : GL_NEAREST);
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA,
|
||||
(GLsizei)width,
|
||||
(GLsizei)height,
|
||||
0,
|
||||
format,
|
||||
GL_UNSIGNED_BYTE,
|
||||
data->getData());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Glyph::unloadVolatile()
|
||||
{
|
||||
// Delete the hardware texture.
|
||||
if(texture != 0)
|
||||
{
|
||||
glDeleteTextures(1, (GLuint*)&texture);
|
||||
texture = 0;
|
||||
}
|
||||
}
|
||||
|
||||
float Glyph::getWidth() const
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
float Glyph::getHeight() const
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -1,82 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_GLYPH_H
|
||||
#define LOVE_GRAPHICS_OPENGL_GLYPH_H
|
||||
|
||||
// LOVE
|
||||
#include <common/config.h>
|
||||
#include <common/math.h>
|
||||
#include <common/Matrix.h>
|
||||
#include <font/GlyphData.h>
|
||||
#include <graphics/Drawable.h>
|
||||
#include <graphics/Volatile.h>
|
||||
#include <graphics/Image.h>
|
||||
|
||||
// OpenGL
|
||||
#include "GLee.h"
|
||||
#include <SDL/SDL_opengl.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
class Glyph : public Drawable, public Volatile
|
||||
{
|
||||
private:
|
||||
|
||||
love::font::GlyphData * data;
|
||||
|
||||
float width, height;
|
||||
|
||||
GLuint texture;
|
||||
|
||||
vertex vertices[4];
|
||||
|
||||
Image::Filter filter;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
Glyph(love::font::GlyphData * data, const Image::Filter& filter_ = Image::Filter());
|
||||
virtual ~Glyph();
|
||||
|
||||
bool load();
|
||||
void unload();
|
||||
|
||||
// Implements Volatile.
|
||||
bool loadVolatile();
|
||||
void unloadVolatile();
|
||||
|
||||
float getWidth() const;
|
||||
float getHeight() const;
|
||||
|
||||
void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const;
|
||||
|
||||
}; // Glyph
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_GLYPH_H
|
||||
@@ -281,6 +281,9 @@ namespace opengl
|
||||
// Reset modelview matrix
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
// Set pixel row alignment
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
|
||||
|
||||
// Set the new display mode as the current display mode.
|
||||
currentMode.width = width;
|
||||
@@ -472,9 +475,9 @@ namespace opengl
|
||||
return new Quad(v, sw, sh);
|
||||
}
|
||||
|
||||
Font * Graphics::newFont(love::font::FontData * data, const Image::Filter& filter)
|
||||
Font * Graphics::newFont(love::font::Rasterizer * r, const Image::Filter& filter)
|
||||
{
|
||||
Font * font = new Font(data, filter);
|
||||
Font * font = new Font(r, filter);
|
||||
|
||||
// Load it and check for errors.
|
||||
if(!font)
|
||||
|
||||
@@ -33,8 +33,6 @@
|
||||
// LOVE
|
||||
#include <graphics/Graphics.h>
|
||||
|
||||
#include <font/FontData.h>
|
||||
|
||||
#include <image/Image.h>
|
||||
#include <image/ImageData.h>
|
||||
|
||||
@@ -261,7 +259,7 @@ namespace opengl
|
||||
/**
|
||||
* Creates a Font object.
|
||||
**/
|
||||
Font * newFont(love::font::FontData * data, const Image::Filter& filter = Image::Filter());
|
||||
Font * newFont(love::font::Rasterizer * data, const Image::Filter& filter = Image::Filter());
|
||||
|
||||
SpriteBatch * newSpriteBatch(Image * image, int size, int usage);
|
||||
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Glyph.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Glyph * luax_checkglyph(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<Glyph>(L, idx, "Glyph", GRAPHICS_GLYPH_T);
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int luaopen_glyph(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "Glyph", functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -1,41 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_GLYPH_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_GLYPH_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "Glyph.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Glyph * luax_checkglyph(lua_State * L, int idx);
|
||||
int luaopen_glyph(lua_State * L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_GLYPH_H
|
||||
@@ -22,7 +22,6 @@
|
||||
|
||||
#include <image/ImageData.h>
|
||||
#include <font/Rasterizer.h>
|
||||
#include <font/FontData.h>
|
||||
|
||||
#include <scripts/graphics.lua.h>
|
||||
|
||||
@@ -175,20 +174,6 @@ namespace opengl
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newGlyph(lua_State * L)
|
||||
{
|
||||
love::font::GlyphData * data = luax_checktype<love::font::GlyphData>(L, 1, "GlyphData", FONT_GLYPH_DATA_T);
|
||||
|
||||
// Create the image.
|
||||
Glyph * t = new Glyph(data);
|
||||
t->load();
|
||||
|
||||
// Push the type.
|
||||
luax_newtype(L, "Glyph", GRAPHICS_GLYPH_T, (void*)t);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newQuad(lua_State * L)
|
||||
{
|
||||
int x = luaL_checkint(L, 1);
|
||||
@@ -234,14 +219,10 @@ namespace opengl
|
||||
luax_convobj(L, idxs, 2, "font", "newRasterizer");
|
||||
}
|
||||
|
||||
// Convert to FontData, if necessary.
|
||||
if(luax_istype(L, 1, FONT_RASTERIZER_T))
|
||||
luax_convobj(L, 1, "font", "newFontData");
|
||||
|
||||
love::font::FontData * data = luax_checktype<love::font::FontData>(L, 1, "FontData", FONT_FONT_DATA_T);
|
||||
love::font::Rasterizer * rasterizer = luax_checktype<love::font::Rasterizer>(L, 1, "Rasterizer", FONT_RASTERIZER_T);
|
||||
|
||||
// Create the font.
|
||||
Font * font = instance->newFont(data);
|
||||
Font * font = instance->newFont(rasterizer);
|
||||
|
||||
if(font == 0)
|
||||
return luaL_error(L, "Could not load font.");
|
||||
@@ -274,14 +255,10 @@ namespace opengl
|
||||
luax_convobj(L, idxs, 2, "font", "newRasterizer");
|
||||
}
|
||||
|
||||
// Convert to FontData, if necessary.
|
||||
if(luax_istype(L, 1, FONT_RASTERIZER_T))
|
||||
luax_convobj(L, 1, "font", "newFontData");
|
||||
|
||||
love::font::FontData * data = luax_checktype<love::font::FontData>(L, 1, "FontData", FONT_FONT_DATA_T);
|
||||
love::font::Rasterizer * rasterizer = luax_checktype<love::font::Rasterizer>(L, 1, "Rasterizer", FONT_RASTERIZER_T);
|
||||
|
||||
// Create the font.
|
||||
Font * font = instance->newFont(data, img_filter);
|
||||
Font * font = instance->newFont(rasterizer, img_filter);
|
||||
|
||||
if(font == 0)
|
||||
return luaL_error(L, "Could not load font.");
|
||||
@@ -469,14 +446,10 @@ namespace opengl
|
||||
luax_convobj(L, idxs, 2, "font", "newRasterizer");
|
||||
}
|
||||
|
||||
// Convert to FontData, if necessary.
|
||||
if(luax_istype(L, 1, FONT_RASTERIZER_T))
|
||||
luax_convobj(L, 1, "font", "newFontData");
|
||||
|
||||
love::font::FontData * data = luax_checktype<love::font::FontData>(L, 1, "FontData", FONT_FONT_DATA_T);
|
||||
love::font::Rasterizer * rasterizer = luax_checktype<love::font::Rasterizer>(L, 1, "Rasterizer", FONT_RASTERIZER_T);
|
||||
|
||||
// Create the font.
|
||||
font = instance->newFont(data);
|
||||
font = instance->newFont(rasterizer);
|
||||
|
||||
if(font == 0)
|
||||
return luaL_error(L, "Could not load font.");
|
||||
@@ -934,7 +907,6 @@ namespace opengl
|
||||
{ "present", w_present },
|
||||
|
||||
{ "newImage", w_newImage },
|
||||
{ "newGlyph", w_newGlyph },
|
||||
{ "newQuad", w_newQuad },
|
||||
{ "newFont1", w_newFont1 },
|
||||
{ "newImageFont", w_newImageFont },
|
||||
@@ -1017,7 +989,6 @@ namespace opengl
|
||||
static const lua_CFunction types[] = {
|
||||
luaopen_font,
|
||||
luaopen_image,
|
||||
luaopen_glyph,
|
||||
luaopen_frame,
|
||||
luaopen_spritebatch,
|
||||
luaopen_particlesystem,
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
// LOVE
|
||||
#include "wrap_Font.h"
|
||||
#include "wrap_Image.h"
|
||||
#include "wrap_Glyph.h"
|
||||
#include "wrap_Quad.h"
|
||||
#include "wrap_SpriteBatch.h"
|
||||
#include "wrap_ParticleSystem.h"
|
||||
@@ -52,7 +51,6 @@ namespace opengl
|
||||
int w_setScissor(lua_State * L);
|
||||
int w_getScissor(lua_State * L);
|
||||
int w_newImage(lua_State * L);
|
||||
int w_newGlyph(lua_State * L);
|
||||
int w_newQuad(lua_State * L);
|
||||
int w_newFrame(lua_State * L);
|
||||
int w_newFont1(lua_State * L);
|
||||
|
||||
Reference in New Issue
Block a user