|
Post by mic on Nov 29, 2014 11:23:15 GMT -8
Hi, i draw some primitives like lines and text. Then I want to show only a part of the screen like scissor, but not a rectangle. I want a circle. Are there any solution? thanks
|
|
|
Post by jamesbowman on Nov 30, 2014 8:33:53 GMT -8
Yes, you can use Stencil to do this. The book only mentions it briefly, on p.106. You draw the circle into the "stencil buffer", then draw everything else using a stencil test (called "StencilFunc") so that only pixels inside the circle are touched. Here is a fragment of code to do it: // First draw some things 'A' here...
// Draw a circle into the stencil GD.SaveContext(); GD.ColorMask(0,0,0,0); // Don't touch color GD.StencilOp(INCR, INCR); // incrementing stencil GD.PointSize(135 * 16); GD.Begin(POINTS); GD.Vertex2ii(240, 136); GD.RestoreContext();
// Set the stencil test, to only inside the circle GD.StencilFunc(EQUAL, 1, 255);
// Things drawn 'B' here are stenciled to inside the circle
FT800's stencil functions are very similar to OpenGL's: en.wikibooks.org/wiki/OpenGL_Programming/Stencil_buffer
|
|
|
Post by mic on Nov 30, 2014 22:45:42 GMT -8
Fantastic!
Thanks a lot.
|
|