forked from multimediamike/dreamroq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-dreamroq.c
executable file
·62 lines (52 loc) · 1.32 KB
/
test-dreamroq.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* Dreamroq by Mike Melanson
*
* This is a simple, sample program that helps test the Dreamroq library.
*/
#include <stdio.h>
#include "dreamroqlib.h"
int quit_cb()
{
/* big, fat no-op for command line tool */
return 0;
}
int render_cb(unsigned short *buf, int width, int height, int stride,
int texture_height)
{
static int count = 0;
FILE *out;
char filename[20];
int x, y, pixel;
sprintf(filename, "%04d.pnm", count);
printf("writing frame %d to file %s\n", count, filename);
count++;
out = fopen(filename, "wb");
if (!out)
return ROQ_CLIENT_PROBLEM;
fprintf(out, "P6\n%d %d\n255\n", width, height);
for (y = 0; y < height; y++)
{
for (x = 0; x < width; x++)
{
pixel = *buf++;
fputc(((pixel >> 11) << 3) & 0xFF, out); /* red */
fputc(((pixel >> 5) << 2) & 0xFF, out); /* green */
fputc(((pixel >> 0) << 3) & 0xFF, out); /* blue */
}
buf += (stride - width);
}
fclose(out);
return ROQ_SUCCESS;
}
int main(int argc, char *argv[])
{
int status;
if (argc < 2)
{
printf("USAGE: newroq-cli <file.roq>\n");
return 1;
}
status = dreamroq_play(argv[1], 0, render_cb, 0, quit_cb);
printf("final status = %d\n", status);
return status;
}