protected override void OnUpdateFrame(FrameEventArgs e) { if (state == GameState.Playing || state == GameState.Menu) { // calculate mouse movement //gameInput.calcDelta(); // calculate frame Times frameTime += (float)e.Time; lastFrameDuration = (float)e.Time; // exit game? bool ESC = Keyboard[Key.Escape]; if (ESC && !prevESC) { if (state == GameState.Menu) { exitGame(); } if (state == GameState.Playing) { enterMenu(); } } prevESC = ESC; bool F5 = Keyboard[Key.F5]; if (F5 && !prevF5) { if (state == GameState.Playing) { textureLoader.GrabScreenshot(); } } prevF5 = F5; // call scene tree to update mScene.update(); } else if (state == GameState.Started) { //search for related files FileSeeker mFileSeeker = new FileSeeker(this); //create framebufferset for waterreflections waterFramebuffer = framebufferCreator.createFrameBuffer("waterFramebuffer", (int)(virtual_size.X * 0.5), (int)(virtual_size.Y * 0.5)); RenderOptions mOptionsWater = new RenderOptions(virtual_size); mOptionsWater.postProcessing = true; mOptionsWater.ssAmbientOccluison = false; mOptionsWater.bloom = false; mOptionsWater.depthOfField = false; waterFramebufferSet = new FramebufferSet(framebufferCreator, waterFramebuffer, mOptionsWater); //crate shadow framebuffer shadowFramebuffer = framebufferCreator.createFrameBuffer("shadowFramebuffer", mScene.ShadowRes, mScene.ShadowRes, PixelInternalFormat.Rgba16f, false); //create main framebufferset RenderOptions mOptions = new RenderOptions(virtual_size); mOptions.postProcessing = true; mOptions.ssAmbientOccluison = true; mOptions.bloom = true; //mOptions.depthOfField = true; mainFramebufferSet = new FramebufferSet(framebufferCreator, framebufferCreator.defaultFb, mOptions); state = GameState.InitLoading; } else if (state == GameState.InitLoading) { //loading rutine - loads one object each time its called float percentageA = 0; float percentageB = 0; float percentageC = 0; float percentageD = 0; float percentageE = 0; percentageA = meshLoader.loadSingleMeshes(); if (percentageA == 1) { percentageB = shaderLoader.loadSingleShaders(); } if (percentageB == 1) { percentageC = textureLoader.loadSingleTextures(); } if (percentageC == 1) { percentageD = materialLoader.loadSingleMaterials(); } if (percentageD == 1) { percentageE = templateLoader.loadSingleTemplates(); } loadingPercentage = (percentageA + percentageB + percentageC + percentageD + percentageE) / 5f; //loadingPercentage = (float)Math.Sqrt(loadingPercentage); if (loadingPercentage == 1) { //create cubemap buffers mCubemapBufferSets = new CubemapBufferSets(mScene, framebufferCreator, 128); mScene.envTextures = mCubemapBufferSets.outTextures; // create viewInfo for reflection waterViewInfo = new ViewInfo(); waterViewInfo.aspect = (float)Width / (float)Height; waterViewInfo.updateProjectionMatrix(); //set noise texture mScene.noiseTexture = textureLoader.getTexture("noise_pixel.png"); //set shaders for postprocessing mScene.ssaoShader = shaderLoader.getShader("ssao.xsp"); mScene.ssaoBlrShader = shaderLoader.getShader("ao_blur.xsp"); mScene.ssaoBlrShaderA = shaderLoader.getShader("ao_blur_a.xsp"); mScene.bloomCurveShader = shaderLoader.getShader("bloom_curve.xsp"); mScene.bloomShader = shaderLoader.getShader("bloom_shader.xsp"); mScene.dofpreShader = shaderLoader.getShader("dof_preshader.xsp"); mScene.dofShader = shaderLoader.getShader("dof_shader.xsp"); mScene.compositeShader = shaderLoader.getShader("composite.xsp"); mScene.ssaoBlendShader = shaderLoader.getShader("ssao_blend.xsp"); mScene.normalShader = shaderLoader.getShader("ssnormals.xsp"); mScene.selectionShader = shaderLoader.getShader("selection.xsp"); mScene.copycatShader = shaderLoader.getShader("backdrop.xsp"); mScene.wipingShader = shaderLoader.getShader("sMapWipe.xsp"); // spawn the player player = new Player(mScene, new Vector3(0, 3, 10), new Vector3(0, 0, -1), gameInput); mScene.sunLight.Parent = player; //player.setInput(gameInput); mScene.init(); // load objects saved in database mScene.loadObjects(); mScene.selectionShader = shaderLoader.getShader("selection.xsp"); mScene.ssNormalShader = shaderLoader.getShader("ssnormals.xsp"); mScene.ssNormalShaderNoTex = shaderLoader.getShader("ssnormals_notex.xsp"); state = GameState.Playing; } } }
protected override void OnUpdateFrame(FrameEventArgs e) { if (state == GameState.Playing || state == GameState.Menu) { // calculate mouse movement //gameInput.calcDelta(); // calculate frame Times frameTime += (float)e.Time; lastFrameDuration = (float)e.Time; // exit game? bool ESC = Keyboard[Key.Escape]; if (ESC && !prevESC) { if (state == GameState.Menu) { exitGame(); } if (state == GameState.Playing) { enterMenu(); } } prevESC = ESC; bool F5 = Keyboard[Key.F5]; if (F5 && !prevF5) { if (state == GameState.Playing) { textureLoader.GrabScreenshot(); } } prevF5 = F5; // call scene tree to update mScene.update(); } else if (state == GameState.Started) { //search for related files FileSeeker mFileSeeker = new FileSeeker(this); //create framebufferset for waterreflections waterFramebuffer = framebufferCreator.createFrameBuffer("waterFramebuffer", (int)(virtual_size.X * 0.5), (int)(virtual_size.Y * 0.5)); RenderOptions mOptionsWater = Settings.Instance.video.CreateRenderOptions(VideoSettings.Target.water); waterFramebufferSet = new FramebufferSet(framebufferCreator, waterFramebuffer, mOptionsWater); //crate shadow framebuffer shadowFramebuffer = framebufferCreator.createFrameBuffer(mScene.ShadowRes, mScene.ShadowRes, PixelInternalFormat.Rgba16f, false); //create main framebufferset RenderOptions mOptions = Settings.Instance.video.CreateRenderOptions(VideoSettings.Target.main); mainFramebufferSet = new FramebufferSet(framebufferCreator, framebufferCreator.defaultFb, mOptions); state = GameState.InitLoading; } else if (state == GameState.InitLoading) { //loading rutine - loads one object each time its called float percentageA = 0; float percentageB = 0; float percentageC = 0; float percentageD = 0; float percentageE = 0; percentageA = meshLoader.loadSingleMeshes(); if (percentageA == 1) { percentageB = shaderLoader.loadSingleShaders(); } if (percentageB == 1) { percentageC = textureLoader.loadSingleTextures(); } if (percentageC == 1) { percentageD = materialLoader.loadSingleMaterials(); } if (percentageD == 1) { percentageE = templateLoader.loadSingleTemplates(); } loadingPercentage = (percentageA + percentageB + percentageC + percentageD + percentageE) / 5f; //loadingPercentage = (float)Math.Sqrt(loadingPercentage); if (loadingPercentage == 1) { //cache results if (Settings.Instance.game.generateCache) { meshLoader.writeCacheFile(); shaderLoader.writeCacheFile(); //textureLoader.writeCacheFile(); materialLoader.writeCacheFile(); templateLoader.writeCacheFile(); } //create cubemap buffers mCubemapBufferSets = new CubemapBufferSets(mScene, framebufferCreator, 128); mScene.envTextures = mCubemapBufferSets.outTextures; // create viewInfo for reflection waterViewInfo = new ViewInfo(); waterViewInfo.aspect = (float)Width / (float)Height; waterViewInfo.updateProjectionMatrix(); //set noise texture mScene.setTextureId(Material.WorldTexture.noise, textureLoader.getTextureId("noise_pixel.png")); //set shaders for postprocessing /* now managed * mScene.ssaoPreShader = shaderLoader.getShader("ssMaker.xsp"); * mScene.ssaoShader = shaderLoader.getShader("ssao.xsp"); * mScene.ssaoBlrShader = shaderLoader.getShader("ao_blur.xsp"); * mScene.ssaoBlrShaderA = shaderLoader.getShader("ao_blur_a.xsp"); * mScene.bloomCurveShader = shaderLoader.getShader("bloom_curve.xsp"); * mScene.bloomShader = shaderLoader.getShader("bloom_shader.xsp"); * mScene.dofpreShader = shaderLoader.getShader("dof_preshader.xsp"); * mScene.dofShader = shaderLoader.getShader("dof_shader.xsp"); * mScene.compositeShader = shaderLoader.getShader("composite.xsp"); * mScene.ssaoBlendShader = shaderLoader.getShader("ssao_blend.xsp"); * mScene.copycatShader = shaderLoader.getShader("backdrop.xsp"); * mScene.wipingShader = shaderLoader.getShader("sMapWipe.xsp"); * mScene.reflectionShader = shaderLoader.getShader("defReflections.xsp"); * mScene.lightBlurShader = shaderLoader.getShader("lightBlur.xsp"); */ // managed setup of shaders mScene.setupShaders(); // spawn the player player = new Player(mScene, new Vector3(0, 3, 10), new Vector3(0, 0, -1), gameInput); mScene.init(); mScene.sunLight.Parent = player; // load objects saved in database mScene.loadObjects(); state = GameState.Playing; } } }