Example #1
0
 def wrapper(_self):
     unpatched_gl_display(_self)
     err = glGetError()
     if err != 0:
         logger.error(
             f"Encountered OpenGL Error in Plugin '{_self.class_name}'!"
             f" Error code: {err}, msg: {gluErrorString(err)}")
Example #2
0
def check_gl_errors():
    caller = getframeinfo(stack()[1][0])
    gl_error = glGetError()

    if (gl_error == GL_NO_ERROR):
        return

    if (gl_error == GL_INVALID_ENUM):
        print("%s:%d - GL_INVALID_ENUM" % (caller.filename, caller.lineno))

    if (gl_error == GL_INVALID_VALUE):
        print("%s:%d - GL_INVALID_VALUE" % (caller.filename, caller.lineno))

    if (gl_error == GL_INVALID_OPERATION):
        print("%s:%d - GL_INVALID_OPERATION" % (caller.filename, caller.lineno))

    if (gl_error == GL_STACK_OVERFLOW):
        print("%s:%d - GL_STACK_OVERFLOW" % (caller.filename, caller.lineno))

    if (gl_error == GL_STACK_UNDERFLOW):
        print("%s:%d - GL_STACK_UNDERFLOW" % (caller.filename, caller.lineno))

    if (gl_error == GL_OUT_OF_MEMORY):
        print("%s:%d - GL_OUT_OF_MEMORY" % (caller.filename, caller.lineno))

    if (gl_error == GL_TABLE_TOO_LARGE):
        print("%s:%d - GL_TABLE_TOO_LARGE" % (caller.filename, caller.lineno))
Example #3
0
def custom_gl_error_handling(
    error_checker, result, baseOperation=None, cArguments=None, *args
):
    try:
        return _original_gl_error_check(
            error_checker, result, baseOperation, cArguments, *args
        )
    except Exception as e:
        logging.error(f"Encountered PyOpenGL error: {e}")
        found_more_errors = False
        while True:
            err = glGetError()
            if err == GL_NO_ERROR:
                break
            if not found_more_errors:
                found_more_errors = True
                logging.debug("Emptying OpenGL error queue:")
            logging.debug(f"  glError: {err} -> {gluErrorString(err)}")
        if not found_more_errors:
            logging.debug("No more errors found in OpenGL error queue!")
def main():
    if not glfw.init():
        print('Failed to initialize GLFW.')
        return
    
    glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3)
    glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3)
    glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
    glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, GL_TRUE)
    glfw.window_hint(glfw.SAMPLES, config['sampling_level'])
    
    if config['fullscreen']:
        global width, height
        mode = glfw.get_video_mode(glfw.get_primary_monitor())
        width, height = mode.size.width, mode.size.height
        window = glfw.create_window(mode.size.width, mode.size.height, config['app_name'], glfw.get_primary_monitor(), None)
    else:
        window = glfw.create_window(width, height, config['app_name'], None, None)
    if not window:
        print('Failed to create GLFW Window.')
        glfw.terminate()
        return

    # подключаем наши функции для эвентов 
    #
    glfw.make_context_current(window)
    glfw.set_framebuffer_size_callback(window, ResizeCallback)
    glfw.set_cursor_pos_callback(window, MouseLookCallback)
    glfw.set_key_callback(window, KeyInputCallback) 
    glfw.set_input_mode(window, glfw.CURSOR, glfw.CURSOR_DISABLED)

    glEnable(GL_DEPTH_TEST)
    glEnable(GL_CULL_FACE)
    
    # подключаем фрагментный и вершинный шейдеры
    #
    program = Program()
    program.attachShader(Shader('resources/shaders/vert.vs', GL_VERTEX_SHADER))
    program.attachShader(Shader('resources/shaders/frag.fs', GL_FRAGMENT_SHADER))
    program.link()
    
    # подключаем шейдер для создания карты теней
    #  
    depthProgram = Program()
    depthProgram.attachShader(Shader('resources/shaders/depth.vs', GL_VERTEX_SHADER))
    depthProgram.attachShader(Shader('resources/shaders/depth.fs', GL_FRAGMENT_SHADER))
    depthProgram.attachShader(Shader('resources/shaders/depth.gs', GL_GEOMETRY_SHADER))
    depthProgram.link()

    # создаем depthBuffer и frameBuffer
    #
    shadow = Shadow(config['near_plane_depth'], config['far_plane_depth'])
    shadow.create(config['shadow_width'], config['shadow_height'])

    program.use()
    program.setInt("diffuseTexture", 0)
    program.setInt("depthMap", 1)

    # позиция источника света
    #
    lightPos = glm.vec3(0.0, 2.35, 0.0)
    
    # загрузка всех объектов сцены
    #
    room = Model('resources/models/dinning_room.json')
    
    # цикл обработки
    #
    while not glfw.window_should_close(window):
        if config['debug_mode']:
            print(glGetError())

        # обработка нажатий клавиатуры для камеры
        #
        DoMovement()
        
        # движение источника света
        #
        if light_movement:
            lightPos.z = math.sin(glfw.get_time() * 0.5) * 3.0

        glClearColor(0.1, 0.1, 0.1, 1.0)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        
        # обработка с помощью depthProgram - карта теней
        #
        shadow.castShadow(depthProgram, lightPos)
        room.draw(depthProgram)
        shadow.endCastShadow(program)

        
        glViewport(0, 0, width, height)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        # обработка с помощью program - на основе полученной карты теней
        #
        program.use()
        view = cam.get_view_matrix()
        viewPos = glm.vec3(cam.camera_pos[0],cam.camera_pos[1],cam.camera_pos[2])
        perspective = glm.perspective(45, width / height, config['near_plane'], config['far_plane'])
        program.setMat4('projection', perspective)
        program.setMat4('view', view)
        program.setVec3('lightPos', lightPos)
        program.setVec3('viewPos', viewPos)
        program.setInt('shadows', True)
        program.setFloat("far_plane", config["far_plane_depth"])
        glActiveTexture(GL_TEXTURE1)
        glBindTexture(GL_TEXTURE_CUBE_MAP, shadow.depthbuffer.texture)
        room.draw(program)

        glfw.swap_buffers(window)
        glfw.poll_events()
        

    glfw.terminate()