annotate vptest.c @ 253:61eb5fb4a5e6

Fix a silly rendering issue.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 09 Oct 2012 21:11:07 +0300
parents 4b4123143b9e
children 370521e7a960
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #include "dmlib.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 #include "dmargs.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 #include "dmres.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 #include "dmimage.h"
62
daeb5d4f6bad Do include "dmtext.h" where necessary.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
5 #include "dmtext.h"
241
3bff024a91be Move 3D line/sprite renderer to separate module.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
6 #include "dmq3d.h"
3bff024a91be Move 3D line/sprite renderer to separate module.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
7 #include "dmvecmat.h"
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #include <math.h>
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #define DM_COLORS (256)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 char *optFontFile = "font.ttf",
248
e6303e0c62cb Radial blur stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
13 *optBitmapFilename = "blurri.png";
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 BOOL optBenchmark = FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 int optVFlags = SDL_SWSURFACE | SDL_HWPALETTE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 int optScrWidth = 640, optScrHeight = 480, optFontSize = 20, optScrDepth = 32;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 int optBenchmarkLen = 20;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 DMOptArg optList[] = {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 { 0, '?', "help", "Show this help", OPT_NONE },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 { 2, 'v', "verbose", "Be more verbose", OPT_NONE },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 { 3, 'f', "full", "Fullscreen", OPT_NONE },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 { 4, 'h', "hw", "Use SDL hardware surface", OPT_NONE },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 { 5, 's', "size", "Initial window size/resolution -s 640x480", OPT_ARGREQ },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 { 6, 'd', "depth", "Color depth of mode/window in bits (8/15/16/32)", OPT_ARGREQ },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 { 7, 'b', "bench", "Run in benchmark mode", OPT_NONE },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 };
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 const int optListN = sizeof(optList) / sizeof(optList[0]);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 void argShowHelp()
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 dmArgsPrintHelp(stdout, optList, optListN);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 switch (optN) {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 case 0:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 argShowHelp();
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 exit(0);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 case 2:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 dmVerbosity++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 case 3:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 optVFlags |= SDL_FULLSCREEN;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 case 6:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 if (optArg)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 optScrDepth = atoi(optArg);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 case 5:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 int w, h;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 if (sscanf(optArg, "%dx%d", &w, &h) == 2)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 if (w < 320 || h < 200 || w > 3200 || h > 3200)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 dmError("Invalid width or height: %d x %d\n", w, h);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 return FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 optScrWidth = w;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 optScrHeight = h;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 dmError("Invalid size argument '%s'.\n", optArg);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 return FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 case 7:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 optBenchmark = TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 default:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 dmError("Unknown option '%s'.\n", currArg);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 return FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 return TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 void DM_MakePalette(SDL_Surface *scr)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 SDL_Color pal[DM_COLORS];
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 int n;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 for (n = 0; n < 256; n++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 pal[n].r = n;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 pal[n].g = n;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 pal[n].b = n;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 SDL_SetColors(scr, pal, 0, DM_COLORS);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 void DM_PrintRect(FILE *f, SDL_Rect *r)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 fprintf(f, "SDL_Rect <%d, %d : %d, %d>\n",
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 r->x, r->y, r->w, r->h);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 BOOL DM_InitializeVideo(SDL_Surface **screen)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 *screen = SDL_SetVideoMode(optScrWidth, optScrHeight, optScrDepth, optVFlags | SDL_RESIZABLE);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 if (*screen == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError());
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 return FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 return TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126
247
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
127 #define DM_RADIAL_BLUR(YC, XC) \
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
128 DMVector p1 = { xc, yc, 0, 0 }, p2 = { cx, cy, 0, 0 }, v; \
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
129 dm_vector_sub_r(&v, &p2, &p1); \
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
130 dm_vector_scale(&v, scale); \
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
131 dm_vector_add(&v, &p1); \
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
132 if (v.y YC || v.x XC) continue; \
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
133 DMRGBA32 *dp = pix + xc, \
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
134 *q = ((DMRGBA32 *)img->pixels) + ((int)(v.y) * pitch) + (int)v.x; \
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
135 dp->r = (q->r + dp->r) / 2; \
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
136 dp->g = (q->g + dp->g) / 2; \
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
137 dp->b = (q->b + dp->b) / 2;
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
138
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
139 /*
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
140 asm("movq %2, %%xmm1\n" \
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
141 "movq %1, %%xmm2\n" \
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
142 "paddusb %%xmm2, %%xmm1\n" \
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
143 "movq %%xmm1, %0\n" \
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
144 : "=m" (*c) \
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
145 : "m" (*c), "m" (*px) \
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
146 : "memory", "%xmm1", "%xmm2");
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
147 */
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
148
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
149 const Uint64 qpmask[2] = { 0xffffffff, 0 };
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
150 const Uint64 *qmask = qpmask;
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
151
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
152
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
153 void dmRadialBlur(SDL_Surface *img, int cx, int cy, DMFloat scale)
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
154 {
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
155 int pitch = img->pitch / sizeof(DMRGBA32);
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
156 int xc, yc;
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
157
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
158 for (yc = cy; yc >= 0; yc--)
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
159 {
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
160 DMRGBA32 *pix = ((DMRGBA32 *)img->pixels) + yc * pitch;
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
161 for (xc = cx + 1; xc < img->w; xc++)
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
162 {
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
163 DM_RADIAL_BLUR(< 0, >= img->w)
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
164 }
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
165 }
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
166
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
167 for (yc = cy; yc >= 0; yc--)
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
168 {
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
169 DMRGBA32 *pix = ((DMRGBA32 *)img->pixels) + yc * pitch;
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
170 for (xc = cx; xc > 0; xc--)
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
171 {
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
172 DM_RADIAL_BLUR(< 0, < 0)
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
173 }
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
174 }
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
175
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
176 for (yc = cy + 1; yc < img->h; yc++)
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
177 {
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
178 DMRGBA32 *pix = ((DMRGBA32 *)img->pixels) + yc * pitch;
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
179 for (xc = cx; xc > 0; xc--)
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
180 {
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
181 DM_RADIAL_BLUR(>= img->h, < 0)
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
182 }
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
183 }
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
184
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
185 for (yc = cy + 1; yc < img->h; yc++)
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
186 {
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
187 DMRGBA32 *pix = ((DMRGBA32 *)img->pixels) + yc * pitch;
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
188 for (xc = cx + 1; xc < img->w; xc++)
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
189 {
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
190 DM_RADIAL_BLUR(>= img->h, >= img->w)
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
191 }
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
192 }
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
193 }
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
194
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
195
cfde1deedd62 Add radial blur function.
Matti Hamalainen <ccr@tnsp.org>
parents: 245
diff changeset
196
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 int main(int argc, char *argv[])
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 {
248
e6303e0c62cb Radial blur stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
199 SDL_Surface *screen = NULL, *bmap = NULL, *fbmap = NULL, *screen2 = NULL;
238
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
200 SDL_Color fontcol = { 255, 155, 155, 0 };
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
201 SDL_Event event;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 TTF_Font *font = NULL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 int mouseX, mouseY, bx, by;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 BOOL initSDL = FALSE, initTTF = FALSE, exitFlag;
245
eed8eed58f82 Changes in the 3d loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 241
diff changeset
205 DM3DLineSpriteModel *model;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 dmVerbosity = 5;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 if (!dmArgsProcess(argc, argv, optList, optListN,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 argHandleOpt, NULL, FALSE))
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 exit(1);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 dmError("Could not initialize SDL: %s\n", SDL_GetError());
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 goto error_exit;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 initSDL = TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 if (TTF_Init() < 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 dmError("Could not initialize FreeType/TTF: %s\n", SDL_GetError());
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 goto error_exit;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 initTTF = TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 font = TTF_OpenFont(optFontFile, optFontSize);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 if (font == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 dmError("Could not load TTF font '%s' (%d): %s\n",
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 optFontFile, optFontSize, SDL_GetError());
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 goto error_exit;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 TTF_SetFontStyle(font, TTF_STYLE_NORMAL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235
77
c6cdaa675801 Add the file mode parameter to dmf_create_stdio() calls, and throw in some
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
236 DMResource *res = dmf_create_stdio(optBitmapFilename, "rb");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 if (res == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 dmError("Could not open resource file '%s'.\n", optBitmapFilename);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 goto error_exit;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 bmap = dmLoadImage(res);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 dmf_close(res);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 if (bmap == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 dmError("Could not load image file '%s'.\n", optBitmapFilename);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 goto error_exit;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 }
238
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
249
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
250 res = dmf_create_stdio("trans6x6.png", "rb");
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
251 if (res == NULL)
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
252 {
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
253 dmError("Could not open resource file '%s'.\n", optBitmapFilename);
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
254 goto error_exit;
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
255 }
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
256 fbmap = dmLoadImage(res);
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
257 dmf_close(res);
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
258 if (fbmap == NULL)
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
259 {
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
260 dmError("Could not load image file '%s'.\n", optBitmapFilename);
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
261 goto error_exit;
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
262 }
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
263
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
264
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
265 res = dmf_create_stdio("mole.3d", "r");
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
266 if (res == NULL)
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
267 {
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
268 dmError("Could not open resource file '%s'.\n", optBitmapFilename);
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
269 goto error_exit;
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
270 }
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
271 dmRead3DLineSpriteModel(res, &model);
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
272 dmf_close(res);
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
273
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275 if (optBenchmark)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 screen = SDL_CreateRGBSurface(SDL_SWSURFACE, optScrWidth, optScrHeight, optScrDepth, 0, 0, 0, 0);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 if (screen == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 dmError("Could not create screen surface.\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 goto error_exit;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 dmMsg(0, "Benchmark mode, not opening window.\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288 if (!DM_InitializeVideo(&screen))
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 goto error_exit;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 SDL_WM_SetCaption("Halleluja", "DMT");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293
248
e6303e0c62cb Radial blur stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
294 screen2 = SDL_CreateRGBSurface(SDL_SWSURFACE, optScrWidth, optScrHeight, optScrDepth, 0, 0, 0, 0);
23
f2f6963080bd Add test for line drawing.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
295 Uint32 lcol = dmMapRGB(screen, 255,255,255);
f2f6963080bd Add test for line drawing.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
296
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 int numFrames = 0, startTime = SDL_GetTicks(), endTime = 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 exitFlag = FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300 if (optBenchmark)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 dmMsg(0, "Starting benchmark, running for %d seconds.\n", optBenchmarkLen);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303 while (!exitFlag)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305 if (!optBenchmark)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307 while (SDL_PollEvent(&event))
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308 switch (event.type)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 case SDL_KEYDOWN:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311 switch (event.key.keysym.sym)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313 case SDLK_ESCAPE: exitFlag = TRUE; break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315 default:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 case SDL_VIDEORESIZE:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 optScrWidth = event.resize.w;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 optScrHeight = event.resize.h;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325 if (!DM_InitializeVideo(&screen))
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 goto error_exit;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330 case SDL_VIDEOEXPOSE:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 case SDL_QUIT:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334 exit(0);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 SDL_GetMouseState(&mouseX, &mouseY);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 bx = 300 - ((DMFloat) mouseX * 500.0f ) / (DMFloat) optScrWidth;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339 by = 300 - ((DMFloat) mouseY * 500.0f ) / (DMFloat) optScrHeight;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 }
11
eb0072860fb0 Improve benchmarking.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
341 else
eb0072860fb0 Improve benchmarking.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
342 {
eb0072860fb0 Improve benchmarking.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
343 bx = 0;
eb0072860fb0 Improve benchmarking.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
344 by = 0;
eb0072860fb0 Improve benchmarking.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
345 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347 if (!optBenchmark && SDL_MUSTLOCK(screen) != 0 && SDL_LockSurface(screen) != 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349 dmError("Can't lock surface.\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350 goto error_exit;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
352
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 dmClearSurface(screen, 0);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355
11
eb0072860fb0 Improve benchmarking.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
356 float f = SDL_GetTicks() / 150.0f,
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357 qw2 = (float) 132.0 * (1.0 + sin(f) * 0.1),
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 qh2 = (float) 132.0 * (1.0 + sin(f) * 0.1);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359
241
3bff024a91be Move 3D line/sprite renderer to separate module.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
360 #if 1
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 dmScaledBlitSurfaceAny(bmap, bx-qw2, by-qh2, bmap->w+qw2, bmap->h+qh2, screen,
248
e6303e0c62cb Radial blur stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
362 DMD_TRANSPARENT
e6303e0c62cb Radial blur stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
363 // DMD_SATURATE
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364 // DMD_NONE
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 );
241
3bff024a91be Move 3D line/sprite renderer to separate module.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
366 #endif
3bff024a91be Move 3D line/sprite renderer to separate module.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
367 #if 0
3bff024a91be Move 3D line/sprite renderer to separate module.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
368 float qw = (float) 32.0 * (1.0 + sin(f) * 0.1),
3bff024a91be Move 3D line/sprite renderer to separate module.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
369 qh = (float) 32.0 * (1.0 + sin(f) * 0.1),
20
6b0ba6d062bb Moar testing!
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
370 dmScaledBlitSurface32to32TransparentGA(bmap, bx*2-qw, by*2-qh, bmap->w+qw, bmap->h+qh, screen,
6b0ba6d062bb Moar testing!
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
371 128 + sin(f*0.1) * 120.0f);
241
3bff024a91be Move 3D line/sprite renderer to separate module.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
372 #endif
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373
241
3bff024a91be Move 3D line/sprite renderer to separate module.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
374 #if 1
238
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
375 DMVector pos;
252
4b4123143b9e Adjust default distance.
Matti Hamalainen <ccr@tnsp.org>
parents: 248
diff changeset
376 pos.x = 0;
4b4123143b9e Adjust default distance.
Matti Hamalainen <ccr@tnsp.org>
parents: 248
diff changeset
377 pos.y = 0;
253
61eb5fb4a5e6 Fix a silly rendering issue.
Matti Hamalainen <ccr@tnsp.org>
parents: 252
diff changeset
378 pos.z = 800;
238
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
379
241
3bff024a91be Move 3D line/sprite renderer to separate module.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
380 DMMatrix mat;
3bff024a91be Move 3D line/sprite renderer to separate module.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
381 // dm_matrix_rot_a(&mat, f*0.1, 0, (3.1415926535f * 2.0f * ((DMFloat) mouseX + (DMFloat) mouseY) ) / 500.0f);
253
61eb5fb4a5e6 Fix a silly rendering issue.
Matti Hamalainen <ccr@tnsp.org>
parents: 252
diff changeset
382 dm_matrix_rot_a(&mat, f*0.1, f*0.1, f*0.1);
241
3bff024a91be Move 3D line/sprite renderer to separate module.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
383
245
eed8eed58f82 Changes in the 3d loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 241
diff changeset
384 dmDraw3DLineSpriteModel(screen, model, &pos, &mat, fbmap, lcol);
241
3bff024a91be Move 3D line/sprite renderer to separate module.
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
385 #endif
238
9643c517967d Beginnings of a lines + sprites "3D" "model" renderer.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
386
248
e6303e0c62cb Radial blur stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
387 #if 0
e6303e0c62cb Radial blur stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
388 int np;
e6303e0c62cb Radial blur stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
389 dmClearSurface(screen2, 0);
e6303e0c62cb Radial blur stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
390 for (np = 1; np <= 4; np++)
e6303e0c62cb Radial blur stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
391 {
e6303e0c62cb Radial blur stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
392 float n = ((np + 1) * (np + 1) * np) * 0.6;
e6303e0c62cb Radial blur stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
393 dmScaledBlitSurface32to32TransparentGA(screen, -n, -n, screen->w + n*2.0f, screen->h + n*2.0f, screen2,
e6303e0c62cb Radial blur stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
394 200 - np * 5
e6303e0c62cb Radial blur stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
395 );
e6303e0c62cb Radial blur stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
396 dmDirectBlitSurface(screen2, screen);
e6303e0c62cb Radial blur stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
397 }
e6303e0c62cb Radial blur stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
398
e6303e0c62cb Radial blur stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
399 dmDraw3DLineSpriteModel(screen, &model, &pos, &mat, fbmap, lcol);
e6303e0c62cb Radial blur stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
400
e6303e0c62cb Radial blur stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
401 dmRadialBlur(screen, 320, 240, 0.010);
e6303e0c62cb Radial blur stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
402 dmRadialBlur(screen, 325, 245, 0.016);
e6303e0c62cb Radial blur stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
403 #endif
23
f2f6963080bd Add test for line drawing.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
404
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405 if (!optBenchmark)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
407 dmDrawTTFText(screen, font, fontcol, 0, 0, "%3.1f FPS",
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
408 (float) (numFrames * 1000.0f) / (float) (endTime - startTime));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
409
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
410 if (SDL_MUSTLOCK(screen) != 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
411 SDL_UnlockSurface(screen);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
412
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413 SDL_Flip(screen);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
414 SDL_Delay(25);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
415 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417 endTime = SDL_GetTicks();
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418 numFrames++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420 if (optBenchmark)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422 if (endTime - startTime > optBenchmarkLen * 1000)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423 exitFlag = TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427 // Print benchmark results
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
428 dmMsg(0, "%d frames in %d ms, fps = %1.3f\n",
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429 numFrames, endTime - startTime,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430 (float) (numFrames * 1000.0f) / (float) (endTime - startTime));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
433 error_exit:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434 dmMsg(0, "Shutting down dmlib.\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
435 if (screen)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
436 SDL_FreeSurface(screen);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
437
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
438 if (bmap)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 SDL_FreeSurface(bmap);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
440
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 if (font)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442 TTF_CloseFont(font);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444 if (initSDL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
445 SDL_Quit();
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
447 if (initTTF)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
448 TTF_Quit();
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450 return 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 }