Originally Posted by
Devils Child
dude, this is awfuly slow!
Thats because SDL wasn't designed to be used that way. Any per pixel manipulations like that are going to be extremely slow.
Code:
#include <SDL/SDL.h>
int main ( int argc, char** argv ){
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
return 1;
SDL_Surface* screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE|SDL_DOUBLEBUF);
if ( !screen )
return 1;
bool done = false;
while (!done) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
done = true;
break;
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_ESCAPE)
done = true;
break;
}
}
SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, rand()%256, rand()%256, rand()%256));
SDL_Flip(screen);
}
SDL_Quit();
return 0;
}
You will need to set up SDL_gfx for anything other than rectangles.