gpt4 book ai didi

c++ - 使用 SDL2 渲染器绘制填充四边形/三角形的最快方法?

转载 作者:行者123 更新时间:2023-12-04 13:06:05 25 4
gpt4 key购买 nike

我有一个使用 SDL2 编写的游戏,以及用于绘图的 SDL2 渲染器(硬件加速)。是否有绘制填充四边形或三角形的技巧?
目前我只是通过绘制大量线条(SDL_Drawlines)来填充它们,但性能很差。
我不想进入 OpenGL。

最佳答案

SDL_RenderGeometry() / SDL_RenderGeometryRaw() 最近(2021 年 8 月)添加到 SDL main :

/**
* The structure that defines a point (floating point)
*
* \sa SDL_EnclosePoints
* \sa SDL_PointInRect
*/
typedef struct SDL_FPoint
{
float x;
float y;
} SDL_FPoint;

...

/**
* Vertex structure
*/
typedef struct SDL_Vertex
{
SDL_FPoint position; /**< Vertex position, in SDL_Renderer coordinates */
SDL_Color color; /**< Vertex color */
SDL_FPoint tex_coord; /**< Normalized texture coordinates, if needed */
} SDL_Vertex;

...

/**
* Render a list of triangles, optionally using a texture and indices into the
* vertex array Color and alpha modulation is done per vertex
* (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored).
*
* \param texture (optional) The SDL texture to use.
* \param vertices Vertices.
* \param num_vertices Number of vertices.
* \param indices (optional) An array of integer indices into the 'vertices'
* array, if NULL all vertices will be rendered in sequential
* order.
* \param num_indices Number of indices.
* \return 0 on success, or -1 if the operation is not supported
*
* \sa SDL_Vertex
*/
extern DECLSPEC int SDLCALL SDL_RenderGeometry(SDL_Renderer *renderer,
SDL_Texture *texture,
const SDL_Vertex *vertices, int num_vertices,
const int *indices, int num_indices);

/**
* Render a list of triangles, optionally using a texture and indices into the
* vertex arrays Color and alpha modulation is done per vertex
* (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored).
*
* \param texture (optional) The SDL texture to use.
* \param xy Vertex positions
* \param xy_stride Byte size to move from one element to the next element
* \param color Vertex colors (as SDL_Color)
* \param color_stride Byte size to move from one element to the next element
* \param uv Vertex normalized texture coordinates
* \param uv_stride Byte size to move from one element to the next element
* \param num_vertices Number of vertices.
* \param indices (optional) An array of indices into the 'vertices' arrays,
* if NULL all vertices will be rendered in sequential order.
* \param num_indices Number of indices.
* \param size_indices Index size: 1 (byte), 2 (short), 4 (int)
* \return 0 on success, or -1 if the operation is not supported
*/
extern DECLSPEC int SDLCALL SDL_RenderGeometryRaw(SDL_Renderer *renderer,
SDL_Texture *texture,
const float *xy, int xy_stride,
const int *color, int color_stride,
const float *uv, int uv_stride,
int num_vertices,
const void *indices, int num_indices, int size_indices);
请注意,由于 API 仅缺少 Z 坐标的数据 channel affine texturing是可以实现的。

关于c++ - 使用 SDL2 渲染器绘制填充四边形/三角形的最快方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69447778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com