OpenComputers · Addon guide · Advanced

How to Create a Custom AR HUD with OpenGlasses2

Monitoring a massive modded base normally requires running back and forth between walls of OpenComputers screens or carrying a bulky Tablet. By combining OpenComputers with the OpenGlasses2 addon, you can program a completely customizable Augmented Reality (AR) Heads-Up Display that renders live base power levels, item storage metrics, and 3D world markers directly onto your player screen. This guide will walk you through networking the hardware, linking your glasses, and writing the retained-mode Lua script to drive your live HUD.

What you need

  • A running OpenComputers setup (Computer Case Tier 2 or 3, CPU, RAM, Graphics Card, Hard Disk Drive with OpenOS installed, Screen, and Keyboard)
  • OpenGlasses Terminal block (from the OpenGlasses2 addon)
  • OpenGlasses wearable item (equipped in the helmet slot or designated Baubles slot)
  • Adapter block(s) and OpenComputers Cables
  • Power Converter (along with a strong energy source from another mod to power the computer and terminal)
  • A modded energy storage block (e.g., Capacitor Bank, Energy Cell) or storage controller to monitor

Step by step

  1. 1Network the Terminal and Adapters

    Place your OpenGlasses Terminal adjacent to your Computer Case, or connect it using OpenComputers Cables. Next, place an Adapter block directly touching your base's main energy storage block (or storage network controller) and run cables from the Adapter back to your computer network. Because OpenGlasses2 draws significant energy based on the number of active widgets and wireless transmission, ensure your Power Converter is connected to the network and fed by a stable power line.

    Tip: Use the Analyzer tool by sneaking and right-clicking on your Adapter and Terminal to verify they share the same network and to inspect their component addresses.

  2. 2Link and Equip the OpenGlasses

    Hold the OpenGlasses item in your main hand and sneak-right-click directly onto the OpenGlasses Terminal block. You will receive a chat notification confirming the cryptographic link, and the item's tooltip will update with a unique UUID. Once bound, equip the glasses into your armor helmet slot or your Baubles head slot.

    Tip: If you are using OpenGlasses2, check the keybind controls menu for the 'OpenGlasses Overlay' key, which lets you interact with your HUD using your mouse cursor.

  3. 3Verify Component Proxies in Lua

    Boot up your computer into OpenOS. Run the interactive Lua prompt by typing `lua` and pressing Enter. Type `=component.glasses` to ensure the Terminal is recognized, and type `=component.list()` to find the exact component name of the energy block connected to your Adapter (commonly `energy_device`, `capacitor_bank`, or a mod-specific name). Type `os.exit()` to return to the shell once you have noted the exact component name.

    Tip: Always check JEI or the in-game OpenComputers manual if an external mod block does not show up; some multi-block structures require the Adapter to touch a specific 'Controller' or 'Port' block rather than a generic casing.

  4. 4Initialize the Canvas and Wipe Ghost Widgets

    Create a new script by typing `edit hud.lua`. At the very top of your script, require the component library, grab the proxies for the glasses and your energy storage, and immediately call `removeAll()`. Because the OpenGlasses Terminal stores widget data inside its own internal tile entity memory, failing to clear it on startup will result in duplicate overlapping shapes every time you restart your script. Write this initialization code: ```lua local component = require("component") local glasses = component.glasses local energy = component.energy_device -- Replace with your energy component name glasses.removeAll() ```

  5. 5Instantiate 2D Screen Widgets

    Unlike standard OpenComputers screens that redraw text every frame, OpenGlasses2 uses an object-oriented widget architecture. You must instantiate widgets *once* before your main loop and store their object references in local variables. Add a background box, a dynamic progress bar, and a text readout to the top-left of your screen by appending this code to your script: ```lua local bgBar = glasses.addRect() bgBar.setPosition(10, 10) bgBar.setSize(120, 16) bgBar.setColor(0.1, 0.1, 0.1) bgBar.setAlpha(0.7) local fillBar = glasses.addRect() fillBar.setPosition(12, 12) fillBar.setSize(0, 12) fillBar.setColor(0.2, 0.8, 0.2) local statusText = glasses.addText2D() statusText.setPosition(16, 14) statusText.setText("Initializing...") ```

    Tip: Note that OpenGlasses2 method names can vary slightly between early and late builds (e.g., `addRect` vs `addBox2D`, or modifier tables). If a method throws a nil error, run `=component.glasses` in the Lua prompt to view the exact method table for your version.

  6. 6Add a 3D World Marker Overlay

    One of the strongest features of OpenGlasses2 is rendering 3D elements anchored to world coordinates that stay in place as you walk around. In OpenGlasses2, 3D coordinates are always calculated *relative to the Terminal block*, where the Terminal itself is `(0, 0, 0)`. To place a floating translucent waypoint cube 2 blocks above your Terminal (or over a problematic machine nearby), append this code: ```lua local marker = glasses.addCube3D() marker.set3DPos(0, 2, 0) -- X, Y, Z offset from the Terminal block marker.setColor(0.0, 0.6, 1.0) marker.setAlpha(0.4) marker.setVisibleThroughObjects(true) ```

    Tip: Setting `setVisibleThroughObjects(true)` disables the OpenGL depth check for that specific widget, allowing you to see the marker through walls across your base.

  7. 7Write the Update Loop to Mutate Widget State

    Now, write a `while true` loop at the bottom of the script to poll your Adapter for live energy statistics and update your existing widgets. Never call `addRect` or `addText2D` inside this loop; only call setter methods on the variables you already created: ```lua while true do local cur = energy.getEnergyStored() local max = energy.getMaxEnergyStored() local ratio = 0 if max > 0 then ratio = cur / max end -- Scale the inner bar width up to 116 pixels max fillBar.setSize(math.floor(116 * ratio), 12) -- Change bar color to red if power drops below 25% if ratio < 0.25 then fillBar.setColor(0.9, 0.2, 0.2) else fillBar.setColor(0.2, 0.8, 0.2) end statusText.setText(string.format("Power: %.1f%%", ratio * 100)) os.sleep(1) end ``` Save your script with `Ctrl+S`, exit the editor with `Ctrl+W`, and run it by typing `hud.lua`.

    Tip: To keep the HUD running while you still use the computer terminal for other tasks, run the script as a background process by typing `hud.lua &`.

How it works

To program OpenGlasses2 effectively, you must understand the difference between Immediate Mode and Retained Mode rendering. A standard OpenComputers GPU and Screen operate in Immediate Mode: your script tells the GPU to fill characters on a grid, and those pixels stay dumbly frozen until overwritten. OpenGlasses2 operates in Retained Mode (similar to a web browser's DOM). When you call `glasses.addRect()`, the server creates a persistent widget object with a unique ID, stores it inside the Terminal block's NBT data, and sends a network packet to your Minecraft client.

Once your client receives that packet, your client's own rendering engine redraws that rectangle at 60+ frames per second without asking the OpenComputers server for further instructions. When your Lua script calls `fillBar.setSize()` inside the `while` loop, the computer is not redrawing the screen—it is merely sending a lightweight state-update packet telling your client to resize Widget #2. This architecture saves immense server CPU time and network bandwidth, which is why creating new widgets inside a loop instead of mutating existing ones will quickly crash or lag out your client.

Meanwhile, the Adapter block acts as a hardware bridge using OpenComputers' architecture driver system. When placed next to a supported third-party block (like an energy cell or Applied Energistics controller), the Adapter wraps that block's Java interfaces into Lua-accessible callbacks. By polling those callbacks every second and translating the raw numbers into normalized ratios (`0.0` to `1.0`), you can dynamically scale pixel widths and RGB color floats (`0.0` to `1.0`) on your AR canvas.

Common mistakes

  • Calling `addRect()` or `addText2D()` inside the `while true` loop: This spawns dozens of new persistent objects every second, quickly hitting the Terminal's widget limit, draining your base's power supply, and tanking your client FPS. Always instantiate widgets once before the loop and only use `.set...()` methods inside the loop.
  • Using absolute F3 world coordinates for 3D widgets: Players often put coordinates like `(1250, 64, -800)` into `set3DPos()` and wonder why their 3D marker disappears. OpenGlasses 3D space is strictly relative to the Terminal block. Calculate the offset by subtracting the Terminal's X, Y, Z coordinates from your target block's coordinates.
  • Forgetting to chunkload the Computer and Terminal: Because OpenComputers scripts persist across saves, your script won't break if you walk away, but the HUD will completely freeze if you explore far enough that the chunk containing your base's Terminal unloads.
  • Omitting `os.sleep()` in the update loop: Even though OpenGlasses updates are fast, a `while true` loop without a sleep yield will either trigger a 'too long without yielding' crash or flood the server-to-client network pipeline with hundreds of redundant widget packets per second.

FAQ

Why do my HUD widgets look huge or tiny when I resize my Minecraft window?

OpenGlasses 2D coordinates map to Minecraft's scaled GUI resolution. If you change your Minecraft 'GUI Scale' video setting or resize the game window, the relative pixel grid shifts. Position your widgets away from the far edges or query the player's screen resolution via glasses events if your addon version supports it.

Can multiple players wear glasses linked to the same Terminal?

Yes! Multiple pairs of OpenGlasses can be bound to a single Terminal block. By default, global widgets drawn on the root `component.glasses` proxy will display on every linked player's screen simultaneously, though advanced scripts can isolate canvases per user UUID.

How do I monitor Applied Energistics 2 or Refined Storage items on my HUD?

Connect an Adapter to an AE2 ME Controller (or ME Interface) or a Refined Storage block. In Lua, access the component proxy and call `.getItemsInNetwork()` or `.getCpus()` to retrieve tables of item counts and crafting statuses, then format those numbers into `statusText.setText()`.

How do I clear my screen if my script crashes midway through?

Open the interactive Lua prompt on your computer by typing `lua`, then run `require('component').glasses.removeAll()`. This will immediately purge the Terminal's internal widget memory and wipe your screen clean.

By treating the OpenGlasses2 Terminal as a retained-mode object canvas and feeding it live telemetry from Adapter blocks, you can build an ultra-low-latency AR HUD that keeps you connected to your base's vital stats anywhere in the world.

More OpenComputers guides

OpenComputers · Getting startedHow to Build Your First Computer and Install OpenOSIn this guide, you will learn how to assemble your very first modular Tier 1 computer in OpenComputers and install the standard OpenOS operating system onto its hard drive. Mastering this initial setup is essential because it provides the foundational terminal required to write Lua scripts, control redstone, and automate complex factory systems.Beginner8 steps
OpenComputers · ProgressionOpenComputers Hardware Tiers and Progression GuideOpenComputers relies on a strict modular tier system where every component, from memory sticks to graphics cards, must be carefully matched to your computer case. This guide will walk you through the progression from a basic Tier 1 machine up to a fully loaded Tier 3 Server Rack. Mastering these hardware limits ensures you never waste valuable resources on incompatible parts or crash your scripts due to insufficient memory.Beginner7 steps
OpenComputers · PowerOpenComputers Power Converter and Networking ExplainedIn OpenComputers, a single Cable carries power, component connections, and network messages all at the same time. While convenient, this all-in-one behavior causes massive chaos when you try to power two computers from the same energy source, as they will accidentally hijack each other's screens and keyboards. This guide explains how to convert modded energy using the Power Converter and how to isolate your systems using Power Distributors and Relays.Beginner7 steps
OpenComputers · AutomationHow to Automate Other Mods with the OpenComputers AdapterIn this guide, you will learn how to use the OpenComputers Adapter and Redstone I/O blocks to read data from external tech mod machines and automatically control them using Lua scripts. Mastering this setup allows you to build smart power grids that toggle generators based on energy storage levels, prevent reactor meltdowns, and coordinate complex factory lines without manual intervention.Intermediate8 steps
OpenComputers · Setup guideOpenComputers 3D Printer and Hologram Projector Setup GuideTransform your OpenComputers network from a simple text terminal into an interactive architectural and visual suite. In this guide, you will learn how to configure a 3D Printer to fabricate custom multi-state decorative blocks, and set up a Hologram Projector to render real-time 3D voxel displays. Mastering these peripherals allows you to create custom doors, buttons, and dynamic base status displays that standard blocks cannot achieve.Intermediate7 steps
OpenComputers · Setup guideHow to Build a Wireless Network and Server Rack InfrastructureIn this advanced guide, you will learn how to construct a centralized server infrastructure and a multi-node wireless network in OpenComputers. Mastering Server Racks, Access Points, and Linked Cards allows you to centralize your Lua processing power and automate remote areas of your base without running endless lines of physical Cable.Advanced7 steps