|
从 www.libsdl.org上抄的一段例子,在X window下运行可以正常退出,但在控制台下运行,程序执行完毕后就死机,怎么会这样?
系统是:Fedora Core 4
[code:1]
#include <SDL.h>
void DrawPixel(SDL_Surface *Surface, int x, int y,Uint8 R, Uint8 G,Uint8 B)
{
Uint32 color = SDL_MapRGB(Surface->format, R, G, B);
Uint8 * bufp= (Uint8 *)Surface->pixels + y*Surface->pitch + x*Surface->format->BytesPerPixel;
switch (Surface->format->BytesPerPixel) {
case 4:
bufp[3] = color >> 24;
case 3:
bufp[2] = color >> 16;
case 2:
bufp[1] = color >> 8;
case 1:
bufp[0] = color;
}
return;
}
int main(){
SDL_Surface *display;
Uint32 x,y,i;
SDL_Init(SDL_INIT_VIDEO);
display=SDL_SetVideoMode( 320, 320, 32, SDL_HWSURFACE );
for(i=0;i!=255;i++){
if(SDL_MUSTLOCK(display))
SDL_LockSurface(display);
for(y=0;y<(display->h);y++){
for(x=0;x<(display->w);x++){
DrawPixel(display, x, y, x+i, y+i, i);
}
}
if ( SDL_MUSTLOCK(display) )
SDL_UnlockSurface(display);
SDL_UpdateRect(display, 0, 0, display->w, display->h);
}
SDL_UpdateRect(display, 0, 0, display->w, display->h);
SDL_Delay(3000);
return 0;
}
[/code:1] |
|