refactor: 移除测试代码并简化应用配置

移除application.cpp中的测试绘制代码
简化main.cpp中的初始化逻辑,移除相机相关代码
调整窗口大小和渲染器视口配置
This commit is contained in:
Lenheart 2026-02-26 13:19:43 +08:00
parent 6f8d1f1255
commit f8c2c26cdc
2 changed files with 8 additions and 54 deletions

View File

@ -250,28 +250,6 @@ void Application::render() {
}
}
// 简单的测试代码 - 绘制彩色方块
if (renderer_) {
static float angle = 0.0f;
angle += 0.02f;
renderer_->beginFrame();
// 绘制橙色方块
renderer_->drawQuad(Vec2(0, 0), Size(200, 150), 1.0f, 0.5f, 0.2f);
// 绘制蓝色移动方块
float x = 1920.0 / 2 + cosf(angle) * 100.0f;
float y = 1080.0 / 2 + sinf(angle) * 100.0f;
renderer_->drawQuad(Vec2(x, y), Size(100, 100), 0.3f, 0.5f, 1.0f);
renderer_->drawQuad(Vec2(1920 - 100, 1080 - 150), Size(100, 150), 1.0f,
0.5f, 0.2f);
renderer_->endFrame();
renderer_->flush();
}
if (window_) {
window_->swap();
}

View File

@ -2,7 +2,6 @@
#include <SDL2/SDL.h>
#include <frostbite2D/core/application.h>
#include <frostbite2D/core/window.h>
#include <frostbite2D/graphics/camera.h>
#include <frostbite2D/graphics/renderer.h>
#include <frostbite2D/graphics/texture.h>
#include <frostbite2D/utils/asset.h>
@ -14,48 +13,25 @@ int main(int argc, char **argv) {
AppConfig config = AppConfig::createDefault();
config.appName = "Frostbite2D Test App";
config.appVersion = "1.0.0";
config.windowConfig.width = 1920;
config.windowConfig.height = 1080;
config.windowConfig.width = 800;
config.windowConfig.height = 600;
config.windowConfig.title = "Frostbite2D - Renderer Test";
Application &app = Application::get();
Application& app = Application::get();
if (!app.init(config)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to initialize application!");
return -1;
}
auto &renderer = Renderer::get();
renderer.setClearColor(0.1f, 0.1f, 0.15f);
auto& renderer = Renderer::get();
renderer.setClearColor(0.2f, 0.3f, 1.0f);
renderer.setViewport(0, 0, 800, 600);
// 获取屏幕实际大小
auto *window = app.getWindow();
int screenWidth = window ? window->width() : config.windowConfig.width;
int screenHeight = window ? window->height() : config.windowConfig.height;
// 设置 Renderer 的视口到屏幕大小
renderer.setViewport(0, 0, screenWidth, screenHeight);
// 相机使用游戏逻辑分辨率 (1280x720)
static Camera camera;
camera.setViewport(config.windowConfig.width, config.windowConfig.height);
renderer.setCamera(&camera);
auto &asset = Asset::get();
#ifdef __SWITCH__
asset.setWorkingDirectory("/switch/testgame");
#else
asset.setWorkingDirectory(".");
#endif
// 初始化着色器管理器
auto &shaderManager = renderer.getShaderManager();
shaderManager.init("shaders");
auto& asset = Asset::get();
asset.setWorkingDirectory("assets");
SDL_Log("Application initialized successfully");
SDL_Log("Screen size: %dx%d", screenWidth, screenHeight);
SDL_Log("Render size: %dx%d", config.windowConfig.width,
config.windowConfig.height);
SDL_Log("Starting main loop...");
app.run();