Skip to content

Instantly share code, notes, and snippets.

@infogulch
Created July 27, 2012 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infogulch/3191075 to your computer and use it in GitHub Desktop.
Save infogulch/3191075 to your computer and use it in GitHub Desktop.
Excerpt from slab6.c: savevox()
void savevox (char *filnam)
{
FILE *fil;
long i, x, y, z;
voxtype *vptr, *vptr2;
optimizexdimen();
optimizeydimen();
optimizezdimen();
if (!(fil = fopen(filnam,"wb"))) return;
fwrite(&xsiz,4,1,fil);
fwrite(&ysiz,4,1,fil);
fwrite(&zsiz,4,1,fil);
vptr = voxdata;
for(x=0;x<xsiz;x++)
for(y=0;y<ysiz;y++)
{
vptr2 = &vptr[ylen[x][y]];
for(z=0;z<zsiz;z++)
{
if ((vptr < vptr2) && (vptr->z == z))
{ fputc(vptr->col,fil); vptr++; }
else
{
i = (x*MAXYSIZ+y)*BUFZSIZ+z;
if (!(vbit[i>>5]&(1<<i))) fputc(0,fil);
else fputc(255,fil);
}
}
}
fwrite(fipalette,768,1,fil);
fclose(fil);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment