// tick for OpenGL rendering code public void RenderGL() { HandleInput(); // measure frame duration float frameDuration = timer.ElapsedMilliseconds; timer.Reset(); timer.Start(); UpdateScene(); //update transformations of all objects that are not static // update rotation a += 0.001f * frameDuration; if (a > 1000 * PI) { a -= 1000 * PI; //reset a to prevent stack overflows } if (useRenderTarget) { // enable render target target.Bind(); // render scene to render target sceneGraph.RenderHierarchy(camera); // render quad target.Unbind(); quad.Render(postproc, target.GetTextureID()); } else { // render scene directly to the screen sceneGraph.RenderHierarchy(camera); } }
public void Render() { // measure frame duration float frameDuration = (float)timer.Elapsed.TotalSeconds; //timer.ElapsedMilliseconds; timer.Reset(); timer.Start(); CameraControls(frameDuration); //prepare matrices for vertex shader Vector3 campos3 = -cameraM.Row3.Xyz; camID = GL.GetUniformLocation(shader.programID, "campos"); GL.UseProgram(shader.programID); GL.Uniform3(camID, campos3); Vector3 newlightpos3 = lightpos3; lightID = GL.GetUniformLocation(shader.programID, "lightPos"); GL.UseProgram(shader.programID); GL.Uniform3(lightID, newlightpos3); Matrix4 teapotT = Matrix4.CreateFromAxisAngle(new Vector3(0, 1, 0), -a); teapotN.localM = teapotT; Matrix4 smallteapotT = Matrix4.CreateFromAxisAngle(new Vector3(0, 1, 0), -b); smallteapotT *= Matrix4.CreateScale(0.6f); smallteapotT *= Matrix4.CreateTranslation(8f, 7f, 0); smallteapot.localM = smallteapotT; Matrix4 carT = Matrix4.CreateScale(0.8f); carT *= Matrix4.CreateFromAxisAngle(new Vector3(0, 1, 0), 0.8f * (float)Math.PI);; carT *= Matrix4.CreateTranslation(4f, -2.2f, 0); carT *= Matrix4.CreateFromAxisAngle(new Vector3(0, 1, 0), b); carN.localM = carT; Matrix4 carT2 = Matrix4.CreateScale(0.8f); carT2 *= Matrix4.CreateFromAxisAngle(new Vector3(0, -1, 0), 0.2f * (float)Math.PI);; carT2 *= Matrix4.CreateTranslation(-3.5f, -2.25f, 0); carT2 *= Matrix4.CreateFromAxisAngle(new Vector3(0, 1, 0), b); carN2.localM = carT2; // update rotation a += 1f * frameDuration; b += 1.5f * frameDuration; if (a > 2 * PI) { a -= 2 * PI; } if (b > 2 * PI) { b -= 2 * PI; } if (useRenderTarget) { // enable render target target.Bind(); // render scene to render target root.Render(ToWorld, cameraM); // render quad target.Unbind(); quad.Render(postproc, target.GetTextureID()); } else { // render scene directly to the screen root.Render(ToWorld, cameraM); } }