Page 1 of 1
Need help drawing a texture on the map
Posted: 01 Apr 2012, 06:15
by Forboding Angel
Code: Select all
function widget:GetInfo()
return {
name = "GeoVent Texture Placer",
desc = "Places Geovent Textures",
author = "Forboding Angel",
date = "03/30/2012",
license = "Public Domain",
layer = 0,
enabled = true -- loaded by default?
}
end
local function geoTextures()
local features = Spring.GetAllFeatures()
for i = 1, #features do
local fID = features[i]
if FeatureDefs[Spring.GetFeatureDefID(fID)].geoThermal then
local fx, fy, fz = Spring.GetFeaturePosition(fID)
--place texture on map here
end
end
end
Would someone help finish this widget? It is to include in maps so that you can place geovents with lua, and still have the geovent textures drawn on the map (same basic idea as drawing metal textures on the map).
--place texture on map here << This line is where the code for actually drawing the image should go, but I don't have the foggiest idea how to do it. Anyone feel like taking a stab at it?

- geovent.png (1.27 KiB) Viewed 1964 times
Re: Need help drawing a texture on the map
Posted: 01 Apr 2012, 11:34
by FLOZi
Isn't there a widget for drawing metalspots? Could be readily adapted i imagine.
Re: Need help drawing a texture on the map
Posted: 01 Apr 2012, 11:38
by knorke
yea, just take the metalspot thing, replace the texturefile and the part where it gets the position for drawing.
Re: Need help drawing a texture on the map
Posted: 01 Apr 2012, 11:54
by Forboding Angel
Have you seen that monstrosity of a widget? That was my first idea... I gave up that idea in a hurry.
I see where the texture is being placed, but it's drawing a box to place the texture in, which is all fine and good, but I don't understand enough of what I'm reading to use it.
Re: Need help drawing a texture on the map
Posted: 01 Apr 2012, 12:06
by Forboding Angel
Code: Select all
function createDL()
local x = 0
local y = 0
local z = 0
gl.PushMatrix()
gl.Color( rgbr, rgbg, rgbb, 1.0)
for i = 1, #mSpots do
gl.Texture( searchPath .. "metal_high.png" )
gl.Translate( mSpots[i].x, Spring.GetGroundHeight(mSpots[i].x, mSpots[i].z), mSpots[i].z )
gl.Rotate( 90, 1, 0, 0 )
gl.Rotate( rotations[i], 0, 0, 1 )
gl.TexRect( -metalSpotWidth/2, -metalSpotHeight/2, metalSpotWidth/2, metalSpotHeight/2 )
gl.Rotate( -rotations[i], 0, 0, 1 )
gl.Rotate( -90, 1, 0, 0 )
gl.Translate( -mSpots[i].x, -Spring.GetGroundHeight(mSpots[i].x, mSpots[i].z), -mSpots[i].z )
end
gl.PopMatrix()
end
That's the relevant section. I don't understand what is happening there, nor how to adapt it for my needs.
http://www.tasdownloads.com/tasuploader ... ted-v3.lua
Re: Need help drawing a texture on the map
Posted: 01 Apr 2012, 12:30
by knorke
That is not the relevant part, it is the drawing and can remain unchanged.
edit that:
function GetSpots()
to return positions of geos instead of metalspots.
Format is like
spots.x, spots.y, spots.z
Re: Need help drawing a texture on the map
Posted: 01 Apr 2012, 12:40
by Niobium
http://springrts.com/wiki/Lua_OpenGL_Ap ... Primitives
Code: Select all
gl.Texture('texture.png')
gl.DrawGroundQuad(x1, z1, x2, z2, true, true)
gl.Texture(false)
Wiki wrote:Note: x1,z1,x2 & z2 are rounded
Re: Need help drawing a texture on the map
Posted: 01 Apr 2012, 14:11
by PicassoCT
Any time I've had that sort of issue I've always had to do it by hand.
Re: Need help drawing a texture on the map
Posted: 01 Apr 2012, 23:46
by Forboding Angel
I have no idea wtf you guys are talking about.
Re: Need help drawing a texture on the map
Posted: 02 Apr 2012, 21:21
by Cheesecan
If you're modifying metal spots use the version from here
http://springfiles.com/downloadmain/start/15606
DrawGroundQuad doesn't work as you might believe from the description in the wiki. If the terrain is not flat enough, the ground texture will clip through. I basically wrote a hack around that problem. My best guess would be that the engine calculates the normal of a quad. But in reality spring terrain is probably drawn with triangle strips(more efficient than drawing quads). That would mean there are two normals(one for each polygon half of the quad). So to draw it perfectly you would calculate those normals and apply the texture(which might have to be drawn in halves). Although since DrawGroundQuad doesn't work(and devs didn't fix it), it might be more difficult than that.
If this tells you nothing it's basically doing this twice:
http://i.neoseeker.com/a/r420preview/normal.jpg
and applying the texture onto that region.
Not even sure why this problem exists, I think opengl calculates normals itself when you draw quads on polygon strips..
Re: Need help drawing a texture on the map
Posted: 02 Apr 2012, 21:55
by Kloot
It has _nothing_ to do with normals, those only affect shading...
Hint: the terrain mesh is _dynamically tesselated_ while ground quads have fixed-resolution geometry.
Re: Need help drawing a texture on the map
Posted: 02 Apr 2012, 23:50
by Cheesecan
Okey as I thought, I'm wrong.
I know nothing about dynamic tessellation or what it implies. Only the frustrating outcome. My experience with opengl is limited to writing a very basic heightmap renderer as seen
here. But I hope to learn more in the future.
I guess this is as close to an
explanation as we'll have..
Re: Need help drawing a texture on the map
Posted: 03 Apr 2012, 11:30
by Google_Frog