|
楼主 |
发表于 2004-7-25 10:20:30
|
显示全部楼层
这是我改过的程序
#include <stdlib.h>
#include <SDL.h>
void putpixel(SDL_Surface *surface,int x,int y,Uint32 color);
SDL_Surface *screen;
int x;
int y;
Uint32 color;
SDL_Surface *surface;
SDL_Surface *background;
main()
{ int i;
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, "无法初始化SDL: %s\n", SDL_GetError());
exit(1);}
screen=SDL_SetVideoMode(640,480,16,SDL_SWSURFACE);
/*if(screen==NULL){
fprintf(stderr,"Can't set mode 640x480:%s\n",SDL_GetError());
exit(1);*/
color=SDL_MapRGB(background->format,200,200,200);
for(i=0;i<10;i++){putpixel(surface, x,y,color);
x+=2;
y+=2;}}
void putpixel(SDL_Surface *surface,int x,int y,Uint32 color)
{
Uint16 *bufp;
if(SDL_MUSTLOCK(surface)){
if(SDL_LockSurface(surface)<0)return;
}
bufp=(Uint16 *)surface->pixels+y*surface->pitch/2+x;
*bufp=color;
SDL_UpdateRect(surface,x,y,1,1);
if(SDL_MUSTLOCK(surface))
{SDL_UnlockSurface(surface);}} |
|