<s> import textwrap <EOL> import numpy <EOL> from OpenGL import GL <EOL> from pygly . shader import Shader , VertexShader , FragmentShader , ShaderProgram <EOL> from pygly . vertex_buffer import VertexBuffer , BufferAttributes , GenericAttribute , VertexAttribute , TextureCoordAttribute <EOL> from pygly . vertex_array import VertexArray <EOL> from pyrr import geometry <EOL> vertices , indices = geometry . create_quad ( scale = ( <NUM_LIT> , <NUM_LIT> ) , st = True , dtype = '<STR_LIT>' ) <EOL> vertices = vertices [ indices ] <EOL> vertices . dtype = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' , ( <NUM_LIT:3> , ) ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , ( <NUM_LIT:2> , ) ) , <EOL> ] <EOL> def create ( core_profile = True ) : <EOL> if core_profile : <EOL> return CoreQuad ( ) <EOL> else : <EOL> return LegacyQuad ( ) <EOL> class CoreQuad ( object ) : <EOL> vertex_shader = textwrap . dedent ( """<STR_LIT>""" ) <EOL> fragment_shader = textwrap . dedent ( """<STR_LIT>""" ) <EOL> def __init__ ( self ) : <EOL> super ( CoreQuad , self ) . __init__ ( ) <EOL> global vertices <EOL> self . shader = ShaderProgram ( <EOL> VertexShader ( self . vertex_shader ) , <EOL> FragmentShader ( self . fragment_shader ) <EOL> ) <EOL> self . buffer = VertexBuffer ( <EOL> GL . GL_ARRAY_BUFFER , <EOL> GL . GL_STATIC_DRAW , <EOL> data = vertices , <EOL> ) <EOL> self . buffer_attributes = BufferAttributes ( ) <EOL> self . buffer_attributes [ '<STR_LIT>' ] = GenericAttribute . from_dtype ( <EOL> self . buffer , <EOL> vertices . dtype , <EOL> '<STR_LIT>' , <EOL> location = self . shader . attributes [ '<STR_LIT>' ] <EOL> ) <EOL> self . buffer_attributes [ '<STR_LIT>' ] = GenericAttribute . from_dtype ( <EOL> self . buffer , <EOL> vertices . dtype , <EOL> '<STR_LIT>' , <EOL> location = self . shader . attributes [ '<STR_LIT>' ] <EOL> ) <EOL> self . vao = VertexArray ( ) <EOL> self . vao . bind ( ) <EOL> self . buffer . bind ( ) <EOL> self . buffer_attributes . set ( ) <EOL> self . buffer . unbind ( ) <EOL> self . vao . unbind ( ) <EOL> def draw ( self , projection , model_view ) : <EOL> global vertices <EOL> self . shader . bind ( ) <EOL> self . shader . uniforms [ '<STR_LIT>' ] . value = projection <EOL> self . shader . uniforms [ '<STR_LIT>' ] . value = model_view <EOL> self . shader . uniforms [ '<STR_LIT>' ] . value = <NUM_LIT:0> <EOL> self . vao . bind ( ) <EOL> GL . glDrawArrays ( GL . GL_TRIANGLES , <NUM_LIT:0> , len ( vertices ) ) <EOL> self . vao . unbind ( ) <EOL> self . shader . unbind ( ) <EOL> class LegacyQuad ( object ) : <EOL> vertex_shader = textwrap . dedent ( """<STR_LIT>""" ) <EOL> fragment_shader = textwrap . dedent ( """<STR_LIT>""" ) <EOL> def __init__ ( self ) : <EOL> super ( LegacyQuad , self ) . __init__ ( ) <EOL> global vertices <EOL> self . use_shaders = True <EOL> GL . glEnable ( GL . GL_TEXTURE_2D ) <EOL> self . shader = ShaderProgram ( <EOL> VertexShader ( self . vertex_shader ) , <EOL> FragmentShader ( self . fragment_shader ) <EOL> ) <EOL> self . buffer = VertexBuffer ( <EOL> GL . GL_ARRAY_BUFFER , <EOL> GL . GL_STATIC_DRAW , <EOL> data = vertices , <EOL> ) <EOL> self . buffer_attributes = BufferAttributes ( ) <EOL> self . buffer_attributes [ '<STR_LIT>' ] = VertexAttribute . from_dtype ( <EOL> self . buffer , <EOL> vertices . dtype , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . buffer_attributes [ '<STR_LIT>' ] = TextureCoordAttribute . from_dtype ( <EOL> self . buffer , <EOL> vertices . dtype , <EOL> '<STR_LIT>' <EOL> ) <EOL> def draw ( self ) : <EOL> global vertices <EOL> if self . use_shaders : <EOL> self . shader . bind ( ) <EOL> self . shader . uniforms [ '<STR_LIT>' ] . value = <NUM_LIT:0> <EOL> self . buffer_attributes . push_attributes ( ) <EOL> self . buffer . bind ( ) <EOL> self . buffer_attributes . set ( ) <EOL> self . buffer . unbind ( ) <EOL> GL . glDrawArrays ( GL . GL_TRIANGLES , <NUM_LIT:0> , len ( vertices ) ) <EOL> self . buffer_attributes . pop_attributes ( ) <EOL> if self . use_shaders : <EOL> self . shader . unbind ( ) </s>
