int main(int argc, char* args[] )
{
    srand( time( NULL ));

    if( !init() )
    {
        cout << "Falha ao inicializar o programa!" << endl;
    }
    else
    {
        if( !loadMedia() )
        {
            cout << "Falha ao carregar media!" << endl;
        }
        else
        {
            bool quit = false;
            SDL_Event e;

            int x = 0;

            //Limpando a tela.
            SDL_RenderClear( gRenderer );

            Uint8 r = 255;
            Uint8 g = 255;
            Uint8 b = 255;

            while( !quit )
            {
                while( SDL_PollEvent( &e) != 0 )
                {
                    if( e.type == SDL_QUIT )
                    {
                        quit = true;
                    }
                    if( e.type == SDL_KEYDOWN )
                    {
                        if( e.key.keysym.sym == SDLK_RETURN )
                        {
                            SDL_RenderClear( gRenderer );
                        }
                        else if( e.key.keysym.sym == SDLK_q )
                        {
                            r += 5;
                        }
                        else if( e.key.keysym.sym == SDLK_w )
                        {
                            g += 5;
                        }
                        else if( e.key.keysym.sym == SDLK_e )
                        {
                            b += 5;
                        }
                        else if( e.key.keysym.sym == SDLK_a )
                        {
                            r -= 5;
                        }
                        else if( e.key.keysym.sym == SDLK_s )
                        {
                            g -= 5;
                        }
                        else if( e.key.keysym.sym == SDLK_d )
                        {
                            b -= 5;
                        }
                    }
                }
                //Altera a cor.
                gSquare.setColor( num_ale(0, r), num_ale(0, g), num_ale(0, b), num_ale(0, 255) );

                //Render Animation.
                gSquare.render( num_ale(0, SCREEN_WIDTH) - gSpriteClips[0].w / 32, num_ale(0, SCREEN_HEIGHT) - gSpriteClips[0].h / 32, gSpriteClips[0].w / 16, gSpriteClips[0].h / 16, &gSpriteClips[x] );

                SDL_RenderPresent( gRenderer );
            }
        }
    }

    return 0;
}
Ejemplo n.º 2
0
int
main(int argc, char *argv[])
{
	int quit = 0;
	/* event handler */
	SDL_Event event;
	/* modulation components */
	Uint8 r = 255;
	Uint8 g = 255;
	Uint8 b = 255;

	/* starts up SDL and create window */
	if (init_sdl() == -1) {
		fprintf(stderr, "Failed to initialize SDL!\n");
		return -1;
	}

	/* load media */
	if (load_media() == -1) {
		fprintf(stderr, "Failed to load media!\n");
		return -2;
	}

	/* main loop */
	while (quit == 0) {
		/* handle events on queue */
		while (SDL_PollEvent(&event) != 0) {
			/* users request quit */
			if (event.type == SDL_QUIT)
				quit = 1;

			/* on key press change rgb values */
			else if (event.type == SDL_KEYDOWN) {
				switch (event.key.keysym.sym) {
				case SDLK_q:	/* increase red */
					r += 32;
					break;
				case SDLK_w:	/* increase green */
					g += 32;
					break;
				case SDLK_e:	/* increase blue */
					b += 32;
					break;
				case SDLK_a:	/* decrease red */
					r -= 32;
					break;
				case SDLK_s:	/* decrease green */
					g -= 32;
					break;
				case SDLK_d:	/* decrease blue */
					b -= 32;
					break;
				}
			}
		}

		/* clear screen */
		SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
		SDL_RenderClear(gRenderer);

		/* modulate and render texture */
		gModulatedTexture.setColor(r, g, b);
		gModulatedTexture.render(0, 0);


		/* update screen */
		SDL_RenderPresent(gRenderer);
	}

	/* free resources and close */
	close_sdl();

	return 0;
}
Ejemplo n.º 3
0
int main( int argc, char* args[] ) {
  //Start up SDL and create window
  if( !init() ) {
    printf( "Failed to initialize!\n" );
  } else {
    //Load media
    if( !loadMedia() ) {
      printf( "Failed to load media!\n" );
    } else {
      //Main loop flag
      bool quit = false;

      //Event handler
      SDL_Event e;

      //Modulation components
      Uint8 r = 255;
      Uint8 g = 255;
      Uint8 b = 255;

      //While application is running
      while( !quit ) {
        //Handle events on queue
        while( SDL_PollEvent( &e ) != 0 ) {
          //User requests quit
          if( e.type == SDL_QUIT ) {
            quit = true;
          }
          //On keypress change rgb values
          else if( e.type == SDL_KEYDOWN ) {
            switch( e.key.keysym.sym ) {
            //Increase red
            case SDLK_q:
              r += 32;
              break;

            //Increase green
            case SDLK_w:
              g += 32;
              break;

            //Increase blue
            case SDLK_e:
              b += 32;
              break;

            //Decrease red
            case SDLK_a:
              r -= 32;
              break;

            //Decrease green
            case SDLK_s:
              g -= 32;
              break;

            //Decrease blue
            case SDLK_d:
              b -= 32;
              break;
            }
          }
        }

        //Clear screen
        SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
        SDL_RenderClear( gRenderer );

        //Modulate and render texture
        gModulatedTexture.setColor( r, g, b );
        gModulatedTexture.render( 0, 0 );

        //Update screen
        SDL_RenderPresent( gRenderer );
      }
    }
  }

  //Free resources and close SDL
  close();

  return 0;
}