Exemple #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;
}
Exemple #2
0
/**
 * @brief Handles global input.
 *
 * Basically separates the event types
 *
 *    @param event Incoming SDL_Event.
 */
void input_handle( SDL_Event* event )
{
   int ismouse = 0;

   /* Special case mouse stuff. */
   if ((event->type == SDL_MOUSEMOTION)  ||
         (event->type == SDL_MOUSEBUTTONDOWN) ||
         (event->type == SDL_MOUSEBUTTONUP)) {
      input_mouseTimer = MOUSE_HIDE;
      SDL_ShowCursor( SDL_ENABLE );
      ismouse = 1;
   }

   if (toolkit_isOpen()) { /* toolkit handled completely separately */
      if (toolkit_input(event))
         return; /* we don't process it if toolkit grabs it */
      if (ismouse)
         return; /* Toolkit absorbs everything mousy. */
   }

   if (ovr_isOpen())
      if (ovr_input(event))
         return; /* Don't process if the map overlay wants it. */

   /* GUI gets event. */
   if (gui_handleEvent(event))
      return;

   switch (event->type) {

      /*
       * game itself
       */
      case SDL_JOYAXISMOTION:
         input_joyaxis(event->jaxis.axis, event->jaxis.value);
         break;

      case SDL_JOYBUTTONDOWN:
         input_joyevent(KEY_PRESS, event->jbutton.button);
         break;

      case SDL_JOYBUTTONUP:
         input_joyevent(KEY_RELEASE, event->jbutton.button);
         break;

      case SDL_KEYDOWN:
#if SDL_VERSION_ATLEAST(2,0,0)
         if (event->key.repeat != 0)
            return;
#endif /* SDL_VERSION_ATLEAST(2,0,0) */
         input_keyevent(KEY_PRESS, event->key.keysym.sym, event->key.keysym.mod, 0);
         break;

      case SDL_KEYUP:
#if SDL_VERSION_ATLEAST(2,0,0)
         if (event->key.repeat !=0)
            return;
#endif /* SDL_VERSION_ATLEAST(2,0,0) */
         input_keyevent(KEY_RELEASE, event->key.keysym.sym, event->key.keysym.mod, 0);
         break;


      /* Mouse stuff. */
      case SDL_MOUSEBUTTONDOWN:
         input_clickevent( event );
         break;

#if SDL_VERSION_ATLEAST(2,0,0)
      case SDL_MOUSEWHEEL:
         if (event->wheel.y > 0)
            input_clickZoom( 1.1 );
         else
            input_clickZoom( 0.9 );
         break;
#endif /* SDL_VERSION_ATLEAST(2,0,0) */

      case SDL_MOUSEMOTION:
         input_mouseMove( event );
         break;

      default:
         break;
   }
}
Exemple #3
0
/**
 * @brief Handles global input.
 *
 * Basically seperates the event types
 *
 *    @param event Incoming SDL_Event.
 */
void input_handle( SDL_Event* event )
{
   /* Special case mouse stuff. */
   if ((event->type == SDL_MOUSEMOTION)  ||
         (event->type == SDL_MOUSEBUTTONDOWN) ||
         (event->type == SDL_MOUSEBUTTONUP)) {
      input_mouseTimer = MOUSE_HIDE;
      SDL_ShowCursor( SDL_ENABLE );
   }

   if (toolkit_isOpen()) /* toolkit handled seperately completely */
      if (toolkit_input(event))
         return; /* we don't process it if toolkit grabs it */

   if (ovr_isOpen())
      if (ovr_input(event))
         return; /* Don't process if the map overlay wants it. */

   /* GUI gets event. */
   if (gui_handleEvent(event))
      return;

   switch (event->type) {

      /*
       * game itself
       */
      case SDL_JOYAXISMOTION:
         input_joyaxis(event->jaxis.axis, event->jaxis.value);
         break;

      case SDL_JOYBUTTONDOWN:
         input_joyevent(KEY_PRESS, event->jbutton.button);
         break;

      case SDL_JOYBUTTONUP:
         input_joyevent(KEY_RELEASE, event->jbutton.button);
         break;

      case SDL_KEYDOWN:
         input_keyevent(KEY_PRESS, event->key.keysym.sym, event->key.keysym.mod, 0);
         break;

      case SDL_KEYUP:
         input_keyevent(KEY_RELEASE, event->key.keysym.sym, event->key.keysym.mod, 0);
         break;


      /* Mouse stuff. */
      case SDL_MOUSEBUTTONDOWN:
         input_clickevent( event );
         break;

      case SDL_MOUSEMOTION:
         input_mouseMove( event );
         break;

      default:
         break;
   }
}
Exemple #4
0
/*
 * SDL_main
 */
int SDL_main(int argc, char* argv[])
{
	SDL_Event		event;
	SDL_Surface		*screen, *icon;

	putenv(strdup("SDL_VIDEO_CENTERED=1"));

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

    icon = SDL_LoadBMP("gui/icon.bmp");
    SDL_WM_SetIcon(icon, NULL);

	SDL_WM_SetCaption("Convex Hull Testing", "Convex Hull Testing");
	SDL_ShowCursor(SDL_DISABLE);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, etrue);

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

    SDL_WarpMouse(512.0, 384.0);

    //gameState = STATE_MAINMENU;

    timer_init();
    renderer_init();
    world_init();
    //model_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:
				user_exit = etrue;
			}
		}

		timer_update();

		while(timer.accumulated >= TIMESTEP)
		{
			input_update();
			world_update();

			timer.accumulated -= TIMESTEP;
		}

		world_lerpPositions(timer.accumulated);
		renderer_drawFrame();
	}

    SDL_Quit();

    return EXIT_SUCCESS;
}
Exemple #5
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;
}
Exemple #6
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;
}