trashed old unnecessary font stuff - compiles, but obviously will not work yet

--HG--
branch : newfont
This commit is contained in:
Bill Meltsner
2011-03-05 23:17:36 -05:00
parent ba44dfb682
commit 94b4319878
20 changed files with 28 additions and 627 deletions
+11 -19
View File
@@ -31,18 +31,15 @@ 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)
{
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();
gd = r->getGlyphData(i);
widths[i] = gd->getWidth();
spacing[i] = gd->getAdvance();
bearingX[i] = gd->getBearingX();
@@ -53,11 +50,6 @@ namespace opengl
Font::~Font()
{
for(unsigned int i = 0; i < MAX_CHARS; i++)
{
glyphs[i]->release();
}
delete[] glyphs;
}
float Font::getHeight() const
@@ -67,7 +59,7 @@ namespace opengl
void Font::print(std::string text, float x, float y, float angle, float sx, float sy) const
{
float dx = 0.0f; // spacing counter for newline handling
/*float dx = 0.0f; // spacing counter for newline handling
glPushMatrix();
glTranslatef(ceil(x), ceil(y), 0.0f);
@@ -89,16 +81,16 @@ namespace opengl
glTranslatef(static_cast<GLfloat>(spacing[g]), 0, 0);
dx += spacing[g];
}
glPopMatrix();
glPopMatrix();*/
}
void Font::print(char character, float x, float y) const
{
if (!glyphs[(int)character]) character = ' ';
/*if (!glyphs[(int)character]) character = ' ';
glPushMatrix();
glTranslatef(x, floor(y+getHeight() + 0.5f), 0.0f);
glCallList(list+character);
glPopMatrix();
glPopMatrix();*/
}
int Font::getWidth(const std::string & line) const
@@ -181,7 +173,7 @@ namespace opengl
bool Font::loadVolatile()
{
// reload all glyphs
/*// reload all glyphs
for(unsigned int i = 0; i < MAX_CHARS; i++)
{
glyphs[i]->load();
@@ -189,13 +181,13 @@ namespace opengl
glyphs[i]->draw(0, 0, 0, 1, 1, 0, 0);
glEndList();
}
return true;
return true;*/
}
void Font::unloadVolatile()
{
// delete the glyphs
glDeleteLists(list, MAX_CHARS);
/*// delete the glyphs
glDeleteLists(list, MAX_CHARS);*/
}
} // opengl
+6 -4
View File
@@ -26,9 +26,10 @@
// 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,11 +47,12 @@ namespace opengl
FONT_IMAGE,
FONT_UNKNOWN
};
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
FontType type;
@@ -70,7 +72,7 @@ namespace opengl
*
* @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();
-147
View File
@@ -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
-82
View File
@@ -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
+2 -2
View File
@@ -472,9 +472,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)
+1 -3
View File
@@ -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
-41
View File
@@ -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
+6 -27
View File
@@ -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.");
@@ -278,10 +259,10 @@ namespace opengl
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.");
@@ -473,10 +454,10 @@ namespace opengl
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 +915,6 @@ namespace opengl
{ "present", w_present },
{ "newImage", w_newImage },
{ "newGlyph", w_newGlyph },
{ "newQuad", w_newQuad },
{ "newFont1", w_newFont1 },
{ "newImageFont", w_newImageFont },
@@ -1017,7 +997,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);