Class: Quake::Renderer::GLHud

Inherits:
Object
  • Object
show all
Defined in:
lib/quake/renderer/gl_hud.rb

Overview

Renders Quake's status bar HUD using graphics from gfx.wad. Uses orthographic projection for 2D rendering on top of the 3D scene.

Layout matches original Quake sbar.c (320x200 virtual resolution):

Bottom bar (sbar): [armor_icon][armor] [face] [health] [ammo_icon][ammo]
Above that (ibar): weapon slots and ammo counts

Constant Summary collapse

VIRTUAL_WIDTH =
320
VIRTUAL_HEIGHT =
200
SBAR_HEIGHT =

status bar height

24
DIGIT_WIDTH =

big number digit width

24
CHAR_SIZE =
8
WEAPON_ICONS =
[
  [:shotgun, "shotgun"],
  [:super_shotgun, "sshotgun"],
  [:nailgun, "nailgun"],
  [:super_nailgun, "snailgun"],
  [:grenade_launcher, "rlaunch"],
  [:rocket_launcher, "srlaunch"],
  [:lightning_gun, "lightng"]
].freeze
INVENTORY_ITEMS =
[
  [:key, :silver, "sb_key1"],
  [:key, :gold, "sb_key2"],
  [:powerup, :ring, "sb_invis"],
  [:powerup, :pentagram, "sb_invuln"],
  [:powerup, :biosuit, "sb_suit"],
  [:powerup, :quad, "sb_quad"]
].freeze
INVENTORY_AMMO_TYPES =
%i[shells nails rockets cells].freeze

Instance Method Summary collapse

Constructor Details

#initialize(wad, palette, screen_width, screen_height, pak: nil) ⇒ GLHud

Returns a new instance of GLHud.



38
39
40
41
42
43
44
45
46
47
# File 'lib/quake/renderer/gl_hud.rb', line 38

def initialize(wad, palette, screen_width, screen_height, pak: nil)
  @wad = wad
  @palette = palette
  @pak = pak
  @screen_width = screen_width
  @screen_height = screen_height
  @textures = {} # name -> { id:, width:, height: }

  upload_hud_graphics
end

Instance Method Details

#render(player_state, time: 0.0, stats: nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/quake/renderer/gl_hud.rb', line 49

def render(player_state, time: 0.0, stats: nil)
  setup_ortho

  GL.Enable(GL::TEXTURE_2D)
  GL.Enable(GL::BLEND)
  GL.BlendFunc(GL::SRC_ALPHA, GL::ONE_MINUS_SRC_ALPHA)
  GL.Disable(GL::DEPTH_TEST)
  GL.Color4f(1.0, 1.0, 1.0, 1.0)

  draw_hud(player_state, time: time, stats: stats)

  GL.Enable(GL::DEPTH_TEST)
  GL.Disable(GL::BLEND)

  restore_projection
end