bool replaceTexture(const QString &oldfile, const QString &newfile) { char tmpname[iV_TEXNAME_MAX]; // Load new one to replace it iV_Image image; if (!iV_loadImage_PNG(QString("texpages/" + newfile).toUtf8().constData(), &image)) { debug(LOG_ERROR, "Failed to load image: %s", newfile.toUtf8().constData()); return false; } sstrcpy(tmpname, oldfile.toUtf8().constData()); pie_MakeTexPageName(tmpname); // Have we already loaded this one? for (int i = 0; i < _TEX_PAGE.size(); i++) { if (strcmp(tmpname, _TEX_PAGE[i].name) == 0) { GL_DEBUG("Replacing texture"); debug(LOG_TEXTURE, "Replacing texture %s with %s from index %d (tex id %u)", _TEX_PAGE[i].name, newfile.toUtf8().constData(), i, _TEX_PAGE[i].id); sstrcpy(tmpname, newfile.toUtf8().constData()); pie_MakeTexPageName(tmpname); pie_AddTexPage(&image, tmpname, true, i); iV_unloadImage(&image); return true; } } iV_unloadImage(&image); debug(LOG_ERROR, "Nothing to replace!"); return false; }
void GFX::loadTexture(const char *filename, GLenum filter) { const char *extension = strrchr(filename, '.'); // determine the filetype iV_Image image; if (!extension || strcmp(extension, ".png") != 0) { debug(LOG_ERROR, "Bad image filename: %s", filename); return; } if (iV_loadImage_PNG(filename, &image)) { makeTexture(image.width, image.height, filter, iV_getPixelFormat(&image), image.bmp); iV_unloadImage(&image); } }
void screen_SetBackDropFromFile(const char* filename) { // HACK : We should use a resource handler here! const char *extension = strrchr(filename, '.');// determine the filetype iV_Image image; if(!extension) { debug(LOG_ERROR, "Image without extension: \"%s\"!", filename); return; // filename without extension... don't bother } // Make sure the current texture page is reloaded after we are finished // Otherwise WZ will think it is still loaded and not load it again pie_SetTexturePage(TEXPAGE_EXTERN); if( strcmp(extension,".png") == 0 ) { if (iV_loadImage_PNG( filename, &image ) ) { if (~backDropTexture == 0) glGenTextures(1, &backDropTexture); glBindTexture(GL_TEXTURE_2D, backDropTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width, image.height, 0, iV_getPixelFormat(&image), GL_UNSIGNED_BYTE, image.bmp); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); iV_unloadImage(&image); } return; } else debug(LOG_ERROR, "Unknown extension \"%s\" for image \"%s\"!", extension, filename); }