// Write the dat file that contains the GifTag and data to draw // Basic: // QW 0 - GIFTAG: // NLOOP=3, // EOP=1, // PRE=1, // PRIM=tri,gouraud,notex,nofog,noalpha,noaa,N/A,ctxt1,unfixed // FLG=PACKED // NREG=2 // REGS=0x51 // QW 1 - COLOR 1 (red) // QW 2 - VERTEX 1 (2048-100,2048-50,1) // QW 3 - COLOR 2 (green) // QW 4 - VERTEX 2 (2048+100,2048-50,1) // QW 5 - COLOR 3 (blue) // QW 6 - VERTEX 3 (2048+100,2048+50,1) #include #include "packet.h" typedef union { u_long128 ul128; u_long64 ul64[2]; u_int ui32[4]; float f32[4]; } qword_t; int main(int argc, char **argv) { FILE *output; int bytes=0; int prim=0; qword_t color; qword_t vertex; u_long128 packet_data[1024]; gifpacket_t gifpacket; if (argc!=2) { fprintf(stderr, "Usage: gen_data output_file\n"); return -1; } gifpacket_init(&gifpacket, packet_data); prim=GS_SET_PRIM(GS_PRIM_TRI, GOURAUD(1), TEXTURED(0), FOG(0), ABE(0), ALPHA(0), AA(0), CTXT(0), FIX(0)); gifpacket_addgsdata(&gifpacket, GIF_SET_TAG(NLOOP(3), EOP(1), PRE(1), prim, GIF_PACKED, NREG(2))); gifpacket_addgsdata(&gifpacket, 0x51); color.ui32[0]=0xFF; color.ui32[1]=0x0; color.ui32[2]=0x0; color.ui32[3]=0x0; gifpacket_addgspacked(&gifpacket, color.ul128); vertex.ui32[0]=(2048-100)<<4; vertex.ui32[1]=(2048-50)<<4; vertex.ui32[2]=1; vertex.ui32[3]=1; gifpacket_addgspacked(&gifpacket, vertex.ul128); color.ui32[0]=0x0; color.ui32[1]=0xFF; color.ui32[2]=0x0; color.ui32[3]=0x0; gifpacket_addgspacked(&gifpacket, color.ul128); vertex.ui32[0]=(2048+100)<<4; vertex.ui32[1]=(2048-50)<<4; vertex.ui32[2]=1; vertex.ui32[3]=1; gifpacket_addgspacked(&gifpacket, vertex.ul128); color.ui32[0]=0x0; color.ui32[1]=0x0; color.ui32[2]=0xFF; color.ui32[3]=0x0; gifpacket_addgspacked(&gifpacket, color.ul128); vertex.ui32[0]=(2048+100)<<4; vertex.ui32[1]=(2048+50)<<4; vertex.ui32[2]=1; vertex.ui32[3]=1; gifpacket_addgspacked(&gifpacket, vertex.ul128); gifpacket_terminate(&gifpacket); output=fopen(argv[1], "wb"); if (output==NULL) { fprintf(stderr, "Could not open file \"%s\"\n", argv[1]); return -1; } fwrite(packet_data, sizeof(packet_data)/sizeof(qword_t), sizeof(qword_t), output); bytes=ftell(output); fclose(output); printf("Written %d bytes to \"%s\"\n", bytes, argv[1]); return 0; }