Python 在PyGame和PyOpengl中导入裁剪的图像
如何在PyGame中裁剪图像并将其保存为2个OpenGL纹理 这是我加载完整图像的代码:Python 在PyGame和PyOpengl中导入裁剪的图像,python,image,pygame,crop,pyopengl,Python,Image,Pygame,Crop,Pyopengl,如何在PyGame中裁剪图像并将其保存为2个OpenGL纹理 这是我加载完整图像的代码: def loadImage(image): img = pygame.image.load(image)) textureData = pygame.image.tostring(img, "RGBA", 1) texture = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, texture) glTexImage2D(
def loadImage(image):
img = pygame.image.load(image))
textureData = pygame.image.tostring(img, "RGBA", 1)
texture = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, texture)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.get_width(), img.get_height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData)
return texture
是否可以使用图像的裁剪部分创建
textureData
,或者可以使用OpenGL函数完成此操作?我发现您可以将img.get_height()
替换为img.get_height()/2
,如果您愿意的话,但您无法选择一个不从(0,0)开始的矩形通过更改第4和第5个参数 您可以将图像的一部分blit()
放在新的、更小的表面上。或者尝试使用pygame.Surface.subground()
-谢谢,我使用了pygame.Surface.subground(),效果很好