From 607f548712ae5a41eceb668085c87d10089849b9 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 14 Feb 2011 16:10:46 +0200 Subject: [PATCH] cube inventory texture rendering thing (not good yet) --- src/tile.cpp | 142 ++++++++++++++++++++++++++++++++++++++------------- src/tile.h | 2 - 2 files changed, 107 insertions(+), 37 deletions(-) diff --git a/src/tile.cpp b/src/tile.cpp index c3ca5837..4a6523ac 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -136,7 +136,7 @@ void make_progressbar(float value, video::IImage *image); if baseimg is NULL, it is created. Otherwise stuff is made on it. */ bool generate_image(std::string part_of_name, video::IImage *& baseimg, - video::IVideoDriver* driver); + IrrlichtDevice *device); /* Generates an image from a full string like @@ -145,7 +145,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg, This is used by buildMainAtlas(). */ video::IImage* generate_image_from_scratch(std::string name, - video::IVideoDriver* driver); + IrrlichtDevice *device); /* This method generates all the textures @@ -284,7 +284,7 @@ u32 TextureSource::getTextureIdDirect(const std::string &name) dstream<<"last_part_of_name="<drop();*/ // Generate image by name - video::IImage *img2 = generate_image_from_scratch(name, driver); + video::IImage *img2 = generate_image_from_scratch(name, m_device); if(img2 == NULL) { dstream<<"WARNING: TextureSource::buildMainAtlas(): Couldn't generate texture atlas: Couldn't generate image \""<getVideoDriver(); + assert(driver); + // Stuff starting with [ are special commands if(part_of_name[0] != '[') { @@ -857,8 +863,6 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg, return false; } - // This is just a placeholder - str_replace_char(part_of_name, '&', '^'); Strfnd sf(part_of_name); sf.next("{"); @@ -866,47 +870,115 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg, std::string imagename_left = sf.next("{"); std::string imagename_right = sf.next("{"); - baseimg = generate_image_from_scratch( - imagename_top, driver); - +#if 1 //TODO -#if 0 + if(driver->queryFeature(video::EVDF_RENDER_TO_TARGET) == false) { dstream<<"WARNING: getTextureIdDirect(): EVDF_RENDER_TO_TARGET" - " not supported"<addRenderTargetTexture(dim, rtt_name.c_str()); - assert(rtt); - - + imagename_right, device); + assert(img_top && img_left && img_right); + + // TODO: Create textures from images + video::ITexture *texture_top = driver->addTexture( + (imagename_top + "__temp__").c_str(), img_top); + assert(texture_top); + // Drop images img_top->drop(); img_left->drop(); img_right->drop(); - //TODO - assert(0); + // Create render target texture + video::ITexture *rtt = NULL; + std::string rtt_name = part_of_name + "_RTT"; + rtt = driver->addRenderTargetTexture(dim, rtt_name.c_str(), + video::ECF_A8R8G8B8); + assert(rtt); + + // Set render target + driver->setRenderTarget(rtt, true, true, + video::SColor(0,0,0,0)); + + // Get a scene manager + scene::ISceneManager *smgr_main = device->getSceneManager(); + assert(smgr_main); + scene::ISceneManager *smgr = smgr_main->createNewSceneManager(); + assert(smgr); + + /* + Create scene: + - An unit cube is centered at 0,0,0 + - Camera looks at cube from Y+, Z- towards Y-, Z+ + NOTE: Cube has to be changed to something else because + the textures cannot be set individually (or can they?) + */ + + scene::ISceneNode* cube = smgr->addCubeSceneNode(1.0, NULL, -1, + v3f(0,0,0), v3f(0, 45, 0)); + // Set texture of cube + cube->setMaterialTexture(0, texture_top); + //cube->setMaterialFlag(video::EMF_LIGHTING, false); + cube->setMaterialFlag(video::EMF_ANTI_ALIASING, false); + cube->setMaterialFlag(video::EMF_BILINEAR_FILTER, false); + + scene::ICameraSceneNode* camera = smgr->addCameraSceneNode(0, + v3f(0, 1.0, -1.5), v3f(0, 0, 0)); + // Set orthogonal projection + core::CMatrix4 pm; + pm.buildProjectionMatrixOrthoLH(1.65, 1.65, 0, 100); + camera->setProjectionMatrix(pm, true); + + scene::ILightSceneNode *light = smgr->addLightSceneNode(0, + v3f(-50, 100, 0), video::SColorf(0.5,0.5,0.5), 1000); + + // Render scene + driver->beginScene(true, true, video::SColor(0,0,0,0)); + smgr->drawAll(); + driver->endScene(); + + // Drop scene + cube->drop(); + camera->drop(); + light->drop(); + // Drop scene manager FIXME: Segfaults + //smgr->drop(); + + // Unset render target + driver->setRenderTarget(0, true, true, 0); + + //TODO: Free textures of images + driver->removeTexture(texture_top); + + // Create image of render target + video::IImage *image = driver->createImage(rtt, v2s32(0,0), dim); + + assert(image); + + baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); + + if(image) + { + image->copyTo(baseimg); + image->drop(); + } #endif } else diff --git a/src/tile.h b/src/tile.h index 1e339806..d1189943 100644 --- a/src/tile.h +++ b/src/tile.h @@ -261,8 +261,6 @@ enum MaterialType{ /* This fully defines the looks of a tile. The SMaterial of a tile is constructed according to this. - - TODO: Change this to use an AtlasPointer */ struct TileSpec {