1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
program triangle;
{$J+}
{$macro on}
{$mode objfpc}
{$inline on}
uses
cmem, ctypes, gctypes, gccore;
var
framebuffer: pcuint32;
screenMode: PGXRModeObj = nil;
readyForCopy: cuint8;
const
FIFO_SIZE = (256*1024);
var
vertices: array[0..2, 0..2] of cint16 =((0, 15, 0),(-15, -15, 0),(15, -15, 0));
colors: array[0..2, 0..3] of cuint8 = ((255, 0, 0, 255),(0, 255, 0, 255),(0, 0, 255, 255));
procedure update_screen(viewMatrix: Mtx);
var
modelView: Mtx;
begin
guMtxIdentity(modelView);
guMtxTransApply(modelView, modelView, 0.0, 0.0, -50.0);
guMtxConcat(viewMatrix,modelView,modelView);
GX_LoadPosMtxImm(modelView, GX_PNMTX0);
GX_Begin(GX_TRIANGLES, GX_VTXFMT0, 3);
GX_Position1x8(0);
GX_Color1x8(0);
GX_Position1x8(1);
GX_Color1x8(1);
GX_Position1x8(2);
GX_Color1x8(2);
GX_End();
GX_DrawDone();
readyForCopy := GX_TRUE;
VIDEO_WaitVSync();
end;
procedure copy_buffers(count: cuint32); cdecl;
begin
if (readyForCopy = GX_TRUE) then
begin
GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE);
GX_SetColorUpdate(GX_TRUE);
GX_CopyDisp(frameBuffer,GX_TRUE);
GX_Flush();
readyForCopy := GX_FALSE;
end;
end;
var
view: Mtx;
projection: Mtx44;
backgroundColor: GXColor = (r:0; g:0; b:0; a:255;);
fifoBuffer: pcuint32 = nil;
camera, up, look: guVector;
begin
VIDEO_Init();
WPAD_Init();
screenMode := VIDEO_GetPreferredMode(nil);
frameBuffer := MEM_K0_TO_K1(integer(SYS_AllocateFramebuffer(screenMode)));
VIDEO_Configure(screenMode);
VIDEO_SetNextFramebuffer(frameBuffer);
VIDEO_SetPostRetraceCallback(@copy_buffers);
VIDEO_SetBlack(FALSE);
VIDEO_Flush();
fifoBuffer := MEM_K0_TO_K1(integer(memalign(32,FIFO_SIZE)));
memset(fifoBuffer, 0, FIFO_SIZE);
GX_Init(fifoBuffer, FIFO_SIZE);
GX_SetCopyClear(backgroundColor, $00ffffff);
GX_SetViewport(0,0,screenMode^.fbWidth,screenMode^.efbHeight,0,1);
GX_SetDispCopyYScale(f32(screenMode^.xfbHeight) / f32(screenMode^.efbHeight));
GX_SetScissor(0,0,screenMode^.fbWidth,screenMode^.efbHeight);
GX_SetDispCopySrc(0,0,screenMode^.fbWidth,screenMode^.efbHeight);
GX_SetDispCopyDst(screenMode^.fbWidth,screenMode^.xfbHeight);
GX_SetCopyFilter(screenMode^.aa, screenMode^.sample_pattern,
GX_TRUE, screenMode^.vfilter);
if screenMode^.viHeight = 2*screenMode^.xfbHeight then
GX_SetFieldMode(screenMode^.field_rendering,GX_ENABLE)
else
GX_SetFieldMode(screenMode^.field_rendering,GX_DISABLE);
GX_SetCullMode(GX_CULL_NONE);
GX_CopyDisp(frameBuffer,GX_TRUE);
GX_SetDispCopyGamma(GX_GM_1_0);
camera.x := 0.0;
camera.y := 0.0;
camera.z := 0.0;
up.x := 0.0;
up.y := 1.0;
up.z := 0.0;
look.x := 0.0;
look.y := 0.0;
look.z := -1.0;
guPerspective(projection, 60, 1.33, 10.0, 300.0);
GX_LoadProjectionMtx(projection, GX_PERSPECTIVE);
GX_ClearVtxDesc();
GX_SetVtxDesc(GX_VA_POS, GX_INDEX8);
GX_SetVtxDesc(GX_VA_CLR0, GX_INDEX8);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, 0);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
GX_SetArray(GX_VA_POS, @vertices, 3*sizeof(cint16));
GX_SetArray(GX_VA_CLR0, @colors, 4*sizeof(cuint8));
GX_SetNumChans(1);
GX_SetNumTexGens(0);
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0);
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
while true do
begin
guLookAt(view, @camera, @up, @look);
GX_SetViewport(0,0,screenMode^.fbWidth,screenMode^.efbHeight,0,1);
GX_InvVtxCache();
GX_InvalidateTexAll();
update_screen(view);
WPAD_ScanPads();
if (WPAD_ButtonsDown(0) and WPAD_BUTTON_HOME) <> 0 then
exit;
end;
end.
|