我制作了自己的体素引擎,当我在 trinagle 上设置纹理时,它看起来很奇怪并且不正确 这是我的三角形渲染代码:
vertices[0].position.x = draw_face.point0.x;
vertices[0].position.y = draw_face.point0.y;
vertices[0].tex_coord = {float(draw_face.t_ind0.x), float(draw_face.t_ind0.y)};
vertices[0].color = {
(unsigned char)(255 - (int)(draw_face.point_shadow0)),
(unsigned char)(255 - (int)(draw_face.point_shadow0)),
(unsigned char)(255 - (int)(draw_face.point_shadow0)),
255
};
vertices[1].position.x = draw_face.point1.x;
vertices[1].position.y = draw_face.point1.y;
vertices[1].tex_coord = {float(draw_face.t_ind1.x), float(draw_face.t_ind1.y)};
vertices[1].color = {
(unsigned char)(255 - (int)(draw_face.point_shadow1)),
(unsigned char)(255 - (int)(draw_face.point_shadow1)),
(unsigned char)(255 - (int)(draw_face.point_shadow1)),
255
};
vertices[2].position.x = draw_face.point2.x;
vertices[2].position.y = draw_face.point2.y;
vertices[2].tex_coord = {float(draw_face.t_ind2.x), float(draw_face.t_ind2.y)};
vertices[2].color = {
(unsigned char)(255 - (int)(draw_face.point_shadow2)),
(unsigned char)(255 - (int)(draw_face.point_shadow2)),
(unsigned char)(255 - (int)(draw_face.point_shadow2)),
255
};
SDL_RenderGeometry(renderer, texture, vertices, 3, NULL, 4);
当相机角度为0时在此输入图像描述
这是我在旋转相机时遇到的问题在此处输入图像描述
SDL 线性插值纹理坐标,而您要求透视正确插值。
我认为
SDL_RenderGeometry()
不支持这一点。 (除非您愿意将每个纹理元素绘制为单独的四边形?)
现在可能是学习 SDL3 中提供的新渲染 API 的好时机,这应该没有问题。