@@ -32,7 +32,8 @@ typedef struct br_demo_mirror {
3232 br_uint_32 mouse_buttons ;
3333 br_uint_32 kb_buttons ;
3434
35- br_pixelmap * render_pm , * reflected_pm ;
35+ br_pixelmap * render_pm ;
36+ br_pixelmap * reflected_pm , * reflected_depth ;
3637 br_pixelmap * palette ;
3738 br_pixelmap * blend_table ;
3839
@@ -50,42 +51,28 @@ typedef struct br_demo_mirror {
5051 br_light * light ;
5152} br_demo_mirror ;
5253
53- void xyprintf (br_pixelmap * pm , int x , int y , char * fmt , ...);
54- void PrintMatrix34 (br_pixelmap * pm , int x , int y , br_matrix34 * t );
54+ void xyprintf (br_demo * demo , br_pixelmap * pm , int x , int y , const char * fmt , ...);
55+ void PrintMatrix34 (br_demo * demo , br_pixelmap * pm , int x , int y , br_matrix34 * t );
5556
5657void BuildTestWorld (br_demo * demo , br_model * model_cube , br_model * model_mirror );
5758
5859void BlendPixelmaps (br_pixelmap * , br_pixelmap * , br_pixelmap * , br_pixelmap * );
5960
60- void ControlObject (br_demo_mirror * state , br_actor * camera_actor , br_actor * translate_actor , br_actor * rotate_actor ,
61- br_scalar mouse_x , br_scalar mouse_y );
61+ void ControlObject (br_demo_mirror * state , br_actor * camera_actor , br_actor * translate_actor , br_actor * rotate_actor , br_scalar mouse_x ,
62+ br_scalar mouse_y );
6263
6364void UpdateMirror (br_actor * dest , br_actor * src , br_actor * world );
6465
65- br_error MirrorInit (br_demo * demo )
66+ static br_error MirrorLoadSWRes (br_demo * demo )
6667{
67- br_demo_mirror * state ;
68- br_model * cube_model , * mirror_model ;
69- br_pixelmap * shade_table ;
70- int nmats ;
71- br_material * mats [8 ];
68+ br_pixelmap * shade_table ;
7269
73- state = BrResAllocate (demo , sizeof (br_demo_mirror ), BR_MEMORY_APPLICATION );
74- demo -> user = state ;
75-
76- * state = (br_demo_mirror ){
77- .mouse_x = 0 ,
78- .mouse_y = 0 ,
79- .mouse_buttons = 0 ,
80- .kb_buttons = 0 ,
81- };
70+ br_demo_mirror * state = demo -> user ;
8271
8372 if ((state -> palette = BrPixelmapLoad ("winstd.pal" )) == NULL ) {
8473 BrLogError ("DEMO" , "Could not load winstd.pal." );
8574 return BRE_FAIL ;
8675 }
87- BrTableAdd (state -> palette );
88- BrPixelmapPaletteSet (demo -> colour_buffer , state -> palette );
8976
9077 if ((shade_table = BrPixelmapLoad ("winsh8.tab" )) == NULL ) {
9178 BrLogError ("DEMO" , "Could not load winsh8.tab." );
@@ -97,16 +84,46 @@ br_error MirrorInit(br_demo *demo)
9784 BrLogError ("DEMO" , "Cound not load blend.tab." );
9885 return BRE_FAIL ;
9986 }
87+ BrTableAdd (state -> blend_table );
10088
101- /*
102- * Load some materials
103- */
89+ if (demo -> colour_buffer -> type == BR_PMT_INDEX_8 ) {
90+ BrPixelmapPaletteSet (demo -> colour_buffer , state -> palette );
91+ demo -> text_colour = 41 ;
92+ }
93+
94+ return BRE_OK ;
95+ }
96+
97+ static br_error MirrorLoadHWRes (br_demo * demo )
98+ {
99+ return BRE_OK ;
100+ }
101+
102+ br_error MirrorInit (br_demo * demo )
103+ {
104+ br_demo_mirror * state ;
105+ br_model * cube_model , * mirror_model ;
106+
107+ int nmats ;
108+ br_material * mats [8 ];
109+ br_error err ;
110+
111+ state = BrResAllocate (demo , sizeof (br_demo_mirror ), BR_MEMORY_APPLICATION );
112+ demo -> user = state ;
113+
114+ * state = (br_demo_mirror ){
115+ .mouse_x = 0 ,
116+ .mouse_y = 0 ,
117+ .mouse_buttons = 0 ,
118+ .kb_buttons = 0 ,
119+ };
120+
121+ if ((err = demo -> hw_accel ? MirrorLoadHWRes (demo ) : MirrorLoadSWRes (demo )) != BRE_OK )
122+ return err ;
104123
105124 /*
106- * The demo framework will install the de-CLUT'ting hook.
107- * We don't want that.
125+ * Load some materials
108126 */
109- BrMapFindHook (BrMapFindFailedLoad );
110127
111128 if ((nmats = BrFmtScriptMaterialLoadMany ("test.mat" , mats , BR_ASIZE (mats ))) == 0 ) {
112129 BrLogError ("DEMO" , "Cound not load test.mat." );
@@ -277,21 +294,16 @@ static void MirrorRender(br_demo *demo)
277294 * Clear the buffers
278295 */
279296
297+ BrRendererFrameBegin ();
298+
280299 BrPixelmapFill (state -> render_pm , 0 );
281- BrPixelmapFill (state -> reflected_pm , 0 );
300+ BrPixelmapFill (demo -> depth_buffer , 0xFFFFFFFF );
282301
283- if (demo -> colour_buffer -> type != BR_PMT_INDEX_8 ) {
284- BrPixelmapTextF (demo -> colour_buffer ,
285- - (BrPixelmapTextWidth (demo -> colour_buffer , BrFontProp7x9 , "ONLY 8 BIT SCREEN MODES ARE SUPPORTED" ) / 2 ),
286- (BrFontProp7x9 -> glyph_y ) / 2 , BR_COLOUR_RGB (200 , 200 , 200 ), BrFontProp7x9 ,
287- "ONLY 8 BIT SCREEN MODES ARE SUPPORTED" );
288- return ;
289- }
302+ BrPixelmapFill (state -> reflected_pm , 0 );
303+ BrPixelmapFill (state -> reflected_depth , 0xFFFFFFFF );
290304
291305 BrClipPlaneEnable (state -> mirror_actor );
292306
293- BrPixelmapFill (demo -> depth_buffer , 0xFFFFFFFF );
294-
295307 state -> floor_actor -> render_style = BR_RSTYLE_NONE ;
296308 state -> world -> render_style = BR_RSTYLE_DEFAULT ;
297309
@@ -305,7 +317,7 @@ static void MirrorRender(br_demo *demo)
305317 * Render the reflection
306318 */
307319 UpdateMirror (state -> world , state -> mirror_actor , state -> world );
308- BrZbSceneRender (demo -> world , demo -> camera , state -> reflected_pm , demo -> depth_buffer );
320+ BrZbSceneRender (demo -> world , demo -> camera , state -> reflected_pm , state -> reflected_depth );
309321
310322 BrClipPlaneDisable (state -> mirror_actor );
311323
@@ -317,17 +329,21 @@ static void MirrorRender(br_demo *demo)
317329 BrActorToActorMatrix34 (& state -> floor_actor -> t .t .mat , state -> mirror_actor , state -> world );
318330 BrZbSceneRender (demo -> world , demo -> camera , state -> render_pm , demo -> depth_buffer );
319331
320- BlendPixelmaps (state -> render_pm , state -> render_pm , state -> reflected_pm , state -> blend_table );
332+ if (state -> blend_table != NULL && state -> render_pm -> type == BR_PMT_INDEX_8 ) {
333+ BlendPixelmaps (state -> render_pm , state -> render_pm , state -> reflected_pm , state -> blend_table );
334+ }
321335
322336#if 1
323- PrintMatrix34 (demo -> colour_buffer , 0 , 0 , & state -> model_actor -> t .t .mat );
337+ PrintMatrix34 (demo , demo -> colour_buffer , 0 , 0 , & state -> model_actor -> t .t .mat );
324338#endif
339+ BrRendererFrameEnd ();
325340}
326341
327342void MirrorDestroy (br_demo * demo )
328343{
329344 br_demo_mirror * state = demo -> user ;
330345
346+ BrPixelmapFree (state -> reflected_depth );
331347 BrPixelmapFree (state -> reflected_pm );
332348}
333349
@@ -342,20 +358,29 @@ void MirrorOnResize(br_demo *demo, br_uint_16 width, br_uint_16 height)
342358 state -> render_pm -> origin_x = (br_int_16 )(state -> render_pm -> width / 2 );
343359 state -> render_pm -> origin_y = (br_int_16 )(state -> render_pm -> height / 2 );
344360
361+ if (state -> reflected_depth != NULL )
362+ BrPixelmapFree (state -> reflected_depth );
363+
345364 if (state -> reflected_pm != NULL )
346365 BrPixelmapFree (state -> reflected_pm );
347366
348367 state -> reflected_pm = BrPixelmapMatch (demo -> colour_buffer , BR_PMMATCH_OFFSCREEN );
349368 state -> reflected_pm -> origin_x = (br_int_16 )(state -> reflected_pm -> width / 2 );
350369 state -> reflected_pm -> origin_y = (br_int_16 )(state -> reflected_pm -> height / 2 );
351370
352- BrPixelmapPaletteSet (state -> reflected_pm , state -> palette );
371+ state -> reflected_depth = BrPixelmapMatch (state -> reflected_pm , BR_PMMATCH_DEPTH );
372+ state -> reflected_depth -> origin_x = (br_int_16 )(state -> reflected_depth -> width / 2 );
373+ state -> reflected_depth -> origin_y = (br_int_16 )(state -> reflected_depth -> height / 2 );
374+
375+ if (demo -> colour_buffer -> type == BR_PMT_INDEX_8 ) {
376+ BrPixelmapPaletteSet (state -> reflected_pm , state -> palette );
377+ }
353378}
354379
355380#define MSCALE BR_SCALAR(0.006)
356381
357- void ControlObject (br_demo_mirror * state , br_actor * camera_actor , br_actor * translate_actor , br_actor * rotate_actor ,
358- br_scalar mouse_x , br_scalar mouse_y )
382+ void ControlObject (br_demo_mirror * state , br_actor * camera_actor , br_actor * translate_actor , br_actor * rotate_actor , br_scalar mouse_x ,
383+ br_scalar mouse_y )
359384{
360385 br_matrix34 mat_roll ;
361386 br_scalar tx , ty , tz ;
@@ -384,28 +409,27 @@ void ControlObject(br_demo_mirror *state, br_actor *camera_actor, br_actor *tran
384409 }
385410}
386411
387- void PrintMatrix34 (br_pixelmap * pm , int x , int y , br_matrix34 * t )
412+ void PrintMatrix34 (br_demo * demo , br_pixelmap * pm , int x , int y , br_matrix34 * t )
388413{
389- int i , j ;
390-
391- for (i = 0 ; i < 3 ; i ++ )
392- for (j = 0 ; j < 4 ; j ++ )
393- xyprintf (pm , x + i * 12 , y + j * 2 , "%11.5f" , BrScalarToFloat (t -> m [j ][i ]));
414+ for (int i = 0 ; i < 3 ; i ++ ) {
415+ for (int j = 0 ; j < 4 ; j ++ )
416+ xyprintf (demo , pm , x + i * 12 , y + j * 2 , "%11.5f" , BrScalarToFloat (t -> m [j ][i ]));
417+ }
394418}
395419
396- void xyprintf (br_pixelmap * pm , int x , int y , char * fmt , ...)
420+ void xyprintf (br_demo * demo , br_pixelmap * pm , int x , int y , const char * fmt , ...)
397421{
398422 char temp [256 ];
399423 va_list args ;
400- int o = 0 ;
424+
401425 /*
402426 * Build output string
403427 */
404428 va_start (args , fmt );
405429 BrVSprintf (temp , fmt , args );
406430 va_end (args );
407431
408- BrPixelmapText (pm , x * 4 , y * 6 , 255 , BrFontFixed3x5 , temp );
432+ BrPixelmapText (pm , x * 4 , y * 6 , demo -> text_colour , BrFontFixed3x5 , temp );
409433}
410434
411435void BuildTestWorld (br_demo * demo , br_model * model_cube , br_model * model_mirror )
@@ -517,12 +541,10 @@ void BlendPixelmaps(br_pixelmap *dest, br_pixelmap *a, br_pixelmap *b, br_pixelm
517541
518542 if (a -> pixels ) {
519543 BrPixelmapDirectUnlock (a );
520- ap = a -> pixels ;
521544 }
522545
523546 if (b -> pixels ) {
524547 BrPixelmapDirectUnlock (b );
525- bp = b -> pixels ;
526548 }
527549}
528550
@@ -537,5 +559,5 @@ const static br_demo_dispatch dispatch = {
537559
538560int main (int argc , char * * argv )
539561{
540- return BrDemoRun ("Mirror Demo" , 1280 , 720 , & dispatch );
562+ return BrDemoRunArgv ("Mirror Demo" , & dispatch , argc , argv );
541563}
0 commit comments