Updated love.font, and added Glyph object in love.graphics.

This commit is contained in:
rude
2009-07-30 21:43:00 +02:00
parent 26625c46cb
commit 477d5a05b8
32 changed files with 862 additions and 248 deletions
+129
View File
@@ -0,0 +1,129 @@
/**
* Copyright (c) 2006-2009 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)
: data(data), texture(0), width((float)data->getWidth()), height((float)data->getHeight())
{
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());
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()
{
glGenTextures(1,&texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
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,
GL_LUMINANCE_ALPHA,
GL_UNSIGNED_BYTE,
data->getData());
return true;
}
void Glyph::unloadVolatile()
{
// Delete the hardware texture.
if(texture != 0)
{
glDeleteTextures(1, (GLuint*)&texture);
texture = 0;
}
}
} // opengl
} // graphics
} // love
+75
View File
@@ -0,0 +1,75 @@
/**
* Copyright (c) 2006-2009 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>
// OpenGL
#include "GLee.h"
#include <SDL/SDL_opengl.h>
namespace love
{
namespace graphics
{
namespace opengl
{
class Glyph : public Drawable
{
private:
love::font::GlyphData * data;
float width, height;
GLuint texture;
vertex vertices[4];
public:
Glyph(love::font::GlyphData * data);
virtual ~Glyph();
bool load();
void unload();
// Implements Volatile.
bool loadVolatile();
void unloadVolatile();
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
@@ -0,0 +1,47 @@
/**
* Copyright (c) 2006-2009 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", LOVE_GRAPHICS_GLYPH_BITS);
}
static const luaL_Reg wrap_Glyph_functions[] = {
{ 0, 0 }
};
int wrap_Glyph_open(lua_State * L)
{
luax_register_type(L, "Glyph", wrap_Glyph_functions);
return 0;
}
} // opengl
} // graphics
} // love
+41
View File
@@ -0,0 +1,41 @@
/**
* Copyright (c) 2006-2009 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 wrap_Glyph_open(lua_State * L);
} // opengl
} // graphics
} // love
#endif // LOVE_GRAPHICS_OPENGL_WRAP_GLYPH_H
+22 -2
View File
@@ -20,6 +20,8 @@
#include "wrap_Graphics.h"
#include <font/wrap_GlyphData.h>
namespace love
{
namespace graphics
@@ -153,6 +155,21 @@ namespace opengl
return 1;
}
int _wrap_newGlyph(lua_State * L)
{
love::font::GlyphData * data = love::font::luax_checkglyphdata(L, 1);
// Create the image.
Glyph * t = new Glyph(data);
t->load();
// Push the type.
luax_newtype(L, "Glyph", LOVE_GRAPHICS_GLYPH_BITS, (void*)t);
return 1;
}
int _wrap_newFrame(lua_State * L)
{
@@ -699,6 +716,7 @@ namespace opengl
{ "present", _wrap_present },
{ "newImage", _wrap_newImage },
{ "newGlyph", _wrap_newGlyph },
{ "newFrame", _wrap_newFrame },
{ "newFont", _wrap_newFont },
{ "newImageFont", _wrap_newImageFont },
@@ -764,6 +782,7 @@ namespace opengl
{ "pop", _wrap_pop },
{ "rotate", _wrap_rotate },
{ "scale", _wrap_scale },
{ "translate", _wrap_translate },
{ 0, 0 }
@@ -773,6 +792,7 @@ namespace opengl
const lua_CFunction wrap_Graphics_types[] = {
wrap_Font_open,
wrap_Image_open,
wrap_Glyph_open,
wrap_Frame_open,
wrap_SpriteBatch_open,
0
@@ -795,8 +815,8 @@ namespace opengl
luax_register_gc(L, "love.graphics", instance);
luax_register_module(L, wrap_Graphics_functions, wrap_Graphics_types, "graphics");
//# include <scripts/graphics.lua.h>
luaL_dofile(L, "../../src/scripts/graphics.lua");
# include <scripts/graphics.lua.h>
//luaL_dofile(L, "../../src/scripts/graphics.lua");
return 0;
}
@@ -24,6 +24,7 @@
// LOVE
#include "wrap_Font.h"
#include "wrap_Image.h"
#include "wrap_Glyph.h"
#include "wrap_Frame.h"
#include "wrap_SpriteBatch.h"
#include "Graphics.h"
@@ -48,6 +49,7 @@ namespace opengl
int _wrap_setScissor(lua_State * L);
int _wrap_getScissor(lua_State * L);
int _wrap_newImage(lua_State * L);
int _wrap_newGlyph(lua_State * L);
int _wrap_newFrame(lua_State * L);
int _wrap_newFont(lua_State * L);
int _wrap_newImageFont(lua_State * L);