|
Post by NeX on Oct 9, 2015 9:32:53 GMT -8
Hi,
is it possible to make a cut out that is not rectangular? maybe using a polygon in some way?
|
|
|
Post by jamesbowman on Oct 9, 2015 11:54:11 GMT -8
Yes! This example draws a background image, and then uses "Poly" to draw an octagon into the stencil buffer. The StencilFunc() is then switched on so that only pixels inside the octagon shape are drawn. #include <EEPROM.h> #include <SPI.h> #include <GD2.h>
void setup() { GD.begin(); GD.cmd_loadimage(0, 0); GD.load("tree.jpg"); }
void loop() { GD.Clear(); GD.Begin(BITMAPS); GD.Vertex2ii(0, 0);
// Draw an octagon into the stencil buffer, stencil value 255 GD.SaveContext(); Poly po; po.begin(); int centerx = 16 * 240, centery = 16 * 136; for (int i = 0; i < 8; i++) { int th = 0x2000 * i; // angle int r = 16 * 120; po.v(centerx + GD.rsin(r, th), centery + GD.rcos(r, th)); } po.paint(); GD.RestoreContext();
// Now only draw pixels whose stencil is 255 GD.StencilFunc(EQUAL, 255, 255);
// Clear by drawing a black fullscreen rectangle GD.ColorRGB(0, 0, 0); GD.Begin(RECTS); GD.Vertex2ii(0, 0); GD.Vertex2ii(480, 272);
// Taken from 'fizz' GD.Begin(POINTS); for (int i = 0; i < 100; i++) { GD.PointSize(GD.random(16 * 50)); GD.ColorRGB(GD.random(256), GD.random(256), GD.random(256)); GD.ColorA(GD.random(256)); GD.Vertex2ii(GD.random(480), GD.random(272)); }
GD.swap(); }
|
|
|
Post by NeX on Oct 10, 2015 2:41:18 GMT -8
Worked flawlessly as usual, thanks for the help!
|
|