def renderFrame(width, height): aspectRatio = float(width) / float(height) #shadow pass? view = ViewParams() # Projection (view to clip space transform) view.viewToClipTransform = lu.make_perspective(g_fov, aspectRatio, g_nearDistance, g_farDistance) # Transform from world space to view space. view.worldToViewTransform = lu.make_lookAt(g_viewPosition, g_viewTarget, g_viewUp) #debug #view.worldToViewTransform = lu.make_lookAt(g_sunPosition,[0.0,0.0,0.0],g_viewUp) view.width = width view.height = height # the values are taken from Tutorial 16 lightPOV = lu.make_lookAt(g_sunPosition, g_viewTarget, g_viewUp) view.depthMVPTransform = lu.orthographic_projection_matrix( 0, 1024, 0, 1024, g_nearDistance, g_farDistance) * lightPOV shadow.shadowRenderPass(g_shadowShader, view, g_renderingSystem, g_shadowTexId, g_terrain, g_fbo) glViewport(0, 0, width, height) glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT) # ViewParams is used to contain the needed data to represent a 'view' mostly we want to get at the # projection and world-to-view transform, as these are used in all shaders. Keeping them in one # object makes it easier to pass around. It is also convenient future-proofing if we want to add more # views (e.g., for a shadow map). # Call each part of the scene to render itself g_terrain.render(view, g_renderingSystem, g_shadowTexId) g_racer.render(view, g_renderingSystem) for p in g_props: p.render(view, g_renderingSystem)
def renderFrame(width, height): glViewport(0, 0, width, height) glClearColor(g_backGroundColour[0], g_backGroundColour[1], g_backGroundColour[2], 1.0) glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT) aspectRatio = float(width) / float(height) # ViewParams is used to contain the needed data to represent a 'view' mostly we want to get at the # projection and world-to-view transform, as these are used in all shaders. Keeping them in one # object makes it easier to pass around. It is also convenient future-proofing if we want to add more # views (e.g., for a shadow map). view = ViewParams() # Projection (view to clip space transform) view.viewToClipTransform = lu.make_perspective(g_fov, aspectRatio, g_nearDistance, g_farDistance) # Transform from world space to view space. view.worldToViewTransform = lu.make_lookAt(g_viewPosition, g_viewTarget, g_viewUp) view.width = width view.height = height # Call each part of the scene to render itself g_terrain.render(view, g_renderingSystem) g_racer.render(view, g_renderingSystem) #g_props.render(view, g_renderingSystem) for prop in g_props: prop.render(view, g_renderingSystem)
def renderFrame(uiWidth, width, height): global g_triangleVerts global g_cameraDistance global g_cameraYawDeg global g_cameraPitchDeg global g_yFovDeg global g_lightYaw global g_lightDistance global g_lightPitch # This configures the fixed-function transformation from Normalized Device Coordinates (NDC) # to the screen (pixels - called 'window coordinates' in OpenGL documentation). # See: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glViewport.xhtml glViewport(0, 0, width, height) # Set the colour we want the frame buffer cleared to, glClearColor(0.2, 0.5, 0.1, 1.0) # Tell OpenGL to clear the render target to the clear values for both depth and colour buffers (depth uses the default) glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT) viewToClipTransform = lu.make_perspective(g_yFovDeg, width / height, 0.1, 50.0) eyePos = lu.Mat3(lu.make_rotation_y( math.radians(g_cameraYawDeg))) * lu.Mat3( lu.make_rotation_x( math.radians(g_cameraPitchDeg))) * [0, 0, g_cameraDistance] worldToViewTransform = magic.make_lookAt(eyePos, [0, 0, 0], [0, 1, 0]) worldToClipTransform = viewToClipTransform * worldToViewTransform lightRotation = lu.Mat3(lu.make_rotation_y( math.radians(g_lightYaw))) * lu.Mat3( lu.make_rotation_x(math.radians(g_lightPitch))) lightPosition = [0.02, 0, 0] + lu.vec3(0, 23, 0.2) draw_court(worldToClipTransform, lightPosition) lu.drawSphere([0.23, -0.45, 0.1, 0], 0.007, [0, 1, 0, 0.5], viewToClipTransform, worldToViewTransform) lu.drawSphere(lightPosition, 0.01, [1, 1, 0, 1], viewToClipTransform, worldToViewTransform)
def renderFrame(xOffset, width, height, time, textures, vao): global g_camera global g_yFovDeg global g_model lightPosition = lu.vec3(0, 0, 0) sunPosition = lu.vec3(0, 0, 0) mercuryPosition = getPosition(80, 0.01, time) saturnPosition = getPosition(300, 0.05, time) experimentPosition = getPosition(150, 0.02, time) moonPosition = getPosition(25, 0.1, time) # This configures the fixed-function transformation from Normalized Device Coordinates (NDC) # to the screen (pixels - called 'window coordinates' in OpenGL documentation). # See: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glViewport.xhtml glViewport(xOffset, 0, width, height) # Set the colour we want the frame buffer cleared to, glClearColor(0.0, 0.0, 0.0, 1.0) # Tell OpenGL to clear the render target to the clear values for both depth and colour buffers (depth uses the default) glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT) worldToViewTransform = g_camera.getWorldToViewMatrix([0, 1, 0]) viewToClipTransform = lu.make_perspective(g_yFovDeg, width / height, 0.1, 1500.0) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) Sphere.drawSphereWithTexture( experimentPosition, 20.0, "planet1.png", viewToClipTransform, worldToViewTransform, textures, vao, lu.transformPoint(worldToViewTransform, lightPosition), "shaders/allVertexShader.glsl", "shaders/planetFragmentShader.glsl") Sphere.drawSphereWithTexture( mercuryPosition, 10.0, "planet2.png", viewToClipTransform, worldToViewTransform, textures, vao, lu.transformPoint(worldToViewTransform, lightPosition), "shaders/allVertexShader.glsl", "shaders/planetFragmentShader.glsl") Sphere.drawSphereWithTexture( saturnPosition, 10.0, "fire.png", viewToClipTransform, worldToViewTransform, textures, vao, lu.transformPoint(worldToViewTransform, lightPosition), "shaders/allVertexShader.glsl", "shaders/planetFragmentShader.glsl") randomNo = random.random() Sphere.drawSphereWithTexture( sunPosition, 15.0, "sun.png", viewToClipTransform, worldToViewTransform, textures, vao, lu.transformPoint(worldToViewTransform, lightPosition), "shaders/allVertexShader.glsl", "shaders/sunFragmentShader.glsl") Sphere.drawSphereWithTexture( sunPosition, 16.0 + 1 * randomNo, "sun.png", viewToClipTransform, worldToViewTransform, textures, vao, lu.transformPoint(worldToViewTransform, lightPosition), "shaders/allVertexShader.glsl", "shaders/cheekyShader.glsl") Sphere.drawSphereWithTexture( sunPosition, 17.0 + 2 * randomNo, "sun.png", viewToClipTransform, worldToViewTransform, textures, vao, lu.transformPoint(worldToViewTransform, lightPosition), "shaders/allVertexShader.glsl", "shaders/cheekyShader.glsl") Sphere.drawSphereWithTexture( sunPosition, 18.0 + 3 * randomNo, "sun.png", viewToClipTransform, worldToViewTransform, textures, vao, lu.transformPoint(worldToViewTransform, lightPosition), "shaders/allVertexShader.glsl", "shaders/cheekyShader.glsl") Sphere.drawSphereWithTexture( sunPosition, 20.0 + 5 * randomNo, "sun.png", viewToClipTransform, worldToViewTransform, textures, vao, lu.transformPoint(worldToViewTransform, lightPosition), "shaders/allVertexShader.glsl", "shaders/cheekyShader.1.glsl") Sphere.drawSphereWithTexture( sunPosition, 24.0 + 9 * randomNo, "sun.png", viewToClipTransform, worldToViewTransform, textures, vao, lu.transformPoint(worldToViewTransform, lightPosition), "shaders/allVertexShader.glsl", "shaders/cheekyShader.2.glsl") Sphere.drawSphereWithTexture( sunPosition, 700, "stars3.png", viewToClipTransform, worldToViewTransform, textures, vao, lu.transformPoint(worldToViewTransform, lightPosition), "shaders/allVertexShader.glsl", "shaders/sunFragmentShader.1.glsl") glDisable(GL_BLEND)
def render_frame(width, height): """ Renders the frame """ global g_shader global g_squares global g_square_colors global g_square_normals global g_cam global g_light_1 global g_light_color_1 global g_ambi_color global g_spec_color # Make the camera position eye_pos = g_cam look_at = [1.5, 1.5, -1.5] up_dir = [0, 1, 0] y_fov = 45 # Light constants ambient_light = g_ambi_color specular_light = g_spec_color world_to_view = lu.make_lookAt(eye_pos, look_at, up_dir) view_to_clip = lu.make_perspective(y_fov, width / height, 0.1, 260) world_to_clip = view_to_clip * world_to_view model_to_view_normal = lu.inverse(lu.transpose(lu.Mat3(world_to_view))) # Make openGL use transform from screen space to NDC glViewport(0, 0, width, height) # Set the clear colour (i.e. background colour) glClearColor(0.7, 0.8, 1.0, 1.0) make_squares() make_texture_coords() # Unbind the buffers glBindBuffer(GL_ARRAY_BUFFER, 0) glBindVertexArray(0) # Clear the colour and depth buffers glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT) # Buffer the world to clip transform matrix tfm_uniform_index = glGetUniformLocation(g_shader, "worldToClipTfm") glUseProgram(g_shader) glUniformMatrix4fv(tfm_uniform_index, 1, GL_TRUE, world_to_clip.getData()) glBindVertexArray(g_vertex_array) model_uniform_index = glGetUniformLocation(g_shader, "modelToView") glUseProgram(g_shader) glUniformMatrix4fv(model_uniform_index, 1, GL_TRUE, world_to_view.getData()) norm_uniform_index = glGetUniformLocation(g_shader, "modelToViewNormal") glUseProgram(g_shader) glUniformMatrix3fv(norm_uniform_index, 1, GL_TRUE, model_to_view_normal.getData()) lu.setUniform(g_shader, "camPos", eye_pos) # Add light 1 uniforms lu.setUniform(g_shader, "lightColourAndIntensity1", g_light_color_1) lu.setUniform(g_shader, "viewSpaceLightPosition1", g_light_1) # Add light 2 uniforms lu.setUniform(g_shader, "lightColourAndIntensity2", g_light_color_2) lu.setUniform(g_shader, "viewSpaceLightPosition2", g_light_2) # Add light 3 uniforms lu.setUniform(g_shader, "lightColourAndIntensity3", g_light_color_3) lu.setUniform(g_shader, "viewSpaceLightPosition3", g_light_3) # Add light 4 uniforms lu.setUniform(g_shader, "lightColourAndIntensity4", g_light_color_4) lu.setUniform(g_shader, "viewSpaceLightPosition4", g_light_4) lu.setUniform(g_shader, "ambientLightColourAndIntensity", ambient_light) lu.setUniform(g_shader, "materialSpecular", specular_light) # Fog settings lu.setUniform(g_shader, "fogColor", g_fog_color) lu.setUniform(g_shader, "fogDensityConst", g_fog_density) lu.setUniform(g_shader, "fogHeightConst", g_fog_height) lu.setUniform(g_shader, "fogMax", g_fog_max) glActiveTexture(GL_TEXTURE0) glBindTexture(GL_TEXTURE_2D, g_texture_id) loc = glGetUniformLocation(g_shader, "plasticTexture") glUniform1i(loc, 0) for i in range(int(len(g_squares) / 4)): lu.setUniform(g_shader, "squareColorIndex", g_square_colors[i]) lu.setUniform(g_shader, "squareNormal", g_square_normals[i]) glDrawArrays(GL_TRIANGLE_FAN, i * 4, 4)