remove umbrella sprite on level start
[awish.git] / src / video.c
blob695704f733336a9fecef1744e63a1386bf287fd4
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
5 #include "video.h"
8 ////////////////////////////////////////////////////////////////////////////////
9 SDL_Surface *screen = NULL;
10 Uint32 palette[256]; // converted
11 Uint8 font[256][8];
14 ////////////////////////////////////////////////////////////////////////////////
15 static void quitCleanupCB (void) {
16 //if (TTF_WasInit()) TTF_Quit();
17 SDL_Quit();
21 ////////////////////////////////////////////////////////////////////////////////
22 void sdlInit (void) {
23 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
24 fprintf(stderr, "FATAL: can't set videomode!\n");
25 exit(1);
27 atexit(quitCleanupCB);
29 SDL_WM_SetCaption("Awish", "Awish");
30 SDL_EnableKeyRepeat(200, 25);
31 //SDL_EnableUNICODE(1); // just4fun
32 SDL_EnableUNICODE(0); // just4fun
36 void initVideo (void) {
37 screen = SDL_SetVideoMode(640, 400, 32, SDL_SWSURFACE/*|SDL_DOUBLEBUF*/);
38 if (screen == NULL) {
39 fprintf(stderr, "FATAL: can't set videomode!\n");
40 exit(1);
42 //fprintf(stderr, "BPP: %u\n", screen->format->BytesPerPixel);
46 ////////////////////////////////////////////////////////////////////////////////
47 // create 24bpp surface with color key
48 SDL_Surface *createSurface (int w, int h) {
49 //Uint32 rmask, gmask, bmask/*, amask*/;
50 SDL_Surface *s;
52 if (w < 1 || h < 1) return NULL;
54 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
55 rmask = 0xff000000;
56 gmask = 0x00ff0000;
57 bmask = 0x0000ff00;
58 //amask = 0x000000ff;
59 #else
60 rmask = 0x000000ff;
61 gmask = 0x0000ff00;
62 bmask = 0x00ff0000;
63 //amask = 0xff000000;
64 #endif
65 s = SDL_CreateRGBSurface(SDL_SRCCOLORKEY, w, h, 32, rmask, gmask, bmask, amask);
67 s = SDL_CreateRGBSurface(SDL_SRCCOLORKEY, w, h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
68 if (s != NULL) {
69 SDL_SetColorKey(s, SDL_SRCCOLORKEY, palette[255]);
71 return s;
75 void blitSurfaceEx (SDL_Surface *dests, int destx, int desty, SDL_Surface *srcs, int srcx, int srcy, int srcw, int srch) {
76 SDL_Rect src, dst;
78 if (srcw < 0) srcw = srcs->w;
79 if (srch < 0) srch = srcs->h;
80 src.x = srcx;
81 src.y = srcy;
82 src.w = srcw;
83 src.h = srch;
84 dst.x = destx;
85 dst.y = desty;
86 SDL_BlitSurface(srcs, &src, dests, &dst);
90 ////////////////////////////////////////////////////////////////////////////////
91 void lockSurface (SurfaceLock *lock, SDL_Surface *s) {
92 if (lock) {
93 lock->s = s;
94 lock->needUnlock = 0;
95 if (s != NULL && SDL_MUSTLOCK(s)) {
96 lock->needUnlock = (SDL_LockSurface(s) == 0);
102 void unlockSurface (SurfaceLock *lock) {
103 if (lock && lock->s && lock->needUnlock) {
104 SDL_UnlockSurface(lock->s);
105 lock->needUnlock = 0;
110 ////////////////////////////////////////////////////////////////////////////////
111 // surface must be locked!
112 void drawChar (SDL_Surface *s, char ch, int x, int y, Uint8 clr) {
113 unsigned char c = (unsigned char)(ch);
115 for (int dy = 0; dy < 8; ++dy) {
116 Uint8 b = font[c][dy];
118 for (int dx = 0; dx < 8; ++dx) {
119 if (b&0x80) putPixel2x(s, x+dx, y+dy, clr);
120 b = (b&0x7f)<<1;
126 void drawString (SDL_Surface *s, const char *str, int x, int y, Uint8 clr) {
127 for (; *str; ++str) {
128 drawChar(s, *str, x, y, clr);
129 x += 8;