added ag::drawImage()
git-svn-id: svn://anubis/anaglym/trunk@185 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
f410c305c2
commit
5de4ed348b
78
Engine.cc
78
Engine.cc
@ -541,36 +541,70 @@ void Engine::drawLine(float r, float g, float b,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Engine::drawRect(float r, float g, float b,
|
void Engine::drawRect(float r, float g, float b,
|
||||||
float width, float height, float x, float y)
|
float width, float height, float x, float y, float rot)
|
||||||
{
|
{
|
||||||
glPushAttrib(GL_ENABLE_BIT);
|
glPushAttrib(GL_ENABLE_BIT);
|
||||||
glDisable(GL_DEPTH_TEST);
|
glPushMatrix();
|
||||||
glDisable(GL_LIGHTING);
|
glTranslatef(x, y, 0);
|
||||||
glEnable(GL_LINE_SMOOTH);
|
glRotatef(rot, 0, 0, 1);
|
||||||
glBegin(GL_LINE_LOOP);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glColor3f(r, g, b);
|
glDisable(GL_LIGHTING);
|
||||||
glVertex2f(x - width / 2, y - height / 2);
|
glEnable(GL_LINE_SMOOTH);
|
||||||
glVertex2f(x + width / 2, y - height / 2);
|
glBegin(GL_LINE_LOOP);
|
||||||
glVertex2f(x + width / 2, y + height / 2);
|
glColor3f(r, g, b);
|
||||||
glVertex2f(x - width / 2, y + height / 2);
|
glVertex2f(-width / 2, -height / 2);
|
||||||
glEnd();
|
glVertex2f(width / 2, -height / 2);
|
||||||
|
glVertex2f(width / 2, height / 2);
|
||||||
|
glVertex2f(-width / 2, height / 2);
|
||||||
|
glEnd();
|
||||||
|
glPopMatrix();
|
||||||
glPopAttrib();
|
glPopAttrib();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::fillRect(float r, float g, float b,
|
void Engine::fillRect(float r, float g, float b,
|
||||||
float width, float height, float x, float y)
|
float width, float height, float x, float y, float rot)
|
||||||
{
|
{
|
||||||
glPushAttrib(GL_ENABLE_BIT);
|
glPushAttrib(GL_ENABLE_BIT);
|
||||||
glDisable(GL_DEPTH_TEST);
|
glPushMatrix();
|
||||||
glDisable(GL_LIGHTING);
|
glTranslatef(x, y, 0);
|
||||||
glEnable(GL_POLYGON_SMOOTH);
|
glRotatef(rot, 0, 0, 1);
|
||||||
glBegin(GL_QUADS);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glColor3f(r, g, b);
|
glDisable(GL_LIGHTING);
|
||||||
glVertex2f(x - width / 2, y - height / 2);
|
glEnable(GL_POLYGON_SMOOTH);
|
||||||
glVertex2f(x + width / 2, y - height / 2);
|
glBegin(GL_QUADS);
|
||||||
glVertex2f(x + width / 2, y + height / 2);
|
glColor3f(r, g, b);
|
||||||
glVertex2f(x - width / 2, y + height / 2);
|
glVertex2f(-width / 2, -height / 2);
|
||||||
glEnd();
|
glVertex2f(width / 2, -height / 2);
|
||||||
|
glVertex2f(width / 2, height / 2);
|
||||||
|
glVertex2f(-width / 2, height / 2);
|
||||||
|
glEnd();
|
||||||
|
glPopMatrix();
|
||||||
|
glPopAttrib();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::drawImage(float width, float height, float x, float y,
|
||||||
|
int tex, float rot)
|
||||||
|
{
|
||||||
|
glPushAttrib(GL_ENABLE_BIT);
|
||||||
|
glPushMatrix();
|
||||||
|
glTranslatef(x, y, 0);
|
||||||
|
glRotatef(rot, 0, 0, 1);
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
|
glEnable(GL_POLYGON_SMOOTH);
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, tex);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glTexCoord2f(0, 0);
|
||||||
|
glVertex2f(-width / 2, -height / 2);
|
||||||
|
glTexCoord2f(1, 0);
|
||||||
|
glVertex2f(width / 2, -height / 2);
|
||||||
|
glTexCoord2f(1, 1);
|
||||||
|
glVertex2f(width / 2, height / 2);
|
||||||
|
glTexCoord2f(0, 1);
|
||||||
|
glVertex2f(-width / 2, height / 2);
|
||||||
|
glEnd();
|
||||||
|
glPopMatrix();
|
||||||
glPopAttrib();
|
glPopAttrib();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
Engine.h
6
Engine.h
@ -146,9 +146,11 @@ class Engine
|
|||||||
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,
|
void drawRect(float r, float g, float b,
|
||||||
float width, float height, float x, float y);
|
float width, float height, float x, float y, float rot = 0.0f);
|
||||||
void fillRect(float r, float g, float b,
|
void fillRect(float r, float g, float b,
|
||||||
float width, float height, float x, float y);
|
float width, float height, float x, float y, float rot = 0.0f);
|
||||||
|
void drawImage(float width, float height, float x, float y,
|
||||||
|
int tex, float rot = 0.0f);
|
||||||
|
|
||||||
/* lua services */
|
/* lua services */
|
||||||
int setCamera(lua_State * L);
|
int setCamera(lua_State * L);
|
||||||
|
51
ag.cc
51
ag.cc
@ -49,6 +49,7 @@ namespace ag
|
|||||||
{ "drawLine", drawLine},
|
{ "drawLine", drawLine},
|
||||||
{ "drawRect", drawRect},
|
{ "drawRect", drawRect},
|
||||||
{ "fillRect", fillRect},
|
{ "fillRect", fillRect},
|
||||||
|
{ "drawImage", drawImage},
|
||||||
|
|
||||||
{ "createBox", createBox},
|
{ "createBox", createBox},
|
||||||
{ "createStaticBox", createStaticBox},
|
{ "createStaticBox", createStaticBox},
|
||||||
@ -425,7 +426,7 @@ namespace ag
|
|||||||
int drawRect(lua_State * L)
|
int drawRect(lua_State * L)
|
||||||
{
|
{
|
||||||
int argc = lua_gettop(L);
|
int argc = lua_gettop(L);
|
||||||
if (argc == 7)
|
if (argc == 7 || argc == 8)
|
||||||
{
|
{
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
for (int i = 1; i <= argc; i++)
|
for (int i = 1; i <= argc; i++)
|
||||||
@ -433,6 +434,9 @@ namespace ag
|
|||||||
valid = false;
|
valid = false;
|
||||||
if (valid)
|
if (valid)
|
||||||
{
|
{
|
||||||
|
float rot = 0.0f;
|
||||||
|
if (argc == 8)
|
||||||
|
rot = lua_tonumber(L, 8);
|
||||||
g_engine->drawRect(
|
g_engine->drawRect(
|
||||||
lua_tonumber(L, 1),
|
lua_tonumber(L, 1),
|
||||||
lua_tonumber(L, 2),
|
lua_tonumber(L, 2),
|
||||||
@ -440,7 +444,8 @@ namespace ag
|
|||||||
lua_tonumber(L, 4),
|
lua_tonumber(L, 4),
|
||||||
lua_tonumber(L, 5),
|
lua_tonumber(L, 5),
|
||||||
lua_tonumber(L, 6),
|
lua_tonumber(L, 6),
|
||||||
lua_tonumber(L, 7));
|
lua_tonumber(L, 7),
|
||||||
|
rot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -449,7 +454,7 @@ namespace ag
|
|||||||
int fillRect(lua_State * L)
|
int fillRect(lua_State * L)
|
||||||
{
|
{
|
||||||
int argc = lua_gettop(L);
|
int argc = lua_gettop(L);
|
||||||
if (argc == 7)
|
if (argc == 7 || argc == 8)
|
||||||
{
|
{
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
for (int i = 1; i <= argc; i++)
|
for (int i = 1; i <= argc; i++)
|
||||||
@ -457,6 +462,9 @@ namespace ag
|
|||||||
valid = false;
|
valid = false;
|
||||||
if (valid)
|
if (valid)
|
||||||
{
|
{
|
||||||
|
float rot = 0.0f;
|
||||||
|
if (argc == 8)
|
||||||
|
rot = lua_tonumber(L, 8);
|
||||||
g_engine->fillRect(
|
g_engine->fillRect(
|
||||||
lua_tonumber(L, 1),
|
lua_tonumber(L, 1),
|
||||||
lua_tonumber(L, 2),
|
lua_tonumber(L, 2),
|
||||||
@ -464,7 +472,42 @@ namespace ag
|
|||||||
lua_tonumber(L, 4),
|
lua_tonumber(L, 4),
|
||||||
lua_tonumber(L, 5),
|
lua_tonumber(L, 5),
|
||||||
lua_tonumber(L, 6),
|
lua_tonumber(L, 6),
|
||||||
lua_tonumber(L, 7));
|
lua_tonumber(L, 7),
|
||||||
|
rot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int drawImage(lua_State * L)
|
||||||
|
{
|
||||||
|
int argc = lua_gettop(L);
|
||||||
|
if (argc == 5 || argc == 6)
|
||||||
|
{
|
||||||
|
bool valid = true;
|
||||||
|
for (int i = 1; i <= 6; i++)
|
||||||
|
if (i != 5 && !lua_isnumber(L, i))
|
||||||
|
valid = false;
|
||||||
|
if (!lua_istable(L, 5))
|
||||||
|
valid = false;
|
||||||
|
if (valid)
|
||||||
|
{
|
||||||
|
lua_getfield(L, 5, "id");
|
||||||
|
if (lua_isnumber(L, -1))
|
||||||
|
{
|
||||||
|
float rot = 0.0f;
|
||||||
|
if (argc == 6)
|
||||||
|
rot = lua_tonumber(L, 6);
|
||||||
|
GLuint texture_id = (GLuint) lua_tointeger(L, -1);
|
||||||
|
g_engine->drawImage(
|
||||||
|
lua_tonumber(L, 1),
|
||||||
|
lua_tonumber(L, 2),
|
||||||
|
lua_tonumber(L, 3),
|
||||||
|
lua_tonumber(L, 4),
|
||||||
|
texture_id,
|
||||||
|
rot);
|
||||||
|
}
|
||||||
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
4
ag.h
4
ag.h
@ -30,12 +30,16 @@ namespace ag
|
|||||||
int import(lua_State * L);
|
int import(lua_State * L);
|
||||||
int loadTexture(lua_State * L);
|
int loadTexture(lua_State * L);
|
||||||
int getScreenSize(lua_State * L);
|
int getScreenSize(lua_State * L);
|
||||||
|
|
||||||
|
/* 2D overlay functions */
|
||||||
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 drawRect(lua_State * L);
|
||||||
int fillRect(lua_State * L);
|
int fillRect(lua_State * L);
|
||||||
|
int drawImage(lua_State * L);
|
||||||
|
|
||||||
|
/* managed object creation functions */
|
||||||
int createBox(lua_State * L);
|
int createBox(lua_State * L);
|
||||||
int createStaticBox(lua_State * L);
|
int createStaticBox(lua_State * L);
|
||||||
int createSphere(lua_State * L);
|
int createSphere(lua_State * L);
|
||||||
|
@ -25,6 +25,8 @@ function init()
|
|||||||
ball:setMass(5)
|
ball:setMass(5)
|
||||||
--ball = ag.createSphere(0.4)
|
--ball = ag.createSphere(0.4)
|
||||||
--ball:setColor(0.2, 0.2, 0.9)
|
--ball:setColor(0.2, 0.2, 0.9)
|
||||||
|
|
||||||
|
crate_texture = ag.loadTexture("crate.png")
|
||||||
end
|
end
|
||||||
|
|
||||||
function mousebutton_down_event(button)
|
function mousebutton_down_event(button)
|
||||||
@ -59,4 +61,6 @@ function update_overlay_event(width, height)
|
|||||||
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.drawRect(0, 1, 0, 40, 40, width / 2, height / 2)
|
||||||
ag.fillRect(0, 0, 1, 20, 30, width / 2, height / 2)
|
ag.fillRect(0, 0, 1, 20, 30, width / 2, height / 2)
|
||||||
|
local rot = ag.elapsedTime() / 10
|
||||||
|
ag.drawImage(50, 50, 80, 160, crate_texture, rot)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user