3d on top of 2d question

Problems building or running the engine, queries about how to use features etc.
Post Reply
pao
Gnoblar
Posts: 5
Joined: Wed Apr 06, 2005 4:45 am
Contact:

3d on top of 2d question

Post by pao »

Hello,

I'm just starting to play with OGRE and am so far extremely impressed. This is great work you guys have done! I've tried using other systems such as Crystal Space before and everything was always just way over my head. I really appreciate the in-depth documentation provided here and especially like that the manual is very low on code and more about the theory of how OGRE works - that is extremely helpful. Of course the API reference is also invaluable.

Now, I do have a quick question about creating a scene with 3d objects rendered on top of a 2d background. I couldn't find much about it on the forums or in the manual/wiki/etc. Basically what I'm interested in is drawing a background image to the screen and then rendering any 3d objects on top of it. In the end I'd like to be able to scroll the background image (that is display only a portion of a larger image) but I need to be able to draw some image first.

Possible options I could think of are creating a Rectangle2D or just a simple plane or something, but I'm not sure how to implement it all. How would I tell the SceneManager to render the rectangle, for example? Here are a few other threads I found that looked promising, but no luck so far:

http://www.ogre3d.org/phpBB2/viewtopic. ... ound+image
http://www.ogre3d.org/phpBB2/viewtopic. ... background
http://www.ogre3d.org/phpBB2/viewtopic. ... ectangle2d

If anyone has any hints/ideas/example code/etc I'd greatly appreciate some help. If I do get this working I will write an article about it and put it on the wiki.

Thanks!
Daniel G. Taylor
http://programmer-art.org

User avatar
DWORD
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 1365
Joined: Tue Sep 07, 2004 12:43 pm
Location: Aalborg, Denmark
Contact:

Post by DWORD »

This is asked rather frequently, so now I've put up a piece of code on the wiki which shows how to use Rectangle2D for this purpose.

***WIKIED***

pao
Gnoblar
Posts: 5
Joined: Wed Apr 06, 2005 4:45 am
Contact:

Thanks!

Post by pao »

Excellent! Seems I was mainly just missing the bounding box hack. :-)
Could you explain why this is needed (and why it needs to be so large) for it to render?

I also suggest adding

Code: Select all

material->getTechnique(0)->getPass(0)->setLightingEnabled(false);
so that the ambient lighting doesn't affect the background. In fact, I just added it to the wiki (hope you don't mind!) I also disabled texture filtering in my local code because I will be using large images that don't need to be filtered.

Now, would it be considered bad practice to load a PNG that is a few times larger than the view, set the corners outside of the view, and scroll it around (like scrolling a map looking at it form the top)? I'm thinking of a 2d map with 3d entities on it (so I would shift the background corners and the camera position when using the arrow keys to keep the 2d/3d in sync).
Daniel G. Taylor
http://programmer-art.org

User avatar
DWORD
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 1365
Joined: Tue Sep 07, 2004 12:43 pm
Location: Aalborg, Denmark
Contact:

Re: Thanks!

Post by DWORD »

pao wrote:Excellent! Seems I was mainly just missing the bounding box hack. :-)
Could you explain why this is needed (and why it needs to be so large) for it to render?
See this post. BTW to see what else could happen, try setting the bounding box to +/- Vector3::UNIT_SCALE, and move around the camera. Then the background will go on and off, and that's why this solution is a bit hacky IMHO.
pao wrote:I also suggest adding

Code: Select all

material->getTechnique(0)->getPass(0)->setLightingEnabled(false);
so that the ambient lighting doesn't affect the background. In fact, I just added it to the wiki (hope you don't mind!)
Any improvement is welcome. :)
pao wrote:Now, would it be considered bad practice to load a PNG that is a few times larger than the view, set the corners outside of the view, and scroll it around (like scrolling a map looking at it form the top)? I'm thinking of a 2d map with 3d entities on it (so I would shift the background corners and the camera position when using the arrow keys to keep the 2d/3d in sync).
I think this is the way to go as long as the image isn't too big. Maybe you should just scroll around the texture using TextureUnitState::setTextureScroll() & co., as that should give slightly better performance than setting the corners, although that probably doesn't matter in this case. Heh, just do it the easiest way. :)

Vectrex
Ogre Magi
Posts: 1266
Joined: Tue Aug 12, 2003 1:53 am
Location: Melbourne, Australia
x 1
Contact:

Post by Vectrex »

howdy. Wouldn't it be better to use billboards for 2d/3d stuff? Then you could use scenenodes for scrolling etc. I've no idea really, just getting into ogre :)

pao
Gnoblar
Posts: 5
Joined: Wed Apr 06, 2005 4:45 am
Contact:

Post by pao »

Vectrex wrote:howdy. Wouldn't it be better to use billboards for 2d/3d stuff? Then you could use scenenodes for scrolling etc. I've no idea really, just getting into ogre :)
That's actually not a bad idea, and I just tried it with a few billboards. There are a few problems I run into though:
  • -Billboards have to be stored in BillboardSets and can only have one texture per BillboardSet that applies to all Billboards in that set.
    -Billboards always face the camera, so when tiling them and tilting the camera they no longer sit side-by-side correctly.
I'm working on a project that would need a 2d map made up of 32x32 pixel tiles where the 3d view is slightly at an angle (instead of directly down), so this solution doesn't really work for me. It would be nice to create a huge billboard to manage the map as a single texture, but not only does that take a boatload of memory, it also forces you into using 2^x sizes for the map (which won't work for me).

I'm going to see how possible all this is to do with Rectangle2D objects. It should be relatively simple (although I suppose it will involve quite a bit of math to keep all the tiles positioned correctly). I also now see the usefullness of Billboards (especially for some of the effects I have planned).
Daniel G. Taylor
http://programmer-art.org

Post Reply