将游戏层和UI层分开渲染 并提高了缩放质量

This commit is contained in:
2025-10-26 14:38:14 +08:00
parent 585724b512
commit dc0213dc16
5 changed files with 56 additions and 24 deletions

View File

@@ -26,8 +26,11 @@ RenderManager::RenderManager(SDL_Window *window)
// 设置窗口尺寸
_windowWidth = width;
_windowHeight = height;
// 设置正交投影矩阵
_orthoMatrix = glm::ortho(0.0f, (float)width, (float)height, 0.0f, -1.0f, 1.0f);
// 游戏的初始正交投影矩阵
_GameOrthoMatrix = glm::ortho(0.0f, (float)width / 1.2f, (float)height / 1.2f, 0.0f, -1.0f, 1.0f);
// UI的初始正交投影矩阵
_UIOrthoMatrix = glm::ortho(0.0f, (float)width, (float)height, 0.0f, -1.0f, 1.0f);
// 设置清屏颜色
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
@@ -217,7 +220,7 @@ void RenderManager::Init2DTextureProgram()
// 设置着色器 uniforms
glUniformMatrix4fv(_currentRenderParams.UnimLocs[0], 1, GL_FALSE, glm::value_ptr(model));
glUniformMatrix4fv(_currentRenderParams.UnimLocs[1], 1, GL_FALSE, glm::value_ptr(_orthoMatrix));
glUniformMatrix4fv(_currentRenderParams.UnimLocs[1], 1, GL_FALSE, glm::value_ptr(_OrthoMatrix));
// 绑定纹理并设置采样器
glActiveTexture(GL_TEXTURE0);
@@ -297,6 +300,7 @@ void RenderManager::SetCurrentBufferObject(std::string name)
void RenderManager::ClearScreen()
{
glClear(GL_COLOR_BUFFER_BIT);
_frameRenderCount = 0;
}
void RenderManager::SwapBuffer()
@@ -317,12 +321,21 @@ void RenderManager::CloseClipRect()
void RenderManager::DrawTexture(RefPtr<Texture> textureObj, const SDL_Rect *srcrect, const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip, void *userdata)
{
_frameRenderCount++;
if (_currentRenderParams.DrawFunc != nullptr)
_currentRenderParams.DrawFunc(textureObj, srcrect, dstrect, angle, center, flip, userdata);
else
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "找不到渲染逻辑函数\n");
}
void RenderManager::SetOrthoMatrixType(int type)
{
if (type == 0)
_OrthoMatrix = _GameOrthoMatrix;
else
_OrthoMatrix = _UIOrthoMatrix;
}
GLuint RenderManager::CompileShader(GLenum type, std::string Path)
{
std::ifstream Source("shader/" + Path);