diff options
Diffstat (limited to 'src/irrlichtwrapper.cpp')
-rw-r--r-- | src/irrlichtwrapper.cpp | 71 |
1 files changed, 55 insertions, 16 deletions
diff --git a/src/irrlichtwrapper.cpp b/src/irrlichtwrapper.cpp index 69b08a6d8..51511eb34 100644 --- a/src/irrlichtwrapper.cpp +++ b/src/irrlichtwrapper.cpp @@ -17,7 +17,8 @@ void IrrlichtWrapper::Run() GetRequest<TextureSpec, video::ITexture*, u8, u8> request = m_get_texture_queue.pop(); - dstream<<"got request with key.name="<<request.key.name<<std::endl; + dstream<<"got texture request with key.name=" + <<request.key.name<<std::endl; GetResult<TextureSpec, video::ITexture*, u8, u8> result; @@ -37,7 +38,9 @@ video::ITexture* IrrlichtWrapper::getTexture(TextureSpec spec) if(get_current_thread_id() == m_main_thread) { - dstream<<"Loading texture directly: "<<spec.name<<std::endl; + dstream<<"Getting texture directly: name=" + <<spec.name<<std::endl; + t = getTextureDirect(spec); } else @@ -52,7 +55,7 @@ video::ITexture* IrrlichtWrapper::getTexture(TextureSpec spec) // Wait result GetResult<TextureSpec, video::ITexture*, u8, u8> - result = result_queue.pop_front(true); + result = result_queue.pop_front(1000); // Check that at least something worked OK assert(result.key.name == spec.name); @@ -67,10 +70,6 @@ video::ITexture* IrrlichtWrapper::getTexture(TextureSpec spec) video::ITexture* IrrlichtWrapper::getTexture(const std::string &path) { - /*TextureSpec spec; - spec.name = path; - spec.path = path; - return getTexture(spec);*/ return getTexture(TextureSpec(path, path, NULL)); } @@ -81,21 +80,61 @@ video::ITexture* IrrlichtWrapper::getTexture(const std::string &path) video::ITexture* IrrlichtWrapper::getTextureDirect(TextureSpec spec) { video::IVideoDriver* driver = m_device->getVideoDriver(); - //TODO - if(spec.mod != NULL) + + if(spec.mod == NULL) { - dstream<<"IrrlichtWrapper::getTextureDirect: Modified textures" - " not supported"<<std::endl; + dstream<<"IrrlichtWrapper::getTextureDirect: Loading texture " + <<spec.path<<std::endl; + return driver->getTexture(spec.path.c_str()); } - return driver->getTexture(spec.path.c_str()); + + dstream<<"IrrlichtWrapper::getTextureDirect: Loading and modifying " + "texture "<<spec.path<<" to make "<<spec.name<<std::endl; + + video::ITexture *base = driver->getTexture(spec.path.c_str()); + video::ITexture *result = spec.mod->make(base, spec.name.c_str(), driver); + + delete spec.mod; + + return result; } video::ITexture * CrackTextureMod::make(video::ITexture *original, - video::IVideoDriver* driver) + const char *newname, video::IVideoDriver* driver) { - //TODO - dstream<<__FUNCTION_NAME<<std::endl; - return NULL; + core::dimension2d<u32> dim(16, 16); + core::position2d<s32> pos_base(0, 0); + core::position2d<s32> pos_other(0, 16 * progression); + + video::IImage *baseimage = driver->createImage(original, pos_base, dim); + assert(baseimage); + + video::ITexture *other = driver->getTexture("../data/crack.png"); + // We have to get the whole texture because getting a smaller area + // messes the whole thing. It is probably a bug in Irrlicht. + video::IImage *otherimage = driver->createImage( + other, core::position2d<s32>(0,0), other->getSize()); + + assert(otherimage); + + /*core::rect<s32> clip_rect(v2s32(0,0), dim); + otherimage->copyToWithAlpha(baseimage, v2s32(0,0), + core::rect<s32>(pos_other, dim), + video::SColor(255,255,255,255), + &clip_rect);*/ + + otherimage->copyToWithAlpha(baseimage, v2s32(0,0), + core::rect<s32>(pos_other, dim), + video::SColor(255,255,255,255), + NULL); + + otherimage->drop(); + + video::ITexture *newtexture = driver->addTexture(newname, baseimage); + + baseimage->drop(); + + return newtexture; } #if 0 |