cube inventory texture rendering thing (not good yet)
This commit is contained in:
parent
00810408a8
commit
607f548712
142
src/tile.cpp
142
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.
|
if baseimg is NULL, it is created. Otherwise stuff is made on it.
|
||||||
*/
|
*/
|
||||||
bool generate_image(std::string part_of_name, video::IImage *& baseimg,
|
bool generate_image(std::string part_of_name, video::IImage *& baseimg,
|
||||||
video::IVideoDriver* driver);
|
IrrlichtDevice *device);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Generates an image from a full string like
|
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().
|
This is used by buildMainAtlas().
|
||||||
*/
|
*/
|
||||||
video::IImage* generate_image_from_scratch(std::string name,
|
video::IImage* generate_image_from_scratch(std::string name,
|
||||||
video::IVideoDriver* driver);
|
IrrlichtDevice *device);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This method generates all the textures
|
This method generates all the textures
|
||||||
|
@ -284,7 +284,7 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
|
||||||
dstream<<"last_part_of_name="<<last_part_of_name<<std::endl;
|
dstream<<"last_part_of_name="<<last_part_of_name<<std::endl;
|
||||||
|
|
||||||
// Generate image according to part of name
|
// Generate image according to part of name
|
||||||
if(generate_image(last_part_of_name, baseimg, driver) == false)
|
if(generate_image(last_part_of_name, baseimg, m_device) == false)
|
||||||
{
|
{
|
||||||
dstream<<"INFO: getTextureIdDirect(): "
|
dstream<<"INFO: getTextureIdDirect(): "
|
||||||
"failed to generate \""<<last_part_of_name<<"\""
|
"failed to generate \""<<last_part_of_name<<"\""
|
||||||
|
@ -424,7 +424,7 @@ void TextureSource::buildMainAtlas()
|
||||||
img->drop();*/
|
img->drop();*/
|
||||||
|
|
||||||
// Generate image by name
|
// 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)
|
if(img2 == NULL)
|
||||||
{
|
{
|
||||||
dstream<<"WARNING: TextureSource::buildMainAtlas(): Couldn't generate texture atlas: Couldn't generate image \""<<name<<"\""<<std::endl;
|
dstream<<"WARNING: TextureSource::buildMainAtlas(): Couldn't generate texture atlas: Couldn't generate image \""<<name<<"\""<<std::endl;
|
||||||
|
@ -521,11 +521,14 @@ void TextureSource::buildMainAtlas()
|
||||||
}
|
}
|
||||||
|
|
||||||
video::IImage* generate_image_from_scratch(std::string name,
|
video::IImage* generate_image_from_scratch(std::string name,
|
||||||
video::IVideoDriver* driver)
|
IrrlichtDevice *device)
|
||||||
{
|
{
|
||||||
dstream<<"INFO: generate_image_from_scratch(): "
|
dstream<<"INFO: generate_image_from_scratch(): "
|
||||||
"name="<<name<<std::endl;
|
"name="<<name<<std::endl;
|
||||||
|
|
||||||
|
video::IVideoDriver* driver = device->getVideoDriver();
|
||||||
|
assert(driver);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Get the base image
|
Get the base image
|
||||||
*/
|
*/
|
||||||
|
@ -560,7 +563,7 @@ video::IImage* generate_image_from_scratch(std::string name,
|
||||||
base_image_name = name.substr(0, last_separator_position);
|
base_image_name = name.substr(0, last_separator_position);
|
||||||
dstream<<"INFO: generate_image_from_scratch(): Calling itself recursively"
|
dstream<<"INFO: generate_image_from_scratch(): Calling itself recursively"
|
||||||
" to get base image, name="<<base_image_name<<std::endl;
|
" to get base image, name="<<base_image_name<<std::endl;
|
||||||
baseimg = generate_image_from_scratch(base_image_name, driver);
|
baseimg = generate_image_from_scratch(base_image_name, device);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -572,7 +575,7 @@ video::IImage* generate_image_from_scratch(std::string name,
|
||||||
dstream<<"last_part_of_name="<<last_part_of_name<<std::endl;
|
dstream<<"last_part_of_name="<<last_part_of_name<<std::endl;
|
||||||
|
|
||||||
// Generate image according to part of name
|
// Generate image according to part of name
|
||||||
if(generate_image(last_part_of_name, baseimg, driver) == false)
|
if(generate_image(last_part_of_name, baseimg, device) == false)
|
||||||
{
|
{
|
||||||
dstream<<"INFO: generate_image_from_scratch(): "
|
dstream<<"INFO: generate_image_from_scratch(): "
|
||||||
"failed to generate \""<<last_part_of_name<<"\""
|
"failed to generate \""<<last_part_of_name<<"\""
|
||||||
|
@ -584,8 +587,11 @@ video::IImage* generate_image_from_scratch(std::string name,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool generate_image(std::string part_of_name, video::IImage *& baseimg,
|
bool generate_image(std::string part_of_name, video::IImage *& baseimg,
|
||||||
video::IVideoDriver* driver)
|
IrrlichtDevice *device)
|
||||||
{
|
{
|
||||||
|
video::IVideoDriver* driver = device->getVideoDriver();
|
||||||
|
assert(driver);
|
||||||
|
|
||||||
// Stuff starting with [ are special commands
|
// Stuff starting with [ are special commands
|
||||||
if(part_of_name[0] != '[')
|
if(part_of_name[0] != '[')
|
||||||
{
|
{
|
||||||
|
@ -857,8 +863,6 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is just a placeholder
|
|
||||||
|
|
||||||
str_replace_char(part_of_name, '&', '^');
|
str_replace_char(part_of_name, '&', '^');
|
||||||
Strfnd sf(part_of_name);
|
Strfnd sf(part_of_name);
|
||||||
sf.next("{");
|
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_left = sf.next("{");
|
||||||
std::string imagename_right = sf.next("{");
|
std::string imagename_right = sf.next("{");
|
||||||
|
|
||||||
baseimg = generate_image_from_scratch(
|
#if 1
|
||||||
imagename_top, driver);
|
|
||||||
|
|
||||||
//TODO
|
//TODO
|
||||||
#if 0
|
|
||||||
if(driver->queryFeature(video::EVDF_RENDER_TO_TARGET) == false)
|
if(driver->queryFeature(video::EVDF_RENDER_TO_TARGET) == false)
|
||||||
{
|
{
|
||||||
dstream<<"WARNING: getTextureIdDirect(): EVDF_RENDER_TO_TARGET"
|
dstream<<"WARNING: getTextureIdDirect(): EVDF_RENDER_TO_TARGET"
|
||||||
" not supported"<<std::endl;
|
" not supported. Creating fallback image"<<std::endl;
|
||||||
return false;
|
baseimg = generate_image_from_scratch(
|
||||||
|
imagename_top, device);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 w0 = 16;
|
u32 w0 = 64;
|
||||||
u32 h0 = 16;
|
u32 h0 = 64;
|
||||||
dstream<<"INFO: inventorycube w="<<w0<<" h="<<h0<<std::endl;
|
dstream<<"INFO: inventorycube w="<<w0<<" h="<<h0<<std::endl;
|
||||||
core::dimension2d<u32> dim(w0,h0);
|
core::dimension2d<u32> dim(w0,h0);
|
||||||
|
|
||||||
//baseimg = driver->createImage(video::ECF_A8R8G8B8, dim);
|
// Generate images for the faces of the cube
|
||||||
|
|
||||||
video::IImage *img_top = generate_image_from_scratch(
|
video::IImage *img_top = generate_image_from_scratch(
|
||||||
imagename_top, driver);
|
imagename_top, device);
|
||||||
video::IImage *img_left = generate_image_from_scratch(
|
video::IImage *img_left = generate_image_from_scratch(
|
||||||
imagename_left, driver);
|
imagename_left, device);
|
||||||
video::IImage *img_right = generate_image_from_scratch(
|
video::IImage *img_right = generate_image_from_scratch(
|
||||||
imagename_right, driver);
|
imagename_right, device);
|
||||||
|
assert(img_top && img_left && img_right);
|
||||||
// Render target texture
|
|
||||||
video::ITexture *rtt = NULL;
|
// TODO: Create textures from images
|
||||||
std::string rtt_name = part_of_name + "_RTT";
|
video::ITexture *texture_top = driver->addTexture(
|
||||||
|
(imagename_top + "__temp__").c_str(), img_top);
|
||||||
rtt = driver->addRenderTargetTexture(dim, rtt_name.c_str());
|
assert(texture_top);
|
||||||
assert(rtt);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Drop images
|
||||||
img_top->drop();
|
img_top->drop();
|
||||||
img_left->drop();
|
img_left->drop();
|
||||||
img_right->drop();
|
img_right->drop();
|
||||||
|
|
||||||
//TODO
|
// Create render target texture
|
||||||
assert(0);
|
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<f32> 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
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -261,8 +261,6 @@ enum MaterialType{
|
||||||
/*
|
/*
|
||||||
This fully defines the looks of a tile.
|
This fully defines the looks of a tile.
|
||||||
The SMaterial of a tile is constructed according to this.
|
The SMaterial of a tile is constructed according to this.
|
||||||
|
|
||||||
TODO: Change this to use an AtlasPointer
|
|
||||||
*/
|
*/
|
||||||
struct TileSpec
|
struct TileSpec
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue