Commit before breaking everything
[matches/honours.git] / research / transmission_spectroscopy / universesim / src / video.c
1 /*
2  */
3 #include <video.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <zlib.h>
7
8 #define DUMP_FRAMES     0
9
10 #define USE_SDL 1
11 #define USE_ACESS       0
12
13 #if USE_SDL
14 # include <SDL/SDL.h>
15
16 // === GLOBALS ===
17  int    giFrameNum = 0;
18 #if DUMP_FRAMES
19 gzFile  *gVideoFile = NULL;
20 #endif
21 SDL_Surface     *gScreen;
22
23 // === CODE ===
24 void Video_SetResolution(int Width, int Height)
25 {
26         if(!gScreen) {
27                 SDL_Init(SDL_INIT_VIDEO);
28                 atexit(SDL_Quit);
29         }
30         else {
31                 SDL_FreeSurface(gScreen);
32         }
33         
34         gScreen = SDL_SetVideoMode(Width, Height, 32, SDL_DOUBLEBUF);
35         
36         #if DUMP_FRAMES
37         if(gVideoFile)  gzclose(gVideoFile);
38         
39         gVideoFile = gzopen("universe.mv", "wb");
40         gzwrite(gVideoFile, &gScreen->pitch, 2);
41         gzwrite(gVideoFile, &gScreen->h, 2);
42         #endif
43 }
44
45 void Video_SetName(const char *Format, ...)
46 {
47         char    buf[1024];
48         va_list args;
49         va_start(args, Format);
50         vsprintf(buf, Format, args);
51         SDL_WM_SetCaption(buf, "Universe Simulator");
52         va_end(args);
53 }
54
55 void Video_PSet(int X, int Y, uint8_t R, uint8_t G, uint8_t B)
56 {
57         uint8_t *buf = gScreen->pixels;
58         
59         buf[Y*gScreen->pitch + X*4] = B;
60         buf[Y*gScreen->pitch + X*4+1] = G;
61         buf[Y*gScreen->pitch + X*4+2] = R;
62         buf[Y*gScreen->pitch + X*4+3] = 0;
63 }
64
65 void Video_Flip(void)
66 {
67         #if DUMP_FRAMES
68         gzwrite(gVideoFile, gScreen->pixels, gScreen->pitch*gScreen->h);
69         #endif
70         
71         SDL_Flip(gScreen);
72 }
73
74 void *Thread_Create(void *Function, void *Argument)
75 {
76         return SDL_CreateThread(Function, Argument);
77 }
78
79 void Thread_Yield(void)
80 {
81         SDL_Delay(0);
82 }
83         
84
85 #elif USE_ACESS
86 # error "TODO - Acess FB Output"
87 #endif

UCC git Repository :: git.ucc.asn.au