Search code examples
pythonopenglpygameviewportpyopengl

How to make a resizeble window in pygame with Opengl


I want to make resizeble window in pygame using Pyopengl, and trying to use this code

pygame.display.set_mode(display, DOUBLEBUF|OPENGL, RESIZABLE)

or this

pygame.display.set_mode(display, DOUBLEBUF|OPENGL, pygame.RESIZABLE)

Resizable does not appear. This code is working now:

def main():
pygame.init()
display = (800,600)
pygame.display.set_mode(display, DOUBLEBUF|OPENGL, RESIZABLE)
gluPerspective(45, (display[0]/display[1]), 0.1, 500.0) # настройка камеры угол обзора дальняя и ближняя дистанция рендера
clock = pygame.time.Clock()
FPS = 60
angle=0
distance=20
while True:
     ...
pygame.display.flip()
clock.tick(FPS)

Solution

  • You must adjust the size of the viewport to the size of the window and the current framebuffer, by glViewport:

    glViewport(0, 0, display[0], display[1])