Zoom-in / Zoom-Out a 2D Image? Is it possible?

Post your questions, suggestions and experiences regarding to Image manipulation, 3d modeling and level editing for the Irrlicht engine here.
Post Reply
gauravjha
Posts: 26
Joined: Thu Jan 24, 2013 4:52 am

Zoom-in / Zoom-Out a 2D Image? Is it possible?

Post by gauravjha »

Hi,

Is it possible to change the scale of a 2D image in Irrlicht? i tried using "driver->getMaterial2D().getTextureMatrix(0).setTextureScale(0.01, 0.01);" but this seems to have no effect on the image?

Any help would be appreciated.

Regards,
Gaurav Jha
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Zoom-in / Zoom-Out a 2D Image? Is it possible?

Post by hybrid »

Not sure if we support texture scale via 2d material. You have to enable the 2d material at least, otherwise it does not affect anything. Please check example 6 or so (2d rendering and maybe GUI stuff) as that example explains 2d material as well. Otherwise there's no 2d on-the-fly scale, you'd have to scale the image on CPU first. Or use 3d rendering instead.
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Zoom-in / Zoom-Out a 2D Image? Is it possible?

Post by Nadro »

You can use this method for it:
http://irrlicht.sourceforge.net/docu/cl ... acf7927354
In src rectangle you have to put texture size (in pixels, so UV you have to multiply by texture width and height). In dest you have to define part of screen which will be covered by image. Texture will scale automatically.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
gauravjha
Posts: 26
Joined: Thu Jan 24, 2013 4:52 am

Re: Zoom-in / Zoom-Out a 2D Image? Is it possible?

Post by gauravjha »

Thanx for the help.

I am still a bit confused.

I am using the following statement:

driver->draw2DImage(mapFiles[0], rect<s32>(0, 0, 480, 272), rect<s32>(0, 0, 8, 6), 0, 0, true);

The image size I am using is 800*600pixels.

Still there is no affect on the image? Can you suggest what else needs to be done?

I have enabled material2D with the following scale ststement.

driver->getMaterial2D().getTextureMatrix(0).setTextureScale(0.01, 0.01);

Regards,
Gaurav Jha
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Zoom-in / Zoom-Out a 2D Image? Is it possible?

Post by Nadro »

Just decrease/increase size of dest rectangle. Your src rectangle should be (0,0,800,600). Don't use texture matrix.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
gauravjha
Posts: 26
Joined: Thu Jan 24, 2013 4:52 am

Re: Zoom-in / Zoom-Out a 2D Image? Is it possible?

Post by gauravjha »

Hi,

The solution did not work. Can you please suggest what could be the problem?

Regards,
Gaurav Jha
chronologicaldot
Competition winner
Posts: 684
Joined: Mon Sep 10, 2012 8:51 am

Re: Zoom-in / Zoom-Out a 2D Image? Is it possible?

Post by chronologicaldot »

What are you trying to do with it? Is this a texture for a model or are you just trying to draw an image?
If you're just trying to draw an image, you can always just render to a target GUI element ( IVideoDriver::setRenderTarget() ), draw the image as a texture (on a panel or box), and change the camera distance from the image.
The hardest, slowest, but most effective way, is to draw the image pixel by pixel, inserting pixels when the image is zoomed in and skipping pixels when the image is zoomed out. For speed, you'll have to draw the image to a texture before passing it to the engine, but then you're code would be driver-specific.

... and now I'm musing.
gauravjha
Posts: 26
Joined: Thu Jan 24, 2013 4:52 am

Re: Zoom-in / Zoom-Out a 2D Image? Is it possible?

Post by gauravjha »

Thanx.

I was actually trying to draw some 2d Images. But now I have changed the solution and using a scene node and applying textures on it.

Thanx.
Post Reply