Clipping 2d rendering

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
MolokoTheMole
Posts: 109
Joined: Tue Jan 09, 2007 1:18 pm

Clipping 2d rendering

Post 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.
Crimson Glory full Irrlicht game source code!
What I Do - my blog & dev log
Currently developing Link-Dead
zet.dp.ua
Posts: 66
Joined: Sat Jul 07, 2007 8:10 am

Post 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.
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Re: Clipping 2d rendering

Post 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?
MolokoTheMole
Posts: 109
Joined: Tue Jan 09, 2007 1:18 pm

Post 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 );
}
Crimson Glory full Irrlicht game source code!
What I Do - my blog & dev log
Currently developing Link-Dead
Post Reply