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