[2d in 3d] simple rectangle

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
Keil
Posts: 20
Joined: Fri Nov 25, 2005 2:46 pm
Location: France

[2d in 3d] simple rectangle

Post by Keil »

hello,
i have a 640x480 window.
i have a 3d scene drawed.
i want to draw a 50x60 2d-texturized-panel at the point 10,10 of this window
it will NOT be a GUI element

on this panel, i will write some text. i think the ITextSceneNode will be useful

how would you make it?
Get stronger confronting stronger ones
Guest

Post by Guest »

Well I would (and have) write my own gui class that uses irrlichts Draw2DImage function. And my Own bitmap font class (irrlichts font is ok but very basic).

Also don't go with 50x60. If you have to use that size make it 64x64 and use ALPHA to mask of the parts you don't want.. keep the textures pow2 for quality.

use driver->draw2Dimage(your texture, Position) and call this in your render loop as the last thing so that it is drawn on top of other things.
Keil
Posts: 20
Joined: Fri Nov 25, 2005 2:46 pm
Location: France

Post by Keil »

ok, thanks a lot, i will try it tonight
Get stronger confronting stronger ones
Keil
Posts: 20
Joined: Fri Nov 25, 2005 2:46 pm
Location: France

Post by Keil »

i started thinking, and i will face a problem:

my texture is a 2x2 jpg image.
how will i stretch it in order to cover my 64x64 panel?
Get stronger confronting stronger ones
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

You don't stretch it, the 3D engine does using the texture coordinates of the vertices.
Image
Keil
Posts: 20
Joined: Fri Nov 25, 2005 2:46 pm
Location: France

Post by Keil »

i just don't get it!

how will the engine know that it must strech my 2x2 texture to 64x64 when i'll use:
videoDriver->draw2Dimage(your texture, Position)
Get stronger confronting stronger ones
hybrid

Post by hybrid »

If you don't tell the engine the size of your image it will just draw it 2x2. Use

Code: Select all

draw2DImage(video::ITexture* texture, const core::rect<s32>& destRect,
            const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect = 0,
            video::SColor* colors=0, bool useAlphaChannelOfTexture=false)
to set the destination size as well.
AticAtac
Posts: 29
Joined: Mon Mar 22, 2004 2:46 pm
Location: Germany

Post by AticAtac »

There are different "draw2DImage()" functions.
The one you are looking for is this:

Code: Select all

virtual void irr::video::IVideoDriver::draw2DImage  (  video::ITexture *  texture,  
  const core::rect< s32 > &  destRect,  
  const core::rect< s32 > &  sourceRect,  
  const core::rect< s32 > *  clipRect = 0,  
  video::SColor *  colors = 0,  
  bool  useAlphaChannelOfTexture = false 
 )  [pure virtual] 
So obviously your "destRect" is 64x64 and your "sourceRect" is 2x2.
Keil
Posts: 20
Joined: Fri Nov 25, 2005 2:46 pm
Location: France

Post by Keil »

ok thanks a lot!
Get stronger confronting stronger ones
Keil
Posts: 20
Joined: Fri Nov 25, 2005 2:46 pm
Location: France

Post by Keil »

and to draw 2D Text on it,
must i use the ITextSceneNode or something else?
Get stronger confronting stronger ones
Keil
Posts: 20
Joined: Fri Nov 25, 2005 2:46 pm
Location: France

[Resolved][2d in 3d] simple rectangle

Post by Keil »

ok, works fine!
for the 2d text, i used font->draw()
Get stronger confronting stronger ones
Guest

Post by Guest »

(me from above)

dude - you don't have to use 64x63 for all smaller textures - they just need to be power of 2.

2x2 IS power of 2 so you can use it as is though I would sugest 16x16 as a minimum size.

Pow of 2 also doesn't mean "square" so you can have any combination of 8,16,32,64,128,256,512,1025 etc

for example:

8 x 512 is VALID
512 x 32 is VALID
128 x 128 is VALID
64 x 256 is VALID

they are pow2

Now as for "stretching or not" using rects, that is one way - I didn't mean that though I meant to make a blank texture at a pow 2 size (64x64 for example) then place your 50x60 image in the top left of it - then use an ALPHA CHANNEL on the texture (tga,png) to remove the excess on the right and bottom - the texture size is still 64 x 64 but the visible image in game is still only 50x60 and it needs no scaling/stretching etc (so it looks good) - also be sure to turn MIP MAP CREATION OFF before loading gui / overlay textures.

HTH
Guest

Post by Guest »

Damn typos - I meant 64 x 64 not (63) and also 1024 not 1025 (of course).

Now I also see you image is just a backdrop colour or something 2x2 so you don't mind stretching it up - if you ever use an actual detailed 50x60 image then you could do as I posted. as it is, you are happy just stretching the smaller texture up because you are not getting scaling artifcacts?
Keil
Posts: 20
Joined: Fri Nov 25, 2005 2:46 pm
Location: France

Post by Keil »

Just a precision,
i replace my 2x2 texture by a 640x480 texture, i scale it to lower sizes, and it works fine.
i think your alpha method is correct and improve performances but i don't think this will do slow down my game.

so i have some
videoDriver->draw2DImage (texture,
core::rect< s32 >(20,20,70,80),
core::rect< s32 >(0,0,640,480));
Get stronger confronting stronger ones
bearSoft
Posts: 165
Joined: Fri Apr 01, 2005 9:55 pm
Location: Denmark

Post by bearSoft »

i replace my 2x2 texture by a 640x480 texture
no !
i understand ur confusion because of all those values and corrections and so
valid texture sizes are 2^n
so the values closest to the ones u are refering to is
256, 512, 1024
eg 2^8, 2^9, and 2^10
it is perfectly ok to use 2 different values on a texture -eg a texture sized 256*512 is OK
Regards.
Tech: win98se| 320mb ram| abitbe6| 433mhzceleron| atiRadeon7000.64mb| soundblaster125| dx9.0b | devCPP | IRR 0.12.0 |
Post Reply