Date: Fri, 15 Aug 2003 09:13:59 +0300
From: "Mike Gorchak" Subject: Patches for tests and QNX6 1) graywin - added support for the gray gradient in the 15/16 bpp modes. Added SDL_VIDEOEXPOSE event handling. 2) testalpha - added support for the gray gradient in the 15/16 bpp modes. 3) testbitmap - added support for the gray gradient in the 8/15/16 bpp modes. --HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40692
This commit is contained in:
parent
dc54e92e13
commit
0cc5681acd
3 changed files with 137 additions and 37 deletions
|
@ -20,6 +20,7 @@ void DrawBox(SDL_Surface *screen, int X, int Y, int width, int height)
|
||||||
static unsigned int seeded = 0;
|
static unsigned int seeded = 0;
|
||||||
SDL_Rect area;
|
SDL_Rect area;
|
||||||
Uint32 color;
|
Uint32 color;
|
||||||
|
Uint32 randc;
|
||||||
|
|
||||||
/* Seed the random number generator */
|
/* Seed the random number generator */
|
||||||
if ( seeded == 0 ) {
|
if ( seeded == 0 ) {
|
||||||
|
@ -32,7 +33,16 @@ void DrawBox(SDL_Surface *screen, int X, int Y, int width, int height)
|
||||||
area.h = (rand()%height);
|
area.h = (rand()%height);
|
||||||
area.x = X-(area.w/2);
|
area.x = X-(area.w/2);
|
||||||
area.y = Y-(area.h/2);
|
area.y = Y-(area.h/2);
|
||||||
color = (rand()%NUM_COLORS);
|
randc = (rand()%NUM_COLORS);
|
||||||
|
|
||||||
|
if (screen->format->BytesPerPixel==1)
|
||||||
|
{
|
||||||
|
color = randc;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
color = SDL_MapRGB(screen->format, randc, randc, randc);
|
||||||
|
}
|
||||||
|
|
||||||
/* Do it! */
|
/* Do it! */
|
||||||
SDL_FillRect(screen, &area, color);
|
SDL_FillRect(screen, &area, color);
|
||||||
|
@ -43,12 +53,60 @@ void DrawBox(SDL_Surface *screen, int X, int Y, int width, int height)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DrawBackground(SDL_Surface *screen)
|
||||||
|
{
|
||||||
|
int i, j, k;
|
||||||
|
Uint8 *buffer;
|
||||||
|
Uint16 *buffer16;
|
||||||
|
Uint16 color;
|
||||||
|
Uint8 gradient;
|
||||||
|
|
||||||
|
/* Set the surface pixels and refresh! */
|
||||||
|
/* Use two loops in case the surface is double-buffered (both sides) */
|
||||||
|
|
||||||
|
for ( j=0; j<2; ++j ) {
|
||||||
|
if ( SDL_LockSurface(screen) < 0 ) {
|
||||||
|
fprintf(stderr, "Couldn't lock display surface: %s\n",
|
||||||
|
SDL_GetError());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
buffer = (Uint8 *)screen->pixels;
|
||||||
|
|
||||||
|
if (screen->format->BytesPerPixel!=2) {
|
||||||
|
for ( i=0; i<screen->h; ++i ) {
|
||||||
|
memset(buffer,(i*(NUM_COLORS-1))/screen->h, screen->w * screen->format->BytesPerPixel);
|
||||||
|
buffer += screen->pitch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for ( i=0; i<screen->h; ++i ) {
|
||||||
|
gradient=((i*(NUM_COLORS-1))/screen->h);
|
||||||
|
color = SDL_MapRGB(screen->format, gradient, gradient, gradient);
|
||||||
|
buffer16=(Uint16*)buffer;
|
||||||
|
for (k=0; k<screen->w; k++)
|
||||||
|
{
|
||||||
|
*(buffer16+k)=color;
|
||||||
|
}
|
||||||
|
buffer += screen->pitch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_UnlockSurface(screen);
|
||||||
|
if ( screen->flags & SDL_DOUBLEBUF ) {
|
||||||
|
SDL_Flip(screen);
|
||||||
|
} else {
|
||||||
|
SDL_UpdateRect(screen, 0, 0, 0, 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SDL_Surface *CreateScreen(Uint16 w, Uint16 h, Uint8 bpp, Uint32 flags)
|
SDL_Surface *CreateScreen(Uint16 w, Uint16 h, Uint8 bpp, Uint32 flags)
|
||||||
{
|
{
|
||||||
SDL_Surface *screen;
|
SDL_Surface *screen;
|
||||||
int i;
|
int i;
|
||||||
SDL_Color palette[NUM_COLORS];
|
SDL_Color palette[NUM_COLORS];
|
||||||
Uint8 *buffer;
|
|
||||||
|
|
||||||
/* Set the video mode */
|
/* Set the video mode */
|
||||||
screen = SDL_SetVideoMode(w, h, bpp, flags);
|
screen = SDL_SetVideoMode(w, h, bpp, flags);
|
||||||
|
@ -60,6 +118,7 @@ SDL_Surface *CreateScreen(Uint16 w, Uint16 h, Uint8 bpp, Uint32 flags)
|
||||||
fprintf(stderr, "Screen is in %s mode\n",
|
fprintf(stderr, "Screen is in %s mode\n",
|
||||||
(screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed");
|
(screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed");
|
||||||
|
|
||||||
|
if (bpp==8) {
|
||||||
/* Set a gray colormap, reverse order from white to black */
|
/* Set a gray colormap, reverse order from white to black */
|
||||||
for ( i=0; i<NUM_COLORS; ++i ) {
|
for ( i=0; i<NUM_COLORS; ++i ) {
|
||||||
palette[i].r = (NUM_COLORS-1)-i * (256 / NUM_COLORS);
|
palette[i].r = (NUM_COLORS-1)-i * (256 / NUM_COLORS);
|
||||||
|
@ -67,26 +126,6 @@ SDL_Surface *CreateScreen(Uint16 w, Uint16 h, Uint8 bpp, Uint32 flags)
|
||||||
palette[i].b = (NUM_COLORS-1)-i * (256 / NUM_COLORS);
|
palette[i].b = (NUM_COLORS-1)-i * (256 / NUM_COLORS);
|
||||||
}
|
}
|
||||||
SDL_SetColors(screen, palette, 0, NUM_COLORS);
|
SDL_SetColors(screen, palette, 0, NUM_COLORS);
|
||||||
|
|
||||||
/* Set the surface pixels and refresh! */
|
|
||||||
/* Use two loops in case the surface is double-buffered (both sides) */
|
|
||||||
for ( i=0; i<2; ++i ) {
|
|
||||||
if ( SDL_LockSurface(screen) < 0 ) {
|
|
||||||
fprintf(stderr, "Couldn't lock display surface: %s\n",
|
|
||||||
SDL_GetError());
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
buffer = (Uint8 *)screen->pixels;
|
|
||||||
for ( i=0; i<screen->h; ++i ) {
|
|
||||||
memset(buffer,(i*(NUM_COLORS-1))/screen->h, screen->w * screen->format->BytesPerPixel);
|
|
||||||
buffer += screen->pitch;
|
|
||||||
}
|
|
||||||
SDL_UnlockSurface(screen);
|
|
||||||
if ( screen->flags & SDL_DOUBLEBUF ) {
|
|
||||||
SDL_Flip(screen);
|
|
||||||
} else {
|
|
||||||
SDL_UpdateRect(screen, 0, 0, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return(screen);
|
return(screen);
|
||||||
|
@ -152,6 +191,8 @@ int main(int argc, char *argv[])
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DrawBackground(screen);
|
||||||
|
|
||||||
/* Wait for a keystroke */
|
/* Wait for a keystroke */
|
||||||
done = 0;
|
done = 0;
|
||||||
while ( !done && SDL_WaitEvent(&event) ) {
|
while ( !done && SDL_WaitEvent(&event) ) {
|
||||||
|
@ -182,12 +223,16 @@ int main(int argc, char *argv[])
|
||||||
"Couldn't toggle fullscreen mode\n");
|
"Couldn't toggle fullscreen mode\n");
|
||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
|
DrawBackground(screen);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* Any other key quits the application... */
|
/* Any other key quits the application... */
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
done = 1;
|
done = 1;
|
||||||
break;
|
break;
|
||||||
|
case SDL_VIDEOEXPOSE:
|
||||||
|
DrawBackground(screen);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -279,11 +279,15 @@ int main(int argc, char *argv[])
|
||||||
Uint8 video_bpp;
|
Uint8 video_bpp;
|
||||||
Uint32 videoflags;
|
Uint32 videoflags;
|
||||||
Uint8 *buffer;
|
Uint8 *buffer;
|
||||||
int i, done;
|
int i, k, done;
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
SDL_Surface *light;
|
SDL_Surface *light;
|
||||||
int mouse_pressed;
|
int mouse_pressed;
|
||||||
Uint32 ticks, lastticks;
|
Uint32 ticks, lastticks;
|
||||||
|
Uint16 *buffer16;
|
||||||
|
Uint16 color;
|
||||||
|
Uint8 gradient;
|
||||||
|
|
||||||
|
|
||||||
/* Initialize SDL */
|
/* Initialize SDL */
|
||||||
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
|
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
|
||||||
|
@ -298,12 +302,17 @@ int main(int argc, char *argv[])
|
||||||
video_bpp = info->vfmt->BitsPerPixel;
|
video_bpp = info->vfmt->BitsPerPixel;
|
||||||
} else {
|
} else {
|
||||||
video_bpp = 16;
|
video_bpp = 16;
|
||||||
|
fprintf(stderr, "forced 16 bpp mode\n");
|
||||||
}
|
}
|
||||||
videoflags = SDL_SWSURFACE;
|
videoflags = SDL_SWSURFACE;
|
||||||
while ( argc > 1 ) {
|
while ( argc > 1 ) {
|
||||||
--argc;
|
--argc;
|
||||||
if ( strcmp(argv[argc-1], "-bpp") == 0 ) {
|
if ( strcmp(argv[argc-1], "-bpp") == 0 ) {
|
||||||
video_bpp = atoi(argv[argc]);
|
video_bpp = atoi(argv[argc]);
|
||||||
|
if (video_bpp<=8) {
|
||||||
|
video_bpp=16;
|
||||||
|
fprintf(stderr, "forced 16 bpp mode\n");
|
||||||
|
}
|
||||||
--argc;
|
--argc;
|
||||||
} else
|
} else
|
||||||
if ( strcmp(argv[argc], "-hw") == 0 ) {
|
if ( strcmp(argv[argc], "-hw") == 0 ) {
|
||||||
|
@ -336,10 +345,26 @@ int main(int argc, char *argv[])
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
buffer=(Uint8 *)screen->pixels;
|
buffer=(Uint8 *)screen->pixels;
|
||||||
|
if (screen->format->BytesPerPixel!=2) {
|
||||||
for ( i=0; i<screen->h; ++i ) {
|
for ( i=0; i<screen->h; ++i ) {
|
||||||
memset(buffer,(i*255)/screen->h, screen->pitch);
|
memset(buffer,(i*255)/screen->h, screen->pitch);
|
||||||
buffer += screen->pitch;
|
buffer += screen->pitch;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for ( i=0; i<screen->h; ++i ) {
|
||||||
|
gradient=((i*255)/screen->h);
|
||||||
|
color = SDL_MapRGB(screen->format, gradient, gradient, gradient);
|
||||||
|
buffer16=(Uint16*)buffer;
|
||||||
|
for (k=0; k<screen->w; k++)
|
||||||
|
{
|
||||||
|
*(buffer16+k)=color;
|
||||||
|
}
|
||||||
|
buffer += screen->pitch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SDL_UnlockSurface(screen);
|
SDL_UnlockSurface(screen);
|
||||||
SDL_UpdateRect(screen, 0, 0, 0, 0);
|
SDL_UpdateRect(screen, 0, 0, 0, 0);
|
||||||
|
|
||||||
|
|
|
@ -50,8 +50,13 @@ int main(int argc, char *argv[])
|
||||||
Uint8 video_bpp;
|
Uint8 video_bpp;
|
||||||
Uint32 videoflags;
|
Uint32 videoflags;
|
||||||
Uint8 *buffer;
|
Uint8 *buffer;
|
||||||
int i, done;
|
int i, k, done;
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
|
Uint16 *buffer16;
|
||||||
|
Uint16 color;
|
||||||
|
Uint8 gradient;
|
||||||
|
SDL_Color palette[256];
|
||||||
|
|
||||||
|
|
||||||
/* Initialize SDL */
|
/* Initialize SDL */
|
||||||
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
|
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
|
||||||
|
@ -91,6 +96,16 @@ int main(int argc, char *argv[])
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (video_bpp==8) {
|
||||||
|
/* Set a gray colormap, reverse order from white to black */
|
||||||
|
for ( i=0; i<256; ++i ) {
|
||||||
|
palette[i].r = 255-i;
|
||||||
|
palette[i].g = 255-i;
|
||||||
|
palette[i].b = 255-i;
|
||||||
|
}
|
||||||
|
SDL_SetColors(screen, palette, 0, 256);
|
||||||
|
}
|
||||||
|
|
||||||
/* Set the surface pixels and refresh! */
|
/* Set the surface pixels and refresh! */
|
||||||
if ( SDL_LockSurface(screen) < 0 ) {
|
if ( SDL_LockSurface(screen) < 0 ) {
|
||||||
fprintf(stderr, "Couldn't lock the display surface: %s\n",
|
fprintf(stderr, "Couldn't lock the display surface: %s\n",
|
||||||
|
@ -98,10 +113,25 @@ int main(int argc, char *argv[])
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
buffer=(Uint8 *)screen->pixels;
|
buffer=(Uint8 *)screen->pixels;
|
||||||
|
if (screen->format->BytesPerPixel!=2) {
|
||||||
for ( i=0; i<screen->h; ++i ) {
|
for ( i=0; i<screen->h; ++i ) {
|
||||||
memset(buffer,(i*255)/screen->h, screen->pitch);
|
memset(buffer,(i*255)/screen->h, screen->pitch);
|
||||||
buffer += screen->pitch;
|
buffer += screen->pitch;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for ( i=0; i<screen->h; ++i ) {
|
||||||
|
gradient=((i*255)/screen->h);
|
||||||
|
color = SDL_MapRGB(screen->format, gradient, gradient, gradient);
|
||||||
|
buffer16=(Uint16*)buffer;
|
||||||
|
for (k=0; k<screen->w; k++)
|
||||||
|
{
|
||||||
|
*(buffer16+k)=color;
|
||||||
|
}
|
||||||
|
buffer += screen->pitch;
|
||||||
|
}
|
||||||
|
}
|
||||||
SDL_UnlockSurface(screen);
|
SDL_UnlockSurface(screen);
|
||||||
SDL_UpdateRect(screen, 0, 0, 0, 0);
|
SDL_UpdateRect(screen, 0, 0, 0, 0);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue