【发布时间】:2020-08-17 16:31:13
【问题描述】:
【问题讨论】:
-
请在问题中包含您的代码,而不仅仅是图片。在许多设备上以及对于有无障碍问题的人来说,您的图片是不可读的。此外,如果有人想重现您的问题,他们将不得不重新输入您的代码。请让其他人轻松帮助您。
标签: opengl pygame textures pyopengl opengl-compat
【问题讨论】:
标签: opengl pygame textures pyopengl opengl-compat
您已设置正交投影:
glOrtho(0, self.windowWidth, self.windowHeight, 0, -1, 1)
如果你想让纹理填满整个窗口,那么你必须绘制一个正交投影对应的四边形,纹理坐标从(0, 0)到(1, 1):
glEnable(GL_TEXTURE_2D)
glBegin(GL_QUAD)
glTexCoord2f(0, 0)
glVertex2f(0, 0)
glTexCoord2f(1, 0)
glVertex2f(self.windowWidth, 0)
glTexCoord2f(1, 1)
glVertex2f(self.windowWidth, self.windowHeight)
glTexCoord2f(0, 1)
glVertex2f(0, self.windowHeight)
glEnd()
如果你想保持纹理的纵横比,那么你必须缩放四边形的大小。例如:
left = 0
top = 0
width = self.windowWidth
height = self.windowHeight
sx = self.windowWidth / textureWidth
sy = self.windowHeight / textureHeight
if sx > sy:
width *= sy / sx
left = (self.windowWidth - width) / 2
else:
height *= sx / sy
top = (self.windowHeight - height) / 2
glEnable(GL_TEXTURE_2D)
glBegin(GL_QUAD)
glTexCoord2f(0, 0)
glVertex2f(left, top)
glTexCoord2f(1, 0)
glVertex2f(left + width, top)
glTexCoord2f(1, 1)
glVertex2f(left + width, top + height)
glTexCoord2f(0, 1)
glVertex2f(left, top + height)
glEnd()
【讨论】: