diff --git a/Video.cc b/Video.cc index a6df95e..133c421 100644 --- a/Video.cc +++ b/Video.cc @@ -30,16 +30,19 @@ Video::Video() void Video::start(int width, int height, bool fullscreen) { - if (width == 0) - width = m_defaultWidth; - if (height == 0) - height = m_defaultHeight; - int flags = SDL_HWSURFACE | SDL_OPENGL; - if (fullscreen) - flags |= SDL_FULLSCREEN; + if (m_surface == NULL) + { + if (width == 0) + width = m_defaultWidth; + if (height == 0) + height = m_defaultHeight; + int flags = SDL_HWSURFACE | SDL_OPENGL; + if (fullscreen) + flags |= SDL_FULLSCREEN; - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - m_surface = SDL_SetVideoMode(width, height, 32, flags); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + m_surface = SDL_SetVideoMode(width, height, 32, flags); + } } void Video::stop() diff --git a/ag.cc b/ag.cc index 7a94d7f..ed6a630 100644 --- a/ag.cc +++ b/ag.cc @@ -1,6 +1,7 @@ #include "anaglym.h" #include "ag.h" +#include "Video.h" #include "wfobj/WFObj.hh" #include #include @@ -15,6 +16,8 @@ namespace ag { "print", print }, { "println", println }, { "loadModel", loadModel }, + { "videoStart", videoStart }, + { "videoStop", videoStop }, { NULL, NULL } }; luaL_register(L, "ag", functions); @@ -108,4 +111,14 @@ namespace ag return 0; } + + int videoStart(lua_State * L) + { + g_video->start(); + } + + int videoStop(lua_State * L) + { + g_video->stop(); + } } diff --git a/ag.h b/ag.h index 5113002..757c2f2 100644 --- a/ag.h +++ b/ag.h @@ -10,6 +10,8 @@ namespace ag int print(lua_State * L); int println(lua_State * L); int loadModel(lua_State * L); + int videoStart(lua_State * L); + int videoStop(lua_State * L); } #endif diff --git a/anaglym.cc b/anaglym.cc index 6d48a6b..c24ea37 100644 --- a/anaglym.cc +++ b/anaglym.cc @@ -11,6 +11,8 @@ static void usage(); static void report_errors(lua_State * L, int status); static void register_libraries(lua_State * L); +Video * g_video = NULL; + int main(int argc, char * argv[]) { const char * program = NULL; @@ -39,7 +41,7 @@ int main(int argc, char * argv[]) usage(); } - Video video; + g_video = new Video(); lua_State * L = lua_open(); @@ -61,6 +63,8 @@ int main(int argc, char * argv[]) report_errors(L, s); lua_close(L); + delete g_video; + return 0; } diff --git a/anaglym.h b/anaglym.h index 39bc2e7..51eef69 100644 --- a/anaglym.h +++ b/anaglym.h @@ -3,9 +3,11 @@ #define ANAGLYM_H #include +#include "Video.h" #define FILENAME_SAFE_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-" std::string locateResource(const std::string & shortname); +extern Video * g_video; #endif