Need help drawing a texture on the map

Need help drawing a texture on the map

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

Moderator: Moderators

Post Reply
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Need help drawing a texture on the map

Post 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
geovent.png (1.27 KiB) Viewed 1955 times
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: Need help drawing a texture on the map

Post by FLOZi »

Isn't there a widget for drawing metalspots? Could be readily adapted i imagine.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Need help drawing a texture on the map

Post by knorke »

yea, just take the metalspot thing, replace the texturefile and the part where it gets the position for drawing.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Need help drawing a texture on the map

Post 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.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Need help drawing a texture on the map

Post 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
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Need help drawing a texture on the map

Post 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
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: Need help drawing a texture on the map

Post 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
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10454
Joined: 24 Jan 2006, 21:12

Re: Need help drawing a texture on the map

Post by PicassoCT »

Any time I've had that sort of issue I've always had to do it by hand.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Need help drawing a texture on the map

Post by Forboding Angel »

I have no idea wtf you guys are talking about.
User avatar
Cheesecan
Posts: 1571
Joined: 07 Feb 2005, 21:30

Re: Need help drawing a texture on the map

Post 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..
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: Need help drawing a texture on the map

Post 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.
User avatar
Cheesecan
Posts: 1571
Joined: 07 Feb 2005, 21:30

Re: Need help drawing a texture on the map

Post 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..
Post Reply

Return to “Lua Scripts”