Switch quads over to floats instead of ints (issue #285)

This commit is contained in:
Bart van Strien
2011-08-24 09:58:16 +02:00
parent ceab3f7a44
commit f0dad41f39
4 changed files with 32 additions and 32 deletions
+14 -14
View File
@@ -33,7 +33,7 @@ namespace graphics
{ {
namespace opengl namespace opengl
{ {
Quad::Quad(const Viewport & v, int sw, int sh) Quad::Quad(const Viewport & v, float sw, float sh)
: sw(sw), sh(sh) : sw(sw), sh(sh)
{ {
memset(vertices, 255, sizeof(vertex)*4); 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) if (!GLEE_ARB_texture_non_power_of_two)
{ {
@@ -56,20 +56,20 @@ namespace opengl
vertices[0].x = 0; vertices[0].x = 0;
vertices[0].y = 0; vertices[0].y = 0;
vertices[1].x = 0; vertices[1].x = 0;
vertices[1].y = (float)v.h; vertices[1].y = v.h;
vertices[2].x = (float)v.w; vertices[2].x = v.w;
vertices[2].y = (float)v.h; vertices[2].y = v.h;
vertices[3].x = (float)v.w; vertices[3].x = v.w;
vertices[3].y = 0; vertices[3].y = 0;
vertices[0].s = (float)v.x/(float)sw; vertices[0].s = v.x/sw;
vertices[0].t = (float)v.y/(float)sh; vertices[0].t = v.y/sh;
vertices[1].s = (float)v.x/(float)sw; vertices[1].s = v.x/sw;
vertices[1].t = (float)(v.y+v.h)/(float)sh; vertices[1].t = (v.y+v.h)/sh;
vertices[2].s = (float)(v.x+v.w)/(float)sw; vertices[2].s = (v.x+v.w)/sw;
vertices[2].t = (float)(v.y+v.h)/(float)sh; vertices[2].t = (v.y+v.h)/sh;
vertices[3].s = (float)(v.x+v.w)/(float)sw; vertices[3].s = (v.x+v.w)/sw;
vertices[3].t = (float)v.y/(float)sh; vertices[3].t = v.y/sh;
} }
void Quad::setViewport(const Quad::Viewport & v) void Quad::setViewport(const Quad::Viewport & v)
+4 -4
View File
@@ -38,7 +38,7 @@ namespace opengl
struct Viewport struct Viewport
{ {
int x, y, w, h; float x, y, w, h;
}; };
private: private:
@@ -46,7 +46,7 @@ namespace opengl
vertex vertices[4]; vertex vertices[4];
Viewport viewport; Viewport viewport;
int sw, sh; float sw, sh;
public: public:
@@ -58,11 +58,11 @@ namespace opengl
* @param sw Width of the source image. * @param sw Width of the source image.
* @param sh Height 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(); 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); void setViewport(const Viewport & v);
Viewport getViewport() const; Viewport getViewport() const;
@@ -226,12 +226,12 @@ namespace opengl
int w_newQuad(lua_State * L) int w_newQuad(lua_State * L)
{ {
int x = luaL_checkint(L, 1); int x = luaL_checknumber(L, 1);
int y = luaL_checkint(L, 2); int y = luaL_checknumber(L, 2);
int w = luaL_checkint(L, 3); int w = luaL_checknumber(L, 3);
int h = luaL_checkint(L, 4); int h = luaL_checknumber(L, 4);
int sw = luaL_checkint(L, 5); int sw = luaL_checknumber(L, 5);
int sh = luaL_checkint(L, 6); int sh = luaL_checknumber(L, 6);
Quad * frame = instance->newQuad(x, y, w, h, sw, sh); Quad * frame = instance->newQuad(x, y, w, h, sw, sh);
+8 -8
View File
@@ -43,10 +43,10 @@ namespace opengl
{ {
Quad * quad = luax_checktype<Quad>(L, 1, "Quad", GRAPHICS_QUAD_T); Quad * quad = luax_checktype<Quad>(L, 1, "Quad", GRAPHICS_QUAD_T);
Quad::Viewport v; Quad::Viewport v;
v.x = luaL_checkint(L, 2); v.x = luaL_checknumber(L, 2);
v.y = luaL_checkint(L, 3); v.y = luaL_checknumber(L, 3);
v.w = luaL_checkint(L, 4); v.w = luaL_checknumber(L, 4);
v.h = luaL_checkint(L, 5); v.h = luaL_checknumber(L, 5);
quad->setViewport(v); quad->setViewport(v);
return 0; return 0;
} }
@@ -55,10 +55,10 @@ namespace opengl
{ {
Quad * quad = luax_checktype<Quad>(L, 1, "Quad", GRAPHICS_QUAD_T); Quad * quad = luax_checktype<Quad>(L, 1, "Quad", GRAPHICS_QUAD_T);
Quad::Viewport v = quad->getViewport(); Quad::Viewport v = quad->getViewport();
lua_pushinteger(L, v.x); lua_pushnumber(L, v.x);
lua_pushinteger(L, v.y); lua_pushnumber(L, v.y);
lua_pushinteger(L, v.w); lua_pushnumber(L, v.w);
lua_pushinteger(L, v.h); lua_pushnumber(L, v.h);
return 4; return 4;
} }