Drawing units/features

Drawing units/features

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Drawing units/features

Post by gajop »

With the recent advances I hope it might finally be possible to properly draw both units and features.
Using the latest dev build, this is what I get:

Code: Select all

    gl.Color(1, 1, 1, 0.8)
    gl.UnitShape(unitDefID, teamID)
-> http://i.imgur.com/ZJr3xvT.jpg (proper colors and shape, but the unit faces seem wrong - not ideal but good enough for an editor)

Features are a much bigger problem though:

Code: Select all

    gl.Color(1, 1, 1, 0.8)
    gl.FeatureShape(featureDefID, teamID)
-> http://i.imgur.com/P6bytDr.jpg (there's no color/texture and the vertexes are wrong - pretty bad and makes it hard to tell what unit it is)

Code: Select all

    gl.Texture(1, "%-" .. featureDefID .. ":1")
    gl.Color(1, 1, 1, 0.8)
    gl.FeatureShape(featureDefID, teamID)
-> http://i.imgur.com/N84dhOw.jpg (at least there's a clear model, but still the texture colors are wrong and also the same issue with faces as the unit)
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: Drawing units/features

Post by Kloot »

UnitShape and FeatureShape (*DefID-based) are the only functions I didn't touch, and still await refurbishment.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Drawing units/features

Post by gajop »

Cool, I await your changes :)
I reckon having opengl unitdef animations (scripts) would require huge changes, but at least rendering them correctly (in static pose) would be enough to allow for a number of cool things.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Drawing units/features

Post by smoth »

I am really happy to see this finally getting addressed :)
8611z
Posts: 169
Joined: 08 Jul 2015, 20:20

Re: Drawing units/features

Post by 8611z »

in gl.Texture(1, "%-" .. featureDefID .. ":1") try "0"
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Drawing units/features

Post by gajop »

8611z wrote:in gl.Texture(1, "%-" .. featureDefID .. ":1") try "0"
Tried, nothing gets rendered.
8611z
Posts: 169
Joined: 08 Jul 2015, 20:20

Re: Drawing units/features

Post by 8611z »

https://springrts.com/wiki/Lua_OpenGL_Api#Textures says: (:0->tex1,:1->tex2)
it worked for me.
viewtopic.php?f=9&t=31367&start=260#p563013 and note following posts and linked posts.
Image
left=engine
right=lua
I do not remember any difference to engine-rendering except missing advmodelshading. (perhaps do-able too, not sure)
To have stuff draw in right order it needed depthtest, iirc:
gl.DepthTest(GL.LEQUAL)
gl.DepthMask(true)
Otherwise tree-trunk might be drawn in front of tree-leaves or so.
Attachments
feature draw.jpg
(254.13 KiB) Not downloaded yet
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Drawing units/features

Post by gajop »

That link.. down the rabbit hole again :S
Good news is that depth testing you suggested works great.

Code: Select all

gl.DepthTest(GL.LEQUAL)
gl.DepthMask(true)
The above has fixed unit rendering completely, thanks!

As far as feature rendering goes, I'm starting to think it's probably an issue with the feature types I'm using (Spring Features). Then there's also the issue with engine features (trees) which I can't render no matter what I try.
I guess kloot from the past is just right that it's not completed yet. I don't want to do a bunch of case-by-case work if it'll get fixed soon (hope I won't see this post referenced in 2018 again).

@knorke, can you post your complete code that I might try and adapt to my stuff?
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: Drawing units/features

Post by Kloot »

All of the above blablabla will be rendered (hohoho) obsolete by 101.0, and the rabbit holes filled with concrete.

Just call gl.{Unit,Feature}Shape (without prefacing by gl.Texture/gl.Color/gl.Whatever, you only need to set the transform) and the engine takes care of the rest.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Drawing units/features

Post by gajop »

Kloot wrote:All of the above blablabla will be rendered (hohoho) obsolete by 101.0, and the rabbit holes filled with concrete.

Just call gl.{Unit,Feature}Shape (without prefacing by gl.Texture/gl.Color/gl.Whatever, you only need to set the transform) and the engine takes care of the rest.
That sounds great, I hope gl.Color will still work though. I use it to color units that are being added/manipulated.
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: Drawing units/features

Post by Kloot »

If you want customized rendering you'll have to set the entire state (textures/shaders/...) yourself again, read this.
8611z
Posts: 169
Joined: 08 Jul 2015, 20:20

Re: Drawing units/features

Post by 8611z »

until then it is fixable by 2 easy things:
https://github.com/gajop/Scened-Core/co ... ead6e40L40
It is texture :0 and :1, not :1 and :2
I dont remember if/how texture2 (:1) worked, only :0 will do fine though.

difference between 3do and s3o models: viewtopic.php?f=9&t=31367&start=280#p563530 generally most map-features are s3o and wreckage in many mods is 3do.

No idea if engine-trees will eventually draw normal, but for geovent or other decal-only-features one imo needs to draw some own placeholder anyway.
User avatar
code_man
Posts: 260
Joined: 19 Jan 2014, 13:10

Re: Drawing units/features

Post by code_man »

Actual api to render any model in the world or on the screen?
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Drawing units/features

Post by gajop »

code_man wrote:Actual api to render any model in the world or on the screen?
Rendering in :DrawWorld and :DrawScreen is mostly the same.
I'll post my solution when all the engine issues get sorted out but so far I'm leaning towards the new gl.{Feature,Unit}Shape that uses the engine to set all the required params. Adding a shader to it seems to work more reliably than the old "set everything you need depending on the format" thing.
@knorke: I tried your solution (and more) and it just didn't work for me. I feel I wasted enough hours on it for now so there's no need to revisit it in its original form. Thanks for trying to help though!
Post Reply

Return to “Lua Scripts”