added ag::drawRect() and ag::fillRect()
git-svn-id: svn://anubis/anaglym/trunk@184 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
27c0d4f7b9
commit
f410c305c2
34
Engine.cc
34
Engine.cc
@ -540,6 +540,40 @@ void Engine::drawLine(float r, float g, float b,
|
|||||||
glPopAttrib();
|
glPopAttrib();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Engine::drawRect(float r, float g, float b,
|
||||||
|
float width, float height, float x, float y)
|
||||||
|
{
|
||||||
|
glPushAttrib(GL_ENABLE_BIT);
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
|
glEnable(GL_LINE_SMOOTH);
|
||||||
|
glBegin(GL_LINE_LOOP);
|
||||||
|
glColor3f(r, g, b);
|
||||||
|
glVertex2f(x - width / 2, y - height / 2);
|
||||||
|
glVertex2f(x + width / 2, y - height / 2);
|
||||||
|
glVertex2f(x + width / 2, y + height / 2);
|
||||||
|
glVertex2f(x - width / 2, y + height / 2);
|
||||||
|
glEnd();
|
||||||
|
glPopAttrib();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::fillRect(float r, float g, float b,
|
||||||
|
float width, float height, float x, float y)
|
||||||
|
{
|
||||||
|
glPushAttrib(GL_ENABLE_BIT);
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
|
glEnable(GL_POLYGON_SMOOTH);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glColor3f(r, g, b);
|
||||||
|
glVertex2f(x - width / 2, y - height / 2);
|
||||||
|
glVertex2f(x + width / 2, y - height / 2);
|
||||||
|
glVertex2f(x + width / 2, y + height / 2);
|
||||||
|
glVertex2f(x - width / 2, y + height / 2);
|
||||||
|
glEnd();
|
||||||
|
glPopAttrib();
|
||||||
|
}
|
||||||
|
|
||||||
/* called by SDL when the update timer expires */
|
/* called by SDL when the update timer expires */
|
||||||
Uint32 Engine::updateCallback(Uint32 interval, void * param)
|
Uint32 Engine::updateCallback(Uint32 interval, void * param)
|
||||||
{
|
{
|
||||||
|
4
Engine.h
4
Engine.h
@ -145,6 +145,10 @@ class Engine
|
|||||||
float * width, float * height);
|
float * width, float * height);
|
||||||
void drawLine(float r, float g, float b,
|
void drawLine(float r, float g, float b,
|
||||||
float x1, float y1, float x2, float y2, float width = 1.0f);
|
float x1, float y1, float x2, float y2, float width = 1.0f);
|
||||||
|
void drawRect(float r, float g, float b,
|
||||||
|
float width, float height, float x, float y);
|
||||||
|
void fillRect(float r, float g, float b,
|
||||||
|
float width, float height, float x, float y);
|
||||||
|
|
||||||
/* lua services */
|
/* lua services */
|
||||||
int setCamera(lua_State * L);
|
int setCamera(lua_State * L);
|
||||||
|
50
ag.cc
50
ag.cc
@ -47,6 +47,8 @@ namespace ag
|
|||||||
{ "drawText", drawText},
|
{ "drawText", drawText},
|
||||||
{ "getTextSize", getTextSize},
|
{ "getTextSize", getTextSize},
|
||||||
{ "drawLine", drawLine},
|
{ "drawLine", drawLine},
|
||||||
|
{ "drawRect", drawRect},
|
||||||
|
{ "fillRect", fillRect},
|
||||||
|
|
||||||
{ "createBox", createBox},
|
{ "createBox", createBox},
|
||||||
{ "createStaticBox", createStaticBox},
|
{ "createStaticBox", createStaticBox},
|
||||||
@ -420,6 +422,54 @@ namespace ag
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int drawRect(lua_State * L)
|
||||||
|
{
|
||||||
|
int argc = lua_gettop(L);
|
||||||
|
if (argc == 7)
|
||||||
|
{
|
||||||
|
bool valid = true;
|
||||||
|
for (int i = 1; i <= argc; i++)
|
||||||
|
if (!lua_isnumber(L, i))
|
||||||
|
valid = false;
|
||||||
|
if (valid)
|
||||||
|
{
|
||||||
|
g_engine->drawRect(
|
||||||
|
lua_tonumber(L, 1),
|
||||||
|
lua_tonumber(L, 2),
|
||||||
|
lua_tonumber(L, 3),
|
||||||
|
lua_tonumber(L, 4),
|
||||||
|
lua_tonumber(L, 5),
|
||||||
|
lua_tonumber(L, 6),
|
||||||
|
lua_tonumber(L, 7));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fillRect(lua_State * L)
|
||||||
|
{
|
||||||
|
int argc = lua_gettop(L);
|
||||||
|
if (argc == 7)
|
||||||
|
{
|
||||||
|
bool valid = true;
|
||||||
|
for (int i = 1; i <= argc; i++)
|
||||||
|
if (!lua_isnumber(L, i))
|
||||||
|
valid = false;
|
||||||
|
if (valid)
|
||||||
|
{
|
||||||
|
g_engine->fillRect(
|
||||||
|
lua_tonumber(L, 1),
|
||||||
|
lua_tonumber(L, 2),
|
||||||
|
lua_tonumber(L, 3),
|
||||||
|
lua_tonumber(L, 4),
|
||||||
|
lua_tonumber(L, 5),
|
||||||
|
lua_tonumber(L, 6),
|
||||||
|
lua_tonumber(L, 7));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void addManagedObject(lua_State * L, bool is_static,
|
static void addManagedObject(lua_State * L, bool is_static,
|
||||||
OdeWorld::GeomType geom_type, refptr< vector<float> > args)
|
OdeWorld::GeomType geom_type, refptr< vector<float> > args)
|
||||||
{
|
{
|
||||||
|
2
ag.h
2
ag.h
@ -33,6 +33,8 @@ namespace ag
|
|||||||
int drawText(lua_State * L);
|
int drawText(lua_State * L);
|
||||||
int getTextSize(lua_State * L);
|
int getTextSize(lua_State * L);
|
||||||
int drawLine(lua_State * L);
|
int drawLine(lua_State * L);
|
||||||
|
int drawRect(lua_State * L);
|
||||||
|
int fillRect(lua_State * L);
|
||||||
|
|
||||||
int createBox(lua_State * L);
|
int createBox(lua_State * L);
|
||||||
int createStaticBox(lua_State * L);
|
int createStaticBox(lua_State * L);
|
||||||
|
@ -57,4 +57,6 @@ function update_overlay_event(width, height)
|
|||||||
ag.drawText("Hi there", 1, 1, 1, 18, width - tw - 4, height - th - 4)
|
ag.drawText("Hi there", 1, 1, 1, 18, width - tw - 4, height - th - 4)
|
||||||
ag.drawLine(1, 0, 0.3, 10, 10, 40, 60)
|
ag.drawLine(1, 0, 0.3, 10, 10, 40, 60)
|
||||||
ag.drawLine(1, 0.7, 1, 50, 10, 100, 60, 5)
|
ag.drawLine(1, 0.7, 1, 50, 10, 100, 60, 5)
|
||||||
|
ag.drawRect(0, 1, 0, 40, 40, width / 2, height / 2)
|
||||||
|
ag.fillRect(0, 0, 1, 20, 30, width / 2, height / 2)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user