OpenGL mapping with draw2DImage

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
fortikur
Posts: 25
Joined: Tue Nov 15, 2005 3:59 pm
Location: Hungary

OpenGL mapping with draw2DImage

Post by fortikur »

I modified the 'Render to texture' example like this:

Code: Select all

video::ITexture* mirr = video->getTexture("mirrorbgr.tga");
.
.
.
			// draw scene into render target
			
			// set render target texture
			video->setRenderTarget(rt, true, true, video::SColor(255,255,255,255));     

			// make cube invisible and set fixed camera as active camera
			mirror->setVisible(false);

			video->draw2DImage(mirr, 
                core::position2d<s32>(0,0), 
				core::rect<s32>(0,0,258,258), 0,
				video::SColor(255,255,255,255), true);

			scene->setActiveCamera(fixedCam);


			// draw whole scene into render buffer
			scene->drawAll();                 

			// set back old render target
			video->setRenderTarget(0);          

			// make the cube visible and set the user controlled camera as active one
    		mirror->setVisible(true);
			scene->setActiveCamera(camera);
I think everyone has seen this part of the original code. But what happens here?
If you look at the cube, you will notice, that on the edges you can see a thin edge-line in a colour given by the setrendertarget line.
I used the CSamplescenenode example too and had the same thing.

I modified the engine in COpenGLDriver.cpp.

Under this function:

Code: Select all

//! draws an 2d image, using a color (if color is other then Color(255,255,255,255)) and the alpha channel of the texture if wanted.
void COpenGLDriver::draw2DImage(video::ITexture* texture, const core::position2d<s32>& pos,
				 const core::rect<s32>& sourceRect,
				 const core::rect<s32>* clipRect, SColor color,
				 bool useAlphaChannelOfTexture)
you will find

Code: Select all

	if (targetPos.Y + sourceSize.Height > renderTargetSize.Height)
	{
		sourceSize.Height -= (targetPos.Y + sourceSize.Height) - renderTargetSize.Height;
		if (sourceSize.Height <= 0)
			return;
	}
if i modify the first line like:

Code: Select all

if (targetPos.Y + sourceSize.Height > renderTargetSize.Height+2)
everything will be ok.


Just look at the pictures

BEFORE (with the thin edge)
http://www.kokany.atw.hu/irr/1.jpg

and

AFTER (with the modified source)
http://www.kokany.atw.hu/irr/2.jpg

I don't know why this works, it was the first time I look at the source and spent only 10 minutes with it... maybe Niko will explode of rage seeing such a lame solution, but it works, or at least something is wrong with the v1.1 source here (+SVN on the 06/aug/26). Maybe someone will be able to understand this...

Ok, I found a solution. Even the original Tutorial file works now well with a background on the rotating cube.
Still in COpenGLDriver.cpp:

Code: Select all

    int diff=(targetPos.Y + sourceSize.Height)-renderTargetSize.Height;
	if (targetPos.Y + sourceSize.Height > renderTargetSize.Height+diff)
	{
		sourceSize.Height -= (targetPos.Y + sourceSize.Height) - renderTargetSize.Height;
		if (sourceSize.Height <= 0)
			return;
	}
I tried it with different rendertargettexture dimensions and draw2dimage sizes, like:

Code: Select all

	video->draw2DImage(mirr, 
                core::position2d<s32>(0,0), 
				core::rect<s32>(0,0,255,255), 
                                                                0,  
				video::SColor(255,255,255,255), true);
Instead of (0,0,255,255) I wrote bigger values than 256 too and it worked fine.
Could, please, someone try this? If it works, I will add a patch.
Post Reply