如何以形状/多边形形式渲染图像?
嘿,我现在正在使用 SFML,在完成教程后,我仍然不知道如何为形状提供纹理或图像,而不仅仅是纯色/轮廓。
我知道唯一可以拍摄图像的是精灵,但这太简单了,因为它只允许您以矩形方式渲染矩形图像!
将图像渲染到形状上且仅在形状内部渲染图像的技术是什么?如果你们中的一些人可以提供一些资源或 SFML 特定的东西,那就太好了!
Hey i'm working with SFML right now, and upon finishing the tutorials i still do not know how to give a shape a texture or image, and not just a solid color/outline.
The only thing i know can take an image is a sprite, but thats WAY to simple, as it only allows you to render rectangular images in a rectangluar way!
What are the tecniques for rendering images onto shapes, and ONLY inside the shape? It would be great if some of you could provide some resources or SFML-specific stuff!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
自从这个问题最初被回答以来,SFML 已经更新,您现在可以轻松地向形状添加纹理。 shape 类具有
setTexture()
和setTextureRect()
方法。setTexture()
获取一个指向sf::Texture
的指针。请参阅文档。SFML has been updated since this question was originally answered and you can now add textures to shapes easily. The shape class has the
setTexture()
andsetTextureRect()
methods.setTexture()
takes a pointer to ansf::Texture
. See the documentation.2d:
据我所知,对于 SFML 1.6,不可能使用单独的图像作为蒙版。但是,您可以使用图像的 Alpha 通道从中绘制“形状”。默认支持;只需给你的图像一个 Alpha 通道即可。
这篇关于 SFML 表单的文章 验证了使用不支持单独的图像作为蒙版。
SFML 的作者 Laurent Gomila 发布了一些代码,允许您使用形状、精灵和字符串进行遮罩。可以在这里找到:使用精灵、形状或字符串进行遮罩。然而,要使其正常工作,您需要修改并重新编译 SFML 的某些部分。
3d:
关于使用图像作为纹理并将其映射到 3d 空间中的对象,我认为除了为您设置一个窗口之外,SFML 对此没有太多帮助。不过,Google 代码上有一个名为 sf3d 的项目,它也许可以帮助您找到正确的方向。
2d:
As far as I know, with SFML 1.6 it isn't possible to use a separate image as a mask. You can, however, use the alpha channel of an image to draw a "shape" from it. This is supported by default; just give your image an alpha channel.
This post on the SFML forms verifies that using a separate image as a mask is not supported.
The author of SFML, Laurent Gomila, has posted some code that will allow you to mask using shapes, sprites, and strings. That can be found here: Masking using Sprites, Shapes or Strings. To get this working, however, you need to modify and recompile some parts of SFML.
3d:
With regards to using an image as a texture and mapping it to an object in 3d space, I don't think SFML has too much to help you with this besides setting up a window for you. There is a project on Google Code called sf3d that could maybe get you in the right direction, though.