1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - WM - demos - wep-1
3 File: graphics.c
4
5 Copyright 2005-2008 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 $Date:: 2008-09-18#$
14 $Rev: 8573 $
15 $Author: okubata_ryoma $
16 *---------------------------------------------------------------------------*/
17
18 #ifdef SDK_TWL
19 #include <twl.h>
20 #else
21 #include <nitro.h>
22 #endif
23 #include "graphics.h"
24
initGraphics(void)25 void initGraphics(void)
26 {
27 GX_Init();
28
29 GX_DispOff();
30 GXS_DispOff();
31
32 GX_SetBankForLCDC(GX_VRAM_LCDC_ALL);
33 MI_CpuClearFast((void *)HW_LCDC_VRAM, HW_LCDC_VRAM_SIZE);
34
35 (void)GX_DisableBankForLCDC();
36 MI_CpuFillFast((void *)HW_OAM, 192, HW_OAM_SIZE);
37 MI_CpuClearFast((void *)HW_PLTT, HW_PLTT_SIZE);
38 MI_CpuFillFast((void *)HW_DB_OAM, 192, HW_DB_OAM_SIZE);
39 MI_CpuClearFast((void *)HW_DB_PLTT, HW_DB_PLTT_SIZE);
40
41 G3X_Init();
42 G3X_InitMtxStack();
43
44 GX_SetBankForTex(GX_VRAM_TEX_0_D);
45 GX_SetBankForTexPltt(GX_VRAM_TEXPLTT_0123_E);
46 GX_SetGraphicsMode(GX_DISPMODE_GRAPHICS, GX_BGMODE_3, GX_BG0_AS_3D);
47 G3X_AntiAlias(TRUE);
48 G3_SwapBuffers(GX_SORTMODE_AUTO, GX_BUFFERMODE_W);
49 G3X_SetClearColor(GX_RGB(0, 0, 0), 0, 0x7fff, 63, FALSE);
50
51 G3_ViewPort(0, 0, 255, 191);
52
53 G2_SetBG0Priority(1);
54 G2_SetBG2Priority(0);
55
56 G2_BG0Mosaic(FALSE);
57 G2_BG2Mosaic(FALSE);
58
59 GX_SetVisiblePlane(GX_PLANEMASK_BG0 | GX_PLANEMASK_BG2);
60 }
61
setupPseudo2DCamera(void)62 void setupPseudo2DCamera(void)
63 {
64 VecFx32 Eye = { 0, 0, FX32_ONE };
65 VecFx32 at = { 0, 0, 0 };
66 VecFx32 vUp = { 0, -FX32_ONE, 0 };
67
68 G3_Ortho(96 * PSEUDO2D_ONE, -96 * PSEUDO2D_ONE,
69 128 * PSEUDO2D_ONE, -128 * PSEUDO2D_ONE, FX32_ONE, FX32_ONE * 400, NULL);
70 G3_StoreMtx(0);
71 G3X_Reset();
72 G3_LookAt(&Eye, &vUp, &at, NULL);
73 }
74
drawPseudo2DTexQuad(int sx,int sy,int width,int height,int texw,int texh)75 void drawPseudo2DTexQuad(int sx, int sy, int width, int height, int texw, int texh)
76 {
77 sx -= 128;
78 sy -= 96;
79
80 G3_Begin(GX_BEGIN_QUADS);
81
82 G3_TexCoord(0, 0);
83 G3_Normal(0, 0, FX16_ONE - 1);
84 G3_Vtx((fx16)(sx * PSEUDO2D_ONE), (fx16)(sy * PSEUDO2D_ONE), 0);
85
86 G3_TexCoord(FX32_ONE * texw, 0);
87 G3_Normal(0, 0, FX16_ONE - 1);
88 G3_Vtx((fx16)((sx + width) * PSEUDO2D_ONE), (fx16)(sy * PSEUDO2D_ONE), 0);
89
90 G3_TexCoord(FX32_ONE * texw, FX32_ONE * texh);
91 G3_Normal(0, 0, FX16_ONE - 1);
92 G3_Vtx((fx16)((sx + width) * PSEUDO2D_ONE), (fx16)((sy + height) * PSEUDO2D_ONE), 0);
93
94 G3_TexCoord(0, FX32_ONE * texh);
95 G3_Normal(0, 0, FX16_ONE - 1);
96 G3_Vtx((fx16)(sx * PSEUDO2D_ONE), (fx16)((sy + height) * PSEUDO2D_ONE), 0);
97 G3_End();
98 }
99
drawPseudo2DColorQuad(int sx,int sy,int width,int height,GXRgb color)100 void drawPseudo2DColorQuad(int sx, int sy, int width, int height, GXRgb color)
101 {
102 sx -= 128;
103 sy -= 96;
104
105 G3_Begin(GX_BEGIN_QUADS);
106 G3_Color(color);
107 G3_Vtx((fx16)(sx * PSEUDO2D_ONE), (fx16)(sy * PSEUDO2D_ONE), 0);
108 G3_Vtx((fx16)((sx + width) * PSEUDO2D_ONE), (fx16)(sy * PSEUDO2D_ONE), 0);
109 G3_Vtx((fx16)((sx + width) * PSEUDO2D_ONE), (fx16)((sy + height) * PSEUDO2D_ONE), 0);
110 G3_Vtx((fx16)(sx * PSEUDO2D_ONE), (fx16)((sy + height) * PSEUDO2D_ONE), 0);
111 G3_End();
112 }
113