Page 1 of 1

Clipping 2d rendering

Posted: Wed Mar 24, 2010 10:13 am
by MolokoTheMole
I would like to clip 2d drawing to rectangular viewports. Here are the problems I have encountered:

- draw2DRectangleOutline & draw2DLine don't have clip paramater like for example draw2DImage. Will this be implemented in future versions?

- IGUIFont::Draw clip paramter doesn't seem to work, but maybe it's just me?

- I don't know how to clip the polygons rendered with draw2DVertexPrimitiveList(). Any ideas?

Help will be very much appreciated.

Posted: Wed Mar 24, 2010 11:49 am
by zet.dp.ua
I'm using clipping planes or scissors rect.
If device supports 4 clipping planes, you can emulate rectangular viewport. Scissors are not implemented in the engine, and not sure if it is supported by dx8 (opengl and dx9 support), but they are really helpful with opengles.

Re: Clipping 2d rendering

Posted: Wed Mar 24, 2010 2:14 pm
by slavik262
I ran into a similar problem where I wanted to clip some 2-d stuff. The response I got was basically that there is no current clipping implementation in Irrlicht, so you'll have to find your own strategy for how you want to clip these.

To the devs: I think clipping support for 2D lines/rectangles/vertices would help a lot for people developing their own GUI systems. How hard would this be to implement?

Posted: Wed Mar 24, 2010 2:19 pm
by MolokoTheMole
I used Scissor thanks! It's such a useful function why isn't it implemented? You can use it for a ton of stuff. GUI clipping for viewport, scroll panes, scrolling images etc.

Here's the code I add to COpenGLDriver.cpp

Code: Select all

void COpenGLDriver::setScissor( bool enabled )
{
	if (enabled)
	{
		glEnable(GL_SCISSOR_TEST);                     
	}
	else
	{
		glDisable(GL_SCISSOR_TEST); 
	}
}

void COpenGLDriver::setScissorRect( s32 x, s32 y, s32 width, s32 height )
{
	glScissor( x, y, width, height );
}