Im having a strange problem when using SDL_FillRect() to draw colored
rectangles to the screen. a book i am using has some demo code that works
perfectly
when i insert it into my app. it basically draws randomly colored rectangles
all over the screen. My own code however, seems only capable of producing
blue colors.
It does do shades of blue but thats it. Is there some limitation im missing?
ive included the two blocks of code below.
thanks
kristian
/* the book code */
void randRect( SDL_Surface* screen ) {
/* color components */
Uint8 red, green, blue;
/* color value */
Uint32 color;
/* rectangle */
SDL_Rect rect;
red=rand()%256;
green=rand()%256;
blue=rand()%256;
color=SDL_MapRGB(screen->format,red,green,blue);
/* create a random rectangle */
rect.x=rand()%500;
rect.y=rand()%500;
rect.w=rand()%(500-rect.x);
rect.h=rand()%(500-rect.y);
/* fill the rectangle */
SDL_FillRect(screen,&rect,color);
/* update the screen */
SDL_UpdateRect(screen,0,0,0,0);
}
/* my code */
void AI_MAP::drawMap() {
int unit_width = (SCREEN_WIDTH/COLS) - 2;
int unit_height = (SCREEN_HEIGHT/ROWS) - 2;
tile_colors[0] = SDL_MapRGB( screen->format, rand()%256, rand()%256,
rand()%256 );
tile_colors[1] = SDL_MapRGB( screen->format, rand()%256, rand()%256,
rand()%256 );
for( int i=0; i < ROWS; i++ )
{
for( int j=0;j<COLS;j++ )
{
rect.x = unit_width*i;
rect.y = unit_height*j;
rect.w = (SCREEN_WIDTH/COLS) - 10;
rect.h = (SCREEN_HEIGHT/ROWS) - 10;
/* map_data is a data member of the AI_MAP class that has all
its cells initialised to either 1 or 0 */
SDL_FillRect( screen, &rect, tile_colors[ map_data[i][j] ] );
SDL_UpdateRect( screen,0,0,0,0 );
}
}
}