<s> '''<STR_LIT>''' <EOL> from pyglet . gl import * <EOL> class Projection ( object ) : <EOL> viewport = None <EOL> class OrthographicProjection ( Projection ) : <EOL> def __init__ ( self , viewport , near = - <NUM_LIT:1> , far = <NUM_LIT:1> ) : <EOL> self . viewport = viewport <EOL> self . near = near <EOL> self . far = far <EOL> def apply ( self ) : <EOL> self . viewport . apply ( ) <EOL> glMatrixMode ( GL_PROJECTION ) <EOL> glOrtho ( <NUM_LIT:0> , self . viewport . width , <EOL> <NUM_LIT:0> , self . viewport . height , <EOL> self . near , self . far ) <EOL> glMatrixMode ( GL_MODELVIEW ) <EOL> class PerspectiveProjection ( Projection ) : <EOL> def __init__ ( self , viewport , fov = <NUM_LIT> , near = <NUM_LIT:0.1> , far = <NUM_LIT:1000> ) : <EOL> self . viewport = viewport <EOL> self . fov = fov <EOL> self . near = near <EOL> self . far = far <EOL> def apply ( self ) : <EOL> self . viewport . apply ( ) <EOL> glMatrixMode ( GL_PROJECTION ) <EOL> gluPerspective ( self . fov , <EOL> self . viewport . width / float ( self . viewport . height ) , <EOL> self . near , <EOL> self . far ) <EOL> glMatrixMode ( GL_MODELVIEW ) <EOL> class Viewport ( object ) : <EOL> projection = None <EOL> width = <NUM_LIT:0> <EOL> height = <NUM_LIT:0> <EOL> class WindowViewport ( Viewport ) : <EOL> def __init__ ( self , window ) : <EOL> self . window = window <EOL> def apply ( self ) : <EOL> glMatrixMode ( GL_PROJECTION ) <EOL> glLoadIdentity ( ) <EOL> glMatrixMode ( GL_MODELVIEW ) <EOL> glLoadIdentity ( ) <EOL> glViewport ( <NUM_LIT:0> , <NUM_LIT:0> , self . window . width , self . window . height ) <EOL> glDisable ( GL_CLIP_PLANE0 ) <EOL> glDisable ( GL_CLIP_PLANE1 ) <EOL> glDisable ( GL_CLIP_PLANE2 ) <EOL> glDisable ( GL_CLIP_PLANE3 ) <EOL> width = property ( lambda self : self . window . width ) <EOL> height = property ( lambda self : self . window . height ) <EOL> class OrthographicViewport ( Viewport ) : <EOL> def __init__ ( self , projection , x , y , width , height , near = - <NUM_LIT:1> , far = <NUM_LIT:1> ) : <EOL> assert isinstance ( projection , OrthographicProjection ) <EOL> self . projection = projection <EOL> self . x = x <EOL> self . y = y <EOL> self . width = width <EOL> self . height = height <EOL> self . near = near <EOL> self . far = far <EOL> def apply ( self ) : <EOL> l = self . x <EOL> r = self . x + self . width <EOL> b = self . y <EOL> t = self . y + self . height <EOL> n = self . near <EOL> f = self . far <EOL> self . projection . apply ( ) <EOL> glMatrixMode ( GL_PROJECTION ) <EOL> glMultMatrixf ( ( GLfloat * <NUM_LIT:16> ) ( <EOL> ( r - l ) / <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <EOL> <NUM_LIT:0> , ( t - b ) / <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <NUM_LIT:0> , ( f - n ) / <NUM_LIT:2> , <NUM_LIT:0> , <EOL> ( r + l ) / <NUM_LIT:2> , ( t + b ) / <NUM_LIT:2> , ( f + n ) / <NUM_LIT:2> , <NUM_LIT:1> ) ) <EOL> glMatrixMode ( GL_MODELVIEW ) <EOL> glClipPlane ( GL_CLIP_PLANE0 , ( GLdouble * <NUM_LIT:4> ) ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> glClipPlane ( GL_CLIP_PLANE1 , ( GLdouble * <NUM_LIT:4> ) ( - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , self . width ) ) <EOL> glClipPlane ( GL_CLIP_PLANE2 , ( GLdouble * <NUM_LIT:4> ) ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> glClipPlane ( GL_CLIP_PLANE3 , ( GLdouble * <NUM_LIT:4> ) ( <NUM_LIT:0> , - <NUM_LIT:1> , <NUM_LIT:0> , self . height ) ) <EOL> glEnable ( GL_CLIP_PLANE0 ) <EOL> glEnable ( GL_CLIP_PLANE1 ) <EOL> glEnable ( GL_CLIP_PLANE2 ) <EOL> glEnable ( GL_CLIP_PLANE3 ) </s>
