diff --git a/framework2/src/loaders/LoaderDFF.cpp b/framework2/src/loaders/LoaderDFF.cpp index 49766bf7..df59df8b 100644 --- a/framework2/src/loaders/LoaderDFF.cpp +++ b/framework2/src/loaders/LoaderDFF.cpp @@ -210,6 +210,9 @@ Model* LoaderDFF::loadFromMemory(char *data, GTAData *gameData) // The data is null terminated anyway. textureName = namesec.raw(); alphaName = alphasec.raw(); + + std::transform(textureName.begin(), textureName.end(), textureName.begin(), ::tolower ); + std::transform(alphaName.begin(), alphaName.end(), alphaName.begin(), ::tolower ); geom->materials[m].textures[t] = {textureName, alphaName}; } diff --git a/framework2/src/loaders/TextureLoader.cpp b/framework2/src/loaders/TextureLoader.cpp index 60252703..751cecdf 100644 --- a/framework2/src/loaders/TextureLoader.cpp +++ b/framework2/src/loaders/TextureLoader.cpp @@ -4,6 +4,7 @@ #include #include +#include bool TextureLoader::loadFromFile(std::string filename, GTAData* gameData) { @@ -22,8 +23,11 @@ bool TextureLoader::loadFromFile(std::string filename, GTAData* gameData) return loadFromMemory(data, gameData); } -GLuint gErrorTextureData[] = { 0xFF0000FF, 0xFF00FF00, 0xFFFF0000, 0xFFFF0000 }; +GLuint gErrorTextureData[] = { 0xFFFF00FF, 0xFF000000, 0xFF000000, 0xFFFF00FF }; GLuint gDebugTextureData[] = {0xFF0000FF, 0xFF00FF00}; +GLuint gTextureRed[] = {0xFF0000FF}; +GLuint gTextureGreen[] = {0xFF00FF00}; +GLuint gTextureBlue[] = {0xFFFF0000}; GLuint getErrorTexture() { @@ -37,6 +41,7 @@ GLuint getErrorTexture() 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, gErrorTextureData ); + glGenerateMipmap(GL_TEXTURE_2D); } return errTexName; } @@ -119,8 +124,9 @@ GLuint createTexture(RW::BSTextureNative& texNative, RW::BinaryStreamSection& ro type = GL_UNSIGNED_SHORT_1_5_5_5_REV; break; case RW::BSTextureNative::FORMAT_8888: - format = GL_RGBA; - type = GL_UNSIGNED_INT_8_8_8_8_REV; + format = GL_BGRA; + //type = GL_UNSIGNED_INT_8_8_8_8_REV; + type = GL_UNSIGNED_BYTE; break; case RW::BSTextureNative::FORMAT_888: format = GL_BGRA; @@ -136,6 +142,9 @@ GLuint createTexture(RW::BSTextureNative& texNative, RW::BinaryStreamSection& ro format, type, coldata ); } + else { + return getErrorTexture(); + } GLenum texFilter = GL_LINEAR; switch(texNative.filterflags & 0xFF) { @@ -199,6 +208,7 @@ bool TextureLoader::loadFromMemory(char *data, GTAData *gameData) RW::BSTextureNative texNative = rootSection.readStructure(); std::string name = std::string(texNative.diffuseName); + std::transform(name.begin(), name.end(), name.begin(), ::tolower ); bool transparent = false; GLuint id = createTexture(texNative, rootSection, &transparent); diff --git a/framework2/src/render/GTARenderer.cpp b/framework2/src/render/GTARenderer.cpp index 885a5d43..7319a830 100644 --- a/framework2/src/render/GTARenderer.cpp +++ b/framework2/src/render/GTARenderer.cpp @@ -54,11 +54,8 @@ const char *fragmentShaderSource = "#version 130\n" " if(c.a < 0.1) discard;" " float fogZ = (gl_FragCoord.z / gl_FragCoord.w);" " float fogfac = clamp( (FogEnd-fogZ)/(FogEnd-FogStart), 0.0, 1.0 );" -//" float l = clamp(dot(Normal, SunDirection), 0.0, 1);" -//" gl_FragColor = vec4(vec3(fogfac), 1.0);" +//" gl_FragColor = mix(AmbientColour, c, fogfac);" " gl_FragColor = mix(AmbientColour, BaseColour * (vec4(0.5) + Colour * 0.5) * (vec4(0.5) + DynamicColour * 0.5) * c, fogfac);" -// " gl_FragColor = vec4((Normal*0.5)+0.5, 1.0);" -// " gl_FragColor = c * vec4((Normal*0.5)+0.5, 1.0);" "}"; const char *skydomeVertexShaderSource = "#version 130\n" @@ -471,11 +468,14 @@ bool GTARenderer::renderSubgeometry(Model* model, size_t g, size_t sg, const glm Model::Material& mat = model->geometries[g]->materials[subgeom.material]; if(mat.textures.size() > 0 ) { - TextureInfo& tex = engine->gameData.textures[mat.textures[0].name]; - if(tex.transparent && queueTransparent) { - return false; + auto t = engine->gameData.textures.find(mat.textures[0].name); + if(t != engine->gameData.textures.end()) { + TextureInfo& tex = t->second; + if(tex.transparent && queueTransparent) { + return false; + } + glBindTexture(GL_TEXTURE_2D, tex.texName); } - glBindTexture(GL_TEXTURE_2D, tex.texName); } if( (model->geometries[g]->flags & RW::BSGeometry::ModuleMaterialColor) == RW::BSGeometry::ModuleMaterialColor) { diff --git a/viewer/main.cpp b/viewer/main.cpp index ac8e28b9..71331066 100644 --- a/viewer/main.cpp +++ b/viewer/main.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -548,6 +549,24 @@ void render() auto p = debugObject->getPosition(); ss << "Position: " << p.x << " " << p.y << " " << p.z << std::endl; ss << "Health: " << debugObject->mHealth << std::endl; + if(debugObject->model) { + auto m = debugObject->model; + ss << "Textures: " << std::endl; + for(auto it = m->geometries.begin(); it != m->geometries.end(); + ++it ) + { + auto g = *it; + for(auto itt = g->materials.begin(); itt != g->materials.end(); + ++itt) + { + for(auto tit = itt->textures.begin(); tit != itt->textures.end(); + ++tit) + { + ss << " " << tit->name << std::endl; + } + } + } + } if(debugObject->type() == GTAObject::Vehicle) { GTAVehicle* vehicle = static_cast(debugObject); ss << "ID: " << vehicle->info.handling.ID << std::endl;