Drawing 2d in Multiple Viewports

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
trnrez
Posts: 28
Joined: Wed Dec 27, 2006 5:56 pm
Location: Murfreesboro, TN
Contact:

Drawing 2d in Multiple Viewports

Post by trnrez »

My problem is that I want to render only 2d images to each viewport. When I make a call to draw2DImage() after using setViewPort() to state which viewport I want to render to it all ends up rendering in one viewport.

Also, since i'm only wanting to render 2d images I am under the impression that I do not have to use multiple cameras to get the effect that I want. I searched the forum and found everyone saying to state the setViewPort then make your drawing calls. So i'm pretty sure i'm making a simple mistake. Thanks for any help you can give.

Code: Select all

pseudo code

setViewport to entire screen
beginScene
     setViewport to right half
     draw2DImage
     sceneManager present to screen

     setViewport to left half
     draw2DImage
     sceneManager present to screen
endScene

Code: Select all

// All rendering is done between begin and end
// The begin scene clears the screen with a color and also
// the depth buffer if so needed
driver->setViewPort(rect<s32>(0,0,ResX,ResY));
driver->beginScene(true, true, SColor(0, 0, 200, 200));
	// Set the viewport to be the left half of the screen
	driver->setViewPort(rect<s32>(0,0,ResX/2,ResY));
	driver->draw2DImage(images, position2d<s32>(50,50),
		rect<s32>(0,0,342,224), 0,
		SColor(255,255,255,255), true);

   // Now we let the scenemanager do all its drawing
	smgr->drawAll();
	// and let the gui evn do all of its drawing methods
	guienv->drawAll();

	// Set the viewport to be the right half of the screen
	driver->setViewPort(rect<s32>(ResX/2,0,ResX,ResY));
	driver->draw2DImage(images, position2d<s32>(164,125),
		rect<s32>(349,15,385,78),0,
		SColor(255,255,255,255),true);

	// Now we let the scenemanager do all its drawing
	smgr->drawAll();
	// and let the gui evn do all of its drawing methods
	guienv->drawAll();
		
// and we end the scene
driver->endScene();
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

You shouldn't call smgr->drawAll() after your calls to driver->draw... as it will overwrite whatever the driver has just drawn with the contents of the scene. If you only have 2D images to be drawn by the driver and nothing in the scene manager then it shouldn't matter and in fact you wouldn't need to call smgr->drawAll() or any smgr functions in fact, i think ;)
Image Image Image
trnrez
Posts: 28
Joined: Wed Dec 27, 2006 5:56 pm
Location: Murfreesboro, TN
Contact:

Post by trnrez »

I commented the smgr->drawAll() calls out and it renders the images but they are still both being rendered in the right side of the screen. But that is something I didn't know because I was just looking into using multi scene managers thinking that was the issue. Thanks for the info on that....I know it has to be something silly on my part.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I don't really know much about drawing in 2D with Irrlicht. But maybe you don't even need to worry about changing the viewports? If it's simply a single 2D layer on your screen then you can just do the viewport stuff 'yourself' by just drawing the things you want on the left half in the left half and similarly for the right half?
Image Image Image
trnrez
Posts: 28
Joined: Wed Dec 27, 2006 5:56 pm
Location: Murfreesboro, TN
Contact:

Post by trnrez »

That makes sense. Was just playing with viewports to get the hang of them...but that way would prolly cause less headaches all together.
Post Reply