PySDL2 version: 0.9.3
SDL2 version: 2.0.3
我试图用sdl_gfx(PY)SDL2:绘制纹理多边形
但其显示完全扭曲渲染这个形象在PySDL2多边形纹理,如在右下角可以看出在SDL窗口:
我有this python program在我测试的人l我在a FrameBuffer class中实现的sdlgfx绘图功能负责绘图和渲染。除了一个消除锯齿的多边形(中间的绿色六边形,但这是另一个问题的另一个问题)和纹理多边形之外,它们都工作得很好。
为了提供一个更基本的脚本,我按照这些步骤绘制纹理多边形:
# Initialize SDL2 and window
import sdl2
import sdl2.ext
import sdl2.sdlgfx
import ctypes
sdl2.ext.init()
window = sdl2.ext.Window(size=(800,600))
window.show()
# Create renderer and factories
renderer = sdl2.ext.Renderer(window)
renderer.clear(0)
renderer.present()
# Create sprite factory to create textures with later
texture_factory = sdl2.ext.SpriteFactory(renderer=renderer)
# Create sprite factory to create surfaces with later
surface_factory = sdl2.ext.SpriteFactory(sdl2.ext.SOFTWARE)
# Determine path to image to use as texture
RESOURCES = sdl2.ext.Resources(__file__, "LSD/resources")
image_path = RESOURCES.get_path("Memory.jpeg")
# set polygon coordinates
x = 100
row4 = 470
vx = [x, x+200, x+200, x]
vy = [row4-50, row4-50, row4+50, row4+50]
# Calculate the length of the vectors (which should be the same for x and y)
n = len(vx)
# Make sure all coordinates are integers
vx = map(int,vx)
vy = map(int,vy)
# Cast the list to the appropriate ctypes vectors reabable by
# the sdlgfx polygon functions
vx = ctypes.cast((sdl2.Sint16*n)(*vx), ctypes.POINTER(sdl2.Sint16))
vy = ctypes.cast((sdl2.Sint16*n)(*vy), ctypes.POINTER(sdl2.Sint16))
# Load the image on an SoftwareSprite
# The underlying surface is available at SoftwareSprite.surface
texture = surface_factory.from_image(image_path)
## RENDER THE POLYGON WITH TEXTURE
sdl2.sdlgfx.texturedPolygon(renderer.renderer, vx, vy, n,\
texture.surface, 0, 0)
# Swap buffers
renderer.present()
# Handle window close events
processor = sdl2.ext.TestEventProcessor()
processor.run(window)
sdl2.ext.quit()
这上面的示例脚本只输出:
我觉得这一切很艰巨与SDL2以及所有类型的转换一起工作,我非常高兴我获得了这么多,但我似乎无法自己解决这个问题。有人知道我在哪一步犯了错误,或者有谁能指出我的方向是正确的?作为一个旁注,我知道PySDL具有渲染图像的工厂函数,而且工作得很好,但我真的想要获得多边形的纹理选项。
感谢您的回复!遗憾的是,在实现这个事件循环之后,我仍然得到了与纹理相同的乱码显示。奇怪的是,图像的显示等工作,因为我也认为这是作为引擎盖下的纹理渲染完成的? –