Hello!
I know how to make a billboard with a material and a texture. But how do I put an animated image on that billboard?
It's not an animated gif. It looks like this:
animated image on billboard
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
Re: animated image on billboard
You have to use a texture animator to somehow move the tex coords. Easiest is to define a texture matrix animator, which moves the actual subtexture window along the full texture. I think we don't have such an animator in the engine, yet, but it should be fairly easy to implement. Should also work on a billboard. One more note: It might be worth adding some more spacing to the texture to blow it up to 512x512 pixel. This avoids problems with several gfx cards that don't properly support npot textures.
Re: animated image on billboard
Anyone else good ideas?
Re: animated image on billboard
You can do it in a shader instead, if you prefer.
Re: animated image on billboard
You may animate the image by changing the texture coordinates by hybrid or hendu's method. Below is some hacky code to show how this is done:
Regards
smso
Code: Select all
int main()
{
//...
billboard->setMaterialTexture(0, driver->getTexture("sample_animation_5x5.jpg"));
core::vector2df translate(0.0f);
std::vector<core::vector2df> ts;
for (f32 m=0.0f; m<5.0f; m+=1.0f)
{
for (f32 n=0.0f; n<5.0f; n+=1.0f)
{
//printf("(m,n)=(%f,%f)\n", m, n);
translate = core::vector2df(n, m) * 0.2f;
ts.push_back(translate);
}
}
while (device->run())
if (device->isWindowActive())
{
////////////////////////////////////////////////////////////////////////
static int texindex = 0;
core::vector2df translate = ts[texindex];
core::matrix4 mat;
mat.buildTextureTransform(0.0f, core::vector2df(0.0f), translate, core::vector2df(0.2f));
billboard->getMaterial(0).setTextureMatrix(0, mat);
++texindex;
if (texindex > int(ts.size()-1))
texindex = 0;
////////////////////////////////////////////////////////////////////////
driver->beginScene(true, true, 0);
smgr->drawAll();
driver->endScene();
}
else { device->yield(); }
if (device)
device->drop();
return 0;
}
Regards
smso