1 /*---------------------------------------------------------------------------*
2 Project: Revolution gx/vi demo
3 File: frb-vi-gamma.c
4
5 Copyright 2006 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Log: frb-vi-gamma.c,v $
14 Revision 1.1 06/16/2006 07:48:16 urata
15 Initial checkin.
16
17 $NoKeywords: $
18 *---------------------------------------------------------------------------*/
19 /*---------------------------------------------------------------------------*
20 frb-vi-gamma
21 gamma correction mode demo
22 *---------------------------------------------------------------------------*/
23
24
25 /*---------------------------------------------------------------------------*
26 Header files
27 *---------------------------------------------------------------------------*/
28 #include <demo.h>
29 #include <math.h>
30
31 /*---------------------------------------------------------------------------*
32 Macro definitions
33 *---------------------------------------------------------------------------*/
34 #define MAX_Z 0x00ffffff // max value of Z buffer
35
36 #define NUM_PATTERNS 5
37 #define NUM_COLORBARS 12
38 #define NUM_DONUTS 12
39
40 #define VI_GAMMA 0
41 #define GX_GAMMA 1
42
43 #define Clamp(val,min,max) \
44 ((val) = (((val) < (min)) ? (min) : ((val) > (max)) ? (max) : (val)))
45
46 /*---------------------------------------------------------------------------*
47 Structure definitions
48 *---------------------------------------------------------------------------*/
49 // for entire scene control
50 typedef struct
51 {
52 u32 patternNo;
53 u32 gammaMode;
54 u32 pixMode;
55 u32 colorID;
56 u16 screen_width;
57 u16 screen_height;
58 u8* vfilter;
59 VIGamma vigamma;
60 } MySceneCtrlObj;
61
62 /*---------------------------------------------------------------------------*
63 Forward references
64 *---------------------------------------------------------------------------*/
65 void main ( void );
66 static void DrawInit ( MySceneCtrlObj* sc );
67 static void DrawTick ( MySceneCtrlObj* sc );
68 static void AnimTick ( MySceneCtrlObj* sc );
69 static void DrawColorBars ( MySceneCtrlObj* sc );
70 static void DrawGammaTestImg ( MySceneCtrlObj* sc );
71 static void DrawSampleImg ( MySceneCtrlObj* sc );
72 static void DrawDonuts ( MySceneCtrlObj* sc );
73 static void DrawLitOcta ( MySceneCtrlObj* sc );
74 static void PrintIntro ( void );
75
76 /*---------------------------------------------------------------------------*
77 Model and texture data
78 *---------------------------------------------------------------------------*/
79 #define NUM_COLORS 13
80
81 #define ID_BLACK 0
82 #define ID_WHITE 1
83 #define ID_GRAY 8
84
85 static GXColor MyColorArray[] ATTRIBUTE_ALIGN(32) =
86 {
87 { 0x00, 0x00, 0x00, 0x00 }, // Black
88 { 0xFF, 0xFF, 0xFF, 0xFF }, // White
89 { 0x00, 0xFF, 0xFF, 0xFF }, // Cyan
90 { 0x00, 0xFF, 0x00, 0xFF }, // Green
91 { 0xFF, 0xFF, 0x00, 0xFF }, // Yellow
92 { 0xFF, 0x00, 0x00, 0xFF }, // Red
93 { 0xFF, 0x00, 0xFF, 0xFF }, // Magenta
94 { 0x00, 0x00, 0xFF, 0xFF }, // Blue
95 { 0x80, 0x80, 0x80, 0xFF }, // Gray
96 { 0xFF, 0x80, 0x80, 0xFF }, //
97 { 0x80, 0xFF, 0x80, 0xFF }, //
98 { 0x80, 0x80, 0xFF, 0xFF }, //
99 { 0x40, 0x40, 0x40, 0xFF } //
100 };
101
102 /*---------------------------------------------------------------------------*
103 Gamma correction mode data / pixel mode data
104 *---------------------------------------------------------------------------*/
105 static GXGamma GammaTable[3] =
106 {
107 GX_GM_1_0, GX_GM_1_7, GX_GM_2_2
108 };
109
110 static char* GammaMsg[3] =
111 {
112 "1.0", "1.7", "2.2"
113 };
114
115 static GXPixelFmt PixModeTable[3] =
116 {
117 GX_PF_RGB8_Z24, GX_PF_RGBA6_Z24, GX_PF_RGBA6_Z24
118 };
119
120 static GXBool DitherModeTable[3] =
121 {
122 GX_DISABLE, GX_DISABLE, GX_ENABLE
123 };
124
125 static char* PixModeMsg[3] =
126 {
127 " RGB8", " RGBA6", "RGBA6/Dither"
128 };
129
130 /*---------------------------------------------------------------------------*
131 Global variables
132 *---------------------------------------------------------------------------*/
133 static MySceneCtrlObj SceneCtrl; // scene control parameters
134 static TPLPalettePtr MyTplObj = NULL; // for TPL file
135 static u32 whichIsGamma = GX_GAMMA; // Select GX/VI gamma correction
136 /*---------------------------------------------------------------------------*
137 Application main loop
138 *---------------------------------------------------------------------------*/
main(void)139 void main ( void )
140 {
141 DEMOInit(NULL); // Init the OS, game pad, graphics and video.
142
143 DrawInit(&SceneCtrl); // Initialize vertex formats, array pointers
144 // and default scene settings.
145
146 PrintIntro(); // Print demo directions
147
148 while(!(DEMOPadGetButton(0) & PAD_BUTTON_MENU))
149 {
150 DEMOBeforeRender();
151 DrawTick(&SceneCtrl); // Draw the model.
152 DEMODoneRender();
153 DEMOPadRead(); // Read controller
154 AnimTick(&SceneCtrl); // Do animation
155 }
156
157 OSHalt("End of test");
158 }
159
160 /*---------------------------------------------------------------------------*
161 Functions
162 *---------------------------------------------------------------------------*/
163 /*---------------------------------------------------------------------------*
164 Name: DrawInit
165
166 Description: Initializes the vertex attribute format and sets up
167 the array pointer for the indexed data.
168 This function also initializes scene control parameters.
169
170 Arguments: sc : pointer to the structure of scene control parameters
171
172 Returns: none
173 *---------------------------------------------------------------------------*/
DrawInit(MySceneCtrlObj * sc)174 static void DrawInit( MySceneCtrlObj* sc )
175 {
176 GXRenderModeObj *rmp;
177
178 // Get framebuffer size of current rendering mode
179 rmp = DEMOGetRenderModeObj();
180 sc->screen_width = rmp->fbWidth;
181 sc->screen_height = rmp->efbHeight;
182 sc->vfilter = rmp->vfilter;
183
184 // Background color
185 GXSetCopyClear(MyColorArray[ID_BLACK], MAX_Z);
186
187 // Culling mode
188 GXSetCullMode(GX_CULL_NONE);
189
190 // Vertex Attribute (VTXFMT0 is used by DEMOPuts library)
191 GXSetVtxAttrFmt(GX_VTXFMT1, GX_VA_POS, GX_POS_XYZ, GX_S16, 0);
192 GXSetVtxAttrFmt(GX_VTXFMT1, GX_VA_TEX0, GX_TEX_ST, GX_S16, 8);
193 GXSetVtxAttrFmt(GX_VTXFMT1, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
194
195 // load tpl file
196 TPLGetPalette(&MyTplObj, "gxTests/frb-00.tpl");
197
198
199 // Default scene control parameter settings
200
201 sc->patternNo = 0;
202
203 // gamma mode & pixel mode
204 sc->gammaMode = 0;
205 sc->pixMode = 0;
206 sc->colorID = 1;
207
208 sc->vigamma = VI_GM_1_0;
209 }
210
211 /*---------------------------------------------------------------------------*
212 Name: DrawTick
213
214 Description: Draw the model by using given scene parameters
215
216 Arguments: sc : pointer to the structure of scene control parameters
217
218 Returns: none
219 *---------------------------------------------------------------------------*/
DrawTick(MySceneCtrlObj * sc)220 static void DrawTick( MySceneCtrlObj* sc )
221 {
222 Mtx44 proj;
223
224 // Set pixel mode and gamma mode
225 GXSetPixelFmt(PixModeTable[sc->pixMode], GX_ZC_LINEAR);
226 GXSetDither(DitherModeTable[sc->pixMode]);
227 if(whichIsGamma == GX_GAMMA)
228 {
229 GXSetDispCopyGamma(GammaTable[sc->gammaMode]);
230 }
231 else
232 {
233 GXSetDispCopyGamma(GX_GM_1_0);
234 }
235
236 // Initialize screen space projection
237 MTXOrtho(proj, 0, sc->screen_height, 0, sc->screen_width, 0.0F, 10000.0F);
238 GXSetProjection(proj, GX_ORTHOGRAPHIC);
239
240 // Draw a pattern
241 switch(sc->patternNo)
242 {
243 case 0:
244 DrawColorBars(sc);
245 break;
246 case 1:
247 DrawGammaTestImg(sc);
248 break;
249 case 2:
250 DrawSampleImg(sc);
251 break;
252 case 3:
253 DrawDonuts(sc);
254 break;
255 case 4:
256 default:
257 DrawLitOcta(sc);
258 break;
259 }
260
261 // Caption
262 DEMOInitCaption(DM_FT_OPQ, (s16)(sc->screen_width/2), (s16)(sc->screen_height/2));
263 DEMOPrintf(16, 12, 0, "%s GXGamma = %s \n", (whichIsGamma == GX_GAMMA) ? ">" : " ", GammaMsg[sc->gammaMode]);
264 DEMOPrintf(16, 22, 0, "%s VIGamma = %1.1f\n", (whichIsGamma == VI_GAMMA) ? ">" : " ", sc->vigamma/10.0f);
265 DEMOPuts(200, 12, 0, PixModeMsg[sc->pixMode]);
266
267 if(whichIsGamma == VI_GAMMA)
268 {
269 VISetGamma(sc->vigamma);
270 }
271 else
272 {
273 VISetGamma(VI_GM_1_0);
274 }
275 }
276
277 /*---------------------------------------------------------------------------*
278 Name: AnimTick
279
280 Description: Changes scene parameters according to the pad status.
281
282 Arguments: sc : pointer to the structure of scene control parameters
283
284 Returns: none
285 *---------------------------------------------------------------------------*/
AnimTick(MySceneCtrlObj * sc)286 static void AnimTick( MySceneCtrlObj* sc )
287 {
288
289 // Change the pattern
290 if ( DEMOPadGetButtonDown(0) & PAD_BUTTON_A )
291 {
292 sc->patternNo = ++sc->patternNo % NUM_PATTERNS;
293 }
294
295 // Gamma mode
296 if ( DEMOPadGetButtonDown(0) & PAD_BUTTON_B )
297 {
298 if(whichIsGamma == GX_GAMMA)
299 {
300 sc->gammaMode = ++sc->gammaMode % 3;
301 }
302 else
303 {
304 if(sc->vigamma < VI_GM_2_2)
305 ++sc->vigamma;
306 else
307 sc->vigamma = VI_GM_1_0;
308 }
309 }
310
311 // Pixel mode (8bit/6bit)
312 if ( DEMOPadGetButtonDown(0) & PAD_BUTTON_X )
313 {
314 sc->pixMode = ++sc->pixMode % 3;
315 }
316
317 // Color ID (used in DrawLitOcta)
318 if ( DEMOPadGetButtonDown(0) & PAD_BUTTON_Y )
319 {
320 sc->colorID = ++sc->colorID % NUM_COLORS;
321 }
322
323 // Toggle GX/VI gamma
324 if ( DEMOPadGetButtonDown(0) & PAD_TRIGGER_Z )
325 {
326 if( whichIsGamma == GX_GAMMA)
327 {
328 whichIsGamma = VI_GAMMA;
329 }
330 else
331 {
332 whichIsGamma = GX_GAMMA;
333 }
334 }
335 }
336
337 /*---------------------------------------------------------------------------*
338 Name: DrawColorBars
339
340 Description: Draw color bars
341
342 Arguments: sc : pointer to the structure of scene control parameters
343
344 Returns: none
345 *---------------------------------------------------------------------------*/
DrawColorBars(MySceneCtrlObj * sc)346 static void DrawColorBars( MySceneCtrlObj* sc )
347 {
348 u32 i;
349 u8 c0, c1;
350 Mtx mv;
351
352 // Turn de-flicker filter on
353 GXSetCopyFilter(GX_FALSE, NULL, GX_TRUE, sc->vfilter);
354
355 // Transform matrix
356 MTXIdentity(mv);
357 GXLoadPosMtxImm(mv, GX_PNMTX0);
358 GXSetCurrentMtx(GX_PNMTX0);
359
360 // Lighting off
361 GXSetNumChans(1);
362 GXSetChanCtrl(GX_COLOR0A0, GX_DISABLE, GX_SRC_VTX, GX_SRC_VTX,
363 GX_LIGHT_NULL, GX_DF_CLAMP, GX_AF_NONE);
364
365 // Set TEV operation to use vertex color
366 GXSetNumTexGens(0);
367 GXSetNumTevStages(1);
368 GXSetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
369 GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0);
370
371 // Vertex descriptor
372 GXClearVtxDesc();
373 GXSetVtxDesc(GX_VA_POS, GX_DIRECT);
374 GXSetVtxDesc(GX_VA_CLR0, GX_INDEX8);
375
376 // Array pointer
377 GXSetArray(GX_VA_CLR0, MyColorArray, sizeof(GXColor));
378
379 // Draw each color bar
380 GXBegin(GX_QUADS, GX_VTXFMT1, NUM_COLORBARS*4);
381 for ( i = 0 ; i < NUM_COLORBARS ; ++i )
382 {
383 c0 = (u8)((i % 2) ? i : 0);
384 c1 = (u8)((i % 2) ? 0 : i);
385
386 GXPosition3s16(64, (s16)(i*32+32), 0);
387 GXColor1x8(c0);
388 GXPosition3s16(576, (s16)(i*32+32), 0);
389 GXColor1x8(c1);
390 GXPosition3s16(576, (s16)(i*32+64), 0);
391 GXColor1x8(c1);
392 GXPosition3s16(64, (s16)(i*32+64), 0);
393 GXColor1x8(c0);
394 }
395 GXEnd();
396 }
397
398 /*---------------------------------------------------------------------------*
399 Name: DrawGammaTestImg
400
401 Description: Draw a gamma test pattern
402
403 Arguments: sc : pointer to the structure of scene control parameters
404
405 Returns: none
406 *---------------------------------------------------------------------------*/
407 // Configuration data
408 struct
409 {
410 u32 x;
411 u32 y;
412 GXColor color0;
413 GXColor color1;
414 }
415 GammaImgConfig[4] =
416 {
417 { 160, 64, { 255, 255, 255, 255 }, { 128, 128, 128, 255 } },
418 { 352, 64, { 255, 0, 0, 255 }, { 128, 0, 0, 255 } },
419 { 160, 256, { 0, 255, 0, 255 }, { 0, 128, 0, 255 } },
420 { 352, 256, { 0, 0, 255, 255 }, { 0, 0, 128, 255 } }
421 };
422
DrawGammaTestImg(MySceneCtrlObj * sc)423 static void DrawGammaTestImg( MySceneCtrlObj* sc )
424 {
425 u32 i;
426 GXTexObj tx0, tx1;
427 Mtx mv;
428
429 // Turn de-flicker filter off
430 GXSetCopyFilter(GX_FALSE, NULL, GX_FALSE, sc->vfilter);
431
432 // Lighting off (uses fixed color)
433 GXSetNumChans(1);
434 GXSetChanCtrl(GX_COLOR0A0, GX_DISABLE, GX_SRC_REG, GX_SRC_REG,
435 GX_LIGHT_NULL, GX_DF_CLAMP, GX_AF_NONE);
436
437 // Set TEV operation to use one color/texture each
438 GXSetNumTexGens(1);
439 GXSetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);
440 GXSetNumTevStages(1);
441 GXSetTevOp(GX_TEVSTAGE0, GX_MODULATE);
442 GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
443
444 // Set up textures
445 TPLGetGXTexObjFromPalette(MyTplObj, &tx0, 0); // Stripe pattern
446 TPLGetGXTexObjFromPalette(MyTplObj, &tx1, 1); // Reference pattern
447 GXInitTexObjLOD(&tx0, GX_NEAR, GX_NEAR, 0, 0, 0, 0, 0, GX_ANISO_1);
448 GXInitTexObjLOD(&tx1, GX_NEAR, GX_NEAR, 0, 0, 0, 0, 0, GX_ANISO_1);
449
450 // Vertex descriptor
451 GXClearVtxDesc();
452 GXSetVtxDesc(GX_VA_POS, GX_DIRECT);
453 GXSetVtxDesc(GX_VA_TEX0, GX_DIRECT);
454
455 GXSetCurrentMtx(GX_PNMTX0);
456
457 // Draw four patterns
458 for ( i = 0 ; i < 4 ; ++i )
459 {
460 MTXTrans(mv, GammaImgConfig[i].x, GammaImgConfig[i].y, 0.0F);
461 GXLoadPosMtxImm(mv, GX_PNMTX0);
462
463 GXSetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ZERO, GX_LO_SET);
464 GXLoadTexObj(&tx0, GX_TEXMAP0);
465 GXSetChanMatColor(GX_COLOR0A0, GammaImgConfig[i].color0);
466
467 GXBegin(GX_QUADS, GX_VTXFMT1, 4);
468 GXPosition3s16( 0, 0, 0);
469 GXTexCoord2s16(0x0000, 0x0000);
470 GXPosition3s16(128, 0, 0);
471 GXTexCoord2s16(0x0100, 0x0000);
472 GXPosition3s16(128, 128, 0);
473 GXTexCoord2s16(0x0100, 0x0100);
474 GXPosition3s16( 0, 128, 0);
475 GXTexCoord2s16(0x0000, 0x0100);
476 GXEnd();
477
478 GXSetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_SET);
479 GXLoadTexObj(&tx1, GX_TEXMAP0);
480 GXSetChanMatColor(GX_COLOR0A0, GammaImgConfig[i].color1);
481
482 GXBegin(GX_QUADS, GX_VTXFMT1, 4);
483 GXPosition3s16( 0, 0, 0);
484 GXTexCoord2s16(0x0000, 0x0000);
485 GXPosition3s16(128, 0, 0);
486 GXTexCoord2s16(0x0100, 0x0000);
487 GXPosition3s16(128, 128, 0);
488 GXTexCoord2s16(0x0100, 0x0100);
489 GXPosition3s16( 0, 128, 0);
490 GXTexCoord2s16(0x0000, 0x0100);
491 GXEnd();
492 }
493
494 GXSetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ZERO, GX_LO_SET);
495
496 }
497
498 /*---------------------------------------------------------------------------*
499 Name: DrawSampleImg
500
501 Description: Draw a sample image
502
503 Arguments: sc : pointer to the structure of scene control parameters
504
505 Returns: none
506 *---------------------------------------------------------------------------*/
DrawSampleImg(MySceneCtrlObj * sc)507 static void DrawSampleImg( MySceneCtrlObj* sc )
508 {
509 GXTexObj tx;
510 Mtx mv;
511
512 // De-flicker filter on
513 GXSetCopyFilter(GX_FALSE, NULL, GX_TRUE, sc->vfilter);
514
515 // Transform matrix
516 MTXIdentity(mv);
517 GXLoadPosMtxImm(mv, GX_PNMTX0);
518 GXSetCurrentMtx(GX_PNMTX0);
519
520 // No color channel
521 GXSetNumChans(0);
522
523 // Set TEV operation to use vertex color
524 GXSetNumTexGens(1);
525 GXSetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);
526 GXSetNumTevStages(1);
527 GXSetTevOp(GX_TEVSTAGE0, GX_REPLACE);
528 GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL);
529
530 // Set up texture
531 TPLGetGXTexObjFromPalette(MyTplObj, &tx, 2); // Sample image
532 GXLoadTexObj(&tx, GX_TEXMAP0);
533
534 // Vertex descriptor
535 GXClearVtxDesc();
536 GXSetVtxDesc(GX_VA_POS, GX_DIRECT);
537 GXSetVtxDesc(GX_VA_TEX0, GX_DIRECT);
538
539 // Draw a large quad
540 GXBegin(GX_QUADS, GX_VTXFMT1, 4);
541 GXPosition3s16( 64, 96, 0);
542 GXTexCoord2s16(0x0000, 0x0000);
543 GXPosition3s16(576, 96, 0);
544 GXTexCoord2s16(0x0100, 0x0000);
545 GXPosition3s16(576, 352, 0);
546 GXTexCoord2s16(0x0100, 0x0100);
547 GXPosition3s16( 64, 352, 0);
548 GXTexCoord2s16(0x0000, 0x0100);
549 GXEnd();
550 }
551
552 /*---------------------------------------------------------------------------*
553 Name: DrawDonuts
554
555 Description: Draw doughnuts
556
557 Arguments: sc : pointer to the structure of scene control parameters
558
559 Returns: none
560 *---------------------------------------------------------------------------*/
DrawDonuts(MySceneCtrlObj * sc)561 static void DrawDonuts( MySceneCtrlObj* sc )
562 {
563 static u32 rot = 0;
564 GXLightObj lo;
565 u32 i;
566 Mtx m0, m1, ms;
567 GXColor color1 = { 64, 64, 64, 64 };
568 GXColor color2 = { 192, 192, 192, 192 };
569
570 // De-flicker filter on
571 GXSetCopyFilter(GX_FALSE, NULL, GX_TRUE, sc->vfilter);
572
573 // Z compare on
574 GXSetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE);
575
576 // Lighting on
577 GXSetNumChans(1);
578 GXSetChanCtrl(GX_COLOR0A0, GX_ENABLE, GX_SRC_REG, GX_SRC_REG,
579 GX_LIGHT0, GX_DF_CLAMP, GX_AF_NONE);
580 GXSetChanAmbColor(GX_COLOR0A0, color1);
581
582 GXInitLightColor(&lo, color2);
583 GXInitLightPos(&lo, 10000.0F, -10000.0F, 5000.0F);
584 GXLoadLightObjImm(&lo, GX_LIGHT0);
585
586 // Set TEV operation to use vertex color
587 GXSetNumTexGens(0);
588 GXSetNumTevStages(1);
589 GXSetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
590 GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0);
591
592 // Transform matrix
593 GXSetCurrentMtx(GX_PNMTX0);
594
595 // Draw each icosahedron
596 MTXScale(ms, 48, 48, 48);
597 for ( i = 0 ; i < NUM_DONUTS ; ++i )
598 {
599 MTXRotDeg(m0, 'y', (rot+i*60));
600 MTXConcat(ms, m0, m1);
601 MTXTrans(m0, ((i%4)+1)*128, (i/4)*112+128, -256);
602 MTXConcat(m0, m1, m1);
603 GXLoadPosMtxImm(m1, GX_PNMTX0);
604
605 GXSetChanMatColor(GX_COLOR0A0, MyColorArray[i+1]);
606 GXDrawTorus(0.3F, 12, 16);
607 }
608
609 // Rotation counter
610 rot = ++rot % 360;
611 }
612
613 /*---------------------------------------------------------------------------*
614 Name: DrawLitOcta
615
616 Description: Draw a lit octahedron
617
618 Arguments: sc : pointer to the structure of scene control parameters
619
620 Returns: none
621 *---------------------------------------------------------------------------*/
DrawLitOcta(MySceneCtrlObj * sc)622 static void DrawLitOcta( MySceneCtrlObj* sc )
623 {
624 static u32 rot = 0;
625 GXLightObj lo;
626 Mtx mv, mr, ms, m1;
627 GXColor color1 = { 64, 64, 64, 64 };
628 GXColor color2 = { 160, 160, 160, 160 };
629
630 // De-flicker filter on
631 GXSetCopyFilter(GX_FALSE, NULL, GX_TRUE, sc->vfilter);
632
633 // Z compare on
634 GXSetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE);
635
636 // Lighting on
637 GXSetNumChans(1);
638 GXSetChanCtrl(GX_COLOR0A0, GX_ENABLE, GX_SRC_REG, GX_SRC_REG,
639 GX_LIGHT0, GX_DF_CLAMP, GX_AF_NONE);
640 GXSetChanAmbColor(GX_COLOR0A0, color1);
641 GXSetChanMatColor(GX_COLOR0A0, MyColorArray[sc->colorID]);
642
643 GXInitLightColor(&lo, color2);
644 GXInitLightPos(&lo, 10000.0F, -10000.0F, 5000.0F);
645 GXLoadLightObjImm(&lo, GX_LIGHT0);
646
647 // Set TEV operation to use vertex color
648 GXSetNumTexGens(0);
649 GXSetNumTevStages(1);
650 GXSetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
651 GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0);
652
653 // Transform matrix
654 GXSetCurrentMtx(GX_PNMTX0);
655
656 // Draw an octahedron
657 MTXTrans(m1, 320, 240, -512);
658 MTXRotDeg(mr, 'y', (f32)rot/2);
659 MTXConcat(m1, mr, mv);
660 MTXScale(ms, 192, 192, 192);
661 MTXConcat(mv, ms, m1);
662
663 GXLoadPosMtxImm(m1, GX_PNMTX0);
664 GXLoadNrmMtxImm(m1, GX_PNMTX0);
665
666 GXDrawOctahedron();
667
668 // Rotation counter
669 rot = ++rot % 720;
670 }
671
672 /*---------------------------------------------------------------------------*
673 Name: PrintIntro
674
675 Description: Prints the directions on how to use this demo.
676
677 Arguments: none
678
679 Returns: none
680 *---------------------------------------------------------------------------*/
PrintIntro(void)681 static void PrintIntro( void )
682 {
683 OSReport("\n\n");
684 OSReport("************************************************\n");
685 OSReport("frb-gamma: gamma correction mode demo\n");
686 OSReport("************************************************\n");
687 OSReport("to quit hit the start button\n");
688 OSReport("\n");
689 OSReport("A Button : Change the pattern\n");
690 OSReport("B Button : Change gamma correction\n");
691 OSReport("X Button : Change the pixel format\n");
692 OSReport("Z Trigger: Toggle GX/VI gamma correction\n");
693 OSReport("************************************************\n\n");
694 }
695
696 /*============================================================================*/
697