Exemplo n.º 1
0
int main (int argc, char* argv[]) {
	SDL_Event		event;
	SDL_Surface		*screen;

	if (SDL_Init (SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0) {
		printf ("Unable to initialize SDL: %s\n", SDL_GetError ());
		return 1;
	}

	SDL_WM_SetCaption ("Cube of cubes", "Cube of cubes");
	SDL_ShowCursor(SDL_DISABLE);
	SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);

	//Initialize window
	screen = SDL_SetVideoMode (WINDOW_WIDTH, WINDOW_HEIGHT, 32, SDL_OPENGL);
	if (!screen) {
		printf ("Unable to set video mode: %s\n", SDL_GetError ());
		return 1;
	}

	r_init ();

	//Main loop
	while (!user_exit) {
		//Handle input
		while (SDL_PollEvent (&event)) {
			switch (event.type) {
			case SDL_KEYDOWN:
				input_keyDown (event.key.keysym.sym);
				break;
			case SDL_KEYUP:
				input_keyUp (event.key.keysym.sym);
				break;
			case SDL_MOUSEMOTION:
				input_mouseMove (event.motion.x, event.motion.y);
				break;
			case SDL_QUIT:
				exit (0);
			}
		}
		input_update ();
		r_drawFrame ();
		// Cap it at 100 fps
		usleep (10000);
	}

	SDL_Quit ();

	return 0;
}
Exemplo n.º 2
0
/*
 * SDL_main
 * Program entry point.
 */
int SDL_main(int argc, char* argv[]){
	SDL_Event	event;
	SDL_Surface	*screen;

	if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0)
	{
		printf("Unable to initialize SDL: %s\n", SDL_GetError());
		return 1;
	}

	SDL_WM_SetCaption("Skybox Demo", "Skybox Demo");
	SDL_ShowCursor(SDL_DISABLE);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

	screen = SDL_SetVideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, 32, SDL_OPENGL);
	if(!screen)
	{
		printf("Unable to set video mode: %s\n", SDL_GetError());
		return 1;
	}

	r_init();


	//Declaration of variables used in decoupling.
	int currTime = SDL_GetTicks();
	int prevTime = 0;

	//THIS IS THE GAME LOOP! *********************************************

	while(!user_exit)
	{
		//Set time counters to appropriate values for calculations.
		prevTime = currTime;
		currTime = SDL_GetTicks();

		//Handle input
		while(SDL_PollEvent(&event))
		{
			switch(event.type)
			{
			case SDL_KEYDOWN:
				input_keyDown(event.key.keysym.sym);
				break;
			case SDL_KEYUP:
				input_keyUp(event.key.keysym.sym);
				break;
			case SDL_MOUSEMOTION:
				input_mouseMove(event.motion.x, event.motion.y);
				break;
			case SDL_QUIT:
				user_exit = 1;
			}
		}

		input_update(currTime - prevTime);
		r_drawFrame();
	}

	//********************************************************************

	SDL_Quit();
	return 0;
}
Exemplo n.º 3
0
/*
 * SDL_main
 * Program entry point.
 */
int main(int argc, char* argv[])
{
	size = 32;
	srand(time(NULL));
	SDL_Event	event;
	SDL_Surface	*screen;

	if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0)
	{
		printf("Unable to initialize SDL: %s\n", SDL_GetError());
		return 1;
	}

	SDL_WM_SetCaption("Camera Demo", "Camera Demo");
	SDL_ShowCursor(SDL_DISABLE);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

	screen = SDL_SetVideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, 32, SDL_OPENGL);
	if(!screen)
	{
		printf("Unable to set video mode: %s\n", SDL_GetError());
		return 1;
	}

	r_init();

	float t = 0.0f;
	float dt = 0.1f;

	float currentTime = 0.0f;
	float accumulator = 0.0f;

	while(!user_exit)
	{
		if (won) {
			r_init();
		}
		float newTime = time(0);
		float deltaTime = newTime - currentTime;
		currentTime = newTime;

		if (deltaTime>0.25f)
			deltaTime = 0.25f;

		accumulator += deltaTime;

		while (accumulator>=dt)
		{
			accumulator -= dt;
			t += dt;
		}

		//Handle input
		while(SDL_PollEvent(&event))
		{
			switch(event.type)
			{
			case SDL_KEYDOWN:
				input_keyDown(event.key.keysym.sym);
				break;
			case SDL_KEYUP:
				input_keyUp(event.key.keysym.sym);
				break;
			case SDL_MOUSEMOTION:
				input_mouseMove(event.motion.x, event.motion.y);
				break;
			case SDL_QUIT:
				user_exit = 1;
			}
		}

		input_update();

		r_drawFrame();
	}

	SDL_Quit();
	return 0;
}
Exemplo n.º 4
0
//Program entry point
int SDL_main(int argc, char* argv[])
{
	int i;
	SDL_Event	event;		//Used for handling input events, as you can see later on.
	SDL_Surface	*screen;	//http://www.libsdl.org/cgi/docwiki.cgi/SDL_Surface
	CAMERA_POSITION camera;
	float *colors[3] = {&RED[0], &GREEN[0], &BLUE[0]};

	for (i = 0; i < 256; i++) {
		keys_down[i] = 0;
	}
	resetCamera(&camera);

	//The following is pretty self-explanatory
	if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0)
	{
		printf("Unable to initialize SDL: %s\n", SDL_GetError());
		return 1;
	}

	//You can of course customize this.
	SDL_WM_SetCaption("Perspective Projection", "Perspective Projection");

	//We need to explicitly enable double buffering
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

	//Initialize window, setting the resolution to 1024x768 @ 32 bits per pixel. We want an OpenGL window.
	screen = SDL_SetVideoMode(1024, 768, 32, SDL_OPENGL);
	if(!screen)
	{
		printf("Unable to set video mode: %s\n", SDL_GetError());
		return 1;
	}

	//Any other one-time initialization would typically go here.
	//"Renderer" initialization
	r_init(&camera);

	//This is what is referred to as the "game loop." Obviously there is not much here currently.
	while(!user_exit)
	{
		bool mouseMoved = FALSE;
		int x = 0, y = 0;
		//Handle input
		while(SDL_PollEvent(&event))
		{
			switch(event.type)
			{
			case SDL_KEYDOWN:
				input_keyDown(event.key.keysym.sym, &camera);
				break;
			case SDL_KEYUP:
				input_keyUp(event.key.keysym.sym);
				break;
			case SDL_MOUSEBUTTONDOWN:
				randomizeColors(colors);
				break;
			case SDL_MOUSEMOTION:
				x = event.motion.x;
				y = event.motion.y;
				mouseMoved = TRUE;
				break;
			case SDL_QUIT:
				exit(0);
			}
		}
		input_update(&camera);
		if (mouseMoved) {
			input_mouseMoved(&camera, x, y);
			setUpAndLoadModelViewMatrix(&camera);
		}

		//Here is where you will do any OpenGL drawing. You would also do things like update moving objects, etc.
		//Do whatever we need to do to draw a single image.
		r_drawFrame(colors);
	}

	//Shut down SDL
	SDL_Quit();

	//Everything went OK.
	return 0;
}