Пример #1
0
static int l_surface_new(lua_State *L)
{
    lua_remove(L, 1); // Value inserted by __call

    THRenderTargetCreationParams oParams = l_surface_creation_params(L, 1);
    THRenderTarget* pCanvas = luaT_stdnew<THRenderTarget>(L);
    if(pCanvas->create(&oParams))
        return 1;

    lua_pushnil(L);
    lua_pushstring(L, pCanvas->getLastError());
    return 2;
}
Пример #2
0
static int l_surface_new(lua_State *L)
{
    lua_remove(L, 1); // Value inserted by __call

    THRenderTargetCreationParams oParams;
    oParams.iWidth = luaL_checkint(L, 1);
    oParams.iHeight = luaL_checkint(L, 2);
    int iArg = 3;
    if(lua_type(L, iArg) == LUA_TNUMBER)
        oParams.iBPP = luaL_checkint(L, iArg++);
    else
        oParams.iBPP = 0;
    oParams.iSDLFlags = 0;
    oParams.bHardware = false;
    oParams.bDoubleBuffered = false;
    oParams.bFullscreen = false;
    oParams.bPresentImmediate = false;
    oParams.bReuseContext = false;
    oParams.bOpenGL = false;

#define FLAG(name, field, flag) \
    else if(stricmp(sOption, name) == 0) \
        oParams.field = true, oParams.iSDLFlags |= flag

    for(int iArgCount = lua_gettop(L); iArg <= iArgCount; ++iArg)
    {
        const char* sOption = luaL_checkstring(L, iArg);
        if(sOption[0] == 0)
            continue;
        FLAG("hardware"         , bHardware        , SDL_HWSURFACE );
        FLAG("doublebuf"        , bDoubleBuffered  , SDL_DOUBLEBUF );
        FLAG("fullscreen"       , bFullscreen      , SDL_FULLSCREEN);
        FLAG("present immediate", bPresentImmediate, 0             );
        FLAG("reuse context"    , bReuseContext    , 0             );
        FLAG("opengl"           , bOpenGL          , SDL_OPENGL    );
    }

#undef FLAG

#ifndef CORSIX_TH_USE_DX9_RENDERER
    if(SDL_WasInit(SDL_INIT_VIDEO))
    {
        char *sTitle, *sIcon;
        char *sTitle2 = NULL, *sIcon2 = NULL;
        size_t iLen;
        SDL_WM_GetCaption(&sTitle, &sIcon);
        if(sTitle)
        {
            iLen = strlen(sTitle) + 1;
            sTitle2 = (char*)malloc(iLen);
            memcpy(sTitle2, sTitle, iLen);
        }

        if(sIcon)
        {
            iLen = strlen(sIcon) + 1;
            sIcon2 = (char*)malloc(iLen);
            memcpy(sIcon2, sIcon, iLen);
        }

        SDL_QuitSubSystem(SDL_INIT_VIDEO);
        SDL_InitSubSystem(SDL_INIT_VIDEO);
        SDL_WM_SetCaption(sTitle2, sIcon2);

        free(sTitle2);
        free(sIcon2);
    }
#endif

    THRenderTarget* pCanvas = luaT_stdnew<THRenderTarget>(L);
    if(pCanvas->create(&oParams))
        return 1;

    lua_pushnil(L);
    lua_pushstring(L, pCanvas->getLastError());
    return 2;
}