Problem drawing features

Problem drawing features

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

Moderator: Moderators

Post Reply
User avatar
very_bad_soldier
Posts: 1397
Joined: 20 Feb 2007, 01:10

Problem drawing features

Post by very_bad_soldier »

Hi guys,

I am trying to draw a feature by calling gl.FeatureShape (in a widget). My problem is that it ends up being drawn as a complete white shape:
http://img80.imageshack.us/my.php?image=glshapetp4.png
(Color is 1.0, 1.0, 1.0, 1.0)

I suspect that the texture is not set correctly as it draws units correctly using the same code but gl.UnitShape instead of gl.FeatureShape.

So I tried to set a texture using gl.Texture which gave the rendered feature some color (but the wrong one cause I used a random texture). I just have no idea how to set the corresponding texture for the feature I want to draw. I can't see any texture information in the FeatureDef-Table.
So could someone pls point me in the right direction how to get the texture set correctly (or how to draw the feature correctly, maybe I am doing it entirely wrong)?

Big Thanks in advance!
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Problem drawing features

Post by Argh »

Hmm. Should have sub-sections for Model, like UnitDef does. I.E.:

UnitDefs[216]["model"] = {
["textures"] = {
}
["type"] = "3do",
}

If not, then define it with a customParam, since Features take those.
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: Problem drawing features

Post by Pressure Line »

Code: Select all

gl.Texture

 ( [ number texNum, ] boolean enable | string name ) -> nil | boolean loaded

                          current formats:
 :${opt}:/LuaUI/images/image.png = filename
                             #12 = unitDef 12 buildpic
                           %34:1 = unitDef 34 s3o tex2 (:0->tex1,:1->tex2)
                             !56 = lua generated texture 56
                          $units = 3do textureatlas
                         $shadow = shadowmap
                       $specular = specular cube map
                     $reflection = reflection cube map

                        possible ${opt}'s are:
                             'n' = nearest
                             'l' = linear
                             'a' = aniso
                             'i' = invert
                             'g' = greyed
                             'c' = clamped
                             'b' = border
                             't%r,%g,%b' = tint

                example: ":iac:/LuaUI/images/image.png"
                example2: ":t1.0,0.5,0:/LuaUI/images/image.png"  (orange tint)
/me wanders away humming softly

unfortunately im not 100% sure how to use the %34:0 option :/ the other problem is that as far as i know the textures are loaded as rgba not rgbT (T = Teamcolor) which may present some issues.
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: Problem drawing features

Post by Pressure Line »

oh. btw, v_b_s has figured out how to do multitexturing, and probably in a way that works (and almost certainly a lot easier than my way of doing it) ;)
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: Problem drawing features

Post by Kloot »

I suspect that the texture is not set correctly
FeatureShape() _only_ draws the raw geometry for you (not by design, unlike UnitShape() it's just unfinished). Lighting and texturing states you have to set up yourself, a small hint:

Code: Select all

glTexture(0, '%' .. unitDefID .. ":0")
glTexture(1, '%' .. unitDefID .. ":1")
how to do multitexturing
What do you think the above is an example of? ;)
User avatar
very_bad_soldier
Posts: 1397
Joined: 20 Feb 2007, 01:10

Re: Problem drawing features

Post by very_bad_soldier »

I really appreciate your posts, but sorry, I frankly just dont get it :oops:

I already noticed and tried the "%x:y"-syntax to load a texture from a unitDefinition. But my first problem is: Since I want to draw a feature I would need another syntax to use a texture from the features instead of units, wouldnt I? AFAIK are features and units different "sets" of objects?

A more practical explanation:

Code: Select all

glColor(1.0, 1.0, 1.0, 1.0 )
glDepthTest(true)

local featureDefID = 4 --armJuno
local feature = FeatureDefs[featureDefID]

--added Kloot's example
local unitDefID = featureDefID -- unitDefID? I only have featureDefID?! What should I do?
glTexture(0, '%' .. unitDefID .. ":0")
glTexture(1, '%' .. unitDefID .. ":1")

glPushMatrix()
glTranslate( 59, 700, 220)
gl.FeatureShape( featureDefID, 1 )
glPopMatrix()
I am trying to draw a Juno wreckage in the example (featureDefID 4). But the glTexture-function expects a unitDefID which I dont have.

I tried to choose a random unitDefID just to see what happens but whichever unitDefID I used the shape ended up just white (like in the screenshot).
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Problem drawing features

Post by Argh »

Use $units, if you're drawing a Juno, it's a 3DO.
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: Problem drawing features

Post by Pressure Line »

Argh you dummy,
very_bad_soldier wrote:Juno wreckage
you'll need 4 cases for this (as far as i can tell):
1 - 3do unit
2 - s3o unit
3 - 3do feature
4 - s3o feature

get writing them if-statements yo.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Problem drawing features

Post by Argh »

Isn't the Juno's wreckage still 3DO, though?
User avatar
Hoi
Posts: 2917
Joined: 13 May 2008, 16:51

Re: Problem drawing features

Post by Hoi »

Yes and it's a feature.
User avatar
very_bad_soldier
Posts: 1397
Joined: 20 Feb 2007, 01:10

Re: Problem drawing features

Post by very_bad_soldier »

Argh wrote:Use $units, if you're drawing a Juno, it's a 3DO.
Thanks, I tried it, but it didnt work either. I tried it on both texture stages but it did not render at all (no visible feature).
Pressure Line wrote:you'll need 4 cases for this (as far as i can tell):
1 - 3do unit
2 - s3o unit
3 - 3do feature
4 - s3o feature

get writing them if-statements yo.
Ok, but I still need a proper syntax to load a texture for a given featureDefID or am I wrong?

Meanwhile I invested lots of hours trying all possible stuff I could imagine but still no luck. Maybe there is a bug preventing it from working correctly or can someone confirm it is working (drawing a feature by calling gl.FeatureShape with a correctly set up texture by calling gl.Texture)?
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Problem drawing features

Post by jK »

Code: Select all

function widget:DrawWorld()
  gl.AlphaTest(false)
  gl.Blending(false)
  gl.Texture(0,"$units1")
  --gl.Texture(1,"$units2")
  gl.PushMatrix()
  gl.Color(1,1,1)
  gl.Translate(0,Spring.GetGroundHeight(0,0)+20,0)
  gl.FeatureShape(15,1)
  gl.PopMatrix()
  gl.Texture(0,false)
  --gl.Texture(1,false)
  gl.AlphaTest(true)
  gl.Blending(true)
end
User avatar
very_bad_soldier
Posts: 1397
Joined: 20 Feb 2007, 01:10

Re: Problem drawing features

Post by very_bad_soldier »

Great! Big Thanks (to you all, especially jK)! Textures are applied correctly (my problem was a wrong Blending-Setting obviously). The code has issues drawing the geometry though (looks like faces' normals are inverted or something like that) but I hope it can be fixed by changing some more OpenGL-Switches.
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: Problem drawing features

Post by Kloot »

For 3DO's, you will want to add

Code: Select all

gl.Culling(GL.FRONT)
and in general

Code: Select all

gl.DepthTest(GL.LEQUAL)
gl.DepthMask(true)
prior to drawing. Remember to undo the state changes when done.
Last edited by Kloot on 16 Jan 2009, 20:28, edited 1 time in total.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Problem drawing features

Post by jK »

Kloot wrote:For 3DO's, you will want to add

Code: Select all

gl.Culling(GL.FRONT)
For 3DOs you want to deactivate culling ... (only for S3O you should enable it)
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: Problem drawing features

Post by Kloot »

Ah, right, I keep forgetting 3DO's don't use any (guess it's their CW windings).
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Problem drawing features

Post by jK »

yeah, their normals points in the opposite direction, but that's easy to solve, it is just that the models aren't designed with culling in mind.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Problem drawing features

Post by jK »

http://github.com/spring/spring/commit/ ... 7a81c92d9f

this is/will be needed for s3o features
User avatar
very_bad_soldier
Posts: 1397
Joined: 20 Feb 2007, 01:10

Re: Problem drawing features

Post by very_bad_soldier »

Yay thanks, after playing around with the culling settings, it worked with Kloot's code changing the depth test :mrgreen:
I really hate it to have to ask again (it will be my last question): Any chance to get the rendering to obey glColors' alpha value correctly to draw the feature with a custom transparency?
I suspect it has something to do with the blending and I tried some stuff including:

Code: Select all

gl.Blending(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA)
But again I failed to get it to work correctly.
User avatar
very_bad_soldier
Posts: 1397
Joined: 20 Feb 2007, 01:10

Re: Problem drawing features

Post by very_bad_soldier »

I had a hard time finding out the cause of this but its working now 8) Thanks again to all helpers!
Post Reply

Return to “Lua Scripts”