X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FModels.cpp;h=95b93fe4c489d238a2efe1afbfd6e1b04fdc7885;hb=26debbd380c6922e5a0b60d99567c6374a4fef9a;hp=4db0b741709a39ae0317390f4dd7d750d1fd3390;hpb=483f57f7df7e65f1aacbee8dbcef320ede069a95;p=lugaru.git diff --git a/Source/Models.cpp b/Source/Models.cpp index 4db0b74..95b93fe 100644 --- a/Source/Models.cpp +++ b/Source/Models.cpp @@ -29,7 +29,6 @@ extern float fadestart; extern float texdetail; extern bool decals; -extern Game * pgame; extern bool visibleloading; int Model::LineCheck(XYZ *p1,XYZ *p2, XYZ *p, XYZ *move, float *rotate) @@ -481,7 +480,7 @@ bool Model::load(const char *filename,bool texture ) LOG(std::string("Loading model...") + filename); if(visibleloading) - pgame->LoadingScreen(); + Game::LoadingScreen(); int oldvertexNum,oldTriangleNum; oldvertexNum=vertexNum; @@ -525,7 +524,7 @@ bool Model::load(const char *filename,bool texture ) funpackf(tfile, "Bf Bf Bf", &Triangles[i].gy[0], &Triangles[i].gy[1], &Triangles[i].gy[2]); } - Texture.xsz=0; + modelTexture.xsz=0; fclose(tfile); @@ -608,7 +607,7 @@ bool Model::loaddecal(const char *filename,bool texture ) } - Texture.xsz=0; + modelTexture.xsz=0; fclose(tfile); @@ -844,7 +843,7 @@ void Model::Rotate(float xang,float yang,float zang) void Model::CalculateNormals(bool facenormalise) { if(visibleloading) - pgame->LoadingScreen(); + Game::LoadingScreen(); static int i; if(type!=normaltype&&type!=decalstype)return; @@ -879,7 +878,7 @@ void Model::CalculateNormals(bool facenormalise) void Model::drawimmediate() { - glBindTexture(GL_TEXTURE_2D,(unsigned long)textureptr); + textureptr.bind(); glBegin(GL_TRIANGLES); for(int i=0;i=0&&Triangles[i].vertex[1]>=0&&Triangles[i].vertex[2]>=0){ @@ -920,7 +919,7 @@ void Model::draw() if(!color)glInterleavedArrays( GL_T2F_N3F_V3F,8*sizeof(GLfloat),&vArray[0]); if(color)glInterleavedArrays( GL_T2F_C3F_V3F,8*sizeof(GLfloat),&vArray[0]); - glBindTexture(GL_TEXTURE_2D,(unsigned long)textureptr); + textureptr.bind(); #if PLATFORM_MACOSX glLockArraysEXT( 0, TriangleNum*3); @@ -938,6 +937,7 @@ void Model::draw() //drawimmediate(); } +//TODO: phase out in favor of Texture void Model::drawdifftex(GLuint texture) { glEnableClientState(GL_NORMAL_ARRAY); @@ -951,6 +951,35 @@ void Model::drawdifftex(GLuint texture) glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); +#ifndef WIN32 + glLockArraysEXT( 0, TriangleNum*3); +#endif + glDrawArrays(GL_TRIANGLES, 0, TriangleNum*3); +#ifndef WIN32 + glUnlockArraysEXT(); +#endif + + + if(!color)glDisableClientState(GL_NORMAL_ARRAY); + if(color)glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + //drawdiffteximmediate(texture); +} + +void Model::drawdifftex(Texture texture) +{ + glEnableClientState(GL_NORMAL_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + if(!color)glInterleavedArrays( GL_T2F_N3F_V3F,8*sizeof(GLfloat),&vArray[0]); + if(color)glInterleavedArrays( GL_T2F_C3F_V3F,8*sizeof(GLfloat),&vArray[0]); + + texture.bind(); + glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); + glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); + + #ifndef WIN32 glLockArraysEXT( 0, TriangleNum*3); #endif @@ -1000,7 +1029,7 @@ void Model::drawdiffteximmediate(GLuint texture) glEnd(); } -void Model::drawdecals(GLuint shadowtexture,GLuint bloodtexture,GLuint bloodtexture2,GLuint breaktexture) +void Model::drawdecals(Texture shadowtexture,Texture bloodtexture,Texture bloodtexture2,Texture breaktexture) { if(decals){ if(type!=decalstype)return; @@ -1024,7 +1053,7 @@ void Model::drawdecals(GLuint shadowtexture,GLuint bloodtexture,GLuint bloodtext if(decaltype[i]==blooddecalfast&&decalalivetime[i]<2)decalalivetime[i]=2; if(decaltype[i]==shadowdecal&&decaltype[i]!=lasttype){ - glBindTexture( GL_TEXTURE_2D, shadowtexture); + shadowtexture.bind(); if(!blend){ blend=1; glAlphaFunc(GL_GREATER, 0.0001); @@ -1032,7 +1061,7 @@ void Model::drawdecals(GLuint shadowtexture,GLuint bloodtexture,GLuint bloodtext } } if(decaltype[i]==breakdecal&&decaltype[i]!=lasttype){ - glBindTexture( GL_TEXTURE_2D, breaktexture); + breaktexture.bind(); if(!blend){ blend=1; glAlphaFunc(GL_GREATER, 0.0001); @@ -1040,7 +1069,7 @@ void Model::drawdecals(GLuint shadowtexture,GLuint bloodtexture,GLuint bloodtext } } if((decaltype[i]==blooddecal||decaltype[i]==blooddecalslow)&&decaltype[i]!=lasttype){ - glBindTexture( GL_TEXTURE_2D, bloodtexture); + bloodtexture.bind(); if(blend){ blend=0; glAlphaFunc(GL_GREATER, 0.15); @@ -1048,7 +1077,7 @@ void Model::drawdecals(GLuint shadowtexture,GLuint bloodtexture,GLuint bloodtext } } if((decaltype[i]==blooddecalfast)&&decaltype[i]!=lasttype){ - glBindTexture( GL_TEXTURE_2D, bloodtexture2); + bloodtexture2.bind(); if(blend){ blend=0; glAlphaFunc(GL_GREATER, 0.15); @@ -1386,8 +1415,7 @@ void Model::MakeDecal(int atype, XYZ where,float size, float opacity, float rota Model::~Model() { deallocate(); - - if(textureptr) glDeleteTextures( 1, &textureptr ); + textureptr.destroy(); } void Model::deallocate() @@ -1475,8 +1503,7 @@ Model::Model() Triangles=0; vArray=0; - textureptr = 0; - memset(&Texture, 0, sizeof(Texture)); + memset(&modelTexture, 0, sizeof(modelTexture)); numpossible = 0; color = 0;