Esempio n. 1
0
int main(int argc, char *argv[]){
    SDL_Window * window;
    SDL_GLContext context;

    initwindow(&window, &context);

    drawscene(window);

    destroywindow(window, context);

    return 0;
}
Esempio n. 2
0
int main( int argc, char *argv[ ], char *envp[ ] )
#endif
{
#ifndef _WIN32
	chdir(SPRING_DATADIR);
#endif
	INIT_SYNCIFY;
	bool	done=false;
	BaseCmd *cmdline = BaseCmd::initialize(argc,argv);
	cmdline->addoption('f',"fullscreen",OPTPARM_NONE,"","Run in fullscreen mode");
	cmdline->addoption('w',"window",OPTPARM_NONE,"","Run in windowed mode");
	cmdline->addoption('s',"server",OPTPARM_NONE,"","Run as a server");
	cmdline->addoption('c',"client",OPTPARM_NONE,"","Run as a client");
//	cmdline->addoption('g',"runscript",OPTPARM_STRING,"script.txt", "Run with a game setup script");
	cmdline->parse();
#ifdef _DEBUG
	fullscreen = false;
#else
	fullscreen = configHandler.GetInt("Fullscreen",1)!=0;
#endif
	Uint8 scrollWheelSpeed = configHandler.GetInt("ScrollWheelSpeed",25);

	if (cmdline->result("help")) {
		cmdline->usage("TA:Spring",VERSION_STRING);
		delete cmdline;
		return 0;
	} else if (cmdline->result("version")) {
		std::cout << "TA:Spring " << VERSION_STRING << std::endl;
		delete cmdline;
		return 0;
	} else if (cmdline->result("window"))
		fullscreen = false;
	else if (cmdline->result("fullscreen"))
		fullscreen = true;
#ifdef _WIN32
	// Initialize crash reporting
	Install( (LPGETLOGFILE) crashCallback, "*****@*****.**", "TA Spring Crashreport");
#endif
	// Initialize class system
	creg::ClassBinder::InitializeClasses ();

	// Global structures
	ENTER_SYNCED;
	gs=new CGlobalSyncedStuff();
	ENTER_UNSYNCED;
	gu=new CGlobalUnsyncedStuff();


#ifndef NO_LUA
	// Initialize lua bindings
	CLuaBinder lua;
	if (!lua.LoadScript("testscript.lua")) 
		handleerror(NULL, lua.lastError.c_str(), "lua",MBF_OK|MBF_EXCL);
#endif

	// Check if the commandline parameter is specifying a demo file
	bool playDemo = false;
	string demofile, startscript;

#ifdef _WIN32
	string command(argv[0]);
	int idx = command.rfind("spring");
	string path = command.substr(0,idx);
	if (path.at(0) == '"')
		path.append(1,'"');
	if (path != "")
		_chdir(path.c_str());
#endif

	for (int i = 1; i < argc; i++) {
		if (argv[i][0] != '-') {
			string command(argv[i]);
			int idx = command.rfind("sdf");
			if (idx == command.size()-3) {
				playDemo = true;
				demofile = command;
			} else {
				playDemo = false;
				startscript = command;
			}
		}
	}

	// Create the archive scanner and vfs handler
	archiveScanner = new CArchiveScanner();
	archiveScanner->ReadCacheData();
	archiveScanner->Scan("./maps");
	archiveScanner->Scan("./base");
	archiveScanner->Scan("./mods");
	archiveScanner->WriteCacheData();
	hpiHandler = new CVFSHandler();

	palette.Init();

	ENTER_SYNCED;
	if (!playDemo) {
		gameSetup=new CGameSetup();
		if(!gameSetup->Init(startscript)){
			delete gameSetup;
			gameSetup=0;
		}
	}

	ENTER_MIXED;

	bool server = true;
	if (playDemo)
		server = false;
	else if(gameSetup)
		server=gameSetup->myPlayer-gameSetup->numDemoPlayers == 0;
	else
		server=!cmdline->result("client") || cmdline->result("server");
	
	if (
		!glwindow (
			"RtsSpring",
			configHandler.GetInt("XResolution",XRES_DEFAULT),
			configHandler.GetInt("YResolution",YRES_DEFAULT),
			0,
			fullscreen,
			configHandler.GetInt("DisplayFrequency",0)
		)
	) {
		SDL_Quit();
		return 0;
	}

	SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);

	font = new CglFont(32,223);
	LoadExtensions();
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	SDL_GL_SwapBuffers();
	
	if (playDemo)
		pregame = new CPreGame(false, demofile);
	else
		pregame = new CPreGame(server, "");

#ifdef NEW_GUI
	guicontroller = new GUIcontroller();
#endif

#ifndef NO_LUA
	lua.CreateLateBindings();
#endif

	keys = new Uint8[SDLK_LAST];

	SDL_Event event;
	while (!done) {
		ENTER_UNSYNCED;
		while (SDL_PollEvent(&event)) {
			switch (event.type) {
				case SDL_VIDEORESIZE:
					screen = SDL_SetVideoMode(event.resize.w,event.resize.h,0,SDL_OPENGL|SDL_RESIZABLE|SDL_HWSURFACE|SDL_DOUBLEBUF);
					if (screen)
						resizescene(screen->w,screen->h);
					break;
				case SDL_QUIT:
					done = true;
					break;
				case SDL_MOUSEMOTION:
					if(mouse)
						mouse->MouseMove(event.motion.x,event.motion.y);
					break;
				case SDL_MOUSEBUTTONDOWN:
					if (mouse) {
						if (event.button.button == SDL_BUTTON_WHEELUP)
							mouse->currentCamController->MouseWheelMove(scrollWheelSpeed);
						else if (event.button.button == SDL_BUTTON_WHEELDOWN)
							mouse->currentCamController->MouseWheelMove(-scrollWheelSpeed);
						mouse->MousePress(event.button.x,event.button.y,event.button.button);
					}
					break;
				case SDL_MOUSEBUTTONUP:
					if (mouse)
						mouse->MouseRelease(event.button.x,event.button.y,event.button.button);
					break;
				case SDL_KEYDOWN:
				{
					int i = event.key.keysym.sym;
				
					update_sdlkeys(keys);
					update_sdlmods(keys);
					if (i == SDLK_RETURN)
						keys[i] = 1;
					
					if(activeController) {
						activeController->KeyPressed(i,1);
#ifndef NEW_GUI
						if(activeController->userWriting){ 
							i = event.key.keysym.unicode;
							if (i >= SDLK_SPACE && i <= SDLK_DELETE)
								if(activeController->ignoreNextChar || activeController->ignoreChar==char(i))
									activeController->ignoreNextChar=false;
								else
									activeController->userInput+=char(i);
						}
#endif
					}
#ifdef NEW_GUI
					i = event.key.keysym.unicode;
					if (i > SDLK_FIRST && i <= SDLK_DELETE) /* HACK */
						GUIcontroller::Character(char(i));
						
#endif
					break;
				}
				case SDL_KEYUP:
				{
					int i = event.key.keysym.sym;

					update_sdlkeys(keys);
					update_sdlmods(keys);
					if (i == SDLK_RETURN)
						keys[i] = 0;
					
					if (activeController)
						activeController->KeyReleased(i);
					
					break;
				}
			}
		}
		if (FSAA)
			glEnable(GL_MULTISAMPLE_ARB);
		int ret = drawscene();
		SDL_GL_SwapBuffers();
		if (FSAA)
			glDisable(GL_MULTISAMPLE_ARB);
		if (globalQuit || (active && !ret))
			done=true;
	}
	ENTER_MIXED;

	delete[] keys;

	// Shutdown
	if (pregame)
		delete pregame;			//in case we exit during init
	if (game)
		delete game;
	if (gameSetup)
		delete gameSetup;
	delete font;
	ConfigHandler::Deallocate();
	UnloadExtensions();
#ifndef DEBUG
	SDL_WM_GrabInput(SDL_GRAB_OFF);
#endif
	SDL_Quit();
	delete gs;
	delete gu;
	END_SYNCIFY;
#ifdef USE_MMGR
	m_dumpMemoryReport();
#endif
	delete cmdline;
	return 0;
}
Esempio n. 3
0
static
void display (void)
{
	static GLfloat angle;

	angle += delta;

	pm_framestart();

	GLCHK(glMatrixMode(GL_MODELVIEW));
	GLCHK(glLoadIdentity());

	if (d_exponent != 0) {
		exponent += d_exponent;
		if (exponent >= 128)
			exponent = 128;
		if (exponent < 1)
			exponent = 1;
		lights_changed = 1;
	}

	if (d_cutoff != 0) {
		cutoff += d_cutoff;
		if (cutoff > 90)
			cutoff = 90;
		if (cutoff < 2)
			cutoff = 2;
		lights_changed = 1;
	}

	set_lights();

	static const float len = 6;

	float se = sinf(elevation * M_PI / 180);
	float ce = cosf(elevation * M_PI / 180);
	float sb = sinf(bearing * M_PI / 180);
	float cb = cosf(bearing * M_PI / 180);

	float x = ce * cb * len;
	float y = ce * sb * len;
	float z = se * len;


	GLCHK(glEnable(GL_SCISSOR_TEST));

	glLoadIdentity();
	gluLookAt(0, 0, len,  0,0,.5,  0,1,0);
	GLCHK(glScissor(0,0, width/2, height/2));
	GLCHK(glViewport(0,0, width/2, height/2));
	GLCHK(glClearColor(.2,.2,.3,1));
	GLCHK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
	drawscene(angle);

	glLoadIdentity();
	gluLookAt(-len, 0, .5,  0,0,.5,  0,0,1);
	GLCHK(glScissor(width/2,0, width/2, height/2));
	GLCHK(glViewport(width/2,0, width/2, height/2));
	GLCHK(glClearColor(.3,.2,.2,1));
	GLCHK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
	drawscene(angle);

	glLoadIdentity();
	gluLookAt(x,y,z,  0,0,.5,  0,0,1);
	GLCHK(glScissor(width/2,height/2, width/2, height/2));
	GLCHK(glViewport(width/2,height/2, width/2, height/2));
	GLCHK(glClearColor(.2,.2,.2,1));
	GLCHK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
	drawscene(angle);

	glLoadIdentity();
	gluLookAt(0, -len, .5,  0,0,.5,  0,0,1);
	GLCHK(glScissor(0,height/2, width/2, height/2));
	GLCHK(glViewport(0,height/2, width/2, height/2));
	GLCHK(glClearColor(.2,.3,.2,1));
	GLCHK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
	drawscene(angle);

	GLCHK(glScissor(0, 0, width, height));
	GLCHK(glViewport(0, 0, width, height));

	pm_frameend();

	if (shot) {
		shot = 0;
		screenshot("viewports");
	}

	glutSwapBuffers();
	glutPostRedisplay();
}