Page 1 of 1

Drawing units/features

Posted: 25 Dec 2015, 06:14
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)

Re: Drawing units/features

Posted: 25 Dec 2015, 13:13
by Kloot
UnitShape and FeatureShape (*DefID-based) are the only functions I didn't touch, and still await refurbishment.

Re: Drawing units/features

Posted: 25 Dec 2015, 17:06
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.

Re: Drawing units/features

Posted: 25 Dec 2015, 18:51
by smoth
I am really happy to see this finally getting addressed :)

Re: Drawing units/features

Posted: 26 Dec 2015, 21:03
by 8611z
in gl.Texture(1, "%-" .. featureDefID .. ":1") try "0"

Re: Drawing units/features

Posted: 26 Dec 2015, 21:30
by gajop
8611z wrote:in gl.Texture(1, "%-" .. featureDefID .. ":1") try "0"
Tried, nothing gets rendered.

Re: Drawing units/features

Posted: 27 Dec 2015, 06:09
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.

Re: Drawing units/features

Posted: 27 Dec 2015, 10:14
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?

Re: Drawing units/features

Posted: 27 Dec 2015, 14:13
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.

Re: Drawing units/features

Posted: 27 Dec 2015, 15:03
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.

Re: Drawing units/features

Posted: 27 Dec 2015, 15:26
by Kloot
If you want customized rendering you'll have to set the entire state (textures/shaders/...) yourself again, read this.

Re: Drawing units/features

Posted: 27 Dec 2015, 17:50
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.

Re: Drawing units/features

Posted: 03 Jan 2016, 18:20
by code_man
Actual api to render any model in the world or on the screen?

Re: Drawing units/features

Posted: 03 Jan 2016, 19:29
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!