Steamworks 文獻庫
替 SteamOS 和 Linux 開發

Linux 概覽

Linux 版的 Steam 現已推出,供所有 Steam 使用者選用。 隨著支援 Linux 的遊戲與日俱增,加上活躍的「Steam for Linux」社群群組,現在正是將遊戲移植至 Linux 平台的絕佳時機。

對習慣使用 Windows 或 macOS 作業系統的開發人員來說,製作 Linux 上的遊戲可能頗有難度, 因此我們準備了以下資訊,希望能助您成功把遊戲搬上 Linux 平台的 Steam。

準備開始

想製作 Linux 平台的遊戲,需符合以下條件:

  • 一台開發電腦,執行全面更新至最新版本的 Linux 作業系統。 雙作業系統電腦、專跑 Linux 的電腦,甚至是跑 Linux 的虛擬電腦都可以。 雖然 32 位元或 64 位元版的 Linux 皆可用來進行開發, 但我們最推薦的 Linux 版本為最新的 Ubuntu LTS,原因是 Ubuntu LTS 為 Valve 與 Linux 社群最積極測試的版本。 Ubuntu 可由此下載安裝
  • Linux 版的 Steam 用戶端
  • Build-essential 套件內含的基本 Linux 開發工具組(例:G++、GCC、Make Utility)。 請至 Ubuntu Software Center,或透過開放終端視窗的 apt-get 指令:「sudo apt-get install build-essential」下載此套件。
  • 最新版的 Steam Linux Runtime,其中包含將 Linux 遊戲放上 Steam 所需的工具與一整套函式庫。 Runtime 的使用方法請見儲存機制中的 README.md。

如果您有任何關於 Linux Steamworks 的疑問,或想回報關於 Runtime 的問題,請加入 Steamworks 開發群組、於 Linux 討論區中發文提出。

Linux 工具

從命令列介面至圖形開發者 IDE,現有的 Linux 開發工具琳瑯滿目。 我們根據 Valve Linux 團隊的經驗為您提供以下資訊。

For those with Windows development tool experience, the easiest route to Linux development is Visual Studio on Windows and WinGDB - a Visual C++ extension that allows debugging of remote Linux processes, using the Visual Studio debugging interface.

Valve 的 Linux 團隊使用以下工具進行 Linux 平台上的開發工作:
  • QtCreator – 偵錯工具兼 IDE,具備常見的 Visual Studio 按鍵配置
  • SlickEdit – 提供基本、可設定的 GUI,使用者可自行指定按鍵
  • gdb – 熱門的命令列偵錯工具
  • cgdb – GDB 包裝擴充,執行時,將以分割畫面顯示當下所在位置的原始碼
  • Eclipse – 另一款可針對 Linux 設定的 IDE, 支援 Windows、macOS、Linux 作業系統
  • vim – 基本的命令列文字編輯器

Valve Linux 團隊採用下列偵錯與追蹤工具:
  • QtCreator – 請見上文
  • Symbol Servers
  • PerfStudio – 功能齊全的單幀畫面偵錯工具,
    具備可記錄分析使用 AMD 顯示卡執行的遊戲的 API, 支援 Windows 作業系統
  • Telemetry – 功能齊全的分析工具,用於使用顯示卡的遊戲, 支援
    Linux、Windows、macOS 作業系統
  • gDEBugger - a debugger that debugs, profiles, and analyzes OpenGL code. Active development has shifted to
    CodeXL.
  • perf - a command-line tool with various performance features. Available on Linux.
  • NVIDIA Nsight - an extension for Visual Studio for debugging games running
    on Nvidia graphics cards.
  • lTTng - a Linux tracing tool
  • apitrace project - a set of tools for tracing and replaying OpenGL and OpenGL ES calls from your game
  • Zoom - a CPU profiler with a powerful and friendly user interface

Linux API

Vulkan 是高品質圖形渲染的絕佳選擇, 為 DirectX12 與 Metal 的開源同等選擇。

OpenGL 是歷史悠久的圖形渲染標準。 大多數的遊戲會直接呼叫 OpenGL,但也有遊戲使用轉換法將老舊的渲染碼轉為 OpenGL 呼叫函式, 像《絕地要塞 2》與《絕對武力:次世代》這兩款 Valve 的 Source 老遊戲就採用了這個方法。 如果您選擇 OpenGL,我們推薦您開發遊戲時,選用 OpenGL 3.0 的核心功能。

Simple DirectMedia Layer(SDL)2.0 版的功能繁多,包含低階音訊與視窗化。 透過 OpenGL 可達成 3D 渲染支援。 點此閱讀安裝說明, 詳情說明與說明文件請見 SDL Wiki。 Valve uses this in Steam and most of our games to handle windowing and it provides the backend which powers the Steam Input API.

The following libraries provide support for other aspects of game development:
  • FreeType – Linux 平台上的字型渲染(適用向量與點陣字型)
  • Fontconfig – 設定與自訂字型
  • Miles Sound System - a middleware sound engine for Linux development
  • Bink Video - a video codec designed for game developers
  • WebM - an open media file format; used for recording Team Fortress 2 video instead of QuickTime.

GitHub 儲存機制

The following repositories are public and used for projects related to Steam for Linux:
  • steam-for-linux – 包含 Linux 版的 Steam 用戶端所需內容與該用戶端的錯誤追蹤器
  • steam-runtime – 包含 Steam Linux Runtime 專案, 旨在為 Steam 上的 Linux 遊戲提供一個穩定的執行階段環境

    常見問答

    Q: My Linux game has multiple external library dependencies. How do I solve this problem?
    A: Steam Linux Runtime 已收錄許多熱門的函式庫供開發人員使用,SDL、OpenAL、FreeType、Fontconfig 都包含在內。 如果您有可免費散佈的其他外部函式庫,尚未包含在 Runtime 中,請至 Linux & SteamOS Steamworks 開發討論區提出。

    Q: Is there Steam DRM for Linux?
    A: 有的! 新 drmtoolp DRM 工具支援 Linux, 詳情請見 Steam DRM

    Q: How does driver performance compare between Ubuntu and Windows?
    A: 就穩定性、效能、功能而言,Nvidia 專用驅動程式與 Windows 不相上下。 AMD 與 Intel 也提供 Ubuntu 的專用驅動程式,但目前在性能與穩定性上,都比同等的 Windows 驅動程式差了一截。

    Linux 性能則會受顯示卡與驅動程式的類型,例如開源或專用, 而受到影響。 一般而言,專用驅動程式的性能優於開源驅動程式,功能也更多。 此外,專用與開源版本的更新頻率可能差異甚鉅。

    Q: The Steam 內嵌介面 won't work when launching from outside of Steam.
    A: 在 Linux 作業系統中,LD_PRELOAD 環境變數必須設為載入 gameoverlayrenderer.so。

    應顯示如下:
    export LD_PRELOAD=~/.local/share/Steam/ubuntu12_32/gameoverlayrenderer.so;~/.local/share/Steam/ubuntu12_64/gameoverlayrenderer.so

    Q: What runtime should I use for testing my Linux build?
    A: The recommended Linux distribution is the latest Ubuntu LTS release as it receives the most testing by Valve and the Linux community. Ubuntu can be installed from here.