packages/pyglGA/scripts/basicCubeGUI.py
def initCube():
    """
    initialises basic vertex, fragment shaders in order to display a  basic colored Cube with orthographic projection
    """
    
    # we want to access the three global variables for the shaders
    global  shaderProgram
    global  VAO
    global  VBO
    global TranslationMat
    global points
    
    #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
    
    # build up the 6 basic cube faces
    quad(1, 0, 3, 2)
    quad(2, 3, 7, 6)
    quad(3, 0, 4, 7)
    quad(6, 5, 1, 2)
    quad(4, 5, 6, 7)
    quad(5, 4, 0, 1)

    print(TranslationMat)
    print("--------------------------------------")
    # print(vertices)
    # points = numpy.dot(points, TranslationMat)
    print(points)
    
    vertexShader = shaders.compileShader("""
    #version 410
    layout (location=0) in vec4 vPosition;
    layout (location=1) in vec4 vColor;
    out vec4 color;

    uniform mat4 translate;

    void main()
    {
        // uncomment to witness the effect of translation to the left on X by -0.5
        gl_Position = translate * vPosition;

        // uncomment to have the cube centered on 0.0.0
        //gl_Position =  vPosition;

        color = vColor;
        // debug
        // if(translate[0][0]==-0.5) color=vec4(0.0,1.0,0.0,1.0);
    }
    """, GL_VERTEX_SHADER)

    fragmentShader = shaders.compileShader("""
    #version 410
    in vec4 color;
    out vec4 outputColour;
    void main()
    {
        outputColour = color;
        //outputColour = vec4(0.0,1.0,0.0,1.0);
    }
    """, GL_FRAGMENT_SHADER)
    
    #build the shaderProgram our of the two shaders
    shaderProgram = shaders.compileProgram(vertexShader, fragmentShader)
    
    # active shader program
    glUseProgram(shaderProgram)
    
    # Create vertices VBO on server side GPU
    VBO = glGenBuffers(1)
    glBindBuffer(GL_ARRAY_BUFFER, VBO)
    glBufferData(GL_ARRAY_BUFFER, points.nbytes + colors.nbytes, None, GL_STATIC_DRAW)
    glBufferSubData(GL_ARRAY_BUFFER, 0, points.nbytes, points)
    glBufferSubData(GL_ARRAY_BUFFER, points.nbytes, colors.nbytes, colors)

    # enable array and set up data
    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(points.nbytes))

    glEnable(GL_DEPTH_TEST)
    glClearColor(0.0, 0.0, 0.0, 1.0)

    global TranslateMat
    TranslateMat = glGetUniformLocation(shaderProgram, "translate")
    # glUniformMatrix4fv(TranslateMat, 1, GL_FALSE,  TranslationMat)

    glBindBuffer(GL_ARRAY_BUFFER, 0)
    # Only one VAO can be bound at a time, so disable it to avoid altering it accidentally
    glBindVertexArray(0)
    
    return shaderProgram, VAO, VBO

    initialises basic vertex, fragment shaders in order to display a  basic colored Cube with orthographic projection
    
initialises basic vertex, fragment shaders in order to display a  basic colored Cube with orthographic projection
initialises basic vertex fragment shaders in order to display a basic colored Cube with orthographic projection
def initCube():
    global  shaderProgram
    global  VAO
    global  VBO
    global TranslationMat
    global points
    VAO = glGenVertexArrays(1) 
    glBindVertexArray(VAO) 
    quad(1, 0, 3, 2)
    quad(2, 3, 7, 6)
    quad(3, 0, 4, 7)
    quad(6, 5, 1, 2)
    quad(4, 5, 6, 7)
    quad(5, 4, 0, 1)
    print(TranslationMat)
    print("--------------------------------------")
    print(points)
    vertexShader = shaders.compileShader("""
    #version 410
    layout (location=0) in vec4 vPosition;
    layout (location=1) in vec4 vColor;
    out vec4 color;
    uniform mat4 translate;
    void main()
    {
        // uncomment to witness the effect of translation to the left on X by -0.5
        gl_Position = translate * vPosition;
        // uncomment to have the cube centered on 0.0.0
        //gl_Position =  vPosition;
        color = vColor;
        // debug
        // if(translate[0][0]==-0.5) color=vec4(0.0,1.0,0.0,1.0);
    }
    """, GL_VERTEX_SHADER)
    fragmentShader = shaders.compileShader("""
    #version 410
    in vec4 color;
    out vec4 outputColour;
    void main()
    {
        outputColour = color;
        //outputColour = vec4(0.0,1.0,0.0,1.0);
    }
    """, GL_FRAGMENT_SHADER)
    shaderProgram = shaders.compileProgram(vertexShader, fragmentShader)
    glUseProgram(shaderProgram)
    VBO = glGenBuffers(1)
    glBindBuffer(GL_ARRAY_BUFFER, VBO)
    glBufferData(GL_ARRAY_BUFFER, points.nbytes + colors.nbytes, None, GL_STATIC_DRAW)
    glBufferSubData(GL_ARRAY_BUFFER, 0, points.nbytes, points)
    glBufferSubData(GL_ARRAY_BUFFER, points.nbytes, colors.nbytes, colors)
    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(points.nbytes))
    glEnable(GL_DEPTH_TEST)
    glClearColor(0.0, 0.0, 0.0, 1.0)
    global TranslateMat
    TranslateMat = glGetUniformLocation(shaderProgram, "translate")
    glBindBuffer(GL_ARRAY_BUFFER, 0)
    glBindVertexArray(0)
    return shaderProgram, VAO, VBO
def initCube ( ) : global shaderProgram global VAO global VBO global TranslationMat global points VAO = glGenVertexArrays ( 1 ) glBindVertexArray ( VAO ) quad ( 1 , 0 , 3 , 2 ) quad ( 2 , 3 , 7 , 6 ) quad ( 3 , 0 , 4 , 7 ) quad ( 6 , 5 , 1 , 2 ) quad ( 4 , 5 , 6 , 7 ) quad ( 5 , 4 , 0 , 1 ) print ( TranslationMat ) print ( "--------------------------------------" ) print ( points ) vertexShader = shaders . compileShader ( """
    #version 410
    layout (location=0) in vec4 vPosition;
    layout (location=1) in vec4 vColor;
    out vec4 color;

    uniform mat4 translate;

    void main()
    {
        // uncomment to witness the effect of translation to the left on X by -0.5
        gl_Position = translate * vPosition;

        // uncomment to have the cube centered on 0.0.0
        //gl_Position =  vPosition;

        color = vColor;
        // debug
        // if(translate[0][0]==-0.5) color=vec4(0.0,1.0,0.0,1.0);
    }
    """ , GL_VERTEX_SHADER ) fragmentShader = shaders . compileShader ( """
    #version 410
    in vec4 color;
    out vec4 outputColour;
    void main()
    {
        outputColour = color;
        //outputColour = vec4(0.0,1.0,0.0,1.0);
    }
    """ , GL_FRAGMENT_SHADER ) shaderProgram = shaders . compileProgram ( vertexShader , fragmentShader ) glUseProgram ( shaderProgram ) VBO = glGenBuffers ( 1 ) glBindBuffer ( GL_ARRAY_BUFFER , VBO ) glBufferData ( GL_ARRAY_BUFFER , points . nbytes + colors . nbytes , None , GL_STATIC_DRAW ) glBufferSubData ( GL_ARRAY_BUFFER , 0 , points . nbytes , points ) glBufferSubData ( GL_ARRAY_BUFFER , points . nbytes , colors . nbytes , colors ) 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 ( points . nbytes ) ) glEnable ( GL_DEPTH_TEST ) glClearColor ( 0.0 , 0.0 , 0.0 , 1.0 ) global TranslateMat TranslateMat = glGetUniformLocation ( shaderProgram , "translate" ) glBindBuffer ( GL_ARRAY_BUFFER , 0 ) glBindVertexArray ( 0 ) return shaderProgram , VAO , VBO
initialises basic vertex, fragment shaders in order to display a  basic colored Cube with orthographic projection
initialises basic vertex fragment shaders in order to display a basic colored Cube with orthographic projection
"""
    initialises basic vertex, fragment shaders in order to display a  basic colored Cube 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 up the 6 basic cube faces # print(vertices) # points = numpy.dot(points, TranslationMat) #build the shaderProgram our of the two shaders # active shader program # Create vertices VBO on server side GPU # enable array and set up data # glUniformMatrix4fv(TranslateMat, 1, GL_FALSE,  TranslationMat) # Only one VAO can be bound at a time, so disable it to avoid altering it accidentally