ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
Renderer类 参考final

渲染器,封装 SDL3 绘制 API 更多...

#include <Renderer.h>

Public 成员函数

 Renderer (const Renderer &)=delete
Rendereroperator= (const Renderer &)=delete
 Renderer (Renderer &&)=delete
Rendereroperator= (Renderer &&)=delete

静态 Public 成员函数

static RendererGetInstance ()
static bool Init ()
 初始化渲染器
static void Destroy ()
 析构渲染器(必须在 SDL_Quit 之前调用)
static void ClearScreen ()
 清屏(每帧开头调用)
static void Present ()
 交换缓冲区(每帧末尾调用)
static SDL_Renderer * GetRenderer ()
 获取原生 SDL_Renderer
static bool ReadPixels (void *pixels, int pitch)
 读取渲染缓冲像素(离屏渲染/编辑器预览用)
static bool BeginOffscreen ()
 开始离屏渲染到逻辑尺寸(1280×720)目标纹理(编辑器预览用) 之后 SceneManager::Update 的渲染进该纹理;ReadPixels 读出逻辑尺寸像素, 与相机坐标空间一致(不受窗口物理尺寸影响)。
static void EndOffscreen ()
static int GetLogicalWidth ()
 逻辑分辨率宽度
static int GetLogicalHeight ()
 逻辑分辨率高度
static void DrawSprite (const Sprite &sprite, const Vector2 &position, const std::optional< Vector2 > &size=std::nullopt)
 在屏幕坐标直接绘制精灵(UI 场景用)
static void SetDrawColor (const Color &color)
 设置绘制颜色(SDL_SetRenderDrawColor)
static void FillRect (const SDL_FRect &rect)
 实心矩形(SDL_RenderFillRect)
static void SetClipRect (const SDL_Rect *rect)
 设置裁剪矩形(传 nullptr 清除)
static void ClearClipRect ()
 清除裁剪矩形
static void SetViewport (const SDL_Rect *viewport)
 设置视口(传 nullptr 恢复全屏)
static void ClearViewport ()
 恢复全屏视口
static void DrawTexture (SDL_Texture *texture, const SDL_FRect *src, const SDL_FRect &dst)
 绘制纹理(SDL_RenderTexture)
static void DrawTextureRotated (SDL_Texture *texture, const SDL_FRect *src, const SDL_FRect &dst, double angle, const SDL_FPoint *center, SDL_FlipMode flip)
 旋转/翻转绘制(SDL_RenderTextureRotated)
static void RenderCoordinatesToWindow (float x, float y, float *winX, float *winY)
 逻辑坐标 → 窗口物理像素坐标
static SDL_Texture * CreateTextureFromSurface (SDL_Surface *surface)
 surface → texture(SDL_CreateTextureFromSurface)

友元

class EngineContext

详细描述

渲染器,封装 SDL3 绘制 API

管理逻辑分辨率、清屏、精灵绘制(UI 用)以及 Present。 默认逻辑分辨率 1280×720,通过 settings.json 中的 window.width/height 配置。

构造及析构函数说明

◆ Renderer() [1/2]

Renderer ( const Renderer & )
delete

◆ Renderer() [2/2]

Renderer ( Renderer && )
delete

成员函数说明

◆ BeginOffscreen()

bool BeginOffscreen ( )
inlinestatic

开始离屏渲染到逻辑尺寸(1280×720)目标纹理(编辑器预览用) 之后 SceneManager::Update 的渲染进该纹理;ReadPixels 读出逻辑尺寸像素, 与相机坐标空间一致(不受窗口物理尺寸影响)。

◆ ClearClipRect()

void ClearClipRect ( )
static

清除裁剪矩形

◆ ClearScreen()

void ClearScreen ( )
inlinestatic

清屏(每帧开头调用)

◆ ClearViewport()

void ClearViewport ( )
static

恢复全屏视口

◆ CreateTextureFromSurface()

SDL_Texture * CreateTextureFromSurface ( SDL_Surface * surface)
static

surface → texture(SDL_CreateTextureFromSurface)

◆ Destroy()

void Destroy ( )
inlinestatic

析构渲染器(必须在 SDL_Quit 之前调用)

◆ DrawSprite()

void DrawSprite ( const Sprite & sprite,
const Vector2 & position,
const std::optional< Vector2 > & size = std::nullopt )
static

在屏幕坐标直接绘制精灵(UI 场景用)

参数
sprite精灵数据
position屏幕坐标左上角
size可选目标尺寸,留空用纹理原始尺寸

◆ DrawTexture()

void DrawTexture ( SDL_Texture * texture,
const SDL_FRect * src,
const SDL_FRect & dst )
static

绘制纹理(SDL_RenderTexture)

◆ DrawTextureRotated()

void DrawTextureRotated ( SDL_Texture * texture,
const SDL_FRect * src,
const SDL_FRect & dst,
double angle,
const SDL_FPoint * center,
SDL_FlipMode flip )
static

旋转/翻转绘制(SDL_RenderTextureRotated)

◆ EndOffscreen()

void EndOffscreen ( )
inlinestatic

◆ FillRect()

void FillRect ( const SDL_FRect & rect)
static

实心矩形(SDL_RenderFillRect)

◆ GetInstance()

Renderer & GetInstance ( )
static

◆ GetLogicalHeight()

int GetLogicalHeight ( )
inlinestatic

逻辑分辨率高度

◆ GetLogicalWidth()

int GetLogicalWidth ( )
inlinestatic

逻辑分辨率宽度

◆ GetRenderer()

SDL_Renderer * GetRenderer ( )
inlinestatic

获取原生 SDL_Renderer

◆ Init()

bool Init ( )
inlinestatic

初始化渲染器

◆ operator=() [1/2]

Renderer & operator= ( const Renderer & )
delete

◆ operator=() [2/2]

Renderer & operator= ( Renderer && )
delete

◆ Present()

void Present ( )
inlinestatic

交换缓冲区(每帧末尾调用)

◆ ReadPixels()

bool ReadPixels ( void * pixels,
int pitch )
inlinestatic

读取渲染缓冲像素(离屏渲染/编辑器预览用)

参数
pixels输出缓冲区,至少 width*height*4 字节(ARGB8888)
pitch每行字节数(通常 width*4)
返回
成功返回 true

◆ RenderCoordinatesToWindow()

void RenderCoordinatesToWindow ( float x,
float y,
float * winX,
float * winY )
static

逻辑坐标 → 窗口物理像素坐标

◆ SetClipRect()

void SetClipRect ( const SDL_Rect * rect)
static

设置裁剪矩形(传 nullptr 清除)

◆ SetDrawColor()

void SetDrawColor ( const Color & color)
static

设置绘制颜色(SDL_SetRenderDrawColor)

◆ SetViewport()

void SetViewport ( const SDL_Rect * viewport)
static

设置视口(传 nullptr 恢复全屏)

◆ EngineContext

friend class EngineContext
friend

该类的文档由以下文件生成: