11 std::string current_path =
".";
12 mxvk::VK_Sprite *sprite =
nullptr;
13 int fallback_width = 1280;
14 int fallback_height = 720;
17 ExampleWindow(
const std::string path,
const std::string &text,
int width,
int height,
bool fullscreen,
bool enable_vsync) :
mxvk::
VK_Window(text, width, height, fullscreen,
MXVK_VALIDATION, enable_vsync) {
18 current_path = path.empty() ? std::string(sprite_example_ASSET_DIR) : path;
19 if (current_path ==
".") {
20 current_path = sprite_example_ASSET_DIR;
22 setFont(current_path +
"/data/font.ttf", 24);
23 fallback_width = width;
24 fallback_height = height;
25 const std::string image_path = current_path +
"/data/intro.png";
26 const std::string vertex_shader = current_path +
"/data/sprite.vert.spv";
27 const std::string fragment_shader = current_path +
"/data/fragment.frag.spv";
28 sprite =
createSprite(image_path, vertex_shader, fragment_shader);
31 void event(SDL_Event &e)
override {
32 if (e.type == SDL_EVENT_KEY_DOWN && e.key.key == SDLK_ESCAPE) {
38 if (sprite ==
nullptr) {
41 int target_w = fallback_width;
42 int target_h = fallback_height;
47 sprite->drawSpriteRect(0, 0, target_w, target_h);
48 printText(
"Hello, World!", 15, 15, {255, 255, 255, 255});
53int main(
int argc,
char **argv) {
59 std::cerr << std::format(
"mxvk: Exception: {}\n", e.
text());
62 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.
void proc() override
Execute one processing/update step.
ExampleWindow(const std::string path, const std::string &text, int width, int height, bool fullscreen, bool enable_vsync)
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.
VkExtent2D swapchain_extent
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.
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).