1 /*---------------------------------------------------------------------------*
2 Project: Dolphin
3 File: gd-matrix-create.c
4
5 Copyright 2001 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: gd-matrix-create.c,v $
14 Revision 1.2 02/20/2006 04:13:09 mitu
15 changed include path from dolphin/ to revolution/.
16
17 Revision 1.1 02/08/2006 11:19:43 mitu
18 1st version.
19
20
21 1 9/19/01 5:49p Carl
22 Source files for GD matrix demo.
23
24 $NoKeywords: $
25 *---------------------------------------------------------------------------*/
26
27 #include <revolution/gd.h>
28
29 #ifdef WIN32
30 #include <assert.h>
31 #include <stdlib.h>
32 #else
33 #include <revolution/os.h>
34 #endif
35
36 /*---------------------------------------------------------------------------*
37 Defines
38 *---------------------------------------------------------------------------*/
39
40 #ifdef WIN32
41 #define ASSERT assert
42 #define OSRoundUp32B(x) (((u32)(x) + 31) & ~31)
43 #define OSAlloc(x) ((void*)OSRoundUp32B(malloc((x)+31)))
44 #define OSFree(x) free(x)
45 #endif
46
47 /*---------------------------------------------------------------------------*
48 Forward references
49 *---------------------------------------------------------------------------*/
50
51 void CreateDLs ( void );
52
53 /*---------------------------------------------------------------------------*
54 Global variables
55 *---------------------------------------------------------------------------*/
56
57 // Display lists *************************************************************
58
59 // This set of display lists will each load an indexed position matrix
60 // and an indexed normal matrix, then draw one face of the cube.
61
62 extern GDLObj DrawDLOs[6];
63 #define ALT_DRAW_SIZE 320 // maximum (not actual) size
64
65 /*---------------------------------------------------------------------------*
66 Functions
67 *---------------------------------------------------------------------------*/
68
69 /*---------------------------------------------------------------------------*
70 Name: CreateDLs
71
72 Description: Creates the display lists used by the program.
73
74 Arguments: none
75
76 Returns: none
77 *---------------------------------------------------------------------------*/
CreateDLs(void)78 void CreateDLs ( void )
79 {
80 u8 *DrawList;
81
82 //
83 // Create the cube-face-drawing draw DL's
84 //
85
86 // This set of display lists will each load an indexed position matrix
87 // and an indexed normal matrix, then draw one face of the cube.
88
89 // Note that each DL draws a unique face. Yes, we could have just
90 // used one face and then altered the matrices appropriately, but
91 // that would have been more work.
92
93 // face 1
94
95 DrawList = OSAlloc( ALT_DRAW_SIZE );
96 ASSERT(DrawList);
97
98 GDInitGDLObj( &DrawDLOs[0], DrawList, ALT_DRAW_SIZE );
99 GDSetCurrent( &DrawDLOs[0] );
100
101 GDLoadPosMtxIndx(0, GX_PNMTX0); // Load position mtx for this face
102 GDLoadNrmMtxIndx3x3(0, GX_PNMTX0); // Load normal mtx for this face
103
104 GDBegin( GX_QUADS, GX_VTXFMT0, 4 ); // Draw face
105 GDPosition1x8( 0 ); GDNormal1x8( 0 ); GDTexCoord1x8( 0 );
106 GDPosition1x8( 1 ); GDNormal1x8( 1 ); GDTexCoord1x8( 1 );
107 GDPosition1x8( 2 ); GDNormal1x8( 2 ); GDTexCoord1x8( 2 );
108 GDPosition1x8( 3 ); GDNormal1x8( 3 ); GDTexCoord1x8( 3 );
109 GDEnd();
110
111 // pad & flush
112 GDPadCurr32();
113 GDFlushCurrToMem();
114
115 // face 2
116
117 DrawList = OSAlloc( ALT_DRAW_SIZE );
118 ASSERT(DrawList);
119
120 GDInitGDLObj( &DrawDLOs[1], DrawList, ALT_DRAW_SIZE );
121 GDSetCurrent( &DrawDLOs[1] );
122
123 GDLoadPosMtxIndx(1, GX_PNMTX0);
124 GDLoadNrmMtxIndx3x3(1, GX_PNMTX0);
125
126 GDBegin( GX_QUADS, GX_VTXFMT0, 4 );
127 GDPosition1x8( 4 ); GDNormal1x8( 4 ); GDTexCoord1x8( 0 );
128 GDPosition1x8( 5 ); GDNormal1x8( 5 ); GDTexCoord1x8( 1 );
129 GDPosition1x8( 6 ); GDNormal1x8( 6 ); GDTexCoord1x8( 2 );
130 GDPosition1x8( 7 ); GDNormal1x8( 7 ); GDTexCoord1x8( 3 );
131 GDEnd();
132
133 // pad & flush
134 GDPadCurr32();
135 GDFlushCurrToMem();
136
137 // face 3
138
139 DrawList = OSAlloc( ALT_DRAW_SIZE );
140 ASSERT(DrawList);
141
142 GDInitGDLObj( &DrawDLOs[2], DrawList, ALT_DRAW_SIZE );
143 GDSetCurrent( &DrawDLOs[2] );
144
145 GDLoadPosMtxIndx(2, GX_PNMTX0);
146 GDLoadNrmMtxIndx3x3(2, GX_PNMTX0);
147
148 GDBegin( GX_QUADS, GX_VTXFMT0, 4 );
149 GDPosition1x8( 2 ); GDNormal1x8( 2 ); GDTexCoord1x8( 0 );
150 GDPosition1x8( 6 ); GDNormal1x8( 6 ); GDTexCoord1x8( 1 );
151 GDPosition1x8( 5 ); GDNormal1x8( 5 ); GDTexCoord1x8( 2 );
152 GDPosition1x8( 3 ); GDNormal1x8( 3 ); GDTexCoord1x8( 3 );
153 GDEnd();
154
155 // pad & flush
156 GDPadCurr32();
157 GDFlushCurrToMem();
158
159 // face 4
160
161 DrawList = OSAlloc( ALT_DRAW_SIZE );
162 ASSERT(DrawList);
163
164 GDInitGDLObj( &DrawDLOs[3], DrawList, ALT_DRAW_SIZE );
165 GDSetCurrent( &DrawDLOs[3] );
166
167 GDLoadPosMtxIndx(3, GX_PNMTX0);
168 GDLoadNrmMtxIndx3x3(3, GX_PNMTX0);
169
170 GDBegin( GX_QUADS, GX_VTXFMT0, 4 );
171 GDPosition1x8( 1 ); GDNormal1x8( 1 ); GDTexCoord1x8( 0 );
172 GDPosition1x8( 0 ); GDNormal1x8( 0 ); GDTexCoord1x8( 1 );
173 GDPosition1x8( 4 ); GDNormal1x8( 4 ); GDTexCoord1x8( 2 );
174 GDPosition1x8( 7 ); GDNormal1x8( 7 ); GDTexCoord1x8( 3 );
175 GDEnd();
176
177 // pad & flush
178 GDPadCurr32();
179 GDFlushCurrToMem();
180
181 // face 5
182
183 DrawList = OSAlloc( ALT_DRAW_SIZE );
184 ASSERT(DrawList);
185
186 GDInitGDLObj( &DrawDLOs[4], DrawList, ALT_DRAW_SIZE );
187 GDSetCurrent( &DrawDLOs[4] );
188
189 GDLoadPosMtxIndx(4, GX_PNMTX0);
190 GDLoadNrmMtxIndx3x3(4, GX_PNMTX0);
191
192 GDBegin( GX_QUADS, GX_VTXFMT0, 4 );
193 GDPosition1x8( 5 ); GDNormal1x8( 5 ); GDTexCoord1x8( 0 );
194 GDPosition1x8( 4 ); GDNormal1x8( 4 ); GDTexCoord1x8( 1 );
195 GDPosition1x8( 0 ); GDNormal1x8( 0 ); GDTexCoord1x8( 2 );
196 GDPosition1x8( 3 ); GDNormal1x8( 3 ); GDTexCoord1x8( 3 );
197 GDEnd();
198
199 // pad & flush
200 GDPadCurr32();
201 GDFlushCurrToMem();
202
203 // face 6
204
205 DrawList = OSAlloc( ALT_DRAW_SIZE );
206 ASSERT(DrawList);
207
208 GDInitGDLObj( &DrawDLOs[5], DrawList, ALT_DRAW_SIZE );
209 GDSetCurrent( &DrawDLOs[5] );
210
211 GDLoadPosMtxIndx(5, GX_PNMTX0);
212 GDLoadNrmMtxIndx3x3(5, GX_PNMTX0);
213
214 GDBegin( GX_QUADS, GX_VTXFMT0, 4 );
215 GDPosition1x8( 6 ); GDNormal1x8( 6 ); GDTexCoord1x8( 0 );
216 GDPosition1x8( 2 ); GDNormal1x8( 2 ); GDTexCoord1x8( 1 );
217 GDPosition1x8( 1 ); GDNormal1x8( 1 ); GDTexCoord1x8( 2 );
218 GDPosition1x8( 7 ); GDNormal1x8( 7 ); GDTexCoord1x8( 3 );
219 GDEnd();
220
221 // pad & flush
222 GDPadCurr32();
223 GDFlushCurrToMem();
224
225 GDSetCurrent(NULL); // bug-prevention
226 }
227