Page 1 of 2

Lua FPS huds

Posted: 24 May 2007, 00:24
by trepan
WhiteHawk requested this, so I'll post the code here.

Image

A few points:

1. This will not work with 0.74b3, you'll need an SVN build

2. This is mod specific, and should probably be included in
the mod package as a mod widget. If that's the case, then
you can remove the modName check in widget:Initialize()

3. It would be better to load some HUDs as several cut-up
textures rather than one texture. It's a waste of video ram to
use big textures with large transparent gaps in them.

4. This code does not render "pixel-perfect" images. For that,
you'd need correctly sized textures and the ':n:' prefix for the
texture names (GL_NEAREST filtering mode).

5 The hud is drawn over the FPS info panel. IIRC, lua has the
ability to completely redraw the FPS info panel, and you can
use "fpshud 0" to disable the engine's version. You could also
use a LuaRules gadget instead of a mod widget ... I think that
they get drawn before any of the engine's UI elements.

Code: Select all

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
--  file:    gui_cockpits.lua
--  brief:   cockpits for FPS mode
--  author:  Dave Rodgers
--
--  Copyright (C) 2007.
--  Licensed under the terms of the GNU GPL, v2 or later.
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

function widget:GetInfo()
  return {
    name      = "Cockpits",
    desc      = "Cockpits for FPS mode",
    author    = "trepan",
    date      = "May 23, 2007",
    license   = "GNU GPL, v2 or later",
    layer     = 9,     --  draw early
    enabled   = false  --  loaded by default?
  }
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local modName = 'BA52.sd7'

local IMAGE_DIR = LUAUI_DIRNAME .. 'Images/cockpits/'

local cockpits = {
  armcom = IMAGE_DIR .. 'cauldronbornecockpit.png',
  armmav = IMAGE_DIR .. 'diashicockpit.png',
  armwar = IMAGE_DIR .. 'fireflycockpit.png'
}
 
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local activeImage = nil  -- used to free textures

local vsx, vsy = widgetHandler:GetViewSizes()

function widget:ViewResize(viewSizeX, viewSizeY)
  vsx = viewSizeX
  vsy = viewSizeY
end
   
   
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

function widget:Initialize()
  if (Game.modName ~= modName) then
    widgetHandler:RemoveWidget()   
    return
  end

  -- convert names to numeric ids
  for unitName, image in pairs(cockpits) do
    local ud = UnitDefNames[unitName]
    if (ud) then
      cockpits[ud.id] = image
      print(ud.id, image)
    end
  end  
end    
       
       
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
-- speed-ups
--
local glTexture     = gl.Texture
local glTexRect     = gl.TexRect
local glFreeTexture = gl.FreeTexture
local GetUnitDefID            = Spring.GetUnitDefID
local GetMyPlayerID           = Spring.GetMyPlayerID
local GetPlayerControlledUnit = Spring.GetPlayerControlledUnit


function widget:DrawScreen()
  local unitID = GetPlayerControlledUnit(GetMyPlayerID())
  if (unitID) then
    local udid = GetUnitDefID(unitID)
    local image = udid and cockpits[udid] or nil
    if (image) then
      if (activeImage and (activeImage ~= image)) then
        glFreeTexture(activeImage)
      end
      activeImage = image
      glTexture(image)   
      glTexRect(0, 0, vsx, vsy)
      glTexture(false)
    end
  elseif (activeImage) then
    glFreeTexture(activeImage)
    activeImage = nil
  end
end  
     
     
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

Posted: 24 May 2007, 02:28
by LOrDo
Zomgz. Ive wanted this since the day I discovered Com Shooter. NICE!

EDIT: Waitaminute... thats a flag I see in that screen?
Could it...
possibly...
just mabye...

CAPTURE THE FLAG IN NEXT SPRING?

Posted: 24 May 2007, 02:33
by trepan
If you want to do the lua coding for capture the flag, sure.

The flag is just a test widget for a multi-textured frag/vert shader.
It moves dynamically (with the game wind), and will look pretty
good once I get the normals and specular lighting done. Using a
vertex texture will be the cool way to do it, but I'm not planning on
adding that level of configurability to the lua textures yet.

Posted: 24 May 2007, 08:56
by Zenka
<borg persuasion>You will comply. give us vertex shaders.</borg>
the screen is just stunning. Thjat's all I'd say.

Posted: 24 May 2007, 09:19
by trepan
I'd already added vertex shaders (that's how the flag in the image is done).
http://spring.clan-sy.com/phpbb/viewtop ... 872#190872 introduced
vertex shader texture access (after looking at it, I decided it was too simple not
to add).

Posted: 24 May 2007, 11:58
by WhiteHawk
well, what can I say?

Thats perfect.

Fantastic Job trepan. A sure credits mention for you.

Where can I get the SVN build?

WhiteHawk.

Posted: 24 May 2007, 14:13
by 1v0ry_k1ng
that hud should be on by default for every mod. guess modders could set an alternate or turrn it off seperately, but it looks so pro!

Posted: 24 May 2007, 16:35
by Warlord Zsinj
Haha, and to think 1944 spent all that time trying to model a realistically fluttering flag...

Hmm, I wonder if they could implement some sort of lua-based gaia capture the flag system, with a flag system similar to CoH... hmmm...

Posted: 24 May 2007, 16:51
by Nemo
If by all that time you mean dividing it into four sections and giving it five minutes worth of animation work, then yes :P

Sweet stuff trepan, next release is going to be le awesome.

Posted: 24 May 2007, 17:15
by Snipawolf
lol @ 1944


Now then, this looks pretty interesting, that one looks good, but I can't imagine driving a tank with that... However it looks like it would totally work with a different color scheme for an airplane or mech.

Posted: 24 May 2007, 17:45
by 1v0ry_k1ng
is there some way of making the model you are driving not vanish, so you could see it around you?

Posted: 24 May 2007, 19:45
by Dragon45
Dude
Dude
Dude

Natural Selection in Spring.
As a default mode for all mods

shoudl be possible.

YES.


Edit: OMG, this + better aircraft code = mad TIE FIGHTERZ skillz :O

Posted: 24 May 2007, 20:28
by Zenka
Dragon45 wrote:Edit: OMG, this + better aircraft code = mad TIE FIGHTERZ skillz :O
well turning an originally land based RTS engine into an SW emulator game... err.... I do like tie fighter though :)

Posted: 24 May 2007, 21:59
by rattle
Dragon45 wrote:Dude
Dude
Dude

Natural Selection in Spring.
As a default mode for all mods

shoudl be possible.

YES.
Warp effect for aliens! Haha that'd be great.

Posted: 27 May 2007, 04:53
by NightfallGemini
1v0ry_k1ng wrote:is there some way of making the model you are driving not vanish, so you could see it around you?
Like, for example, to see that Maverick's guns?

{ EDITED by trepan }

If anyone knows if this can be done, PLEASE tell us!

Posted: 27 May 2007, 07:26
by KDR_11k
You can draw a model of the parts you want visible while in FPS mode, kinda like the weapon in a real FPS (which uses a different model in first person than third person, BTW).

Posted: 27 May 2007, 08:05
by Fanger
MECHWARRIOR!!!!!!!!!!!!!!!!!!!!!!!!!

Posted: 29 May 2007, 09:56
by Neddie
Fanger wrote:MECHWARRIOR!!!!!!!!!!!!!!!!!!!!!!!!!
He called it, I echo.

Posted: 15 Jun 2007, 04:38
by gamer17
Where can I get a SVN build from?

Posted: 15 Jun 2007, 06:12
by trepan