Scaling Texture to Fill Display [Solved]

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Scaling Texture to Fill Display [Solved]

Post by slavik262 »

I'm currently working on a dashboard for a robot, and part of the dashboard involves streaming video from a camera on the robot. The fastest way I can think of doing this in Irrlicht is decoding the image from the incoming packets, loading them into a IImage, locking the image and a corresponding texture, and copying the data from the image to the texture (assuming that the pixel formats are the same). I want the texture to be drawn across an entire window, but allow the window to be resized.

How could I dynamically resize the texture so that it fills the entire screen? My first idea would be using a Billboard scene node and a camera, using trial and error to move the camera until the billboard takes up the entire window, but I'd assume there's a better way to do it.

Would a solution be to get the view frustum of the camera and use the coordinates of the corner points to determine size?
Last edited by slavik262 on Thu Mar 04, 2010 4:58 pm, edited 1 time in total.
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

To better summarize my question: what is the best way to create a surface (a pair of triangles, be it a billboard or just a mesh scene node made with createPlaneMesh since the camera position won't be changing) that fills the entire view space?
Sir_Hans
Posts: 143
Joined: Sun Dec 06, 2009 2:23 pm
Location: Germany

Post by Sir_Hans »

Maybe yopu haven't seen this on the wiki: http://www.irrlicht3d.org/wiki/index.ph ... ingAnImage

That's how to scale a picture in Irrlicht. If you don't want that I didn't understand your question.
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

How does the scaling work? I'm just concerned about efficiency here since I want to run as fast as possible.

Let me rummage around in the source for a bit. :D

EDIT: Found it. So one of the overloads for draw2dImage can scale the image? Amusing - after looking at how CD3D9Driver does drawImage, I've found it's almost exactly the way I was doing it. I'll just check which way has better performance and go with it.
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

I did some tests. The method from the wiki squeezes out a few more FPS, but my image had a much smoother look after the scaling. I even tried messing with filtering options and IVideoDriver::getMaterial2d(), but no matter what my method gave smoother, better scaled results.
jawdy
Posts: 14
Joined: Wed Jan 13, 2010 4:20 pm

Post by jawdy »

Can you post how you scaled the texture?
Which overload from the draw2DImage did the trick?
I've tried looking at the link, but can't for the life of me make it work.

Thanks!

*** EDIT ***
Lol, nevermind, I had the wrong bit of code in the wrong place, hahahaha. It now works, and in case anyone's interested, this is how I scaled a texture:

Code: Select all

driver->draw2DImage( textureName, 
	rect<s32>( 0, 0, driver->getScreenSize().Width, driver->getScreenSize().Height ), 
	rect<s32>( 0, 0, billText->getSize().Width, billText->getSize().Height ) );
Uses the standard draw2DImage function, feeding it the desired texture, then the part of the image you want to draw (in this case, all of it), and the last part is where to draw it - from the top-left corner, to the whole size of the window.
Last edited by jawdy on Sat Mar 06, 2010 7:40 pm, edited 1 time in total.
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

I believe this is the function:

Code: Select all

virtual void 	draw2DImage (const video::ITexture *texture, const core::rect< s32 > &destRect, const core::rect< s32 > &sourceRect, const core::rect< s32 > *clipRect=0, const video::SColor *const colors=0, bool useAlphaChannelOfTexture=false)
destRect is the rectangle you want to draw it in, and it automatically scales to fit.
jawdy
Posts: 14
Joined: Wed Jan 13, 2010 4:20 pm

Post by jawdy »

Thanks Ducky, that's what I was doing, but as I said in my edit, I was doing it wrong.
The texture was repeating, because I'd told it set the initial rectangle as the size of the screen, rather than the size of the texture.

Such a stupid mistake! Lol :roll:
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

jawdy wrote:Can you post how you scaled the texture?
I created a rectangular mesh, textured it with my texture, pointed a camera at it, and set the mesh close enough so that it fills the entire screen. I doubt the practicality of this if you need to do it multiple times, but since I'm making a display that will take up the entire screen, I just need to do it once.
Post Reply