Ejemplo n.º 1
0
 def __init__(self,
              angleOfView=90,
              aspectRatio=1080 / 720,
              near=0.1,
              far=1000):
     super().__init__()
     self.projectionMatrix = Matrix.makePersepctive(angleOfView,
                                                    aspectRatio, near, far)
     self.viewMatrix = Matrix.makeIdentity()
Ejemplo n.º 2
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")