<commit_before>from OpenGL.GL import *
from OpenGL.GLUT import *
from shader import BaseShaderProgram
from object import Object
import os
import sys
import numpy as np
from matrix_transform import *
from math import pi, radians
from Camera import Camera

WIDTH = 800
HEIGHT = 600
FPS = 50
ESC = b'\033'
SIZE_OF_FLOAT = 4

window = 0
program_id = 0

# uniform variables
uniform_loc = {}
uniforms = ['myTextureSampler',
            'MVP', 'M', 'V', 'NormalMatrix',
            'lightPos_worldspace',
            'material.ambient',
            'material.diffuse',
            'material.specular',
            'material.shininess',
            ]

# motion control
g_camera = Camera()

lightPos_worldspace = np.array([0, 0, 3])

#Objects
boxObj = None
flowerObj = None
g_object_list = []


def reshape(w, h):
    """TODO"""
    glViewport(0, 0, w, h)


def display():
    global lightPos_worldspace, g_camera
    global boxObj, flowerObj
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

    glUseProgram(program_id)
    # set transform matrix
    # matrix_scale = scale(g_scale_ratio)
    # ModelMatrix = rotate(matrix_scale.T, g_verticalAngle, np.array([1, 0, 0], 'f'))
    # ModelMatrix = rotate(ModelMatrix.T, g_horizontalAngle, np.array([0, 1, 0], 'f'))
    # matrix_translate = translate(g_translate_x, g_translate_y, 0.0)
    # ModelMatrix = np.dot(matrix_translate, ModelMatrix)

    ProjectionMatrix = perspective(radians(g_camera.zoom), 4 / 3, 0.1, 100)
    ViewMatrix = g_camera.getViewMatrix()
    glUniformMatrix4fv(uniform_loc['V'], 1, GL_TRUE, c_matrix(ViewMatrix))

    # set light parameter
    lightPos = g_camera.getLightPosition()
    glUniform3f(uniform_loc['lightPos_worldspace'], lightPos[0], lightPos[1], lightPos[2])
    glUniform1f(uniform_loc['material.shininess'], 32)

    # display
    obj = boxObj
    ModelMatrix = np.identity(4, 'f')
    matrix_translate = translate(2, 0, -5)
    ModelMatrix = dots(matrix_translate, ModelMatrix)
    MVP = dots(ProjectionMatrix, ViewMatrix, ModelMatrix)
    glUniformMatrix4fv(uniform_loc['M'], 1, GL_TRUE, c_matrix(ModelMatrix))
    glUniformMatrix4fv(uniform_loc['MVP'], 1, GL_TRUE, c_matrix(MVP))
    for i in range(len(obj.geom_nums)):
        glBindVertexArray(obj.vao_ids[i])
        # mtl parameter
        mtl = obj.mtl_buffer_list[i]
        glUniform3f(uniform_loc['material.ambient'], mtl.Ka[0], mtl.Ka[1], mtl.Ka[2])
        glUniform3f(uniform_loc['material.diffuse'], mtl.Kd[0], mtl.Kd[1], mtl.Kd[2])
        glUniform3f(uniform_loc['material.specular'], mtl.Ks[0], mtl.Ks[1], mtl.Ks[2])

        # texture
        glActiveTexture(GL_TEXTURE0)
        glBindTexture(GL_TEXTURE_2D, obj.texture_ids[i])
        glUniform1i(uniform_loc['myTextureSampler'], 0)

        # vertex
        glBindBuffer(GL_ARRAY_BUFFER, obj.vertex_buffer_ids[i])
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, None)
        # uv
        glBindBuffer(GL_ARRAY_BUFFER, obj.uv_buffer_ids[i])
        glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, None)
        # normal
        glBindBuffer(GL_ARRAY_BUFFER, obj.normal_buffer_ids[i])
        glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, None)

        glEnableVertexAttribArray(0)
        glEnableVertexAttribArray(1)
        glEnableVertexAttribArray(2)
        # draw
        glDrawArrays(GL_TRIANGLES, 0, obj.geom_nums[i])

        glDisableVertexAttribArray(0)
        glDisableVertexAttribArray(1)
        glEnableVertexAttribArray(2)
        glBindVertexArray(0)
    # flower3d
    obj = flowerObj
    ModelMatrix = scale(0.05)
    MVP = dots(ProjectionMatrix, ViewMatrix, ModelMatrix)
    glUniformMatrix4fv(uniform_loc['M'], 1, GL_TRUE, c_matrix(ModelMatrix))
    glUniformMatrix4fv(uniform_loc['MVP'], 1, GL_TRUE, c_matrix(MVP))
    for i in range(len(obj.geom_nums)):
        glBindVertexArray(obj.vao_ids[i])
        # mtl parameter
        mtl = obj.mtl_buffer_list[i]
        glUniform3f(uniform_loc['material.ambient'], mtl.Ka[0], mtl.Ka[1], mtl.Ka[2])
        glUniform3f(uniform_loc['material.diffuse'], mtl.Kd[0], mtl.Kd[1], mtl.Kd[2])
        glUniform3f(uniform_loc['material.specular'], mtl.Ks[0], mtl.Ks[1], mtl.Ks[2])

        # texture
        glActiveTexture(GL_TEXTURE0)
        glBindTexture(GL_TEXTURE_2D, obj.texture_ids[i])
        glUniform1i(uniform_loc['myTextureSampler'], 0)

        # vertex
        glBindBuffer(GL_ARRAY_BUFFER, obj.vertex_buffer_ids[i])
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, None)
        # uv
        glBindBuffer(GL_ARRAY_BUFFER, obj.uv_buffer_ids[i])
        glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, None)
        # normal
        glBindBuffer(GL_ARRAY_BUFFER, obj.normal_buffer_ids[i])
        glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, None)

        glEnableVertexAttribArray(0)
        glEnableVertexAttribArray(1)
        glEnableVertexAttribArray(2)
        # draw
        glDrawArrays(GL_TRIANGLES, 0, obj.geom_nums[i])

        glDisableVertexAttribArray(0)
        glDisableVertexAttribArray(1)
        glEnableVertexAttribArray(2)
        glBindVertexArray(0)

    # swap buffer
    glutSwapBuffers()


def update(val):
    if val == 1:
        glutPostRedisplay()
        # glutTimerFunc(int(1000 / FPS), update, 1)


def init_opengl():
    """set opengl parameter"""
    # depth test
    glEnable(GL_DEPTH_TEST)
    glDepthFunc(GL_LEQUAL)
    glEnable(GL_CULL_FACE)
    # glEnable(GL_LINE_SMOOTH)
    # glEnable(GL_BLEND)

    glClearColor(0.0, 0.0, 0.4, 0.0)
<commit_msg>delete GL_CULL_FACE<commit_after>from OpenGL.GL import *
from OpenGL.GLUT import *
from shader import BaseShaderProgram
from object import Object
import os
import sys
import numpy as np
from matrix_transform import *
from math import pi, radians
from Camera import Camera

WIDTH = 800
HEIGHT = 600
FPS = 50
ESC = b'\033'
SIZE_OF_FLOAT = 4

window = 0
program_id = 0

# uniform variables
uniform_loc = {}
uniforms = ['myTextureSampler',
            'MVP', 'M', 'V', 'NormalMatrix',
            'lightPos_worldspace',
            'material.ambient',
            'material.diffuse',
            'material.specular',
            'material.shininess',
            ]

# motion control
g_camera = Camera()

lightPos_worldspace = np.array([0, 0, 3])

#Objects
boxObj = None
flowerObj = None
g_object_list = []


def reshape(w, h):
    """TODO"""
    glViewport(0, 0, w, h)


def display():
    global lightPos_worldspace, g_camera
    global boxObj, flowerObj
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

    glUseProgram(program_id)
    # set transform matrix
    # matrix_scale = scale(g_scale_ratio)
    # ModelMatrix = rotate(matrix_scale.T, g_verticalAngle, np.array([1, 0, 0], 'f'))
    # ModelMatrix = rotate(ModelMatrix.T, g_horizontalAngle, np.array([0, 1, 0], 'f'))
    # matrix_translate = translate(g_translate_x, g_translate_y, 0.0)
    # ModelMatrix = np.dot(matrix_translate, ModelMatrix)

    ProjectionMatrix = perspective(radians(g_camera.zoom), 4 / 3, 0.1, 100)
    ViewMatrix = g_camera.getViewMatrix()
    glUniformMatrix4fv(uniform_loc['V'], 1, GL_TRUE, c_matrix(ViewMatrix))

    # set light parameter
    lightPos = g_camera.getLightPosition()
    glUniform3f(uniform_loc['lightPos_worldspace'], lightPos[0], lightPos[1], lightPos[2])
    glUniform1f(uniform_loc['material.shininess'], 32)

    # display
    obj = boxObj
    ModelMatrix = np.identity(4, 'f')
    matrix_translate = translate(2, 0, -5)
    ModelMatrix = dots(matrix_translate, ModelMatrix)
    MVP = dots(ProjectionMatrix, ViewMatrix, ModelMatrix)
    glUniformMatrix4fv(uniform_loc['M'], 1, GL_TRUE, c_matrix(ModelMatrix))
    glUniformMatrix4fv(uniform_loc['MVP'], 1, GL_TRUE, c_matrix(MVP))
    for i in range(len(obj.geom_nums)):
        glBindVertexArray(obj.vao_ids[i])
        # mtl parameter
        mtl = obj.mtl_buffer_list[i]
        glUniform3f(uniform_loc['material.ambient'], mtl.Ka[0], mtl.Ka[1], mtl.Ka[2])
        glUniform3f(uniform_loc['material.diffuse'], mtl.Kd[0], mtl.Kd[1], mtl.Kd[2])
        glUniform3f(uniform_loc['material.specular'], mtl.Ks[0], mtl.Ks[1], mtl.Ks[2])

        # texture
        glActiveTexture(GL_TEXTURE0)
        glBindTexture(GL_TEXTURE_2D, obj.texture_ids[i])
        glUniform1i(uniform_loc['myTextureSampler'], 0)

        # vertex
        glBindBuffer(GL_ARRAY_BUFFER, obj.vertex_buffer_ids[i])
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, None)
        # uv
        glBindBuffer(GL_ARRAY_BUFFER, obj.uv_buffer_ids[i])
        glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, None)
        # normal
        glBindBuffer(GL_ARRAY_BUFFER, obj.normal_buffer_ids[i])
        glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, None)

        glEnableVertexAttribArray(0)
        glEnableVertexAttribArray(1)
        glEnableVertexAttribArray(2)
        # draw
        glDrawArrays(GL_TRIANGLES, 0, obj.geom_nums[i])

        glDisableVertexAttribArray(0)
        glDisableVertexAttribArray(1)
        glEnableVertexAttribArray(2)
        glBindVertexArray(0)
    # flower3d
    obj = flowerObj
    ModelMatrix = scale(0.05)
    MVP = dots(ProjectionMatrix, ViewMatrix, ModelMatrix)
    glUniformMatrix4fv(uniform_loc['M'], 1, GL_TRUE, c_matrix(ModelMatrix))
    glUniformMatrix4fv(uniform_loc['MVP'], 1, GL_TRUE, c_matrix(MVP))
    for i in range(len(obj.geom_nums)):
        glBindVertexArray(obj.vao_ids[i])
        # mtl parameter
        mtl = obj.mtl_buffer_list[i]
        glUniform3f(uniform_loc['material.ambient'], mtl.Ka[0], mtl.Ka[1], mtl.Ka[2])
        glUniform3f(uniform_loc['material.diffuse'], mtl.Kd[0], mtl.Kd[1], mtl.Kd[2])
        glUniform3f(uniform_loc['material.specular'], mtl.Ks[0], mtl.Ks[1], mtl.Ks[2])

        # texture
        glActiveTexture(GL_TEXTURE0)
        glBindTexture(GL_TEXTURE_2D, obj.texture_ids[i])
        glUniform1i(uniform_loc['myTextureSampler'], 0)

        # vertex
        glBindBuffer(GL_ARRAY_BUFFER, obj.vertex_buffer_ids[i])
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, None)
        # uv
        glBindBuffer(GL_ARRAY_BUFFER, obj.uv_buffer_ids[i])
        glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, None)
        # normal
        glBindBuffer(GL_ARRAY_BUFFER, obj.normal_buffer_ids[i])
        glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, None)

        glEnableVertexAttribArray(0)
        glEnableVertexAttribArray(1)
        glEnableVertexAttribArray(2)
        # draw
        glDrawArrays(GL_TRIANGLES, 0, obj.geom_nums[i])

        glDisableVertexAttribArray(0)
        glDisableVertexAttribArray(1)
        glEnableVertexAttribArray(2)
        glBindVertexArray(0)

    # swap buffer
    glutSwapBuffers()


def update(val):
    if val == 1:
        glutPostRedisplay()
        # glutTimerFunc(int(1000 / FPS), update, 1)


def init_opengl():
    """set opengl parameter"""
    # depth test
    glEnable(GL_DEPTH_TEST)
    glDepthFunc(GL_LEQUAL)
    # glEnable(GL_CULL_FACE)
    # glEnable(GL_LINE_SMOOTH)
    # glEnable(GL_BLEND)

    glClearColor(0.0, 0.0, 0.4, 0.0)

{'fraction_non_alphanumeric': 0.11690549610012697, 'fraction_numerical': 0.025213132595682933, 'mean_word_length': 3.4302932904781036, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5646445', 'n_tokens_mistral': 4056, 'n_tokens_neox': 3863, 'n_words': 691}