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