加入 Node节点类 还未测试新框架

This commit is contained in:
2025-10-27 23:12:56 +08:00
parent 80d088316b
commit 0ae47e5d6a
52 changed files with 1642 additions and 458 deletions

View File

@@ -28,7 +28,7 @@ RenderManager::RenderManager(SDL_Window *window)
_windowHeight = height;
// 游戏的初始正交投影矩阵
_GameOrthoMatrix = glm::ortho(0.0f, (float)width / 1.2f, (float)height / 1.2f, 0.0f, -1.0f, 1.0f);
_GameOrthoMatrix = glm::ortho(0.0f, (float)width, (float)height, 0.0f, -1.0f, 1.0f);
// UI的初始正交投影矩阵
_UIOrthoMatrix = glm::ortho(0.0f, (float)width, (float)height, 0.0f, -1.0f, 1.0f);
@@ -36,6 +36,7 @@ RenderManager::RenderManager(SDL_Window *window)
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
// 启用混合模式
glEnable(GL_BLEND);
// 默认设置标准alpha混合
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -228,8 +229,8 @@ void RenderManager::Init2DTextureProgram()
glUniform1i(_currentRenderParams.UnimLocs[2], 0);
// 处理纹理裁剪
int texWidth = textureObj->getSize().width;
int texHeight = textureObj->getSize().height;
float texWidth = (float)textureObj->getSize().width;
float texHeight = (float)textureObj->getSize().height;
// 计算纹理坐标
float minu, minv, maxu, maxv;
@@ -336,6 +337,16 @@ void RenderManager::SetOrthoMatrixType(int type)
_OrthoMatrix = _UIOrthoMatrix;
}
glm::mat4 RenderManager::GetOrthoMatrix()
{
return _OrthoMatrix;
}
void RenderManager::SetOrthoMatrix(glm::mat4 matrix)
{
_OrthoMatrix = matrix;
}
GLuint RenderManager::CompileShader(GLenum type, std::string Path)
{
std::ifstream Source("shader/" + Path);

View File

@@ -78,6 +78,11 @@ public:
void DrawTexture(RefPtr<Texture> texture, const SDL_Rect *srcrect, const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip, void *userdata = nullptr);
// 设置正交投影矩阵类型
void SetOrthoMatrixType(int type);
// 获取渲染的正交投影矩阵
glm::mat4 GetOrthoMatrix();
// 设置渲染的正交投影矩阵
void SetOrthoMatrix(glm::mat4 matrix);
private:

View File

@@ -32,8 +32,9 @@ bool Texture::Init(std::string PngPath)
glBindTexture(GL_TEXTURE_2D, m_TextureID);
// 环绕方式
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// 对2D纹理设置环绕模式S=X轴T=Y轴
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// 缩小过滤:使用最近邻采样
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// 放大过滤:使用最近邻采样
@@ -100,8 +101,9 @@ bool Texture::Init(std::string ImgPath, int Index)
// 设置纹理参数保持与原有SDL纹理相同的采样模式
// 环绕方式:重复
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// 对2D纹理设置环绕模式S=X轴T=Y轴
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// 过滤方式最近邻与SDL_ScaleModeNearest对应
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -139,8 +141,9 @@ bool Texture::Init(SDL_Surface *rgbaSurface)
glBindTexture(GL_TEXTURE_2D, m_TextureID);
// 环绕方式
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// 对2D纹理设置环绕模式S=X轴T=Y轴
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// 缩小过滤:使用最近邻采样
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// 放大过滤:使用最近邻采样
@@ -192,8 +195,9 @@ bool Texture::Init(VecSize size)
m_FrameSize = size;
// 环绕方式
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// 对2D纹理设置环绕模式S=X轴T=Y轴
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// 缩小过滤:使用最近邻采样
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// 放大过滤:使用最近邻采样