Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 3dfx test: texture mapped polygon - ralf 1998
- #define WIN32_LEAN_AND_MEAN
- #include <windows.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <glide.h>
- void LoadTexture(char *filename,GrMipMapId_t *decal)
- { Gu3dfInfo info;
- if(!gu3dfGetInfo(filename,&info))
- { puts("could not load texture\n");
- grGlideShutdown();
- exit(-1);
- }
- info.data=malloc(info.mem_required);//tmp
- if(!info.data)
- { puts("not enough memory\n");
- grGlideShutdown();
- exit(-1);
- }
- if(!gu3dfLoad(filename,&info))
- { puts("can't load texture file\n");
- grGlideShutdown();
- free(info.data);
- exit(-1);
- }
- *decal=guTexAllocateMemory(0,GR_MIPMAPLEVELMASK_BOTH,
- info.header.width,info.header.height,info.header.format,
- GR_MIPMAP_NEAREST,info.header.small_lod,info.header.large_lod,
- info.header.aspect_ratio,GR_TEXTURECLAMP_WRAP,GR_TEXTURECLAMP_WRAP,
- GR_TEXTUREFILTER_BILINEAR,GR_TEXTUREFILTER_BILINEAR,0.0F,FXFALSE);
- if(*decal==GR_NULL_MIPMAP_HANDLE)
- { puts("not enough memory on card\n");
- grGlideShutdown();
- free(info.data);
- exit(-1);
- }
- // send to card
- guTexDownloadMipMap(*decal,info.data,&info.table.nccTable);
- free(info.data);
- }
- void AnimEffect(GrVertex *v,int i)
- { v->x+=(float)i;
- v->y+=(float)i;
- }
- void main(void)
- { GrHwConfiguration hwconfig;
- GrMipMapId_t tex1;
- GrVertex object[4];
- int list[]={0,1,2,3};
- int d=1,i=0;
- object[0].x=100.0f;
- object[0].y=100.0f;
- object[0].z=2.0f;
- object[0].oow=1.0f/object[0].z;
- object[0].tmuvtx[0].sow=0.0f;
- object[0].tmuvtx[0].tow=127.0f;
- object[1].x=400.0f;
- object[1].y=100.0f;
- object[1].z=2.0f;
- object[1].oow=1.0f/object[1].z;
- object[1].tmuvtx[0].sow=127.0f;
- object[1].tmuvtx[0].tow=127.0f;
- object[2].x=400.0f;
- object[2].y=400.0f;
- object[2].z=2.0f;
- object[2].oow=1.0f/object[2].z;
- object[2].tmuvtx[0].sow=127.0f;
- object[2].tmuvtx[0].tow=0.0f;
- object[3].x=100.0f;
- object[3].y=400.0f;
- object[3].z=2.0f;
- object[3].oow=1.0f/object[3].z;
- object[3].tmuvtx[0].sow=0.0f;
- object[3].tmuvtx[0].tow=0.0f;
- puts("texture mapped polygon...");
- grGlideInit();
- if(grSstQueryHardware(&hwconfig)) //card found
- { grSstSelect(0);//useful if more than 1 card
- // set basic screen drawing options
- grSstWinOpen(NULL,GR_RESOLUTION_640x480,GR_REFRESH_60Hz,
- GR_COLORFORMAT_RGBA,GR_ORIGIN_LOWER_LEFT,2,0);
- }
- else
- { puts("voodoo card not found");
- grGlideShutdown();
- exit(1);
- }
- LoadTexture("test.3df",&tex1);//load texture file to card
- guColorCombineFunction(GR_COLORCOMBINE_DECAL_TEXTURE);
- grTexCombineFunction(GR_TMU0,GR_TEXTURECOMBINE_DECAL);
- grDepthBufferMode(GR_DEPTHBUFFER_WBUFFER);
- grDepthBufferFunction(GR_CMP_LESS);
- grDepthMask(FXTRUE);
- while(!kbhit()) //main loop
- { grBufferClear(0,0,GR_WDEPTHVALUE_FARTHEST);
- guTexSource(tex1);
- grDrawPolygon(4,list,object);
- grBufferSwap(1);//flip buffer when drawn
- AnimEffect(&object[0],d);
- AnimEffect(&object[1],d);
- AnimEffect(&object[2],d);
- AnimEffect(&object[3],d);
- if(++i>75) {i=0; d=-d;}
- }
- grGlideShutdown();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement