2026-02-15 09:22:57 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @file main.cpp
|
|
|
|
|
|
* @brief Extra2D 基础示例程序
|
2026-02-15 12:36:36 +08:00
|
|
|
|
*
|
2026-02-15 09:22:57 +08:00
|
|
|
|
* 演示如何使用 Extra2D 引擎创建一个简单的窗口应用程序。
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <extra2d/extra2d.h>
|
2026-02-15 12:36:36 +08:00
|
|
|
|
#include <extra2d/graphics/render_config.h>
|
|
|
|
|
|
#include <extra2d/platform/window_config.h>
|
2026-02-15 09:22:57 +08:00
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
|
|
using namespace extra2d;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 主函数
|
2026-02-15 12:36:36 +08:00
|
|
|
|
*
|
2026-02-15 09:22:57 +08:00
|
|
|
|
* 初始化应用程序,创建场景,运行主循环。
|
|
|
|
|
|
*/
|
2026-02-15 12:36:36 +08:00
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
|
|
(void)argc;
|
|
|
|
|
|
(void)argv;
|
|
|
|
|
|
|
|
|
|
|
|
std::cout << "Extra2D Demo - Starting..." << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
AppConfig config = AppConfig::createDefault();
|
|
|
|
|
|
config.appName = "Extra2D Demo";
|
|
|
|
|
|
config.appVersion = "1.0.0";
|
|
|
|
|
|
|
|
|
|
|
|
Application &app = Application::get();
|
|
|
|
|
|
|
|
|
|
|
|
if (!app.init(config)) {
|
|
|
|
|
|
std::cerr << "Failed to initialize application!" << std::endl;
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::cout << "Application initialized successfully!" << std::endl;
|
|
|
|
|
|
std::cout << "Window: " << app.window().width() << "x"
|
|
|
|
|
|
<< app.window().height() << std::endl;
|
|
|
|
|
|
std::cout << "Running main loop. Press ESC or close window to exit."
|
|
|
|
|
|
<< std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
auto scene = Scene::create();
|
|
|
|
|
|
scene->setBackgroundColor(Colors::SkyBlue);
|
|
|
|
|
|
scene->setViewportSize(static_cast<float>(app.window().width()),
|
|
|
|
|
|
static_cast<float>(app.window().height()));
|
|
|
|
|
|
app.enterScene(scene);
|
|
|
|
|
|
|
|
|
|
|
|
app.run();
|
|
|
|
|
|
|
|
|
|
|
|
std::cout << "Shutting down..." << std::endl;
|
|
|
|
|
|
app.shutdown();
|
|
|
|
|
|
|
|
|
|
|
|
std::cout << "Goodbye!" << std::endl;
|
|
|
|
|
|
return 0;
|
2026-02-15 09:22:57 +08:00
|
|
|
|
}
|