def __init__(self, pModel_loc=None, pSwitcher_loc=None, pCordinates=None, pColor_loc=None): super().__init__(pModel_loc, pSwitcher_loc, pCordinates, pColor_loc) vertices = [-0.2, -0.2, 0.2, 0.0, 0.0, 0.2, -0.2, 0.2, 1.0, 0.0, 0.2, 0.2, 0.2, 1.0, 1.0, -0.2, 0.2, 0.2, 0.0, 1.0, -0.2, -0.2, -0.2, 0.0, 0.0, 0.2, -0.2, -0.2, 1.0, 0.0, 0.2, 0.2, -0.2, 1.0, 1.0, -0.2, 0.2, -0.2, 0.0, 1.0, 0.2, -0.2, -0.2, 0.0, 0.0, 0.2, 0.2, -0.2, 1.0, 0.0, 0.2, 0.2, 0.2, 1.0, 1.0, 0.2, -0.2, 0.2, 0.0, 1.0, -0.2, 0.2, -0.2, 0.0, 0.0, -0.2, -0.2, -0.2, 1.0, 0.0, -0.2, -0.2, 0.2, 1.0, 1.0, -0.2, 0.2, 0.2, 0.0, 1.0, -0.2, -0.2, -0.2, 0.0, 0.0, 0.2, -0.2, -0.2, 1.0, 0.0, 0.2, -0.2, 0.2, 1.0, 1.0, -0.2, -0.2, 0.2, 0.0, 1.0, 0.2, 0.2, -0.2, 0.0, 0.0, -0.2, 0.2, -0.2, 1.0, 0.0, -0.2, 0.2, 0.2, 1.0, 1.0, 0.2, 0.2, 0.2, 0.0, 1.0] indices = [ 0, 1, 2, 2, 3, 0, 4, 5, 6, 6, 7, 4, 8, 9, 10, 10, 11, 8, 12, 13, 14, 14, 15, 12, 16, 17, 18, 18, 19, 16, 20, 21, 22, 22, 23, 20] super()._handleObject(vertices, indices) glEnableVertexAttribArray(0) glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, super()._getVertices().itemsize * 5, ctypes.c_void_p(0)) glEnableVertexAttribArray(1) glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, super()._getVertices().itemsize * 5, ctypes.c_void_p(12)) load_texture("textures/window.webp", super()._getTexture())
def __init__(self, pModel_loc=None, pSwitcher_loc=None, pCordinates=None, pColor_loc=None): super().__init__(pModel_loc, pSwitcher_loc, pCordinates, pColor_loc) quad_vertices = [ -0.5, -0.5, 0.5, 0.0, 0.0, 0.5, -0.5, 0.5, 1.0, 0.0, 0.5, 0.5, 0.5, 1.0, 1.0, -0.5, 0.5, 0.5, 0.0, 1.0, ] quad_indices = [0, 1, 2, 2, 3, 0] super()._handleObject(quad_vertices, quad_indices) glEnableVertexAttribArray(0) glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, self.vertices.itemsize * 5, ctypes.c_void_p(0)) glEnableVertexAttribArray(1) glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, self.vertices.itemsize * 5, ctypes.c_void_p(12)) load_texture("textures/sun.png", super()._getTexture())
if not window: glfw.terminate() raise Exception('glfw window can not be created') glfw.set_window_pos(window, 4000, 200) glfw.set_cursor_pos(window, WINDOW_RESOLUTION[0]/2, WINDOW_RESOLUTION[1]/2) glfw.set_window_size_callback(window, window_resize) glfw.set_cursor_pos_callback(window, cursor_position_callback) glfw.make_context_current(window) light_shader = compileProgram(compileShader(light_vs, GL_VERTEX_SHADER), compileShader(light_fs, GL_FRAGMENT_SHADER)) lamp_shader = compileProgram(compileShader(lamp_vs, GL_VERTEX_SHADER), compileShader(lamp_fs, GL_FRAGMENT_SHADER)) texture = glGenTextures(2) load_texture('lightning_test/textures/container.png', texture[0]) load_texture('lightning_test/textures/container_specular.png', texture[1]) ### BOX ############################### box_VAO = glGenVertexArrays(1) glBindVertexArray(box_VAO) VBO = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, VBO) glBufferData(GL_ARRAY_BUFFER, vertices.nbytes, vertices, GL_STATIC_DRAW) glEnableVertexAttribArray(0) glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, vertices.itemsize * 8, ctypes.c_void_p(0)) glEnableVertexAttribArray(1) glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, vertices.itemsize * 8, ctypes.c_void_p(12)) glEnableVertexAttribArray(2)
glfw.set_window_size_callback(window, window_resize) # glfw.set_key_callback(window, key_callback) glfw.set_cursor_pos_callback(window, cursor_position_callback) glfw.make_context_current(window) car = Car() shader = compileProgram( compileShader(vertex_src, GL_VERTEX_SHADER), compileShader(fragment_src, GL_FRAGMENT_SHADER) ) texture = glGenTextures(2) load_texture(car.texture_path, texture[0]) load_texture("race_game/textures/uv_grid.jpg", texture[1]) # Car ############################################# car_VAO = glGenVertexArrays(1) glBindVertexArray(car_VAO) car_VBO = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, car_VBO) glBufferData(GL_ARRAY_BUFFER, car.buffer.nbytes, car.buffer, GL_STATIC_DRAW) car_EBO = glGenBuffers(1) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, car_EBO) glBufferData(GL_ELEMENT_ARRAY_BUFFER, car.indices.nbytes, car.indices, GL_STATIC_DRAW) glEnableVertexAttribArray(0)
# ============================================================ # # Loading shaders # # ============================================================ # shader = ShaderLoader('lightning_test/shaders/test.vs', 'lightning_test/shaders/test.fs') test_shader = shader.get_compiled_shader() shader = ShaderLoader('lightning_test/shaders/skybox.vs', 'lightning_test/shaders/skybox.fs') skybox_shader = shader.get_compiled_shader() # ============================================================ # # Loading textures # # ============================================================ # textureID = glGenTextures(2) load_texture('lightning_test/textures/container.png', textureID[0]) cubemap_images = [ 'lightning_test/textures/skybox/right.tga', 'lightning_test/textures/skybox/left.tga', 'lightning_test/textures/skybox/top.tga', 'lightning_test/textures/skybox/bottom.tga', 'lightning_test/textures/skybox/back.tga', 'lightning_test/textures/skybox/front.tga', ] cubemapTexture = load_cubemap(cubemap_images, textureID[1]) # ============================================================ # # Setup Cube Vertex Array Object # # ============================================================ # cube_VAO = glGenVertexArrays(1)
# ============================================================ # shader = ShaderLoader('lightning_test/shaders/cube.vs', 'lightning_test/shaders/cube.fs') cube_shader = shader.get_compiled_shader() shader = ShaderLoader('lightning_test/shaders/simple_depth.vs', 'lightning_test/shaders/simple_depth.fs') simple_depth_shader = shader.get_compiled_shader() shader = ShaderLoader('lightning_test/shaders/screen_quad.vs', 'lightning_test/shaders/screen_quad.fs') screen_quad_shader = shader.get_compiled_shader() # ============================================================ # # Loading textures # # ============================================================ # textureID = glGenTextures(2) load_texture('lightning_test/textures/container.png', textureID[0]) load_texture('lightning_test/textures/floor_tiles.jpg', textureID[1]) # ============================================================ # # configure depth map FBO # # ============================================================ # SHADOW_WIDTH = 1024 SHADOW_HEIGHT = 1024 depthMapFBO = glGenFramebuffers(1) # create depth texture depthMap = glGenTextures(1) create_2D_texture_depth(depthMap, SHADOW_WIDTH, SHADOW_HEIGHT) # attach depth texture as FBO's depth buffer glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO) glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D,