Problem drawing features
Moderator: Moderators
- very_bad_soldier
- Posts: 1397
- Joined: 20 Feb 2007, 01:10
Problem drawing features
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!
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!
Re: Problem drawing features
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.
UnitDefs[216]["model"] = {
["textures"] = {
}
["type"] = "3do",
}
If not, then define it with a customParam, since Features take those.
- Pressure Line
- Posts: 2283
- Joined: 21 May 2007, 02:09
Re: Problem drawing features
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)
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.
- Pressure Line
- Posts: 2283
- Joined: 21 May 2007, 02:09
Re: Problem drawing features
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) 

Re: Problem drawing features
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:I suspect that the texture is not set correctly
Code: Select all
glTexture(0, '%' .. unitDefID .. ":0")
glTexture(1, '%' .. unitDefID .. ":1")
What do you think the above is an example of?how to do multitexturing

- very_bad_soldier
- Posts: 1397
- Joined: 20 Feb 2007, 01:10
Re: Problem drawing features
I really appreciate your posts, but sorry, I frankly just dont get it
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:
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).

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 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).
Re: Problem drawing features
Use $units, if you're drawing a Juno, it's a 3DO.
- Pressure Line
- Posts: 2283
- Joined: 21 May 2007, 02:09
Re: Problem drawing features
Argh you dummy,
1 - 3do unit
2 - s3o unit
3 - 3do feature
4 - s3o feature
get writing them if-statements yo.
you'll need 4 cases for this (as far as i can tell):very_bad_soldier wrote:Juno wreckage
1 - 3do unit
2 - s3o unit
3 - 3do feature
4 - s3o feature
get writing them if-statements yo.
Re: Problem drawing features
Isn't the Juno's wreckage still 3DO, though?
- very_bad_soldier
- Posts: 1397
- Joined: 20 Feb 2007, 01:10
Re: Problem drawing features
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).Argh wrote:Use $units, if you're drawing a Juno, it's a 3DO.
Ok, but I still need a proper syntax to load a texture for a given featureDefID or am I wrong?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.
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)?
Re: Problem drawing features
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
- very_bad_soldier
- Posts: 1397
- Joined: 20 Feb 2007, 01:10
Re: Problem drawing features
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.
Re: Problem drawing features
For 3DO's, you will want to add
and in general
prior to drawing. Remember to undo the state changes when done.
Code: Select all
gl.Culling(GL.FRONT)
Code: Select all
gl.DepthTest(GL.LEQUAL)
gl.DepthMask(true)
Last edited by Kloot on 16 Jan 2009, 20:28, edited 1 time in total.
Re: Problem drawing features
For 3DOs you want to deactivate culling ... (only for S3O you should enable it)Kloot wrote:For 3DO's, you will want to add
Code: Select all
gl.Culling(GL.FRONT)
Re: Problem drawing features
Ah, right, I keep forgetting 3DO's don't use any (guess it's their CW windings).
Re: Problem drawing features
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.
- very_bad_soldier
- Posts: 1397
- Joined: 20 Feb 2007, 01:10
Re: Problem drawing features
Yay thanks, after playing around with the culling settings, it worked with Kloot's code changing the depth test
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:
But again I failed to get it to work correctly.

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)
- very_bad_soldier
- Posts: 1397
- Joined: 20 Feb 2007, 01:10
Re: Problem drawing features
I had a hard time finding out the cause of this but its working now
Thanks again to all helpers!
