Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SDL/SDL.h>
- #include <cstdlib>
- #include <ctime>
- #define FPS 30
- void
- generateRGB_noise(SDL_Surface* surface)
- {
- //fills all pixels in surface with random colors.
- Uint32* pixels = (Uint32*) surface->pixels;
- for(int x = 0; x < surface->w; ++x)
- {
- for(int y = 0; y < surface->h; ++y)
- {
- Uint8 r = rand() % 256;
- Uint8 g = rand() % 256;
- Uint8 b = rand() % 256;
- pixels[( y * surface->w ) + x] = SDL_MapRGB(surface->format, r, g, b);
- }
- }
- surface->pixels = pixels;
- }
- int
- main(int argc , char** argv)
- {
- //initialise window and screen
- SDL_Init(SDL_INIT_VIDEO);
- SDL_Surface* window;
- window = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
- srand(time(NULL)); //set rand seed
- bool active = true;
- while(active)
- {
- SDL_Event event;
- while(SDL_PollEvent(&event))
- {
- if(event.type == SDL_KEYUP && event.key.keysym.sym == SDLK_ESCAPE)
- {
- //quit on pressing escape
- active = false;
- }
- }
- generateRGB_noise(window);
- SDL_Flip(window);
- SDL_Delay(1000 / FPS); //to not fry up cpu
- }
- SDL_Quit();
- }
Add Comment
Please, Sign In to add comment