Add Geometries (replaces Quads).

A Geometry is a collection of vertices describing a non self-intersecting
(simple) polygon. In addition to screen coordinates, the vertices have
attributes for texture coordinates (s,t) and color (r,g,b,a).

It can be used as a quad, to display distorted images, or anything in between.

Added:
^^^^^^

-- geometry from table, where table has the format:
-- info = {
-- {x,y, s,t, [r = 255, g = 255, b = 255, a = 255]}
-- {x,y, s,t, [r = 255, g = 255, b = 255, a = 255]}
-- ...
-- }
geom = love.graphics.newGeometry(info)

-- convenience wrapper for quads (same as before)
geom = love.graphics.newQuad(x,y, w,h, sw,sh)

-- retrieve vertex i (1-indexed)
x,y,s,t,r,g,b,a = geom:getVertex(i)

-- set vertex i (1-indexed)
geom:setVertex(i, x,y, s,t, [r,g,b,a])

-- flip geometry
geom:flip(x, y)


Renamed:
^^^^^^^^

love.graphics.drawq() -> love.graphics.drawg()


Removed:
^^^^^^^^

quad:setViewport()
quad:getViewport()
This commit is contained in:
vrld
2013-04-21 18:53:13 +02:00
parent 9d62d0044c
commit 71317c4359
28 changed files with 750 additions and 229 deletions
+17 -6
View File
@@ -101,13 +101,18 @@ void Image::draw(float x, float y, float angle, float sx, float sy, float ox, fl
drawv(t, vertices);
}
void Image::drawq(love::graphics::Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
void Image::drawg(love::graphics::Geometry *geom, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
{
static Matrix t;
const vertex *v = quad->getVertices();
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
drawv(t, v);
// use colors stored in geometry (horrible, horrible hack)
const vertex *v = geom->getVertexArray();
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), (GLvoid *)&v->r);
drawv(t, v, geom->getVertexArraySize(), GL_TRIANGLES);
glDisableClientState(GL_COLOR_ARRAY);
}
void Image::uploadCompressedMipmaps()
@@ -491,7 +496,7 @@ bool Image::refresh()
return true;
}
void Image::drawv(const Matrix &t, const vertex *v) const
void Image::drawv(const Matrix &t, const vertex *v, GLsizei count, GLenum mode) const
{
bind();
@@ -501,9 +506,15 @@ void Image::drawv(const Matrix &t, const vertex *v) const
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
// XXX: drawg() enables/disables GL_COLOR_ARRAY in order to use the color
// defined in the geometry to draw itself.
// if the drawing method below is changed to use something other than
// glDrawArrays(), drawg() needs to be updated accordingly!
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].x);
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].s);
glDrawArrays(GL_QUADS, 0, 4);
glDrawArrays(mode, 0, count);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);