palpic2png.c: improve, make usable with ppic binary files
[rofl0r-openDOW.git] / tests / blittest.c
blob41106bcca222eaac962e6963401f5b9509857602
1 #include "../palpic.h"
2 #include <assert.h>
4 #include <SDL/SDL.h>
5 #pragma RcB2 LINK "-lSDL"
6 #include "../sdl_rgb.h"
7 #include "../vec2f.h"
8 #define VMODE_W 320
9 #define VMODE_H 240
11 #define SCALE 2
13 SDL_Surface *surface;
14 struct vo_desc video;
15 #include "../sprites/map_urban.c"
16 const struct palpic *sprite = &map_urban.header;
18 static void init_video() {
19 SDL_Init(SDL_INIT_VIDEO);
20 surface = SDL_SetVideoMode(VMODE_W, VMODE_H, 32, SDL_RESIZABLE | SDL_HWPALETTE);
21 video.mem = surface->pixels;
22 video.pitch = surface->pitch;
23 video.width = VMODE_W;
24 video.height = VMODE_H;
27 static void update_screen() {
28 SDL_UpdateRect(surface, 0, 0, VMODE_W, VMODE_H);
31 static void clear() {
32 uint_fast16_t x, w = VMODE_W;
33 uint_fast16_t y, h = VMODE_H;
34 sdl_rgb_t *pix, *ptr = pix = (sdl_rgb_t*) surface->pixels;
35 uint_fast32_t pitch = surface->pitch / 4, inc = pitch - VMODE_W;
36 for(y=0;y<h;y++) {
37 for(x=0;x<w;x++) *ptr++ = SRGB(0,0,0);
38 ptr+=inc;
42 static void draw() {
43 clear();
44 blit_sprite(315,240-16, &video, SCALE, sprite, 35*5, 0);
45 update_screen();
46 SDL_Delay(20);
49 int main() {
50 init_video();
51 while(1) draw();