Square with changing colors

This commit is contained in:
Samuel Walker 2025-03-28 10:28:22 -06:00
parent 74d678d0bb
commit e7ae07ae13

29
main.c
View File

@ -76,10 +76,13 @@ int gs_init(int width, int height, int psm, int psmz, int vmode, int gmode) {
return 0;
}
static int tri[] = {
10, 10, 0,
600, 200, 0,
20, 400, 0
static int verts[] = {
100, 100, 0,
300, 100, 0,
100, 300, 0,
300, 100, 0,
300, 300, 0,
100, 300, 0
};
#define SHIFT_AS_I64(x, b) (((uint64_t)x)<<b);
@ -96,8 +99,8 @@ int draw() {
q = draw_clear(q, 0, 2048.0f - 320, 2048.0f - 244, VID_W, VID_H, 20, 20, 20);
//q = draw_enable_tests(q, 0, z);
// GIFTag header - 3x(col, pos)
q->dw[0] = 0x7000000000000001;
q->dw[1] = 0x0000000005151510;
q->dw[0] = 0xD000000000000001;
q->dw[1] = 0x0005151515151510;
q++;
q->dw[0] = GS_PRIM_TRIANGLE;
@ -107,15 +110,15 @@ int draw() {
int cx = myftoi4(2048 - (VID_W/2));
int cy = myftoi4(2048 - (VID_H/2));
for(int i = 0; i < 3; i++){
for(int i = 0; i < 6; i++){
q->dw[0] = (red&0xff) | (green&0xff)<<32;
q->dw[1] = (blue&0xff) | SHIFT_AS_I64(0x80, 32);
q++;
int base = i*3;
int x = myftoi4(tri[base+0]) + cx;
int y = myftoi4(tri[base+1]) + cy;
int z = myftoi4(tri[base+2]);
int x = myftoi4(verts[base+0]) + cx;
int y = myftoi4(verts[base+1]) + cy;
int z = myftoi4(verts[base+2]);
q->dw[0] = x | SHIFT_AS_I64(y, 32);
q->dw[1] = z;
q++;
@ -148,9 +151,9 @@ int main() {
z = malloc(sizeof(zbuffer_t));
while(1) {
tri[0]++;
if(tri[0] > 480) {
tri[0] = 0;
red++;
if(red > 0xFF) {
red = 0;
}
draw();
graph_wait_vsync();