static void SDL_PixelNolock(SDL_Surface* surface, int x, int y, Uint32 color) { int bpp = surface->format->BytesPerPixel; Uint8* p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
static void SDL_PixelColor(SDL_Surface* surface, int x, int y, Uint32 color) { if (SDL_MUSTLOCK(surface)) { if (SDL_LockSurface(surface) < 0) { return; } }
SDL_PixelNolock(surface, x, y, color);
if (SDL_MUSTLOCK(surface)) { SDL_UnlockSurface(surface); } }
void SDL_Pixel(SDL_Surface* surface, int x, int y, Uint32 color) { SDL_PixelColor(surface, x, y, color); }
// somebody must implement these functions extern int graphic_init(void); extern void pixel(int x, int y, uint32 color); extern void myrefresh(); // if you are using color index to show color, do it extern void init_color(uint32 palette[], int len);
///////////////////////////////////////////////////////////////// const int WINDOW_WIDTH = 480; const int WINDOW_HEIGHT = 320; const char* WINDOW_TITLE = "SDL Hello World -- by Late Lee";
// Alpha blending doesn't work well at 8-bit color info = SDL_GetVideoInfo(); if ( info->vfmt->BitsPerPixel > 8 ) { video_bpp = info->vfmt->BitsPerPixel; } else { video_bpp = 16; } videoflags = SDL_SWSURFACE | SDL_DOUBLEBUF;
// Set 640x480 video mode if ( (*screen=SDL_SetVideoMode(WINDOW_WIDTH,WINDOW_HEIGHT,video_bpp,videoflags)) == NULL ) { fprintf(stderr, "Couldn't set %ix%i video mode: %s\n",640,480,SDL_GetError()); return 2; }