将游戏层和UI层分开渲染 并提高了缩放质量
This commit is contained in:
@@ -26,6 +26,10 @@ void Game::Init(std::function<void()> CallBack)
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); // 双缓冲
|
||||
|
||||
// 启用多重采样(关键步骤)
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); // 启用多重采样缓冲
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 8); // 4x 采样(可改为 8 等)
|
||||
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "SDL could not initialize! Error: %s\n", SDL_GetError());
|
||||
@@ -39,6 +43,7 @@ void Game::Init(std::function<void()> CallBack)
|
||||
}
|
||||
// 关闭原生鼠标
|
||||
SDL_ShowCursor(0);
|
||||
|
||||
// 打开所有检测到的控制器
|
||||
int numControllers = SDL_NumJoysticks();
|
||||
for (int i = 0; i < numControllers; i++)
|
||||
@@ -112,6 +117,7 @@ void Game::Run()
|
||||
// 延迟后,重新计算从帧开始到现在的总时间(包含可能的延迟误差)
|
||||
Uint64 actualFrameTime = SDL_GetTicks64() - frameStart;
|
||||
m_deltaTime = actualFrameTime / 1000.0f; // 用实际总时间更新deltaTime
|
||||
m_frameTime_ms = actualFrameTime;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,9 +166,6 @@ void Game::Update(float deltaTime)
|
||||
|
||||
void Game::Render()
|
||||
{
|
||||
// 绘制调用次数清0
|
||||
m_RenderCount = 0;
|
||||
|
||||
// 调用预渲染
|
||||
if (m_scene != nullptr)
|
||||
m_scene->PreRender();
|
||||
@@ -172,9 +175,15 @@ void Game::Render()
|
||||
// 清空渲染器后渲染
|
||||
m_renderer->ClearScreen();
|
||||
if (m_scene != nullptr)
|
||||
{
|
||||
m_renderer->SetOrthoMatrixType(0);
|
||||
m_scene->Render();
|
||||
}
|
||||
if (m_uiScene != nullptr)
|
||||
{
|
||||
m_renderer->SetOrthoMatrixType(1);
|
||||
m_uiScene->Render();
|
||||
}
|
||||
m_renderer->SwapBuffer();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user