2 Copyright (c)2006-2007 - Brett Lajzer
4 See LICENSE for license information.
17 void print_usage(string progname
){
18 cerr
<< "USAGE: " << progname
<< " [dir] | [-h|--help]\n";
19 cerr
<< " dir - directory where game data is\n";
20 cerr
<< " -h --help - displays this usage info\n\n";
23 //configuration loader
24 //loads config into lua, retrieves values and leaves them there
25 SDL_Surface
*load_config(lua_State
*L
, string pname
){
26 if(luaL_loadfile(L
, "scripts/config.lua") || lua_pcall(L
,0,0,0)){
27 cerr
<< "Cannot load configuration script!\n" << "Error: " <<lua_tostring(L
, -1) << "\n";
32 //put the config values on the stack
33 lua_getglobal(L
, "s_fullscreen");
34 lua_getglobal(L
, "s_width");
35 lua_getglobal(L
, "s_height");
36 lua_getglobal(L
, "s_depth");
37 lua_getglobal(L
, "s_gamename");
39 //check values for proper type
40 if(!lua_isnumber(L
,-5)){
41 cerr
<< "Config Error: "<< "'s_fullscreen' should be a number\n";
44 if(!lua_isnumber(L
,-4)){
45 cerr
<< "Config Error: "<< "'s_width' should be a number\n";
48 if(!lua_isnumber(L
,-3)){
49 cerr
<< "Config Error: "<< "'s_height' should be a number\n";
52 if(!lua_isnumber(L
,-2)){
53 cerr
<< "Config Error: "<< "'s_depth' should be a number\n";
56 if(!lua_isstring(L
,-1)){
57 cerr
<< "Config Error: "<< "'s_gamename' should be a string\n";
61 //set caption and return the surface
62 SDL_WM_SetCaption(lua_tostring(L
,-1), lua_tostring(L
, -1));
64 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER
, 1);
66 SDL_Surface
*temp
= SDL_SetVideoMode(lua_tointeger(L
, -4), lua_tointeger(L
, -3), lua_tointeger(L
, -2), SDL_OPENGL
| (lua_tointeger(L
,-5)? SDL_FULLSCREEN
: 0));
69 glShadeModel(GL_FLAT
);
70 glClearColor(0.0f
, 0.0f
, 0.0f
, 0.0f
);
71 glEnable(GL_TEXTURE_RECTANGLE_ARB
);
73 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
77 glViewport(0, 0, (GLsizei
)lua_tointeger(L
, -4), (GLsizei
)lua_tointeger(L
, -3));
79 glMatrixMode(GL_PROJECTION
);
82 glOrtho(0.0f
, (GLfloat
)lua_tointeger(L
, -4), (GLfloat
)lua_tointeger(L
, -3), 0.0f
, -1.0f
, 1.0f
);
84 glMatrixMode(GL_MODELVIEW
);
87 glClear(GL_COLOR_BUFFER_BIT
);
90 for(int i
=0; i
< 5; i
++){lua_pop(L
,-1);}
95 //function for clearing out the image store
97 map
<string
, GLSurface
*>::iterator im
= image_store
.begin();
99 for(; im
!= image_store
.end(); im
++){
100 glDeleteTextures(1, &(im
->second
->texture
));