From e17acec1c9bec3a26d97ca2873bb77bdcb48665e Mon Sep 17 00:00:00 2001 From: icculus Date: Thu, 2 Jan 2003 21:06:00 +0000 Subject: Initial revision git-svn-id: svn://svn.icculus.org/blackshades/trunk@2 5198baeb-e213-0410-be47-fc2ff85ca46f --- Source/Sprites.cpp | 499 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 499 insertions(+) create mode 100644 Source/Sprites.cpp (limited to 'Source/Sprites.cpp') diff --git a/Source/Sprites.cpp b/Source/Sprites.cpp new file mode 100644 index 0000000..f4cacda --- /dev/null +++ b/Source/Sprites.cpp @@ -0,0 +1,499 @@ +#include "Sprites.h" + +extern double multiplier; +extern bool slomo; +extern Fog fog; +extern bool blood; +extern float fogcolorr; +extern float fogcolorg; +extern float fogcolorb; +//Functions +extern float sinefluct; +extern int environment; +extern Model gunmodels[10]; +extern Camera camera; +extern float precipitationhorz; +extern float precipitationvert; +extern float precipitationdensity; +extern float snowdelay; + +int Sprites::MakeSprite(int atype, float abrightness, float acolor1, float acolor2, float acolor3, XYZ alocation, XYZ avelocity, float asize){ + type[howmanysprites]=atype; + rotation[howmanysprites]=Random()%360; + brightness[howmanysprites]=abrightness; + color1[howmanysprites]=acolor1; + color2[howmanysprites]=acolor2; + color3[howmanysprites]=acolor3; + location[howmanysprites]=alocation; + oldlocation[howmanysprites]=alocation; + velocity[howmanysprites]=avelocity; + size[howmanysprites]=asize; + initialsize[howmanysprites]=asize; + initialbrightness[howmanysprites]=abrightness; + initialvelocity[howmanysprites]=avelocity; + alivetime[howmanysprites]=0; + owner[howmanysprites]=0; + if(howmanysprites=0){ + location[which]=location[howmanysprites-1]; + oldlocation[which]=oldlocation[howmanysprites-1]; + velocity[which]=velocity[howmanysprites-1]; + initialsize[which]=initialsize[howmanysprites-1]; + size[which]=size[howmanysprites-1]; + brightness[which]=brightness[howmanysprites-1]; + initialbrightness[which]=initialbrightness[howmanysprites-1]; + color1[which]=color1[howmanysprites-1]; + color2[which]=color2[howmanysprites-1]; + color3[which]=color3[howmanysprites-1]; + alivetime[which]=alivetime[howmanysprites-1]; + rotation[which]=rotation[howmanysprites-1]; + type[which]=type[howmanysprites-1]; + type[howmanysprites-1]=0; + + if(howmanysprites>0){howmanysprites--;} + } +} + +void Sprites::LoadFlareTexture(char *fileName) +{ + TGAImageRec *tempTexture; + GLuint type; + + //Load Image + tempTexture = LoadTGA( fileName ); + //Is it valid? + if(tempTexture){ + //Alpha channel? + if ( tempTexture->bpp == 24 ) + type = GL_RGB; + else + type = GL_RGBA; + + glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); + + glGenTextures( 1, &flaretextureptr ); + glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + + glBindTexture( GL_TEXTURE_2D, flaretextureptr); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + + gluBuild2DMipmaps( GL_TEXTURE_2D, type, tempTexture->sizeX, tempTexture->sizeY, type, GL_UNSIGNED_BYTE, tempTexture->data ); + free( tempTexture->data ); + free( tempTexture ); + } +} + +void Sprites::LoadMuzzleFlareTexture(char *fileName) +{ + TGAImageRec *tempTexture; + GLuint type; + + //Load Image + tempTexture = LoadTGA( fileName ); + //Is it valid? + if(tempTexture){ + //Alpha channel? + if ( tempTexture->bpp == 24 ) + type = GL_RGB; + else + type = GL_RGBA; + + glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); + + glGenTextures( 1, &muzzleflaretextureptr ); + glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + + glBindTexture( GL_TEXTURE_2D, muzzleflaretextureptr); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + + gluBuild2DMipmaps( GL_TEXTURE_2D, type, tempTexture->sizeX, tempTexture->sizeY, type, GL_UNSIGNED_BYTE, tempTexture->data ); + free( tempTexture->data ); + free( tempTexture ); + } +} + +void Sprites::LoadSmokeTexture(char *fileName) +{ + TGAImageRec *tempTexture; + GLuint type; + + //Load Image + tempTexture = LoadTGA( fileName ); + //Is it valid? + if(tempTexture){ + //Alpha channel? + if ( tempTexture->bpp == 24 ) + type = GL_RGB; + else + type = GL_RGBA; + + glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); + + glGenTextures( 1, &smoketextureptr ); + glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + + glBindTexture( GL_TEXTURE_2D, smoketextureptr); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + + gluBuild2DMipmaps( GL_TEXTURE_2D, type, tempTexture->sizeX, tempTexture->sizeY, type, GL_UNSIGNED_BYTE, tempTexture->data ); + free( tempTexture->data ); + free( tempTexture ); + } +} + +void Sprites::LoadBloodTexture(char *fileName) +{ + TGAImageRec *tempTexture; + GLuint type; + + //Load Image + tempTexture = LoadTGA( fileName ); + //Is it valid? + if(tempTexture){ + //Alpha channel? + if ( tempTexture->bpp == 24 ) + type = GL_RGB; + else + type = GL_RGBA; + + glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); + + glGenTextures( 1, &bloodtextureptr ); + glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + + glBindTexture( GL_TEXTURE_2D, bloodtextureptr); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + + gluBuild2DMipmaps( GL_TEXTURE_2D, type, tempTexture->sizeX, tempTexture->sizeY, type, GL_UNSIGNED_BYTE, tempTexture->data ); + free( tempTexture->data ); + free( tempTexture ); + } +} + +void Sprites::LoadRainTexture(char *fileName) +{ + TGAImageRec *tempTexture; + GLuint type; + + //Load Image + tempTexture = LoadTGA( fileName ); + //Is it valid? + if(tempTexture){ + //Alpha channel? + if ( tempTexture->bpp == 24 ) + type = GL_RGB; + else + type = GL_RGBA; + + glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); + + glGenTextures( 1, &raintextureptr ); + glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + + glBindTexture( GL_TEXTURE_2D, raintextureptr); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + + gluBuild2DMipmaps( GL_TEXTURE_2D, type, tempTexture->sizeX, tempTexture->sizeY, type, GL_UNSIGNED_BYTE, tempTexture->data ); + free( tempTexture->data ); + free( tempTexture ); + } +} + +void Sprites::LoadSnowTexture(char *fileName) +{ + TGAImageRec *tempTexture; + GLuint type; + + //Load Image + tempTexture = LoadTGA( fileName ); + //Is it valid? + if(tempTexture){ + //Alpha channel? + if ( tempTexture->bpp == 24 ) + type = GL_RGB; + else + type = GL_RGBA; + + glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); + + glGenTextures( 1, &snowtextureptr ); + glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + + glBindTexture( GL_TEXTURE_2D, snowtextureptr); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + + gluBuild2DMipmaps( GL_TEXTURE_2D, type, tempTexture->sizeX, tempTexture->sizeY, type, GL_UNSIGNED_BYTE, tempTexture->data ); + free( tempTexture->data ); + free( tempTexture ); + } +} + +void Sprites::LoadBulletTexture(char *fileName) +{ + TGAImageRec *tempTexture; + GLuint type; + + //Load Image + tempTexture = LoadTGA( fileName ); + //Is it valid? + if(tempTexture){ + //Alpha channel? + if ( tempTexture->bpp == 24 ) + type = GL_RGB; + else + type = GL_RGBA; + + glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); + + glGenTextures( 1, &bullettextureptr ); + glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + + glBindTexture( GL_TEXTURE_2D, bullettextureptr); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + + gluBuild2DMipmaps( GL_TEXTURE_2D, type, tempTexture->sizeX, tempTexture->sizeY, type, GL_UNSIGNED_BYTE, tempTexture->data ); + free( tempTexture->data ); + free( tempTexture ); + } +} + + +void Sprites::DoStuff() +{ + for(int i=0;i0){ + velocity[i].y+=gravity*multiplier; + rotation[i]+=multiplier*2; + } + } + if(type[i]==bloodspritedown||type[i]==particlesspritedown){ + velocity[i].y+=gravity*multiplier; + } + + if(type[i]!=bulletinstant&&type[i]!=bullet)location[i]=location[i]+velocity[i]*multiplier; + + alivetime[i]+=multiplier; + if(brightness[i]<=0)DeleteSprite(i); + if(type[i]==snowsprite&&(location[i].y<-.1||environment!=snowy_environment))DeleteSprite(i); + if(type[i]==rainsprite&&(location[i].y<-.1||environment!=rainy_environment))DeleteSprite(i); + + if(type[i]==snowsprite){ + if(location[i].xcamera.position.x+precipitationhorz){location[i].x-=precipitationhorz*2;} + if(location[i].z>camera.position.z+precipitationhorz){location[i].z-=precipitationhorz*2;} + if(location[i].y>camera.position.y+precipitationvert){location[i].y-=precipitationvert*2;} + } + if(type[i]==rainsprite){ + if(location[i].xcamera.position.x+precipitationhorz*.5){location[i].x-=precipitationhorz;} + if(location[i].z>camera.position.z+precipitationhorz*.5){location[i].z-=precipitationhorz;} + if(location[i].y>camera.position.y+precipitationvert){location[i].y-=precipitationvert*2;} + } + } +} + +void Sprites::draw() +{ + float M[16]; + XYZ begProj,endProj,avgProj,persp; + XYZ between; + float oolen,dx,dy; + float bulletsize; + XYZ point; + glAlphaFunc(GL_GREATER, 0.01); + + //glEnable(GL_POLYGON_OFFSET_FILL); + + glEnable(GL_BLEND); + glDisable(GL_CULL_FACE); + glEnable(GL_TEXTURE_2D); + glDisable(GL_LIGHTING); + glDepthMask(0); + glAlphaFunc(GL_GREATER, 0.01); + for(int i=0;i