Archived
1
0
Fork 0
This repository has been archived on 2019-12-21. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
cscape/sdl.c

52 lines
1.1 KiB
C
Raw Permalink Normal View History

2002-05-20 12:40:35 +00:00
/* $Revision$ */
2002-05-20 11:07:54 +00:00
#include <SDL.h>
2002-05-20 12:40:35 +00:00
#include <stdlib.h>
2002-05-20 16:45:17 +00:00
#include "sdl.h"
2002-05-20 11:07:54 +00:00
SDL_Surface* sdl_init() {
2002-05-20 16:07:37 +00:00
SDL_Surface* screen;
2002-05-20 11:07:54 +00:00
2002-05-20 16:45:17 +00:00
screen = SDL_SetVideoMode(WIDTH, HEIGHT, 8, SDL_SWSURFACE);
2002-05-20 11:07:54 +00:00
if(screen == NULL) {
fprintf(stderr, "Unable to set video mode: %s\n",
SDL_GetError());
exit(1);
}
return screen;
}
void sdl_putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
{
int bpp = surface->format->BytesPerPixel;
/* Here p is the address to the pixel we want to set */
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
switch(bpp) {
case 1:
*p = pixel;
break;
case 2:
*(Uint16 *)p = pixel;
break;
case 3:
if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
p[0] = (pixel >> 16) & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = pixel & 0xff;
} else {
p[0] = pixel & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = (pixel >> 16) & 0xff;
}
break;
case 4:
*(Uint32 *)p = pixel;
break;
}
}