- 在Batch中添加纹理采样器uniform设置 - 重构Sprite渲染逻辑,使用Renderer的drawSprite方法 - 添加Camera类并集成到Application和Renderer中 - 支持Y轴翻转的投影矩阵以适应2D游戏坐标系 - 改进颜色处理,移除不必要的归一化计算 - 添加渲染错误处理和日志输出
55 lines
1.4 KiB
C++
55 lines
1.4 KiB
C++
#include "SDL_log.h"
|
|
#include <SDL2/SDL.h>
|
|
#include <frostbite2D/core/application.h>
|
|
#include <frostbite2D/core/window.h>
|
|
#include <frostbite2D/graphics/renderer.h>
|
|
#include <frostbite2D/graphics/texture.h>
|
|
#include <glad/glad.h>
|
|
|
|
#include <frostbite2D/scene/scene.h>
|
|
#include <frostbite2D/scene/scene_manager.h>
|
|
#include <frostbite2D/2d/sprite.h>
|
|
|
|
using namespace frostbite2D;
|
|
|
|
int main(int argc, char **argv) {
|
|
AppConfig config = AppConfig::createDefault();
|
|
config.appName = "Frostbite2D Test App";
|
|
config.appVersion = "1.0.0";
|
|
config.windowConfig.width = 800;
|
|
config.windowConfig.height = 600;
|
|
config.windowConfig.title = "Frostbite2D - Renderer Test";
|
|
|
|
Application& app = Application::get();
|
|
|
|
if (!app.init(config)) {
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to initialize application!");
|
|
return -1;
|
|
}
|
|
|
|
SDL_Log("Starting main loop...");
|
|
|
|
auto menuScene = MakePtr<Scene>();
|
|
SceneManager::get().PushScene(menuScene);
|
|
|
|
// 先测试彩色四边形,排除纹理问题
|
|
SDL_Log("Testing colored quad...");
|
|
|
|
// 尝试加载精灵
|
|
auto sprite = Sprite::createFromFile("assets\\player.png");
|
|
if (sprite) {
|
|
sprite->SetPosition(100, 100);
|
|
menuScene->AddActor(sprite);
|
|
SDL_Log("Sprite created and added to scene");
|
|
} else {
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to create sprite from file!");
|
|
}
|
|
|
|
app.run();
|
|
|
|
app.shutdown();
|
|
|
|
SDL_Log("Application exited normally");
|
|
return 0;
|
|
}
|