Skip to content
Snippets Groups Projects
Commit eb52af7e authored by dg's avatar dg
Browse files

Engine can oultine ASCII tiles to make them more visible

Fix dual arrows


git-svn-id: http://svn.net-core.org/repos/t-engine4@823 51575b47-30f0-44d4-a5cc-537603b46e54
parent f9e00801
No related branches found
No related tags found
No related merge requests found
......@@ -165,7 +165,7 @@ function _M:makeMapObject(tiles)
self._mo:tint(self.tint_r, self.tint_g, self.tint_b)
-- Texture 0 is always the normal image/ascii tile
self._mo:texture(0, tiles:get(self.display, self.color_r, self.color_g, self.color_b, self.color_br, self.color_bg, self.color_bb, self.image, self._noalpha and 255))
self._mo:texture(0, tiles:get(self.display, self.color_r, self.color_g, self.color_b, self.color_br, self.color_bg, self.color_bb, self.image, self._noalpha and 255, self.ascii_outline))
-- Setup additional textures
if tiles.use_images and self.textures then
......
......@@ -35,7 +35,7 @@ function _M:init(w, h, fontname, fontsize, texture, allow_backcolor)
self.texture_store = {}
end
function _M:get(char, fr, fg, fb, br, bg, bb, image, alpha)
function _M:get(char, fr, fg, fb, br, bg, bb, image, alpha, do_outline)
alpha = alpha or 0
local dochar = char
local fgidx = 65536 * fr + 256 * fg + fb
......@@ -52,9 +52,11 @@ function _M:get(char, fr, fg, fb, br, bg, bb, image, alpha)
return self.repo[char][fgidx][bgidx]
else
local s
local is_image = false
if (self.use_images or not dochar) and image then
print("Loading tile", image)
s = core.display.loadImage(self.prefix..image)
if s then is_image = true end
end
if not s then
local w, h = self.font:size(dochar)
......@@ -76,7 +78,16 @@ function _M:get(char, fr, fg, fb, br, bg, bb, image, alpha)
-- s = core.display.drawStringNewSurface(self.font, char, fr, fg, fb)
end
if self.texture then s = s:glTexture() end
if self.texture then
s = s:glTexture()
if not is_image and do_outline then
if type(do_outline) == "boolean" then
s = s:makeOutline(2, 2, self.w, self.h, 0, 0, 0, 1) or s
else
s = s:makeOutline(do_outline.x, do_outline.y, self.w, self.h, do_outline.r, do_outline.g, do_outline.b, do_outline.a) or s
end
end
end
self.repo[char] = self.repo[char] or {}
self.repo[char][fgidx] = self.repo[char][fgidx] or {}
......
......@@ -32,8 +32,8 @@ function _M:init(title)
self.max = math.floor((self.ih - 5) / self.font_h) - 1
self:keyCommands({},{
MOVE_UP = function() self.sel = util.boundWrap(self.sel - 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) end,
MOVE_DOWN = function() self.sel = util.boundWrap(self.sel + 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) end,
MOVE_UP = function() self.sel = util.boundWrap(self.sel - 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
MOVE_DOWN = function() self.sel = util.boundWrap(self.sel + 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
EXIT = function() game:unregisterDialog(self) end,
})
self:mouseZones{
......
......@@ -42,8 +42,8 @@ function _M:init(title, actor, filter, action)
end
end,
}, {
MOVE_UP = function() self.sel = util.boundWrap(self.sel - 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) end,
MOVE_DOWN = function() self.sel = util.boundWrap(self.sel + 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) end,
MOVE_UP = function() self.sel = util.boundWrap(self.sel - 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
MOVE_DOWN = function() self.sel = util.boundWrap(self.sel + 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
ACCEPT = function() self:use() end,
EXIT = function() game:unregisterDialog(self) end,
})
......
......@@ -80,8 +80,8 @@ function _M:init(title, inven, filter, action, actor)
HOTKEY_THIRD_11 = function() self:defineHotkey(35) end,
HOTKEY_THIRD_12 = function() self:defineHotkey(36) end,
MOVE_UP = function() self.sel = util.boundWrap(self.sel - 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) end,
MOVE_DOWN = function() self.sel = util.boundWrap(self.sel + 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) end,
MOVE_UP = function() self.sel = util.boundWrap(self.sel - 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
MOVE_DOWN = function() self.sel = util.boundWrap(self.sel + 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
ACCEPT = function() self:use() end,
EXIT = function() game:unregisterDialog(self) end,
})
......
......@@ -43,8 +43,8 @@ function _M:init(title, x, y, filter, action)
end
end,
},{
MOVE_UP = function() self.sel = util.boundWrap(self.sel - 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) end,
MOVE_DOWN = function() self.sel = util.boundWrap(self.sel + 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) end,
MOVE_UP = function() self.sel = util.boundWrap(self.sel - 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
MOVE_DOWN = function() self.sel = util.boundWrap(self.sel + 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
ACCEPT = function() self:use() end,
EXIT = function() game:unregisterDialog(self) end,
})
......
......@@ -163,10 +163,7 @@ function _M:archeryShoot(damtype, mult, on_hit, tg, params)
ammo = self:removeObject(self:getInven("QUIVER"), 1)
if not ammo then return end
end
if params.limit_shots then
if params.limit_shots <= 0 then return end
params.limit_shots = params.limit_shots - 1
end
if params.limit_shots then if params.limit_shots <= 0 then return end end
local target = game.level.map(tx, ty, game.level.map.ACTOR)
if not target then return end
......@@ -176,6 +173,8 @@ function _M:archeryShoot(damtype, mult, on_hit, tg, params)
damtype = damtype or ammo.damtype or DamageType.PHYSICAL
mult = mult or 1
if params.limit_shots then params.limit_shots = params.limit_shots - 1 end
-- Does the blow connect? yes .. complex :/
local atk, def = self:combatAttack(weapon), target:combatDefense()
local dam, apr, armor = self:combatDamage(ammo), self:combatAPR(ammo), target:combatArmor()
......
......@@ -17,10 +17,15 @@
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
-- Entities that are ASCII are outline
local Entity = require "engine.Entity"
Entity.ascii_outline = {x=2, y=2, r=0, g=0, b=0, a=0.8}
-- This file loads the game module, and loads data
local KeyBind = require "engine.KeyBind"
local DamageType = require "engine.DamageType"
local Faction = require "engine.Faction"
local ActorStats = require "engine.interface.ActorStats"
local ActorResource = require "engine.interface.ActorResource"
local ActorTalents = require "engine.interface.ActorTalents"
......@@ -36,6 +41,7 @@ local Quest = require "engine.Quest"
config.settings.tome = config.settings.tome or {}
profile.mod.allow_build = profile.mod.allow_build or {}
-- Achievements
WorldAchievements:loadDefinition("/data/achievements/")
......
......@@ -450,7 +450,6 @@ static int sdl_new_font(lua_State *L)
auxiliar_setclass(L, "sdl{font}", -1);
*f = TTF_OpenFontRW(PHYSFSRWOPS_openRead(name), TRUE, size);
// TTF_SetFontOutline(*f, 2);
return 1;
}
......@@ -602,6 +601,7 @@ static int sdl_new_tile(lua_State *L)
int alpha = luaL_checknumber(L, 13);
SDL_Color color = {r,g,b};
SDL_Color bcolor = {0,0,0};
SDL_Surface *txt = TTF_RenderUTF8_Blended(*f, str, color);
SDL_Surface **s = (SDL_Surface**)lua_newuserdata(L, sizeof(SDL_Surface*));
......@@ -954,6 +954,112 @@ static int sdl_texture_toscreen(lua_State *L)
return 0;
}
static bool _CheckGL_Error(const char* GLcall, const char* file, const int line)
{
GLenum errCode;
if((errCode = glGetError())!=GL_NO_ERROR)
{
printf("OPENGL ERROR #%i: (%s) in file %s on line %i\n",errCode,gluErrorString(errCode), file, line);
printf("OPENGL Call: %s\n",GLcall);
return FALSE;
}
return TRUE;
}
#define CHECKGL( GLcall ) \
GLcall; \
if(!_CheckGL_Error( #GLcall, __FILE__, __LINE__)) \
exit(-1);
static int sdl_texture_outline(lua_State *L)
{
if (!fbo_active) return 0;
GLuint *t = (GLuint*)auxiliar_checkclass(L, "gl{texture}", 1);
int x = luaL_checknumber(L, 2);
int y = luaL_checknumber(L, 3);
int w = luaL_checknumber(L, 4);
int h = luaL_checknumber(L, 5);
float r = luaL_checknumber(L, 6);
float g = luaL_checknumber(L, 7);
float b = luaL_checknumber(L, 8);
float a = luaL_checknumber(L, 9);
// Setup our FBO
GLuint fbo;
CHECKGL(glGenFramebuffersEXT(1, &fbo));
CHECKGL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo));
// Now setup a texture to render to
GLuint *img = (GLuint*)lua_newuserdata(L, sizeof(GLuint));
auxiliar_setclass(L, "gl{texture}", -1);
CHECKGL(glGenTextures(1, img));
CHECKGL(glBindTexture(GL_TEXTURE_2D, *img));
CHECKGL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL));
CHECKGL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT));
CHECKGL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT));
CHECKGL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
CHECKGL(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, *img, 0));
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if(status != GL_FRAMEBUFFER_COMPLETE_EXT)
{
return 0;
}
CHECKGL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
CHECKGL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo));
// Set the viewport and save the old one
CHECKGL(glPushAttrib(GL_VIEWPORT_BIT));
CHECKGL(glViewport(0, 0, w, h));
glMatrixMode(GL_PROJECTION);
CHECKGL(glPushMatrix());
glLoadIdentity();
glOrtho(0, w, 0, h, -100, 100);
glMatrixMode( GL_MODELVIEW );
/* Reset The View */
glLoadIdentity( );
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
CHECKGL(glClear(GL_COLOR_BUFFER_BIT));
CHECKGL(glLoadIdentity());
/* Render to buffer */
CHECKGL(glBindTexture(GL_TEXTURE_2D, *t));
CHECKGL(glColor4f(r, g, b, a));
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex3f(0+x, 0+y, -1);
glTexCoord2f(1,0); glVertex3f(w+x, 0+y, -1);
glTexCoord2f(1,1); glVertex3f(w+x, h+y, -1);
glTexCoord2f(0,1); glVertex3f(0+x, h+y, -1);
glEnd();
CHECKGL(glColor4f(1, 1, 1, 1));
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex3f(0, 0, 0);
glTexCoord2f(1,0); glVertex3f(w, 0, 0);
glTexCoord2f(1,1); glVertex3f(w, h, 0);
glTexCoord2f(0,1); glVertex3f(0, h, 0);
glEnd();
CHECKGL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
// Restore viewport
CHECKGL(glPopAttrib());
// Cleanup
CHECKGL(glDeleteFramebuffersEXT(1, &fbo));
glMatrixMode(GL_PROJECTION);
CHECKGL(glPopMatrix());
glMatrixMode( GL_MODELVIEW );
glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
return 1;
}
static int sdl_set_window_title(lua_State *L)
{
const char *title = luaL_checkstring(L, 1);
......@@ -1018,6 +1124,7 @@ static const struct luaL_reg sdl_texture_reg[] =
{"__gc", sdl_free_texture},
{"close", sdl_free_texture},
{"toScreen", sdl_texture_toscreen},
{"makeOutline", sdl_texture_outline},
{NULL, NULL},
};
......
......@@ -52,6 +52,7 @@ bool no_sound = FALSE;
bool isActive = TRUE;
bool tickPaused = FALSE;
extern bool shaders_active;
bool fbo_active;
/* Some lua stuff that's external but has no headers */
int luaopen_mime_core(lua_State *L);
......@@ -594,7 +595,9 @@ int main(int argc, char *argv[])
/* Sets up OpenGL double buffering */
resizeWindow(WIDTH, HEIGHT);
// Get OpenGL capabilities
shaders_active = glewIsSupported("GL_ARB_shader_objects");
fbo_active = glewIsSupported("GL_EXT_framebuffer_object") || glewIsSupported("GL_ARB_framebuffer_object");
boot_lua(2, FALSE, argc, argv);
......
......@@ -23,6 +23,7 @@
extern int resizeWindow(int width, int height);
extern void do_resize(int w, int h, bool fullscreen);
extern bool fbo_active;
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment