packages/pyglGA/scripts/basicTriangle.py
def initTriangle():
    """
    initialises basic vertex, fragment shaders in order to display a 2D basic Triangle with orthographic projection
    """
    
    # we want to access the three global variables for the shaders
    global  shaderProgram
    global  VAO
    global  VBO
    
    #first we generate and then bind a VAO on the client GPU side that will contain the VBOs for the triangle
    VAO = glGenVertexArrays(1) #id is 1
    glBindVertexArray(VAO) #use, open VAO here
    
    vertexShader = shaders.compileShader("""
        #version 410
        layout (location=0) in vec4 position;
        layout (location=1) in vec4 colour;
        out vec4 theColour;
        void main()
        {
            gl_Position = position;
            theColour = colour;
        }
        """, GL_VERTEX_SHADER)
    
    fragmentShader = shaders.compileShader("""
        #version 410
        in vec4 theColour;
        out vec4 outputColour;
        void main()
        {
            outputColour = theColour;
        }
        """, GL_FRAGMENT_SHADER)
    
    #build the shaderProgram our of the two shaders
    shaderProgram = shaders.compileProgram(vertexShader, fragmentShader)
    
    # create the basic vertex array containing both vertex positions as well as vertex colours
    
    vertexData = numpy.array(
        [
            #vertex positions
            0.0, 0.0, 0.0, 1.0,
            0.5, 1.0, 0.0, 1.0,
            1.0, 0.0, 0.0, 1.0,
            
            #vertex colours
            1.0, 0.0, 0.0, 1.0,
            0.0, 1.0, 0.0, 1.0,
            0.0, 0.0, 1.0, 1.0,
        ],dtype=numpy.float32
    )
    
    #create the VBO on the server memory of the GPU
    VBO = glGenBuffers(1) #id is 1
    glBindBuffer(GL_ARRAY_BUFFER, VBO) # use, open VBO here
    glBufferData(GL_ARRAY_BUFFER, vertexData.nbytes, vertexData, GL_STATIC_DRAW)
    #enable strides vertex array for both positions (first) and colours (subsequently, after first bytes)
    glEnableVertexAttribArray(0) #id is 0
    glVertexAttribPointer(0,4,GL_FLOAT, GL_FALSE, 0, None) #how to fill in the vertex array
    #second colours array
    glEnableVertexAttribArray(1) #id is 1
    glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, ctypes.c_void_p(48)) #float32 is 4 bytes, 12 floats as vertices * 4 = 48 bytes
    
    glBindBuffer(GL_ARRAY_BUFFER,0) #close VBO here
    # Only one VAO can be bound at a time, so disable it to avoid altering it accidentally
    glBindVertexArray(0) # close VAO
    
    print("Yay! Created shaderProgram, VAO and VBO in basicTriangle!\n\n")
    return shaderProgram, VAO, VBO

    initialises basic vertex, fragment shaders in order to display a 2D basic Triangle with orthographic projection
    
initialises basic vertex, fragment shaders in order to display a 2D basic Triangle with orthographic projection
initialises basic vertex fragment shaders in order to display a 2D basic Triangle with orthographic projection
def initTriangle():
    global  shaderProgram
    global  VAO
    global  VBO
    VAO = glGenVertexArrays(1) 
    glBindVertexArray(VAO) 
    vertexShader = shaders.compileShader("""
        #version 410
        layout (location=0) in vec4 position;
        layout (location=1) in vec4 colour;
        out vec4 theColour;
        void main()
        {
            gl_Position = position;
            theColour = colour;
        }
        """, GL_VERTEX_SHADER)
    fragmentShader = shaders.compileShader("""
        #version 410
        in vec4 theColour;
        out vec4 outputColour;
        void main()
        {
            outputColour = theColour;
        }
        """, GL_FRAGMENT_SHADER)
    shaderProgram = shaders.compileProgram(vertexShader, fragmentShader)
    vertexData = numpy.array(
        [
            0.0, 0.0, 0.0, 1.0,
            0.5, 1.0, 0.0, 1.0,
            1.0, 0.0, 0.0, 1.0,
            1.0, 0.0, 0.0, 1.0,
            0.0, 1.0, 0.0, 1.0,
            0.0, 0.0, 1.0, 1.0,
        ],dtype=numpy.float32
    )
    VBO = glGenBuffers(1) 
    glBindBuffer(GL_ARRAY_BUFFER, VBO) 
    glBufferData(GL_ARRAY_BUFFER, vertexData.nbytes, vertexData, GL_STATIC_DRAW)
    glEnableVertexAttribArray(0) 
    glVertexAttribPointer(0,4,GL_FLOAT, GL_FALSE, 0, None) 
    glEnableVertexAttribArray(1) 
    glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, ctypes.c_void_p(48)) 
    glBindBuffer(GL_ARRAY_BUFFER,0) 
    glBindVertexArray(0) 
    print("Yay! Created shaderProgram, VAO and VBO in basicTriangle!\n\n")
    return shaderProgram, VAO, VBO
def initTriangle ( ) : global shaderProgram global VAO global VBO VAO = glGenVertexArrays ( 1 ) glBindVertexArray ( VAO ) vertexShader = shaders . compileShader ( """
        #version 410
        layout (location=0) in vec4 position;
        layout (location=1) in vec4 colour;
        out vec4 theColour;
        void main()
        {
            gl_Position = position;
            theColour = colour;
        }
        """ , GL_VERTEX_SHADER ) fragmentShader = shaders . compileShader ( """
        #version 410
        in vec4 theColour;
        out vec4 outputColour;
        void main()
        {
            outputColour = theColour;
        }
        """ , GL_FRAGMENT_SHADER ) shaderProgram = shaders . compileProgram ( vertexShader , fragmentShader ) vertexData = numpy . array ( [ 0.0 , 0.0 , 0.0 , 1.0 , 0.5 , 1.0 , 0.0 , 1.0 , 1.0 , 0.0 , 0.0 , 1.0 , 1.0 , 0.0 , 0.0 , 1.0 , 0.0 , 1.0 , 0.0 , 1.0 , 0.0 , 0.0 , 1.0 , 1.0 , ] , dtype = numpy . float32 ) VBO = glGenBuffers ( 1 ) glBindBuffer ( GL_ARRAY_BUFFER , VBO ) glBufferData ( GL_ARRAY_BUFFER , vertexData . nbytes , vertexData , GL_STATIC_DRAW ) glEnableVertexAttribArray ( 0 ) glVertexAttribPointer ( 0 , 4 , GL_FLOAT , GL_FALSE , 0 , None ) glEnableVertexAttribArray ( 1 ) glVertexAttribPointer ( 1 , 4 , GL_FLOAT , GL_FALSE , 0 , ctypes . c_void_p ( 48 ) ) glBindBuffer ( GL_ARRAY_BUFFER , 0 ) glBindVertexArray ( 0 ) print ( "Yay! Created shaderProgram, VAO and VBO in basicTriangle!\n\n" ) return shaderProgram , VAO , VBO
initialises basic vertex, fragment shaders in order to display a 2D basic Triangle with orthographic projection
initialises basic vertex fragment shaders in order to display a 2D basic Triangle with orthographic projection
"""
    initialises basic vertex, fragment shaders in order to display a 2D basic Triangle with orthographic projection
    """ # we want to access the three global variables for the shaders #first we generate and then bind a VAO on the client GPU side that will contain the VBOs for the triangle #id is 1 #use, open VAO here #build the shaderProgram our of the two shaders # create the basic vertex array containing both vertex positions as well as vertex colours #vertex positions #vertex colours #create the VBO on the server memory of the GPU #id is 1 # use, open VBO here #enable strides vertex array for both positions (first) and colours (subsequently, after first bytes) #id is 0 #how to fill in the vertex array #second colours array #id is 1 #float32 is 4 bytes, 12 floats as vertices * 4 = 48 bytes #close VBO here # Only one VAO can be bound at a time, so disable it to avoid altering it accidentally # close VAO