Renamed Frame to Quad; added drawq/addq; fixed some bugs.

This commit is contained in:
rude
2009-08-17 23:35:04 +02:00
parent d4a97d49f3
commit c52c218ba1
25 changed files with 317 additions and 299 deletions
+1 -1
View File
@@ -42,7 +42,7 @@
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="0" Optimization="0"
AdditionalIncludeDirectories="../include" AdditionalIncludeDirectories="../include"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB" PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS"
MinimalRebuild="true" MinimalRebuild="true"
BasicRuntimeChecks="3" BasicRuntimeChecks="3"
RuntimeLibrary="1" RuntimeLibrary="1"
+16 -32
View File
@@ -188,22 +188,6 @@
RelativePath="..\..\..\src\modules\graphics\opengl\Font.h" RelativePath="..\..\..\src\modules\graphics\opengl\Font.h"
> >
</File> </File>
<File
RelativePath="..\..\..\src\modules\graphics\opengl\Frame.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\graphics\opengl\"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\..\src\modules\graphics\opengl\Frame.h"
>
</File>
<File <File
RelativePath="..\..\..\src\modules\graphics\opengl\GLee.c" RelativePath="..\..\..\src\modules\graphics\opengl\GLee.c"
> >
@@ -285,6 +269,14 @@
RelativePath="..\..\..\src\modules\graphics\opengl\ImageFont.h" RelativePath="..\..\..\src\modules\graphics\opengl\ImageFont.h"
> >
</File> </File>
<File
RelativePath="..\..\..\src\modules\graphics\opengl\Quad.cpp"
>
</File>
<File
RelativePath="..\..\..\src\modules\graphics\opengl\Quad.h"
>
</File>
<File <File
RelativePath="..\..\..\src\modules\graphics\opengl\SpriteBatch.cpp" RelativePath="..\..\..\src\modules\graphics\opengl\SpriteBatch.cpp"
> >
@@ -333,22 +325,6 @@
RelativePath="..\..\..\src\modules\graphics\opengl\wrap_Font.h" RelativePath="..\..\..\src\modules\graphics\opengl\wrap_Font.h"
> >
</File> </File>
<File
RelativePath="..\..\..\src\modules\graphics\opengl\wrap_Frame.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\graphics\opengl\"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\..\src\modules\graphics\opengl\wrap_Frame.h"
>
</File>
<File <File
RelativePath="..\..\..\src\modules\graphics\opengl\wrap_Glyph.cpp" RelativePath="..\..\..\src\modules\graphics\opengl\wrap_Glyph.cpp"
> >
@@ -397,6 +373,14 @@
RelativePath="..\..\..\src\modules\graphics\opengl\wrap_Image.h" RelativePath="..\..\..\src\modules\graphics\opengl\wrap_Image.h"
> >
</File> </File>
<File
RelativePath="..\..\..\src\modules\graphics\opengl\wrap_Quad.cpp"
>
</File>
<File
RelativePath="..\..\..\src\modules\graphics\opengl\wrap_Quad.h"
>
</File>
<File <File
RelativePath="..\..\..\src\modules\graphics\opengl\wrap_SpriteBatch.cpp" RelativePath="..\..\..\src\modules\graphics\opengl\wrap_SpriteBatch.cpp"
> >
+16 -48
View File
@@ -821,30 +821,6 @@
RelativePath="..\..\src\modules\graphics\opengl\Font.h" RelativePath="..\..\src\modules\graphics\opengl\Font.h"
> >
</File> </File>
<File
RelativePath="..\..\src\modules\graphics\opengl\Frame.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\graphics\opengl\"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\graphics\opengl\"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\src\modules\graphics\opengl\Frame.h"
>
</File>
<File <File
RelativePath="..\..\src\modules\graphics\opengl\GLee.c" RelativePath="..\..\src\modules\graphics\opengl\GLee.c"
> >
@@ -949,6 +925,14 @@
RelativePath="..\..\src\modules\graphics\opengl\ImageFont.h" RelativePath="..\..\src\modules\graphics\opengl\ImageFont.h"
> >
</File> </File>
<File
RelativePath="..\..\src\modules\graphics\opengl\Quad.cpp"
>
</File>
<File
RelativePath="..\..\src\modules\graphics\opengl\Quad.h"
>
</File>
<File <File
RelativePath="..\..\src\modules\graphics\opengl\SpriteBatch.cpp" RelativePath="..\..\src\modules\graphics\opengl\SpriteBatch.cpp"
> >
@@ -1005,30 +989,6 @@
RelativePath="..\..\src\modules\graphics\opengl\wrap_Font.h" RelativePath="..\..\src\modules\graphics\opengl\wrap_Font.h"
> >
</File> </File>
<File
RelativePath="..\..\src\modules\graphics\opengl\wrap_Frame.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\graphics\opengl\"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\graphics\opengl\"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\src\modules\graphics\opengl\wrap_Frame.h"
>
</File>
<File <File
RelativePath="..\..\src\modules\graphics\opengl\wrap_Glyph.cpp" RelativePath="..\..\src\modules\graphics\opengl\wrap_Glyph.cpp"
> >
@@ -1085,6 +1045,14 @@
RelativePath="..\..\src\modules\graphics\opengl\wrap_Image.h" RelativePath="..\..\src\modules\graphics\opengl\wrap_Image.h"
> >
</File> </File>
<File
RelativePath="..\..\src\modules\graphics\opengl\wrap_Quad.cpp"
>
</File>
<File
RelativePath="..\..\src\modules\graphics\opengl\wrap_Quad.h"
>
</File>
<File <File
RelativePath="..\..\src\modules\graphics\opengl\wrap_SpriteBatch.cpp" RelativePath="..\..\src\modules\graphics\opengl\wrap_SpriteBatch.cpp"
> >
+1 -1
View File
@@ -156,7 +156,7 @@ namespace love
// | e2 e6 e10 e14 | // | e2 e6 e10 e14 |
// | e3 e7 e11 e15 | // | e3 e7 e11 e15 |
void Matrix::transform(vertex * dst, const vertex * src, int size) void Matrix::transform(vertex * dst, const vertex * src, int size) const
{ {
for(int i = 0;i<size;i++) for(int i = 0;i<size;i++)
{ {
+1 -1
View File
@@ -141,7 +141,7 @@ namespace love
* @param src The source vertices. * @param src The source vertices.
* @param size The number of vertices. * @param size The number of vertices.
**/ **/
void transform(vertex * dst, const vertex * src, int size); void transform(vertex * dst, const vertex * src, int size) const;
}; // Matrix }; // Matrix
+2 -2
View File
@@ -43,7 +43,7 @@ namespace love
// Graphics // Graphics
GRAPHICS_DRAWABLE_ID, GRAPHICS_DRAWABLE_ID,
GRAPHICS_IMAGE_ID, GRAPHICS_IMAGE_ID,
GRAPHICS_FRAME_ID, GRAPHICS_QUAD_ID,
GRAPHICS_GLYPH_ID, GRAPHICS_GLYPH_ID,
GRAPHICS_ANIMATION_ID, GRAPHICS_ANIMATION_ID,
GRAPHICS_COLOR_ID, GRAPHICS_COLOR_ID,
@@ -99,7 +99,7 @@ namespace love
// Graphics. // Graphics.
const bits GRAPHICS_DRAWABLE_T = (bits(1) << GRAPHICS_DRAWABLE_ID) | OBJECT_T; const bits GRAPHICS_DRAWABLE_T = (bits(1) << GRAPHICS_DRAWABLE_ID) | OBJECT_T;
const bits GRAPHICS_IMAGE_T = (bits(1) << GRAPHICS_IMAGE_ID) | GRAPHICS_DRAWABLE_T; const bits GRAPHICS_IMAGE_T = (bits(1) << GRAPHICS_IMAGE_ID) | GRAPHICS_DRAWABLE_T;
const bits GRAPHICS_FRAME_T = (bits(1) << GRAPHICS_FRAME_ID) | OBJECT_T; const bits GRAPHICS_QUAD_T = (bits(1) << GRAPHICS_QUAD_ID) | OBJECT_T;
const bits GRAPHICS_GLYPH_T = (bits(1) << GRAPHICS_GLYPH_ID) | GRAPHICS_DRAWABLE_T; const bits GRAPHICS_GLYPH_T = (bits(1) << GRAPHICS_GLYPH_ID) | GRAPHICS_DRAWABLE_T;
const bits GRAPHICS_ANIMATION_T = (bits(1) << GRAPHICS_ANIMATION_ID) | GRAPHICS_DRAWABLE_T; const bits GRAPHICS_ANIMATION_T = (bits(1) << GRAPHICS_ANIMATION_ID) | GRAPHICS_DRAWABLE_T;
const bits GRAPHICS_COLOR_T = (bits(1) << GRAPHICS_COLOR_ID) | OBJECT_T; const bits GRAPHICS_COLOR_T = (bits(1) << GRAPHICS_COLOR_ID) | OBJECT_T;
@@ -74,8 +74,6 @@ namespace physfs
save_path_full = std::string(getAppdataDirectory()) + std::string(LOVE_PATH_SEPARATOR); save_path_full = std::string(getAppdataDirectory()) + std::string(LOVE_PATH_SEPARATOR);
save_path_full += save_path_relative; save_path_full += save_path_relative;
std::cout << save_path_full << std::endl;
// We now have something like: // We now have something like:
// save_identity: game // save_identity: game
// save_path_relative: ./LOVE/game // save_path_relative: ./LOVE/game
@@ -282,11 +280,6 @@ namespace physfs
if(!lua_isstring(L, 2)) if(!lua_isstring(L, 2))
return luaL_error(L, "Second argument must be a string."); return luaL_error(L, "Second argument must be a string.");
// The third paramter must be a number to indicate the size of
// the data.
if(!lua_isnumber(L, 3))
return luaL_error(L, "Third argument must be a number.");
if(lua_isstring(L, 1)) if(lua_isstring(L, 1))
{ {
// Create the file. // Create the file.
+2 -1
View File
@@ -22,8 +22,9 @@
#define LOVE_GRAPHICS_OPENGL_FONT_H #define LOVE_GRAPHICS_OPENGL_FONT_H
// LOVE // LOVE
#include <filesystem/File.h> #include <common/Object.h>
#include <graphics/Volatile.h> #include <graphics/Volatile.h>
#include <filesystem/File.h>
namespace love namespace love
{ {
+7 -2
View File
@@ -395,9 +395,14 @@ namespace opengl
return image; return image;
} }
Frame * Graphics::newFrame(int x, int y, int w, int h, int sw, int sh) Quad * Graphics::newQuad(int x, int y, int w, int h, int sw, int sh)
{ {
return new Frame(x, y, w, h, sw, sh); Quad::Viewport v;
v.x = x;
v.y = y;
v.w = w;
v.h = h;
return new Quad(v, sw, sh);
} }
Font * Graphics::newFont(Data * data, int size) Font * Graphics::newFont(Data * data, int size)
+2 -2
View File
@@ -36,7 +36,7 @@
#include "Image.h" #include "Image.h"
#include "TrueTypeFont.h" #include "TrueTypeFont.h"
#include "ImageFont.h" #include "ImageFont.h"
#include "Frame.h" #include "Quad.h"
#include "SpriteBatch.h" #include "SpriteBatch.h"
namespace love namespace love
@@ -239,7 +239,7 @@ namespace opengl
/** /**
* Creates a Frame * Creates a Frame
**/ **/
Frame * newFrame(int x, int y, int w, int h, int sw, int sh); Quad * newQuad(int x, int y, int w, int h, int sw, int sh);
/** /**
* Creates a Font object. * Creates a Font object.
+3 -13
View File
@@ -110,21 +110,11 @@ namespace opengl
t.setTransformation(x, y, angle, sx, sy, ox, oy); t.setTransformation(x, y, angle, sx, sy, ox, oy);
drawv(t, vertices); drawv(t, vertices);
} }
void Image::draws(float x, float y, float angle, float sx, float sy, float ox, float oy, float rx, float ry, float rw, float rh) const void Image::drawq(Quad * quad, float x, float y, float angle, float sx, float sy, float ox, float oy) const
{ {
static Matrix t; static Matrix t;
static vertex cache[4]; const vertex * v = quad->getVertices();
getRectangleVertices((int)rx, (int)ry, (int)rw, (int)rh, cache);
t.setTransformation(x, y, angle, sx, sy, ox, oy);
drawv(t, cache);
}
void Image::drawf(float x, float y, float angle, float sx, float sy, float ox, float oy, Frame * frame) const
{
static Matrix t;
const vertex * v = frame->getVertices();
t.setTransformation(x, y, angle, sx, sy, ox, oy); t.setTransformation(x, y, angle, sx, sy, ox, oy);
drawv(t, v); drawv(t, v);
+6 -18
View File
@@ -22,13 +22,12 @@
#define LOVE_GRAPHICS_OPENGL_IMAGE_H #define LOVE_GRAPHICS_OPENGL_IMAGE_H
// LOVE // LOVE
#include <common/config.h>
#include <image/ImageData.h>
#include <common/math.h>
#include <graphics/Image.h>
#include "Frame.h"
#include <common/Matrix.h> #include <common/Matrix.h>
#include <common/math.h> #include <common/math.h>
#include <common/config.h>
#include <image/ImageData.h>
#include <graphics/Image.h>
#include "Quad.h"
// OpenGL // OpenGL
#include "GLee.h" #include "GLee.h"
@@ -105,23 +104,12 @@ namespace opengl
void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const; void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const;
/** /**
* This function draws a section of the image. * This function draws a section of the image using a Quad object.
*
* @copydetails Drawable::draw()
* @param rx The upper-left corner of the source rectangle along the x-axis.
* @param ry The upper-left corner of the source rectangle along the y-axis.
* @param rw The width of the source rectangle.
* @param rw The height of the source rectangle.
**/
void draws(float x, float y, float angle, float sx, float sy, float ox, float oy, float rx, float ry, float rw, float rh) const;
/**
* This function draws a section of the image using a Frame object.
* *
* @copydetails Image::draws() * @copydetails Image::draws()
* @param frame Represents the region of the Image to draw. * @param frame Represents the region of the Image to draw.
**/ **/
void drawf(float x, float y, float angle, float sx, float sy, float ox, float oy, Frame * frame) const; void drawq(Quad * quad, float x, float y, float angle, float sx, float sy, float ox, float oy) const;
/** /**
* Sets the filter mode. * Sets the filter mode.
@@ -18,7 +18,7 @@
* 3. This notice may not be removed or altered from any source distribution. * 3. This notice may not be removed or altered from any source distribution.
**/ **/
#include "Frame.h" #include "Quad.h"
#include <common/Matrix.h> #include <common/Matrix.h>
// STD // STD
@@ -30,26 +30,51 @@ namespace graphics
{ {
namespace opengl namespace opengl
{ {
Frame::Frame(int x, int y, int w, int h, int sw, int sh) Quad::Quad(const Viewport & v, int sw, int sh)
: sw(sw), sh(sh)
{ {
memset(vertices, 255, sizeof(vertex)*4); memset(vertices, 255, sizeof(vertex)*4);
refresh(v, sw, sh);
vertices[0].x = 0; vertices[0].y = 0;
vertices[1].x = 0; vertices[1].y = (float)h;
vertices[2].x = (float)w; vertices[2].y = (float)h;
vertices[3].x = (float)w; vertices[3].y = 0;
vertices[0].s = (float)x/(float)sw; vertices[0].t = (float)y/(float)sh;
vertices[1].s = (float)x/(float)sw; vertices[1].t = (float)(y+h)/(float)sh;
vertices[2].s = (float)(x+w)/(float)sw; vertices[2].t = (float)(y+h)/(float)sh;
vertices[3].s = (float)(x+w)/(float)sw; vertices[3].t = (float)y/(float)sh;
} }
Frame::~Frame() Quad::~Quad()
{ {
} }
void Quad::refresh(const Viewport & v, int sw, int sh)
{
viewport = v;
vertices[0].x = 0;
vertices[0].y = 0;
vertices[1].x = 0;
vertices[1].y = (float)v.h;
vertices[2].x = (float)v.w;
vertices[2].y = (float)v.h;
vertices[3].x = (float)v.w;
vertices[3].y = 0;
vertices[0].s = (float)v.x/(float)sw;
vertices[0].t = (float)v.y/(float)sh;
vertices[1].s = (float)v.x/(float)sw;
vertices[1].t = (float)(v.y+v.h)/(float)sh;
vertices[2].s = (float)(v.x+v.w)/(float)sw;
vertices[2].t = (float)(v.y+v.h)/(float)sh;
vertices[3].s = (float)(v.x+v.w)/(float)sw;
vertices[3].t = (float)v.y/(float)sh;
}
void Quad::setViewport(const Quad::Viewport & v)
{
refresh(v, sw, sh);
}
Quad::Viewport Quad::getViewport() const
{
return viewport;
}
void Frame::flip(bool x, bool y) void Quad::flip(bool x, bool y)
{ {
vertex temp[4]; vertex temp[4];
if (x) if (x)
@@ -70,7 +95,7 @@ namespace opengl
} }
} }
const vertex * Frame::getVertices() const const vertex * Quad::getVertices() const
{ {
return vertices; return vertices;
} }
@@ -18,8 +18,8 @@
* 3. This notice may not be removed or altered from any source distribution. * 3. This notice may not be removed or altered from any source distribution.
**/ **/
#ifndef LOVE_GRAPHICS_OPENGL_FRAME_H #ifndef LOVE_GRAPHICS_OPENGL_QUAD_H
#define LOVE_GRAPHICS_OPENGL_FRAME_H #define LOVE_GRAPHICS_OPENGL_QUAD_H
// LOVE // LOVE
#include <common/Object.h> #include <common/Object.h>
@@ -32,37 +32,50 @@ namespace graphics
{ {
namespace opengl namespace opengl
{ {
class Frame : public Object class Quad : public Object
{ {
private: public:
vertex vertices[4];
public:
/** struct Viewport
* Creates a new Frame of size (w,h), using (x,y) as the top-left {
* anchor point in the source image. The size of the source image is int x, y, w, h;
* is specified by (sw,sh). };
*
* @param x Frame source position along the x-axis.
* @param y Frame source position along the y-axis.
* @param w Frame width.
* @param h Frame width.
* @param sw Width of the source image.
* @param sh Height of the source image.
**/
Frame(int x, int y, int w, int h, int sw, int sh);
virtual ~Frame(); private:
void flip(bool x, bool y); vertex vertices[4];
/** Viewport viewport;
* Gets a pointer to the vertices. int sw, sh;
**/
const vertex * getVertices() const; public:
/**
* Creates a new Quad of size (w,h), using (x,y) as the top-left
* anchor point in the source image. The size of the source image is
* is specified by (sw,sh).
*
* @param sw Width of the source image.
* @param sh Height of the source image.
**/
Quad(const Viewport & v, int sw, int sh);
virtual ~Quad();
void refresh(const Viewport & v, int sw, int sh);
void setViewport(const Viewport & v);
Viewport getViewport() const;
void flip(bool x, bool y);
/**
* Gets a pointer to the vertices.
**/
const vertex * getVertices() const;
}; };
} // opengl } // opengl
} // graphics } // graphics
} // love } // love
#endif // LOVE_GRAPHICS_OPENGL_FRAME_H #endif // LOVE_GRAPHICS_OPENGL_QUAD_H
+48 -12
View File
@@ -25,6 +25,7 @@
// LOVE // LOVE
#include "Image.h" #include "Image.h"
#include "Quad.h"
namespace love namespace love
{ {
@@ -88,6 +89,7 @@ namespace opengl
// Get a pointer to the correct insertion position. // Get a pointer to the correct insertion position.
vertex * v = vertices + next*4; vertex * v = vertices + next*4;
// Needed for texture coordinates.
memcpy(v, image->getVertices(), sizeof(vertex)*4); memcpy(v, image->getVertices(), sizeof(vertex)*4);
// Transform. // Transform.
@@ -95,18 +97,30 @@ namespace opengl
t.setTransformation(x, y, a, sx, sy, ox, oy); t.setTransformation(x, y, a, sx, sy, ox, oy);
t.transform(v, v, 4); t.transform(v, v, 4);
if(lockp != 0) addv(t, v);
{
// Copy into mapped memory if buffer is locked. // Increment counter.
memcpy(lockp + (next*4), v, sizeof(vertex)*4); next++;
} }
else }
{
// ... use glBufferSubData otherwise. void SpriteBatch::addq(Quad * quad, float x, float y, float a, float sx, float sy, float ox, float oy)
glBindBuffer(GL_ARRAY_BUFFER, vbo[0]); {
glBufferSubData(GL_ARRAY_BUFFER, (next*4)*sizeof(vertex), sizeof(vertex)*4, v); // Only do this if there's a free slot.
glBindBuffer(GL_ARRAY_BUFFER, 0); if(next < size)
} {
// Get a pointer to the correct insertion position.
vertex * v = vertices + next*4;
// Needed for colors.
memcpy(v, quad->getVertices(), sizeof(vertex)*4);
// Transform.
Matrix t;
t.setTransformation(x, y, a, sx, sy, ox, oy);
t.transform(v, quad->getVertices(), 4);
addv(t, v);
// Increment counter. // Increment counter.
next++; next++;
@@ -169,6 +183,28 @@ namespace opengl
glPopMatrix(); glPopMatrix();
} }
void SpriteBatch::addv(const Matrix & t, const vertex * v)
{
// Get a pointer to the correct insertion position.
vertex * dst = vertices + next*4;
// Transform.
t.transform(dst, dst, 4);
if(lockp != 0)
{
// Copy into mapped memory if buffer is locked.
memcpy(lockp + (next*4), dst, sizeof(vertex)*4);
}
else
{
// ... use glBufferSubData otherwise.
glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
glBufferSubData(GL_ARRAY_BUFFER, (next*4)*sizeof(vertex), sizeof(vertex)*4, dst);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
}
} // opengl } // opengl
} // graphics } // graphics
} // love } // love
+6 -2
View File
@@ -43,6 +43,7 @@ namespace opengl
{ {
// Forward declarations. // Forward declarations.
class Image; class Image;
class Quad;
class SpriteBatch : public Drawable class SpriteBatch : public Drawable
{ {
@@ -84,8 +85,7 @@ namespace opengl
virtual ~SpriteBatch(); virtual ~SpriteBatch();
void add(float x, float y, float a, float sx, float sy, float ox, float oy); void add(float x, float y, float a, float sx, float sy, float ox, float oy);
//void adds(float x, float y, float a, float sx, float sy, float ox, float oy, float rx, float ry, float rw, float rh); void addq(Quad * quad, float x, float y, float a, float sx, float sy, float ox, float oy);
//void addf(float x, float y, float a, float sx, float sy, float ox, float oy, Frame * frame);
void clear(); void clear();
void * lock(); void * lock();
@@ -94,6 +94,10 @@ namespace opengl
// Implements Drawable. // Implements Drawable.
void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const; void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const;
private:
void addv(const Matrix & t, const vertex * v);
}; // SpriteBatch }; // SpriteBatch
} // opengl } // opengl
@@ -1,54 +0,0 @@
/**
* 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_Frame.h"
namespace love
{
namespace graphics
{
namespace opengl
{
Frame * luax_checkframe(lua_State * L, int idx)
{
return luax_checktype<Frame>(L, idx, "Frame", GRAPHICS_FRAME_T);
}
int w_Frame_flip(lua_State *L)
{
Frame *frame = luax_checktype<Frame>(L, 1, "Frame", GRAPHICS_FRAME_T);
frame->flip(luax_toboolean(L, 2), luax_toboolean(L, 3));
return 0;
}
static const luaL_Reg w_Frame_functions[] = {
{ "flip", w_Frame_flip },
{ 0, 0 }
};
int luaopen_frame(lua_State * L)
{
return luax_register_type(L, "Frame", w_Frame_functions);
}
} // opengl
} // graphics
} // love
+17 -51
View File
@@ -168,7 +168,7 @@ namespace opengl
return 1; return 1;
} }
int w_newFrame(lua_State * L) int w_newQuad(lua_State * L)
{ {
int x = luaL_checkint(L, 1); int x = luaL_checkint(L, 1);
int y = luaL_checkint(L, 2); int y = luaL_checkint(L, 2);
@@ -177,12 +177,12 @@ namespace opengl
int sw = luaL_checkint(L, 5); int sw = luaL_checkint(L, 5);
int sh = luaL_checkint(L, 6); int sh = luaL_checkint(L, 6);
Frame * frame = instance->newFrame(x, y, w, h, sw, sh); Quad * frame = instance->newQuad(x, y, w, h, sw, sh);
if (frame == 0) if (frame == 0)
return luaL_error(L, "Could not create frame."); return luaL_error(L, "Could not create frame.");
luax_newtype(L, "Frame", GRAPHICS_FRAME_T, (void*)frame); luax_newtype(L, "Quad", GRAPHICS_QUAD_T, (void*)frame);
return 1; return 1;
} }
@@ -481,40 +481,7 @@ namespace opengl
} }
/** /**
* Draws an Image at the specified coordinates, with rotation and * Draws an Quad of an Image at the specified coordinates,
* scaling along both axes.
* @param x The x-coordinate.
* @param y The y-coordinate.
* @param angle The amount of rotation.
* @param sx The scale factor along the x-axis. (1 = normal).
* @param sy The scale factor along the y-axis. (1 = normal).
* @param ox The offset along the x-axis.
* @param oy The offset along the y-axis.
* @param rx The upper-left corner of the source rectangle along the x-axis.
* @param ry The upper-left corner of the source rectangle along the y-axis.
* @param rw The width of the source rectangle.
* @param rw The height of the source rectangle.
**/
int w_draws(lua_State * L)
{
Image * image = luax_checktype<Image>(L, 1, "Image", GRAPHICS_IMAGE_T);
float x = (float)luaL_optnumber(L, 2, 0.0f);
float y = (float)luaL_optnumber(L, 3, 0.0f);
float angle = (float)luaL_optnumber(L, 4, 0.0f);
float sx = (float)luaL_optnumber(L, 5, 1.0f);
float sy = (float)luaL_optnumber(L, 6, sx);
float ox = (float)luaL_optnumber(L, 7, 0);
float oy = (float)luaL_optnumber(L, 8, 0);
float rx = (float)luaL_optnumber(L, 9, 0);
float ry = (float)luaL_optnumber(L, 10, 0);
float rw = (float)luaL_optnumber(L, 11, image->getWidth());
float rh = (float)luaL_optnumber(L, 12, image->getHeight());
image->draws(x, y, angle, sx, sy, ox, oy, rx, ry, rw, rh);
return 0;
}
/**
* Draws an Frame of an Image at the specified coordinates,
* with rotation and scaling along both axes. * with rotation and scaling along both axes.
* *
* @param x The x-coordinate. * @param x The x-coordinate.
@@ -524,20 +491,20 @@ namespace opengl
* @param sy The scale factor along the y-axis. (1 = normal). * @param sy The scale factor along the y-axis. (1 = normal).
* @param ox The offset along the x-axis. * @param ox The offset along the x-axis.
* @param oy The offset along the y-axis. * @param oy The offset along the y-axis.
* @param f The Frame to dra. * @param f The Quad to dra.
**/ **/
int w_drawf(lua_State * L) int w_drawq(lua_State * L)
{ {
Image * image = luax_checktype<Image>(L, 1, "Image", GRAPHICS_IMAGE_T); Image * image = luax_checktype<Image>(L, 1, "Image", GRAPHICS_IMAGE_T);
float x = (float)luaL_checknumber(L, 2); Quad * q = luax_checkframe(L, 2);
float y = (float)luaL_checknumber(L, 3); float x = (float)luaL_checknumber(L, 3);
float angle = (float)luaL_checknumber(L, 4); float y = (float)luaL_checknumber(L, 4);
float sx = (float)luaL_checknumber(L, 5); float angle = (float)luaL_checknumber(L, 5);
float sy = (float)luaL_checknumber(L, 6); float sx = (float)luaL_checknumber(L, 6);
float ox = (float)luaL_checknumber(L, 7); float sy = (float)luaL_checknumber(L, 7);
float oy = (float)luaL_checknumber(L, 8); float ox = (float)luaL_checknumber(L, 8);
Frame * f = luax_checkframe(L, 9); float oy = (float)luaL_checknumber(L, 9);
image->drawf(x, y, angle, sx, sy, ox, oy, f); image->drawq(q, x, y, angle, sx, sy, ox, oy);
return 0; return 0;
} }
@@ -715,7 +682,7 @@ namespace opengl
{ "newImage", w_newImage }, { "newImage", w_newImage },
{ "newGlyph", w_newGlyph }, { "newGlyph", w_newGlyph },
{ "newFrame", w_newFrame }, { "newQuad", w_newQuad },
{ "newFont", w_newFont }, { "newFont", w_newFont },
{ "newImageFont", w_newImageFont }, { "newImageFont", w_newImageFont },
{ "newSpriteBatch", w_newSpriteBatch }, { "newSpriteBatch", w_newSpriteBatch },
@@ -747,8 +714,7 @@ namespace opengl
{ "getMaxPointSize", w_getMaxPointSize }, { "getMaxPointSize", w_getMaxPointSize },
{ "draw", w_draw }, { "draw", w_draw },
{ "draws", w_draws }, { "drawq", w_drawq },
{ "drawf", w_drawf },
{ "drawTest", w_drawTest }, { "drawTest", w_drawTest },
{ "print1", w_print1 }, { "print1", w_print1 },
+2 -2
View File
@@ -25,7 +25,7 @@
#include "wrap_Font.h" #include "wrap_Font.h"
#include "wrap_Image.h" #include "wrap_Image.h"
#include "wrap_Glyph.h" #include "wrap_Glyph.h"
#include "wrap_Frame.h" #include "wrap_Quad.h"
#include "wrap_SpriteBatch.h" #include "wrap_SpriteBatch.h"
#include "Graphics.h" #include "Graphics.h"
@@ -78,7 +78,7 @@ namespace opengl
int w_getPointStyle(lua_State * L); int w_getPointStyle(lua_State * L);
int w_getMaxPointSize(lua_State * L); int w_getMaxPointSize(lua_State * L);
int w_draw(lua_State * L); int w_draw(lua_State * L);
int w_draws(lua_State * L); int w_drawq(lua_State * L);
int w_drawTest(lua_State * L); int w_drawTest(lua_State * L);
int w_print1(lua_State * L); int w_print1(lua_State * L);
int w_printf1(lua_State * L); int w_printf1(lua_State * L);
+79
View File
@@ -0,0 +1,79 @@
/**
* 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_Quad.h"
namespace love
{
namespace graphics
{
namespace opengl
{
Quad * luax_checkframe(lua_State * L, int idx)
{
return luax_checktype<Quad>(L, idx, "Quad", GRAPHICS_QUAD_T);
}
int w_Quad_flip(lua_State *L)
{
Quad * quad = luax_checktype<Quad>(L, 1, "Quad", GRAPHICS_QUAD_T);
quad->flip(luax_toboolean(L, 2), luax_toboolean(L, 3));
return 0;
}
int w_Quad_setViewport(lua_State * L)
{
Quad * quad = luax_checktype<Quad>(L, 1, "Quad", GRAPHICS_QUAD_T);
Quad::Viewport v;
v.x = luaL_checkint(L, 2);
v.y = luaL_checkint(L, 3);
v.w = luaL_checkint(L, 4);
v.h = luaL_checkint(L, 5);
quad->setViewport(v);
return 0;
}
int w_Quad_getViewport(lua_State * L)
{
Quad * quad = luax_checktype<Quad>(L, 1, "Quad", GRAPHICS_QUAD_T);
Quad::Viewport v = quad->getViewport();
lua_pushinteger(L, v.x);
lua_pushinteger(L, v.y);
lua_pushinteger(L, v.w);
lua_pushinteger(L, v.h);
return 4;
}
static const luaL_Reg w_Quad_functions[] = {
{ "flip", w_Quad_flip },
{ "setViewport", w_Quad_setViewport },
{ "getViewport", w_Quad_getViewport },
{ 0, 0 }
};
int luaopen_frame(lua_State * L)
{
return luax_register_type(L, "Quad", w_Quad_functions);
}
} // opengl
} // graphics
} // love
@@ -18,12 +18,12 @@
* 3. This notice may not be removed or altered from any source distribution. * 3. This notice may not be removed or altered from any source distribution.
**/ **/
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_FRAME_H #ifndef LOVE_GRAPHICS_OPENGL_WRAP_QUAD_H
#define LOVE_GRAPHICS_OPENGL_WRAP_FRAME_H #define LOVE_GRAPHICS_OPENGL_WRAP_QUAD_H
// LOVE // LOVE
#include <common/runtime.h> #include <common/runtime.h>
#include "Frame.h" #include "Quad.h"
namespace love namespace love
{ {
@@ -31,12 +31,14 @@ namespace graphics
{ {
namespace opengl namespace opengl
{ {
Frame * luax_checkframe(lua_State * L, int idx); Quad * luax_checkframe(lua_State * L, int idx);
int w_Frame_flip(lua_State *L); int w_Quad_flip(lua_State *L);
int w_Quad_setViewport(lua_State * L);
int w_Quad_getViewport(lua_State * L);
int luaopen_frame(lua_State * L); int luaopen_frame(lua_State * L);
} // opengl } // opengl
} // graphics } // graphics
} // love } // love
#endif // LOVE_GRAPHICS_OPENGL_WRAP_FRAME_H #endif // LOVE_GRAPHICS_OPENGL_WRAP_QUAD_H
@@ -45,6 +45,21 @@ namespace opengl
return 0; return 0;
} }
int w_SpriteBatch_addq(lua_State * L)
{
SpriteBatch * t = luax_checkspritebatch(L, 1);
Quad * q = luax_checktype<Quad>(L, 2, "Quad", GRAPHICS_QUAD_T);
float x = (float)luaL_optnumber(L, 3, 0.0f);
float y = (float)luaL_optnumber(L, 4, 0.0f);
float angle = (float)luaL_optnumber(L, 5, 0.0f);
float sx = (float)luaL_optnumber(L, 6, 1.0f);
float sy = (float)luaL_optnumber(L, 7, sx);
float ox = (float)luaL_optnumber(L, 8, 0);
float oy = (float)luaL_optnumber(L, 9, 0);
t->addq(q, x, y, angle, sx, sy, ox, oy);
return 0;
}
int w_SpriteBatch_clear(lua_State * L) int w_SpriteBatch_clear(lua_State * L)
{ {
SpriteBatch * t = luax_checkspritebatch(L, 1); SpriteBatch * t = luax_checkspritebatch(L, 1);
@@ -68,6 +83,7 @@ namespace opengl
static const luaL_Reg functions[] = { static const luaL_Reg functions[] = {
{ "add", w_SpriteBatch_add }, { "add", w_SpriteBatch_add },
{ "addq", w_SpriteBatch_addq },
{ "clear", w_SpriteBatch_clear }, { "clear", w_SpriteBatch_clear },
{ "lock", w_SpriteBatch_lock }, { "lock", w_SpriteBatch_lock },
{ "unlock", w_SpriteBatch_unlock }, { "unlock", w_SpriteBatch_unlock },
@@ -32,6 +32,7 @@ namespace opengl
{ {
SpriteBatch * luax_checkspritebatch(lua_State * L, int idx); SpriteBatch * luax_checkspritebatch(lua_State * L, int idx);
int w_SpriteBatch_add(lua_State * L); int w_SpriteBatch_add(lua_State * L);
int w_SpriteBatch_addq(lua_State * L);
int w_SpriteBatch_clear(lua_State * L); int w_SpriteBatch_clear(lua_State * L);
int w_SpriteBatch_lock(lua_State * L); int w_SpriteBatch_lock(lua_State * L);
int w_SpriteBatch_unlock(lua_State * L); int w_SpriteBatch_unlock(lua_State * L);
+3 -2
View File
@@ -69,9 +69,10 @@ namespace sdl
} }
} }
void Timer::sleep(unsigned int ms) void Timer::sleep(int ms)
{ {
SDL_Delay(ms); if(ms > 0)
SDL_Delay(ms);
} }
float Timer::getDelta() const float Timer::getDelta() const
+1 -1
View File
@@ -90,7 +90,7 @@ namespace sdl
* usually 1ms. * usually 1ms.
* @param ms The number of milliseconds to sleep for. * @param ms The number of milliseconds to sleep for.
**/ **/
void sleep(unsigned int ms); void sleep(int ms);
/** /**
* Gets the time between the last two frames, assuming step is called * Gets the time between the last two frames, assuming step is called