mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Switch quads over to floats instead of ints (issue #285)
This commit is contained in:
@@ -33,7 +33,7 @@ namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Quad::Quad(const Viewport & v, int sw, int sh)
|
||||
Quad::Quad(const Viewport & v, float sw, float sh)
|
||||
: sw(sw), sh(sh)
|
||||
{
|
||||
memset(vertices, 255, sizeof(vertex)*4);
|
||||
@@ -44,7 +44,7 @@ namespace opengl
|
||||
{
|
||||
}
|
||||
|
||||
void Quad::refresh(const Viewport & v, int sw, int sh)
|
||||
void Quad::refresh(const Viewport & v, float sw, float sh)
|
||||
{
|
||||
if (!GLEE_ARB_texture_non_power_of_two)
|
||||
{
|
||||
@@ -56,20 +56,20 @@ namespace opengl
|
||||
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[1].y = v.h;
|
||||
vertices[2].x = v.w;
|
||||
vertices[2].y = v.h;
|
||||
vertices[3].x = 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;
|
||||
vertices[0].s = v.x/sw;
|
||||
vertices[0].t = v.y/sh;
|
||||
vertices[1].s = v.x/sw;
|
||||
vertices[1].t = (v.y+v.h)/sh;
|
||||
vertices[2].s = (v.x+v.w)/sw;
|
||||
vertices[2].t = (v.y+v.h)/sh;
|
||||
vertices[3].s = (v.x+v.w)/sw;
|
||||
vertices[3].t = v.y/sh;
|
||||
}
|
||||
|
||||
void Quad::setViewport(const Quad::Viewport & v)
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace opengl
|
||||
|
||||
struct Viewport
|
||||
{
|
||||
int x, y, w, h;
|
||||
float x, y, w, h;
|
||||
};
|
||||
|
||||
private:
|
||||
@@ -46,7 +46,7 @@ namespace opengl
|
||||
vertex vertices[4];
|
||||
|
||||
Viewport viewport;
|
||||
int sw, sh;
|
||||
float sw, sh;
|
||||
|
||||
public:
|
||||
|
||||
@@ -58,11 +58,11 @@ namespace opengl
|
||||
* @param sw Width of the source image.
|
||||
* @param sh Height of the source image.
|
||||
**/
|
||||
Quad(const Viewport & v, int sw, int sh);
|
||||
Quad(const Viewport & v, float sw, float sh);
|
||||
|
||||
virtual ~Quad();
|
||||
|
||||
void refresh(const Viewport & v, int sw, int sh);
|
||||
void refresh(const Viewport & v, float sw, float sh);
|
||||
|
||||
void setViewport(const Viewport & v);
|
||||
Viewport getViewport() const;
|
||||
|
||||
@@ -226,12 +226,12 @@ namespace opengl
|
||||
|
||||
int w_newQuad(lua_State * L)
|
||||
{
|
||||
int x = luaL_checkint(L, 1);
|
||||
int y = luaL_checkint(L, 2);
|
||||
int w = luaL_checkint(L, 3);
|
||||
int h = luaL_checkint(L, 4);
|
||||
int sw = luaL_checkint(L, 5);
|
||||
int sh = luaL_checkint(L, 6);
|
||||
int x = luaL_checknumber(L, 1);
|
||||
int y = luaL_checknumber(L, 2);
|
||||
int w = luaL_checknumber(L, 3);
|
||||
int h = luaL_checknumber(L, 4);
|
||||
int sw = luaL_checknumber(L, 5);
|
||||
int sh = luaL_checknumber(L, 6);
|
||||
|
||||
Quad * frame = instance->newQuad(x, y, w, h, sw, sh);
|
||||
|
||||
|
||||
@@ -43,10 +43,10 @@ namespace opengl
|
||||
{
|
||||
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);
|
||||
v.x = luaL_checknumber(L, 2);
|
||||
v.y = luaL_checknumber(L, 3);
|
||||
v.w = luaL_checknumber(L, 4);
|
||||
v.h = luaL_checknumber(L, 5);
|
||||
quad->setViewport(v);
|
||||
return 0;
|
||||
}
|
||||
@@ -55,10 +55,10 @@ namespace opengl
|
||||
{
|
||||
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);
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
lua_pushnumber(L, v.w);
|
||||
lua_pushnumber(L, v.h);
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user