View topic - Need help drawing a texture on the map



All times are UTC + 1 hour


Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: 01 Apr 2012, 05:15 
Evolution RTS Developer
User avatar

Joined: 17 Nov 2005, 02:43
Location: Raegquitting Spring on 04/24/12
Code:
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?

Attachment:
geovent.png
geovent.png [ 1.27 KiB | Viewed 434 times ]


Top
 Offline Profile  
 
PostPosted: 01 Apr 2012, 10:34 
Moderator
User avatar

Joined: 29 Apr 2005, 00:14
Location: #moddev - join it!
Isn't there a widget for drawing metalspots? Could be readily adapted i imagine.


Top
 Offline Profile  
 
PostPosted: 01 Apr 2012, 10:38 
Moderator
User avatar

Joined: 22 Feb 2006, 01:02
Location: cheap kitchen
yea, just take the metalspot thing, replace the texturefile and the part where it gets the position for drawing.


Top
 Offline Profile  
 
PostPosted: 01 Apr 2012, 10:54 
Evolution RTS Developer
User avatar

Joined: 17 Nov 2005, 02:43
Location: Raegquitting Spring on 04/24/12
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.


Top
 Offline Profile  
 
PostPosted: 01 Apr 2012, 11:06 
Evolution RTS Developer
User avatar

Joined: 17 Nov 2005, 02:43
Location: Raegquitting Spring on 04/24/12
Code:
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


Top
 Offline Profile  
 
PostPosted: 01 Apr 2012, 11:30 
Moderator
User avatar

Joined: 22 Feb 2006, 01:02
Location: cheap kitchen
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[i].x, spots[i].y, spots[i].z


Top
 Offline Profile  
 
PostPosted: 01 Apr 2012, 11:40 
User avatar

Joined: 07 Dec 2008, 02:35
http://springrts.com/wiki/Lua_OpenGL_Ap ... Primitives

Code:
gl.Texture('texture.png')
gl.DrawGroundQuad(x1, z1, x2, z2, true, true)
gl.Texture(false)

Wiki wrote:
Note: x1,z1,x2 & z2 are rounded


Top
 Offline Profile  
 
PostPosted: 01 Apr 2012, 13:11 
Journeywar Developer & Mapper
User avatar

Joined: 24 Jan 2006, 21:12
Location: There is no god - and reality is his prophetess
Any time I've had that sort of issue I've always had to do it by hand.


Top
 Offline Profile  
 
PostPosted: 01 Apr 2012, 22:46 
Evolution RTS Developer
User avatar

Joined: 17 Nov 2005, 02:43
Location: Raegquitting Spring on 04/24/12
I have no idea wtf you guys are talking about.


Top
 Offline Profile  
 
PostPosted: 02 Apr 2012, 20:21 
User avatar

Joined: 07 Feb 2005, 21:30
Location: Cheese factory
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..


Top
 Offline Profile  
 
PostPosted: 02 Apr 2012, 20:55 
Spring Developer

Joined: 08 Oct 2006, 15:58
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.


Top
 Offline Profile  
 
PostPosted: 02 Apr 2012, 22:50 
User avatar

Joined: 07 Feb 2005, 21:30
Location: Cheese factory
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..


Top
 Offline Profile  
 
PostPosted: 03 Apr 2012, 10:30 
Moderator

Joined: 12 Oct 2007, 08:24
Look into using this: https://github.com/spring/spring/commit ... 63e57f3aca

Somewhat explained here: viewtopic.php?f=12&t=26478&p=495433


Top
 Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Majestic-12 [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group

Site layout created by Roflcopter et al.