Exemplo n.º 1
0
    def initialize(self):
        print("Initializing programm...")

        ### create GPU program ###

        # vertex shader code
        vsCode = """
        void main()
        {
            gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
        }
        """

        # fragment shader code
        fsCode = """
        out vec4 fragColor;
        void main()
        {
            fragColor = vec4(1.0, 1.0, 0.0, 1.0);
        }
        """

        # send code to GPU, compile, store program reference
        self.programRef = OpenGLUtils.initializeProgram(vsCode, fsCode)

        # set up vertex array object
        vaoRef = glGenVertexArrays(1)
        glBindVertexArray(vaoRef)

        # render setting (optional)
        glPointSize(16)
Exemplo n.º 2
0
    def initialize(self):
        print("Initializing program...")

        vsCode = """
        in vec3 position;
        void main()
        {
            gl_Position = vec4(position.x, position.y, position.z, 1.0);
        }
        """

        fsCode = """
        void main()
        {
            gl_FragColor = vec4(0.0, 1.0, 1.0, 1.0);
        }
        """

        self.programRef = OpenGLUtils.initializeProgram(vsCode, fsCode)

        # render settings
        glPointSize(16)
        glLineWidth(8)

        # set up VAOs (vertex array objects)
        vaoRef = glGenVertexArrays(1)
        glBindVertexArray(vaoRef)

        # set up vertex attribute
        positionData = [[0.8, 0.0, 0.0], [0.4, 0.6, 0.0], [-0.4, 0.6, 0.0],
                        [-0.8, 0.0, 0.0], [-0.4, -0.6, 0.0], [0.4, -0.6, 0.0]]
        positionAttribute = Attribute("vec3", positionData)
        positionAttribute.associateVariable(self.programRef, "position")

        self.vertexCount = len(positionData)
Exemplo n.º 3
0
    def initialize(self):
        print("initializing program...")

        vsCode = """
        in vec3 position;
        uniform vec3 translation;
        void main()
        {
            vec3 pos = position + translation;
            gl_Position = vec4(pos.x, pos.y, pos.z, 1.0);
        }
        """

        fsCode = """
        uniform vec3 baseColor;
        void main()
        {
            gl_FragColor = vec4(baseColor.r, baseColor.g, baseColor.b, 1.0);
        }
        """

        self.programRef = OpenGLUtils.initializeProgram(vsCode, fsCode)

        # render settings
        glClearColor(0.6, 0.6, 0.8, 1.0)

        # vertex array object
        vaoRef = glGenVertexArrays(1)
        glBindVertexArray(vaoRef)

        # set up attribute
        positionData = [[ 0.0,  0.2, 0.0],
                        [ 0.2, -0.2, 0.0],
                        [-0.2, -0.2, 0.0]]
        positionAttribute = Attribute("vec3", positionData)
        positionAttribute.associateVariable(self.programRef, "position")
        self.vertexCount = len(positionData)

        # set up uniforms
        self.translation1 = Uniform("vec3", [-0.5, 0.0, 0.0])
        self.translation1.locateVariable(self.programRef, "translation")

        self.translation2 = Uniform("vec3", [ 0.5, 0.0, 0.0])
        self.translation2.locateVariable(self.programRef, "translation")

        self.baseColor1 = Uniform("vec3", [1.0, 0.0, 0.0])
        self.baseColor1.locateVariable(self.programRef, "baseColor")

        self.baseColor2 = Uniform("vec3", [0.0, 0.0, 1.0])
        self.baseColor2.locateVariable(self.programRef, "baseColor")

        self.time = 0
Exemplo n.º 4
0
    def initialize(self):
        print("Initializing...")

        # shaders
        vsCode = """
        in vec3 position;
        uniform mat4 projectionMatrix;
        uniform mat4 modelMatrix;
        void main()
        {
            gl_Position = projectionMatrix * modelMatrix * vec4(position, 1.0);
        }
        """

        fsCode = """
        out vec4 fragColor;
        void main()
        {
            fragColor = vec4(1.0, 1.0, 0.0, 1.0);
        }
        """

        self.programRef = OpenGLUtils.initializeProgram(vsCode, fsCode)

        # render settings
        glClearColor(0.0, 0.0, 0.0, 1.0)
        glEnable(GL_DEPTH_TEST)

        # vao
        vaoRef = glGenVertexArrays(1)
        glBindVertexArray(vaoRef)

        # vertex attribute
        positionData = [[0.0, 0.2, 0.0], [0.1, -0.2, 0.0], [-0.1, -0.2, 0.0]]

        self.vertexCount = len(positionData)
        positionAttribute = Attribute("vec3", positionData)
        positionAttribute.associateVariable(self.programRef, "position")

        # uniforms
        mMatrix = Matrix.makeTranslation(0, 0, -1)
        self.modelMatrix = Uniform("mat4", mMatrix)
        self.modelMatrix.locateVariable(self.programRef, "modelMatrix")

        pMatrix = Matrix.makePersepctive()
        self.projectionMatrix = Uniform("mat4", pMatrix)
        self.projectionMatrix.locateVariable(self.programRef,
                                             "projectionMatrix")
Exemplo n.º 5
0
    def __init__(self, vertexShaderCode, fragmentShaderCode):

        self.programRef = OpenGLUtils.initializeProgram(
            vertexShaderCode, fragmentShaderCode)

        # store Uniform objects
        self.uniforms = {}

        # standard Uniform objects (matrices)
        self.uniforms["modelMatrix"] = Uniform("mat4", None)
        self.uniforms["viewMatrix"] = Uniform("mat4", None)
        self.uniforms["projectionMatrix"] = Uniform("mat4", None)

        # store OpenGL render settings
        self.settings = {}
        self.settings["drawStyle"] = GL_TRIANGLES
Exemplo n.º 6
0
    def initialize(self):
        print("Initializing program...")

        vsCode = """
        in vec3 position;
        void main()
        {
            gl_Position = vec4(position.x, position.y, position.z, 1.0);
        }
        """

        fsCode = """
        void main()
        {
            gl_FragColor = vec4(0.0, 1.0, 1.0, 1.0);
        }
        """

        self.programRef = OpenGLUtils.initializeProgram(vsCode, fsCode)

        # render settings
        glPointSize( 16 )
        glLineWidth( 8 )

        # set of triangle
        self.vaoTri = glGenVertexArrays(1)
        glBindVertexArray(self.vaoTri)
        positionDataTri = [[-0.5, 0.8, 0.0],
                           [-0.2, 0.2, 0.0],
                           [-0.8, 0.2, 0.0]]
        positionAttributeTri = Attribute("vec3", positionDataTri)
        positionAttributeTri.associateVariable(self.programRef, "position")
        self.vertexCountTri = len(positionDataTri)

        # set up square
        self.vaoSq = glGenVertexArrays(1)
        glBindVertexArray(self.vaoSq)
        positionDataSq = [[0.8, 0.8, 0.0],
                          [0.8, 0.2, 0.0],
                          [0.2, 0.2, 0.0],
                          [0.2, 0.8, 0.0]]
        positionAttributeSq = Attribute("vec3", positionDataSq)
        positionAttributeSq.associateVariable(self.programRef, "position")
        self.vertexCountSq = len(positionDataSq)
Exemplo n.º 7
0
    def initialize(self):
        print("Initializing program...")

        vsCode = """
        in vec3 position;
        uniform vec3 translation;
        void main()
        {
            vec3 pos = position + translation;
            gl_Position = vec4(pos.x, pos.y, pos.z, 1.0);
        }
        """

        fsCode = """
        out vec4 fragColor;
        void main()
        {   
            fragColor = vec4(1.0, 1.0, 0.0, 1.0);
        }
        """

        self.programRef = OpenGLUtils.initializeProgram(vsCode, fsCode)

        # vertex array object
        vaoRef = glGenVertexArrays(1)
        glBindVertexArray(vaoRef)

        # attributes
        positionData = [[ 0.0, 0.2, 0.0],
                        [ 0.2,-0.2, 0.0],
                        [-0.2,-0.2, 0.0]]
        positionAttribute = Attribute("vec3", positionData)
        positionAttribute.associateVariable(self.programRef, "position")

        self.vertexCount = len(positionData)

        # uniforms
        self.translationUniform = Uniform("vec3", [0.0, 0.0, 0.0])
        self.translationUniform.locateVariable(self.programRef, "translation")