16 const std::string &title,
19 const bool fullscreen,
bool enable_vsync)
21 const std::string base_path = path.empty() ? std::string(console_demo_ASSET_DIR) : path;
22 const std::string sprite_vert_path = base_path +
"/data/sprite.vert.spv";
23 const std::string shader_path = base_path +
"/data/background_pulse.frag.spv";
25 background =
createSprite(base_path +
"/data/background.png", sprite_vert_path, shader_path);
26 setFont(base_path +
"/data/font.ttf", 20);
27 console.attach(*
this, base_path +
"/data/font.ttf", 20);
28 console.setSpriteYOriginTopLeft(
true);
30 console.printLine(
"Press F3 to open/close the console.");
31 console.printLine(
"Type 'help' for built-in commands.");
33 console.setCommandCallback([
this](
mxvk::VK_Window &,
const std::vector<std::string> &args, std::ostream &out) {
38 if (args[0] ==
"echo") {
39 for (std::size_t i = 1; i < args.size(); ++i) {
48 if (args[0] ==
"quit" || args[0] ==
"exit") {
49 out <<
"Closing window...";
54 if (args[0] ==
"about") {
55 out <<
"console_demo: MXVK Vulkan console sample.\n(C) 2026 LostSideDead Software\n";
63 void event(SDL_Event &e)
override {
66 if (e.type == SDL_EVENT_KEY_DOWN && e.key.key == SDLK_ESCAPE && !
console.isVisible()) {
72 if (background !=
nullptr) {
74 const int target_w =
static_cast<int>(extent.width);
75 const int target_h =
static_cast<int>(extent.height);
76 if (target_w > 0 && target_h > 0) {
77 const float elapsed = std::chrono::duration<float>(std::chrono::steady_clock::now() - start).count();
78 background->setShaderParams(elapsed, 0.0f, 0.0f, 0.0f);
79 background->drawSpriteRect(0, 0, target_w, target_h);
84 printText(
"MXVK Console Demo", 14, 12, SDL_Color{255, 255, 255, 255});
85 printText(
"Press F3 to toggle console. Press ESC to quit when console is hidden.",
88 SDL_Color{180, 180, 220, 255});
94 std::chrono::steady_clock::time_point start{std::chrono::steady_clock::now()};
100int main(
int argc,
char **argv) {
110 std::cerr << std::format(
"mxvk: Exception: {}\n", e.
text());
113 std::cerr << std::format(
"mxvk: Argument Exception: {}\n", e.
text());
Lightweight, header-only, template command-line argument parser.
Arguments proc_args(int &argc, char **argv)
Parse standard libmx2 command-line options from main()'s argv.
Exception thrown by Argz::proc() on unrecognised or malformed options.
void event(SDL_Event &e) override
Handle one SDL event.
ConsoleDemoWindow(const std::string &path, const std::string &title, const int width, const int height, const bool fullscreen, bool enable_vsync)
void proc() override
Execute one processing/update step.
Lightweight command console renderer for mxvk::VK_Window.
Main Vulkan window wrapper for MXVK.
VkExtent2D getSwapchainExtent() const noexcept
Get the current swapchain extent.
void loop()
Run the main event/render loop.
VK_Sprite * createSprite(const std::string &pngPath, const std::string &vertexShaderPath="", const std::string &fragmentShaderPath="")
Create a sprite from a PNG file and register it with this window.
void exit()
Request loop termination.
VK_Window()=default
Construct an empty window object.
void setFont(const std::string &fontPath, int fontSize=24)
Set the active text-render font.
void printText(const std::string &text, int x, int y, const SDL_Color &col)
Queue a text string for rendering during the current frame.
In-game command console for MXVK / Vulkan windows.
Utilities for loading and saving PNG images.
Plain data structure returned by proc_args() with all common libmx2 CLI options.
bool fullscreen
Whether fullscreen mode was requested.
bool enable_vsync
Enable FIFO present mode / v-sync (--enable-vsync).
int height
Viewport height in pixels (default: 720).
std::string path
Asset root; proc_args() defaults it to the executable directory.
int width
Viewport width in pixels (default: 1280).