LuaEngine v0.4

SDL2_gfx built-in support
This commit is contained in:
Kirigaya Kazuto 2020-05-31 18:03:21 +08:00
parent 71059fda47
commit d34aa416b6
11 changed files with 16905 additions and 1 deletions

View File

@ -1,4 +1,5 @@
#include "include.h" #include "include.h"
#include <SDL2/SDL2_gfxPrimitives.h>
/* /*
class Renderer class Renderer
@ -8,6 +9,15 @@ class Renderer
copyTo(text: Texture, x: int, y: int, [w: int, h: int]) copyTo(text: Texture, x: int, y: int, [w: int, h: int])
copyFill(text: Texture, x: int, y: int, w: int, h: int) copyFill(text: Texture, x: int, y: int, w: int, h: int)
copyFullFill(text: Texture) copyFullFill(text: Texture)
drawPoint(x: int, y: int)
drawLine(x1: int, y1: int, x2: int, y2: int)
drawRect(x: int, y: int, w: int, h: int)
fillRect(x: int, y: int, w: int, h: int)
fillTriangle(x1: int, y1: int, x2: int, y2: int, x3: int, y3: int, [r: int, g: int, b:int, a: int]) #SDL2_gfx#
getColor(): r: int, g: int, b: int, a: int
setColor(r: int, g: int, b: int, a: int)
getBlendMode(): string
setBlendMode(mode: string)
*/ */
int render_close(lua_State* L) int render_close(lua_State* L)
@ -212,6 +222,128 @@ int render_fillrect(lua_State* L)
return 0; return 0;
} }
int render_filltriangle(lua_State* L)
{
auto rnd = lua_checkpointer<SDL_Renderer>(L, 1, "LuaEngineRenderer");
int x1 = luaL_checkinteger(L, 2);
int y1 = luaL_checkinteger(L, 3);
int x2 = luaL_checkinteger(L, 4);
int y2 = luaL_checkinteger(L, 5);
int x3 = luaL_checkinteger(L, 6);
int y3 = luaL_checkinteger(L, 7);
Uint8 r, g, b, a;
if (SDL_GetRenderDrawColor(rnd, &r, &g, &b, &a))
{
return SDLError(L, SDL_GetRenderDrawColor);
}
SDL_BlendMode mode;
if (SDL_GetRenderDrawBlendMode(rnd, &mode))
{
return SDLError(L, SDL_GetRenderDrawBlendMode);
}
Uint8 rr, gg, bb, aa;
rr = lua_isnone(L, 8) ? r : luaL_checkinteger(L, 8);
gg = lua_isnone(L, 9) ? g : luaL_checkinteger(L, 9);
bb = lua_isnone(L, 10) ? b : luaL_checkinteger(L, 10);
aa = lua_isnone(L, 11) ? a : luaL_checkinteger(L, 11);
int ret = filledTrigonRGBA(rnd, x1, y1, x2, y2, x3, y3, rr, gg, bb, aa);
if (SDL_SetRenderDrawBlendMode(rnd, mode))
{
return SDLError(L, SDL_SetRenderDrawBlendMode);
}
if (SDL_SetRenderDrawColor(rnd, r, g, b, a))
{
return SDLError(L, SDL_SetRenderDrawColor);
}
if(ret)
{
return SDLError(L, filledTrigonRGBA);
}
return 0;
}
int render_getblendmode(lua_State* L)
{
auto rnd = lua_checkpointer<SDL_Renderer>(L, 1, "LuaEngineRenderer");
SDL_BlendMode mode;
if (SDL_GetRenderDrawBlendMode(rnd, &mode))
{
return SDLError(L, SDL_GetRenderDrawBlendMode);
}
switch (mode)
{
case SDL_BlendMode::SDL_BLENDMODE_ADD:
lua_pushstring(L, "add");
break;
case SDL_BlendMode::SDL_BLENDMODE_BLEND:
lua_pushstring(L, "blend");
break;
case SDL_BlendMode::SDL_BLENDMODE_INVALID:
lua_pushstring(L, "invalid");
break;
case SDL_BlendMode::SDL_BLENDMODE_MOD:
lua_pushstring(L, "mod");
break;
case SDL_BlendMode::SDL_BLENDMODE_MUL:
lua_pushstring(L, "mul");
break;
case SDL_BlendMode::SDL_BLENDMODE_NONE:
lua_pushstring(L, "none");
break;
default:
lua_pushstring(L, "unknown");
break;
}
return 1;
}
int render_setblendmode(lua_State* L)
{
auto rnd = lua_checkpointer<SDL_Renderer>(L, 1, "LuaEngineRenderer");
const char* modestr = luaL_checkstring(L, 2);
SDL_BlendMode mode;
if (strcmp(modestr, "add") == 0)
{
mode = SDL_BlendMode::SDL_BLENDMODE_ADD;
}
else if (strcmp(modestr, "blend") == 0)
{
mode = SDL_BlendMode::SDL_BLENDMODE_BLEND;
}
else if (strcmp(modestr, "invalid") == 0)
{
mode = SDL_BlendMode::SDL_BLENDMODE_INVALID;
}
else if (strcmp(modestr, "mod") == 0)
{
mode = SDL_BlendMode::SDL_BLENDMODE_MOD;
}
else if (strcmp(modestr, "mul") == 0)
{
mode = SDL_BlendMode::SDL_BLENDMODE_MUL;
}
else if (strcmp(modestr, "none") == 0)
{
mode = SDL_BlendMode::SDL_BLENDMODE_NONE;
}
else
{
return 0;
}
if (SDL_SetRenderDrawBlendMode(rnd, mode))
{
return SDLError(L, SDL_SetRenderDrawBlendMode);
}
return 0;
}
int render_setcolor(lua_State* L) int render_setcolor(lua_State* L)
{ {
auto rnd = lua_checkpointer<SDL_Renderer>(L, 1, "LuaEngineRenderer"); auto rnd = lua_checkpointer<SDL_Renderer>(L, 1, "LuaEngineRenderer");
@ -267,8 +399,11 @@ int render_new(lua_State* L)
lua_setfield_function(L, "drawLine", render_drawline); lua_setfield_function(L, "drawLine", render_drawline);
lua_setfield_function(L, "drawRect", render_drawrect); lua_setfield_function(L, "drawRect", render_drawrect);
lua_setfield_function(L, "fillRect", render_fillrect); lua_setfield_function(L, "fillRect", render_fillrect);
lua_setfield_function(L, "fillTriangle", render_filltriangle);
lua_setfield_function(L, "getColor", render_getcolor); lua_setfield_function(L, "getColor", render_getcolor);
lua_setfield_function(L, "setColor", render_setcolor); lua_setfield_function(L, "setColor", render_setcolor);
lua_setfield_function(L, "getBlendMode", render_getblendmode);
lua_setfield_function(L, "setBlendMode", render_setblendmode);
lua_setfield(L, -2, "__index"); lua_setfield(L, -2, "__index");
} }
lua_setmetatable(L, -2); lua_setmetatable(L, -2);

View File

@ -0,0 +1,100 @@
/*
SDL2_framerate.h: framerate manager
Copyright (C) 2012-2014 Andreas Schiffler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
Andreas Schiffler -- aschiffler at ferzkopp dot net
*/
#ifndef _SDL2_framerate_h
#define _SDL2_framerate_h
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/* --- */
#include "SDL.h"
/* --------- Definitions */
/*!
\brief Highest possible rate supported by framerate controller in Hz (1/s).
*/
#define FPS_UPPER_LIMIT 200
/*!
\brief Lowest possible rate supported by framerate controller in Hz (1/s).
*/
#define FPS_LOWER_LIMIT 1
/*!
\brief Default rate of framerate controller in Hz (1/s).
*/
#define FPS_DEFAULT 30
/*!
\brief Structure holding the state and timing information of the framerate controller.
*/
typedef struct {
Uint32 framecount;
float rateticks;
Uint32 baseticks;
Uint32 lastticks;
Uint32 rate;
} FPSmanager;
/* ---- Function Prototypes */
#ifdef _MSC_VER
# if defined(DLL_EXPORT) && !defined(LIBSDL2_GFX_DLL_IMPORT)
# define SDL2_FRAMERATE_SCOPE __declspec(dllexport)
# else
# ifdef LIBSDL2_GFX_DLL_IMPORT
# define SDL2_FRAMERATE_SCOPE __declspec(dllimport)
# endif
# endif
#endif
#ifndef SDL2_FRAMERATE_SCOPE
# define SDL2_FRAMERATE_SCOPE extern
#endif
/* Functions return 0 or value for sucess and -1 for error */
SDL2_FRAMERATE_SCOPE void SDL_initFramerate(FPSmanager * manager);
SDL2_FRAMERATE_SCOPE int SDL_setFramerate(FPSmanager * manager, Uint32 rate);
SDL2_FRAMERATE_SCOPE int SDL_getFramerate(FPSmanager * manager);
SDL2_FRAMERATE_SCOPE int SDL_getFramecount(FPSmanager * manager);
SDL2_FRAMERATE_SCOPE Uint32 SDL_framerateDelay(FPSmanager * manager);
/* --- */
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#endif /* _SDL2_framerate_h */

View File

@ -0,0 +1,241 @@
/*
SDL2_gfxPrimitives.h: graphics primitives for SDL
Copyright (C) 2012-2014 Andreas Schiffler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
Andreas Schiffler -- aschiffler at ferzkopp dot net
*/
#ifndef _SDL2_gfxPrimitives_h
#define _SDL2_gfxPrimitives_h
#include <math.h>
#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795
#endif
#include "SDL.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/* ----- Versioning */
#define SDL2_GFXPRIMITIVES_MAJOR 1
#define SDL2_GFXPRIMITIVES_MINOR 0
#define SDL2_GFXPRIMITIVES_MICRO 4
/* ---- Function Prototypes */
#ifdef _MSC_VER
# if defined(DLL_EXPORT) && !defined(LIBSDL2_GFX_DLL_IMPORT)
# define SDL2_GFXPRIMITIVES_SCOPE __declspec(dllexport)
# else
# ifdef LIBSDL2_GFX_DLL_IMPORT
# define SDL2_GFXPRIMITIVES_SCOPE __declspec(dllimport)
# endif
# endif
#endif
#ifndef SDL2_GFXPRIMITIVES_SCOPE
# define SDL2_GFXPRIMITIVES_SCOPE extern
#endif
/* Note: all ___Color routines expect the color to be in format 0xRRGGBBAA */
/* Pixel */
SDL2_GFXPRIMITIVES_SCOPE int pixelColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int pixelRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Horizontal line */
SDL2_GFXPRIMITIVES_SCOPE int hlineColor(SDL_Renderer * renderer, Sint16 x1, Sint16 x2, Sint16 y, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int hlineRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 x2, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Vertical line */
SDL2_GFXPRIMITIVES_SCOPE int vlineColor(SDL_Renderer * renderer, Sint16 x, Sint16 y1, Sint16 y2, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int vlineRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y1, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Rectangle */
SDL2_GFXPRIMITIVES_SCOPE int rectangleColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int rectangleRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1,
Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Rounded-Corner Rectangle */
SDL2_GFXPRIMITIVES_SCOPE int roundedRectangleColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 rad, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int roundedRectangleRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1,
Sint16 x2, Sint16 y2, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Filled rectangle (Box) */
SDL2_GFXPRIMITIVES_SCOPE int boxColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int boxRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2,
Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Rounded-Corner Filled rectangle (Box) */
SDL2_GFXPRIMITIVES_SCOPE int roundedBoxColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 rad, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int roundedBoxRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2,
Sint16 y2, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Line */
SDL2_GFXPRIMITIVES_SCOPE int lineColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int lineRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1,
Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* AA Line */
SDL2_GFXPRIMITIVES_SCOPE int aalineColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int aalineRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1,
Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Thick Line */
SDL2_GFXPRIMITIVES_SCOPE int thickLineColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2,
Uint8 width, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int thickLineRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2,
Uint8 width, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Circle */
SDL2_GFXPRIMITIVES_SCOPE int circleColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int circleRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Arc */
SDL2_GFXPRIMITIVES_SCOPE int arcColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Sint16 start, Sint16 end, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int arcRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Sint16 start, Sint16 end,
Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* AA Circle */
SDL2_GFXPRIMITIVES_SCOPE int aacircleColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int aacircleRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y,
Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Filled Circle */
SDL2_GFXPRIMITIVES_SCOPE int filledCircleColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 r, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int filledCircleRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y,
Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Ellipse */
SDL2_GFXPRIMITIVES_SCOPE int ellipseColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int ellipseRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y,
Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* AA Ellipse */
SDL2_GFXPRIMITIVES_SCOPE int aaellipseColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int aaellipseRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y,
Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Filled Ellipse */
SDL2_GFXPRIMITIVES_SCOPE int filledEllipseColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int filledEllipseRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y,
Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Pie */
SDL2_GFXPRIMITIVES_SCOPE int pieColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad,
Sint16 start, Sint16 end, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int pieRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad,
Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Filled Pie */
SDL2_GFXPRIMITIVES_SCOPE int filledPieColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad,
Sint16 start, Sint16 end, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int filledPieRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad,
Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Trigon */
SDL2_GFXPRIMITIVES_SCOPE int trigonColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int trigonRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* AA-Trigon */
SDL2_GFXPRIMITIVES_SCOPE int aatrigonColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int aatrigonRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Filled Trigon */
SDL2_GFXPRIMITIVES_SCOPE int filledTrigonColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int filledTrigonRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Polygon */
SDL2_GFXPRIMITIVES_SCOPE int polygonColor(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int polygonRGBA(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy,
int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* AA-Polygon */
SDL2_GFXPRIMITIVES_SCOPE int aapolygonColor(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int aapolygonRGBA(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy,
int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Filled Polygon */
SDL2_GFXPRIMITIVES_SCOPE int filledPolygonColor(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int filledPolygonRGBA(SDL_Renderer * renderer, const Sint16 * vx,
const Sint16 * vy, int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Textured Polygon */
SDL2_GFXPRIMITIVES_SCOPE int texturedPolygon(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, SDL_Surface * texture,int texture_dx,int texture_dy);
/* Bezier */
SDL2_GFXPRIMITIVES_SCOPE int bezierColor(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, int s, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int bezierRGBA(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy,
int n, int s, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Characters/Strings */
SDL2_GFXPRIMITIVES_SCOPE void gfxPrimitivesSetFont(const void *fontdata, Uint32 cw, Uint32 ch);
SDL2_GFXPRIMITIVES_SCOPE void gfxPrimitivesSetFontRotation(Uint32 rotation);
SDL2_GFXPRIMITIVES_SCOPE int characterColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, char c, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int characterRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, char c, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
SDL2_GFXPRIMITIVES_SCOPE int stringColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, const char *s, Uint32 color);
SDL2_GFXPRIMITIVES_SCOPE int stringRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, const char *s, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#endif /* _SDL2_gfxPrimitives_h */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,166 @@
/*
SDL2_imageFilter.h: byte-image "filter" routines
Copyright (C) 2012-2014 Andreas Schiffler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
Andreas Schiffler -- aschiffler at ferzkopp dot net
*/
#ifndef _SDL2_imageFilter_h
#define _SDL2_imageFilter_h
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/* ---- Function Prototypes */
#ifdef _MSC_VER
# if defined(DLL_EXPORT) && !defined(LIBSDL2_GFX_DLL_IMPORT)
# define SDL2_IMAGEFILTER_SCOPE __declspec(dllexport)
# else
# ifdef LIBSDL2_GFX_DLL_IMPORT
# define SDL2_IMAGEFILTER_SCOPE __declspec(dllimport)
# endif
# endif
#endif
#ifndef SDL2_IMAGEFILTER_SCOPE
# define SDL2_IMAGEFILTER_SCOPE extern
#endif
/* Comments: */
/* 1.) MMX functions work best if all data blocks are aligned on a 32 bytes boundary. */
/* 2.) Data that is not within an 8 byte boundary is processed using the C routine. */
/* 3.) Convolution routines do not have C routines at this time. */
// Detect MMX capability in CPU
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterMMXdetect(void);
// Force use of MMX off (or turn possible use back on)
SDL2_IMAGEFILTER_SCOPE void SDL_imageFilterMMXoff(void);
SDL2_IMAGEFILTER_SCOPE void SDL_imageFilterMMXon(void);
//
// All routines return:
// 0 OK
// -1 Error (internal error, parameter error)
//
// SDL_imageFilterAdd: D = saturation255(S1 + S2)
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterAdd(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
// SDL_imageFilterMean: D = S1/2 + S2/2
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterMean(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
// SDL_imageFilterSub: D = saturation0(S1 - S2)
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterSub(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
// SDL_imageFilterAbsDiff: D = | S1 - S2 |
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterAbsDiff(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
// SDL_imageFilterMult: D = saturation(S1 * S2)
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterMult(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
// SDL_imageFilterMultNor: D = S1 * S2 (non-MMX)
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterMultNor(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
// SDL_imageFilterMultDivby2: D = saturation255(S1/2 * S2)
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterMultDivby2(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest,
unsigned int length);
// SDL_imageFilterMultDivby4: D = saturation255(S1/2 * S2/2)
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterMultDivby4(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest,
unsigned int length);
// SDL_imageFilterBitAnd: D = S1 & S2
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterBitAnd(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
// SDL_imageFilterBitOr: D = S1 | S2
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterBitOr(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
// SDL_imageFilterDiv: D = S1 / S2 (non-MMX)
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterDiv(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
// SDL_imageFilterBitNegation: D = !S
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterBitNegation(unsigned char *Src1, unsigned char *Dest, unsigned int length);
// SDL_imageFilterAddByte: D = saturation255(S + C)
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterAddByte(unsigned char *Src1, unsigned char *Dest, unsigned int length, unsigned char C);
// SDL_imageFilterAddUint: D = saturation255(S + (uint)C)
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterAddUint(unsigned char *Src1, unsigned char *Dest, unsigned int length, unsigned int C);
// SDL_imageFilterAddByteToHalf: D = saturation255(S/2 + C)
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterAddByteToHalf(unsigned char *Src1, unsigned char *Dest, unsigned int length,
unsigned char C);
// SDL_imageFilterSubByte: D = saturation0(S - C)
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterSubByte(unsigned char *Src1, unsigned char *Dest, unsigned int length, unsigned char C);
// SDL_imageFilterSubUint: D = saturation0(S - (uint)C)
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterSubUint(unsigned char *Src1, unsigned char *Dest, unsigned int length, unsigned int C);
// SDL_imageFilterShiftRight: D = saturation0(S >> N)
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterShiftRight(unsigned char *Src1, unsigned char *Dest, unsigned int length, unsigned char N);
// SDL_imageFilterShiftRightUint: D = saturation0((uint)S >> N)
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterShiftRightUint(unsigned char *Src1, unsigned char *Dest, unsigned int length, unsigned char N);
// SDL_imageFilterMultByByte: D = saturation255(S * C)
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterMultByByte(unsigned char *Src1, unsigned char *Dest, unsigned int length, unsigned char C);
// SDL_imageFilterShiftRightAndMultByByte: D = saturation255((S >> N) * C)
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterShiftRightAndMultByByte(unsigned char *Src1, unsigned char *Dest, unsigned int length,
unsigned char N, unsigned char C);
// SDL_imageFilterShiftLeftByte: D = (S << N)
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterShiftLeftByte(unsigned char *Src1, unsigned char *Dest, unsigned int length,
unsigned char N);
// SDL_imageFilterShiftLeftUint: D = ((uint)S << N)
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterShiftLeftUint(unsigned char *Src1, unsigned char *Dest, unsigned int length,
unsigned char N);
// SDL_imageFilterShiftLeft: D = saturation255(S << N)
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterShiftLeft(unsigned char *Src1, unsigned char *Dest, unsigned int length, unsigned char N);
// SDL_imageFilterBinarizeUsingThreshold: D = S >= T ? 255:0
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterBinarizeUsingThreshold(unsigned char *Src1, unsigned char *Dest, unsigned int length,
unsigned char T);
// SDL_imageFilterClipToRange: D = (S >= Tmin) & (S <= Tmax) 255:0
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterClipToRange(unsigned char *Src1, unsigned char *Dest, unsigned int length,
unsigned char Tmin, unsigned char Tmax);
// SDL_imageFilterNormalizeLinear: D = saturation255((Nmax - Nmin)/(Cmax - Cmin)*(S - Cmin) + Nmin)
SDL2_IMAGEFILTER_SCOPE int SDL_imageFilterNormalizeLinear(unsigned char *Src, unsigned char *Dest, unsigned int length, int Cmin,
int Cmax, int Nmin, int Nmax);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#endif /* _SDL_imageFilter_h */

View File

@ -0,0 +1,123 @@
/*
SDL2_rotozoom.c: rotozoomer, zoomer and shrinker for 32bit or 8bit surfaces
Copyright (C) 2012-2014 Andreas Schiffler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
Andreas Schiffler -- aschiffler at ferzkopp dot net
*/
#ifndef _SDL2_rotozoom_h
#define _SDL2_rotozoom_h
#include <math.h>
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795
#endif
#include "SDL.h"
/* ---- Defines */
/*!
\brief Disable anti-aliasing (no smoothing).
*/
#define SMOOTHING_OFF 0
/*!
\brief Enable anti-aliasing (smoothing).
*/
#define SMOOTHING_ON 1
/* ---- Function Prototypes */
#ifdef _MSC_VER
# if defined(DLL_EXPORT) && !defined(LIBSDL2_GFX_DLL_IMPORT)
# define SDL2_ROTOZOOM_SCOPE __declspec(dllexport)
# else
# ifdef LIBSDL2_GFX_DLL_IMPORT
# define SDL2_ROTOZOOM_SCOPE __declspec(dllimport)
# endif
# endif
#endif
#ifndef SDL2_ROTOZOOM_SCOPE
# define SDL2_ROTOZOOM_SCOPE extern
#endif
/*
Rotozoom functions
*/
SDL2_ROTOZOOM_SCOPE SDL_Surface *rotozoomSurface(SDL_Surface * src, double angle, double zoom, int smooth);
SDL2_ROTOZOOM_SCOPE SDL_Surface *rotozoomSurfaceXY
(SDL_Surface * src, double angle, double zoomx, double zoomy, int smooth);
SDL2_ROTOZOOM_SCOPE void rotozoomSurfaceSize(int width, int height, double angle, double zoom, int *dstwidth,
int *dstheight);
SDL2_ROTOZOOM_SCOPE void rotozoomSurfaceSizeXY
(int width, int height, double angle, double zoomx, double zoomy,
int *dstwidth, int *dstheight);
/*
Zooming functions
*/
SDL2_ROTOZOOM_SCOPE SDL_Surface *zoomSurface(SDL_Surface * src, double zoomx, double zoomy, int smooth);
SDL2_ROTOZOOM_SCOPE void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight);
/*
Shrinking functions
*/
SDL2_ROTOZOOM_SCOPE SDL_Surface *shrinkSurface(SDL_Surface * src, int factorx, int factory);
/*
Specialized rotation functions
*/
SDL2_ROTOZOOM_SCOPE SDL_Surface* rotateSurface90Degrees(SDL_Surface* src, int numClockwiseTurns);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#endif /* _SDL2_rotozoom_h */

View File

@ -30,7 +30,7 @@ int main()
luaL_openlibs(L); luaL_openlibs(L);
InitLuaEngine(L); InitLuaEngine(L);
_chdir("game"); _chdir("game");
string code = LoadFile("test.lua"); string code = LoadFile("app.lua");
if (luaL_loadstring(L, code.c_str())) if (luaL_loadstring(L, code.c_str()))
{ {
cout << lua_tostring(L, -1) << endl; cout << lua_tostring(L, -1) << endl;

189
src/SDL2_framerate.c Normal file
View File

@ -0,0 +1,189 @@
/*
SDL2_framerate.c: framerate manager
Copyright (C) 2012-2014 Andreas Schiffler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
Andreas Schiffler -- aschiffler at ferzkopp dot net
*/
#include <SDL2/SDL2_framerate.h>
/*!
\brief Internal wrapper to SDL_GetTicks that ensures a non-zero return value.
\return The tick count.
*/
Uint32 _getTicks()
{
Uint32 ticks = SDL_GetTicks();
/*
* Since baseticks!=0 is used to track initialization
* we need to ensure that the tick count is always >0
* since SDL_GetTicks may not have incremented yet and
* return 0 depending on the timing of the calls.
*/
if (ticks == 0) {
return 1;
} else {
return ticks;
}
}
/*!
\brief Initialize the framerate manager.
Initialize the framerate manager, set default framerate of 30Hz and
reset delay interpolation.
\param manager Pointer to the framerate manager.
*/
void SDL_initFramerate(FPSmanager * manager)
{
/*
* Store some sane values
*/
manager->framecount = 0;
manager->rate = FPS_DEFAULT;
manager->rateticks = (1000.0f / (float) FPS_DEFAULT);
manager->baseticks = _getTicks();
manager->lastticks = manager->baseticks;
}
/*!
\brief Set the framerate in Hz
Sets a new framerate for the manager and reset delay interpolation.
Rate values must be between FPS_LOWER_LIMIT and FPS_UPPER_LIMIT inclusive to be accepted.
\param manager Pointer to the framerate manager.
\param rate The new framerate in Hz (frames per second).
\return 0 for sucess and -1 for error.
*/
int SDL_setFramerate(FPSmanager * manager, Uint32 rate)
{
if ((rate >= FPS_LOWER_LIMIT) && (rate <= FPS_UPPER_LIMIT)) {
manager->framecount = 0;
manager->rate = rate;
manager->rateticks = (1000.0f / (float) rate);
return (0);
} else {
return (-1);
}
}
/*!
\brief Return the current target framerate in Hz
Get the currently set framerate of the manager.
\param manager Pointer to the framerate manager.
\return Current framerate in Hz or -1 for error.
*/
int SDL_getFramerate(FPSmanager * manager)
{
if (manager == NULL) {
return (-1);
} else {
return ((int)manager->rate);
}
}
/*!
\brief Return the current framecount.
Get the current framecount from the framerate manager.
A frame is counted each time SDL_framerateDelay is called.
\param manager Pointer to the framerate manager.
\return Current frame count or -1 for error.
*/
int SDL_getFramecount(FPSmanager * manager)
{
if (manager == NULL) {
return (-1);
} else {
return ((int)manager->framecount);
}
}
/*!
\brief Delay execution to maintain a constant framerate and calculate fps.
Generate a delay to accomodate currently set framerate. Call once in the
graphics/rendering loop. If the computer cannot keep up with the rate (i.e.
drawing too slow), the delay is zero and the delay interpolation is reset.
\param manager Pointer to the framerate manager.
\return The time that passed since the last call to the function in ms. May return 0.
*/
Uint32 SDL_framerateDelay(FPSmanager * manager)
{
Uint32 current_ticks;
Uint32 target_ticks;
Uint32 the_delay;
Uint32 time_passed = 0;
/*
* No manager, no delay
*/
if (manager == NULL) {
return 0;
}
/*
* Initialize uninitialized manager
*/
if (manager->baseticks == 0) {
SDL_initFramerate(manager);
}
/*
* Next frame
*/
manager->framecount++;
/*
* Get/calc ticks
*/
current_ticks = _getTicks();
time_passed = current_ticks - manager->lastticks;
manager->lastticks = current_ticks;
target_ticks = manager->baseticks + (Uint32) ((float) manager->framecount * manager->rateticks);
if (current_ticks <= target_ticks) {
the_delay = target_ticks - current_ticks;
SDL_Delay(the_delay);
} else {
manager->framecount = 0;
manager->baseticks = _getTicks();
}
return time_passed;
}

3810
src/SDL2_gfxPrimitives.c Normal file

File diff suppressed because it is too large Load Diff

7371
src/SDL2_imageFilter.c Normal file

File diff suppressed because it is too large Load Diff

1663
src/SDL2_rotozoom.c Normal file

File diff suppressed because it is too large Load Diff