如何在 SDL 中绘制圆、弧和矢量图形? [英] HOWTO draw circles, arcs and vector graphics in SDL?

查看:121
本文介绍了如何在 SDL 中绘制圆、弧和矢量图形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(我使用的是 SDL2)

(I'm using SDL2)

SDL 是一个相对较小的库,用于通过OpenGL 和 Direct3D" 它用于游戏开发,就我而言,它用作简单的视听输出和鼠标+键盘输入.它不是像 GTK、Qt、wxWindows 等那样的工具包".但它是跨平台的.

SDL is a relatively small library for "low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D" It's used for game development and, in my case, as simple audio visual output and mouse+keyboard input. It's not a "toolkit" like GTK, Qt, wxWindows, etc. But it is cross-platform.

但我能找到的绘制形状的唯一方法是使用线、矩形和像素函数.

除了使用三角函数或圆方程"之外,我还能如何绘制曲线?一般的矢量图形怎么样?

Apart from using trig or the "equation of a circle", how could I draw a curve? How about general vector graphics?

SDL 是一个合适的起点还是我应该寻找其他地方?

Is SDL an appropriate starting point or should I look elsewhere?

推荐答案

如果你想编写自己的画圆功能,那么我建议改编 中点算法通过绘制像素到 SDL2.

If you want to write your own circle drawing function, then I'd suggest adapting the midpoint algorithm to SDL2 by drawing pixels.

曲线的绘制方式类似,但会使用更多的椭圆绘制算法.

Curves would be done similarly, but would use more of an ellipses drawing algorithm.

实际的矢量图形开始变得更加复杂,您可能需要找到可以渲染 SVG 文件的东西,我不确定 SDL2 是否有很多选项.

Actual vector graphics start to get much more complicated, and you'd probably have to find something that renders SVG files, which I'm not sure there are many options for SDL2.

但是,如果您只想拥有可以使用的功能,我建议您直接访问 SDL2_gfx 代替.它已经实现了更多功能供您使用.

However, if you would rather simply have functions that you can work with I'd suggest going straight to SDL2_gfx instead. It has many more functions already implemented for you to work with.

这篇关于如何在 SDL 中绘制圆、弧和矢量图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆