Expose triangle drawer*
Moderator: GZDoom Developers
- Major Cooke
- Posts: 8170
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Expose triangle drawer*
* - specifically, the polygonal drawing functions for ZScript.
Wasn't sure but is it possible to export the triangle drawer of the engine, akin to the line drawing function Gutawer exposed? I suggest this because making a filled shape out of lines can become quite costly and not very accurate on the ZScript side. I've tried taking a crack at it myself but considering how each is handled differently, I've never been able to wrap my head around the proper way to call the specific ones needed.
Wasn't sure but is it possible to export the triangle drawer of the engine, akin to the line drawing function Gutawer exposed? I suggest this because making a filled shape out of lines can become quite costly and not very accurate on the ZScript side. I've tried taking a crack at it myself but considering how each is handled differently, I've never been able to wrap my head around the proper way to call the specific ones needed.
- Marisa the Magician
- Posts: 3886
- Joined: Fri Feb 08, 2008 9:15 am
- Preferred Pronouns: She/Her
- Operating System Version (Optional): (btw I use) Arch
- Graphics Processor: nVidia with Vulkan support
- Location: Vigo, Galicia
- Contact:
Re: Expose triangle drawer*
Had no idea this is a thing. Will give it a whirl after joel's contest is over.
- Major Cooke
- Posts: 8170
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: Expose triangle drawer*
What's that?
Re: Expose triangle drawer*
What are you going to be using it for?
The 2D poly drawer (for the automap) might be possible to expose, but I really have second thoughts about exposing anything 3D related right now because they are not available in every renderer, and in addition to that, would be a huge mess, anyhow.
dpJudas was working on a (hardpoly) renderer abstraction a few months back and perhaps we should wait for that to be done, first, before we consider allowing any 3D functions to be done in ZScript.
The 2D poly drawer (for the automap) might be possible to expose, but I really have second thoughts about exposing anything 3D related right now because they are not available in every renderer, and in addition to that, would be a huge mess, anyhow.
dpJudas was working on a (hardpoly) renderer abstraction a few months back and perhaps we should wait for that to be done, first, before we consider allowing any 3D functions to be done in ZScript.
- Major Cooke
- Posts: 8170
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: Expose triangle drawer*
Making shapes such as triangles and squares with a different fill color. Because doing a line function multiple times to fill in a simply shape is costly.
I don't mean the triangle drawing in polysoft specifically. It's actually the FillSimplePoly function. The same area that Gutawer used to expose the line drawing function.
I don't mean the triangle drawing in polysoft specifically. It's actually the FillSimplePoly function. The same area that Gutawer used to expose the line drawing function.
Re: Expose triangle drawer*
I have two implementations of this, I haven't yet pushed either of them to master. They are untested right now.
Freeform:
https://github.com/coelckers/gzdoom/com ... SimplePoly
Triangles only:
https://github.com/coelckers/gzdoom/com ... ly_TriOnly
The idea with the Triangles Only version is the user will have to do the triangle fan, themselves, if they want more complex screen polys.
Freeform:
https://github.com/coelckers/gzdoom/com ... SimplePoly
Triangles only:
https://github.com/coelckers/gzdoom/com ... ly_TriOnly
The idea with the Triangles Only version is the user will have to do the triangle fan, themselves, if they want more complex screen polys.
- Major Cooke
- Posts: 8170
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: Expose triangle drawer*
You have my utmost gratitude Rachael. Hats off to you for this. Will be doing more testing in a bit.
- Marisa the Magician
- Posts: 3886
- Joined: Fri Feb 08, 2008 9:15 am
- Preferred Pronouns: She/Her
- Operating System Version (Optional): (btw I use) Arch
- Graphics Processor: nVidia with Vulkan support
- Location: Vigo, Galicia
- Contact:
Re: Expose triangle drawer*
I'd go for the freeform one, saves a bit of overhead that way.
Re: Expose triangle drawer*
The Tri-only one is a lot safer to use, though, and lowers the risk of OOB access. In the freeform version, the array must also be entered in a very specific way - it will not work if a bunch of arbitrary points are entered. (It must be entered clockwise, and the shape must be completely convex) If there's a way to measure an array in ZScript and pass it back to the native interface, that would certainly be a lot better than requiring the user to count their array entries. OOB can result in all sorts of unpredictable behavior - up to and including access violations.
I left both there, though - Graf might have his own idea how he wants this handled.
I left both there, though - Graf might have his own idea how he wants this handled.
- Marisa the Magician
- Posts: 3886
- Joined: Fri Feb 08, 2008 9:15 am
- Preferred Pronouns: She/Her
- Operating System Version (Optional): (btw I use) Arch
- Graphics Processor: nVidia with Vulkan support
- Location: Vigo, Galicia
- Contact:
Re: Expose triangle drawer*
Ah, very well then. Will any of them be on qzdoom so I can play around?
Re: Expose triangle drawer*
Eventually, yes. For now if you really want to play around just do
on top of G/QZDoom and compile.
Obviously it would be a good idea to open a new branch before doing this if you don't want to mess up your master branch ref pointer.
Code: Select all
git pull https://github.com/coelckers/gzdoom ZScript_FillSimplePoly_TriOnly
Obviously it would be a good idea to open a new branch before doing this if you don't want to mess up your master branch ref pointer.
- Major Cooke
- Posts: 8170
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: Expose triangle drawer*
Hmmm, I cannot seem to get this to work.
I'd show you my attempted changes to make it work better but unfortunately:
Fuck it. Hard way hidey ho!
Simply put it's not reading from the struct at all. This is easily fixed by changing the definition to this:
Another thing I noticed is wrong (and I compared this to the SpawnParticle and SetBlend, just so you're aware), flatcolor is an int; that should most likely be a color variable instead.
With the reflecting change also made on the zscript side as well.
Then you can change:
to:
So that will fix the points but it still won't work.
I'd show you my attempted changes to make it work better but unfortunately:
Fuck it. Hard way hidey ho!
- Download the test file below.
- Add a print message just after the vector stuff inside of vdraw, like this:
Code: Select all
if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); FTexture *tex = TexMan[FSetTextureID(texture)]; colormap.Clear(); FVector2 points[3] = { FVector2(p0x, p0y), FVector2(p1x, p1y), FVector2(p2x, p2y) }; Printf("%01f %01f %01f %01f %01f %01f\n", p0x, p0y, p1x, p1y, p2x, p2y); //<---------------------------------------------------------- screen->FillSimplePoly(tex, points, 3, originx, originy, scalex, scaley, rotation, colormap, flatcolor, lightlevel, bottomclip); return 0;
- Compile and give it a run with test.pk3.
Simply put it's not reading from the struct at all. This is easily fixed by changing the definition to this:
Code: Select all
native static void FillSimpleTriangle(TextureID texture, Vector2 p1, Vector2 p2, Vector2 p3, double originx, double originy, double scalex, double scaley, double rotation, int flatcolor, int lightlevel, int bottomclip);
Code: Select all
PARAM_COLOR(flatcolor);
Then you can change:
Code: Select all
FSimpleTriangle tri;
tri.point[0] = (0.0, 30.0);
tri.point[1] = (30.0, 0.0);
tri.point[2] = (0.0, -30.0);
Screen.FillSimpleTriangle(gfx, tri, 0, 0, 1, 1, 1, 0, 255, 200);
/*
Vector2 t0 = (30, 0);
Vector2 t1 = (0, -30);
Vector2 t2 = (-30, 0);
Screen.FillSimpleTriangle(gfx, t0, t1, t2, 200, 200, 1, 1, 1, "White", 0, 0);
*/
Code: Select all
/*
FSimpleTriangle tri;
tri.point[0] = (0.0, 30.0);
tri.point[1] = (30.0, 0.0);
tri.point[2] = (0.0, -30.0);
Screen.FillSimpleTriangle(gfx, tri, 0, 0, 1, 1, 1, 0, 255, 200);
*/
Vector2 t0 = (30, 0);
Vector2 t1 = (0, -30);
Vector2 t2 = (-30, 0);
Screen.FillSimpleTriangle(gfx, t0, t1, t2, 0, 0, 1, 1, 1, "White", 255, 200);
So that will fix the points but it still won't work.
- Attachments
-
- test.pk3
- (2.47 KiB) Downloaded 51 times
Re: Expose triangle drawer*
I suspect there's a bigger problem then, than just exposing a single triangle drawer. It seems like the one chosen expects a lot and assumes the automap is active since that's the only place where it's really used. It may also be drawing textures contingent on whether the user has textured automap enabled, but I am not 100% sure of that.
At this point, I am tempted to say just make a new one for our purposes here, but that means making a new one for essentially 5 different renderers, since the 2D code is spread out among each and each has to implement their own versions of the drawers.
I implemented the suggested changes but I have not yet tested it.
At this point, I am tempted to say just make a new one for our purposes here, but that means making a new one for essentially 5 different renderers, since the 2D code is spread out among each and each has to implement their own versions of the drawers.
I implemented the suggested changes but I have not yet tested it.
- Major Cooke
- Posts: 8170
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: Expose triangle drawer*
Aye, I don't know how to properly test it either at this point. Guess it'll have to wait.
- Marisa the Magician
- Posts: 3886
- Joined: Fri Feb 08, 2008 9:15 am
- Preferred Pronouns: She/Her
- Operating System Version (Optional): (btw I use) Arch
- Graphics Processor: nVidia with Vulkan support
- Location: Vigo, Galicia
- Contact:
Re: Expose triangle drawer*
Have some example code. This draws a rotating triangle in the middle of the screen with STARTAN2.
Code: Select all
version "3.3"
class mkTestTriangle : StaticEventHandler
{
Vector2 points[3];
override void RenderOverlay( RenderEvent e )
{
float ang = gametic+e.fractic;
Vector2 origin = (Screen.GetWidth(),Screen.GetHeight())*0.5;
// center vertices
Vector2 vert[3];
for ( int i=0; i<3; i++ ) vert[i] = (cos(ang)*points[i].x+sin(ang)*points[i].y,sin(ang)*points[i].x-cos(ang)*points[i].y)+origin;
Screen.FillSimpleTriangle(TexMan.CheckForTexture("STARTAN2",TexMan.Type_Any),vert[0],vert[1],vert[2],origin.x,origin.y,1.0,1.0,-ang,Color(255,255,255),255,0);
}
override void WorldLoaded( WorldEvent e )
{
for ( int i=0; i<3; i++ ) points[i] = (cos(120*i),sin(120*i))*256;
}
}