Extern 2D-Library
Extern 2D-Library
I thought of using an extern Library for things like rotating or scaling images (Background of Menu or Loading screens etc.) as there are no really Irrlicht solutions for that.
Do you think that's the right way, or do you know a fast, lightweight and easy library?
Do you think that's the right way, or do you know a fast, lightweight and easy library?
You don't have to use anything outside of Irrlicht, I think that will be inconvenient and more difficult anyway. For scaling, rotating, positioning of sprites in Irrlicht you can use this simple class I made:
You can see a few vertices and a simple transformation matrix is all that's needed.
To use:
Cheers, I hope that was useful.
Code: Select all
class CSprite
{
public:
CSprite() : scale(irr::core::vector3df(1.0f, 1.0f, 0.0f))
{
Material.Lighting = false;
Material.ZWriteEnable = false;
Vertices[0] = irr::video::S3DVertex(-1.0f,-1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
irr::video::SColor(0xffffffff), 0.0f, 1.0f);
Vertices[1] = irr::video::S3DVertex(-1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
irr::video::SColor(0xffffffff), 0.0f, 0.0f);
Vertices[2] = irr::video::S3DVertex( 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
irr::video::SColor(0xffffffff), 1.0f, 0.0f);
Vertices[3] = irr::video::S3DVertex( 1.0f,-1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
irr::video::SColor(0xffffffff), 1.0f, 1.0f);
Vertices[4] = irr::video::S3DVertex(-1.0f,-1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
irr::video::SColor(0xffffffff), 0.0f, 1.0f);
Vertices[5] = irr::video::S3DVertex( 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
irr::video::SColor(0xffffffff), 1.0f, 0.0f);
}
void setVertexAlpha(irr::u32 alpha)
{
for(irr::u32 i = 0;i < 6;++i)
Vertices[i].Color.setAlpha(alpha);
}
void setVertexColor(irr::video::SColor color)
{
for(irr::u32 i = 0;i < 6;++i)
Vertices[i].Color = color;
}
void render(irr::video::IVideoDriver* driver)
{
const irr::u16 indices[6] = {0, 1, 2, 3, 4, 5};
irr::core::matrix4 mat;
mat.setScale(scale);
irr::core::matrix4 smat;
smat.setRotationDegrees(rotation);
mat *= smat;
mat.setTranslation(position);
driver->setMaterial(Material);
driver->setTransform(irr::video::ETS_WORLD, mat);
driver->setTransform(irr::video::ETS_VIEW, matrix4());
driver->setTransform(irr::video::ETS_PROJECTION, matrix4());
driver->drawIndexedTriangleList(&Vertices[0], 6, &indices[0], 2);
}
virtual irr::video::SMaterial& getMaterial()
{
return Material;
}
void setPosition(const irr::core::vector2df& positionIn)
{
position = irr::core::vector3df(positionIn.X * 2.0f, positionIn.Y * 2.0f, 0.0f)
- irr::core::vector3df(1.0f, 1.0f, 0.0f);
}
void setRotation(const irr::f32 rotationIn)
{
rotation = irr::core::vector3df(0.0f, 0.0f, rotationIn);
}
void setScale(const irr::core::vector2df& scaleIn)
{
scale = irr::core::vector3df(scaleIn.X, scaleIn.Y, 0.0f);
}
private:
irr::video::S3DVertex Vertices[6];
irr::video::SMaterial Material;
irr::core::vector3df position, rotation, scale;
};
To use:
Code: Select all
CSprite mySprite;
mySprite.getMaterial().setTexture(0, driver->getTexture("TEXTURE")); // There is only one material anyway, so no parameter is taken in getMaterial().
mySprite.setPosition(vector2df(0.5, 0.5)); // Position is absolute, so 0.5 means the top-left corner of the sprite is going to be in the middle of the screen.
mySprite.setRotation(45.0f); // You can set rotation in degrees.
mySprite.setScale(vector2df(0.5f, 0.5f)); // And scale along the two axis.
### In your main loop: ###
driver->beginScene();
smgr->drawAll();
mySprite.render(driver); // You can do it after smgr->drawAll(), or before if you want background effects.
driver->endScene();
Last edited by BlindSide on Thu Jul 09, 2009 3:17 am, edited 1 time in total.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Then render the result to a texture of the desired resolution. And that's all you need!
I'm working on a sort of class to do 2D effects, like scrolling, and stuff that return the results to a RTT. All of them in hardware, though, the calculations are done in software. Maybe in a not vere far future i try to do everything in the card, but for now, all i do is programming draw2Dimage sentences one oafter another
I'm working on a sort of class to do 2D effects, like scrolling, and stuff that return the results to a RTT. All of them in hardware, though, the calculations are done in software. Maybe in a not vere far future i try to do everything in the card, but for now, all i do is programming draw2Dimage sentences one oafter another
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
well just make CSprite a children of ISceneNode and u should be fine....
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
My 2D graphics/IMGUI library "Turska" supports also rendering with Irrlicht. It works in similar fashion with the method mentioned above, i.e. renders 3d polygons with custom projection.
http://jet.ro/turska/
http://jet.ro/turska/
Can't get it to work right
I know this thread is a few days old, but I've been trying to get blindside's method to work. I can't get it to work quite right. I put it into the 2d demo that comes with Irrlicht and tried it out. Here's what I did:
I added
after creating the driver; and I have "mySprite.render(driver);" in between the two imps. Unfortunately, I only see the usual dungeon scene. However, if I do this:
The I see the earth map fill the window. If I do any resizing, rotating, or moving, then the first transform won't work right. Any ideas on what's going on?
I added
Code: Select all
CSprite mySprite;
mySprite.getMaterial().setTexture(0, driver->getTexture("../../media/earth.bmp")); // There is only one material anyway, so no parameter is taken in getMaterial().
mySprite.setPosition(vector2df(0.5, 0.5)); // Position is absolute, so 0.5 means the top-left corner of the sprite is going to be in the middle of the screen.
mySprite.setRotation(45.0f); // You can set rotation in degrees.
mySprite.setScale(vector2df(0.5f, 0.5f)); // And scale along the two axis.
Code: Select all
driver->setMaterial(Material);
//driver->setTransform(irr::video::ETS_WORLD, mat);
//driver->setTransform(irr::video::ETS_VIEW, matrix4());
//driver->setTransform(irr::video::ETS_PROJECTION, matrix4());
//driver->drawIndexedTriangleList(&Vertices[0], 6, &indices[0], 2);
Can you paste the full altered example code? I'm happy to try it out and see what's going wrong.
Cheers
Cheers
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
How bad is the deformation? Can I see a screenshot?
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net