// A cada frame é chamado depois do OnUpdateFrame, aqui é desenhado a cena. protected override void OnRenderFrame(FrameEventArgs e) { GL.ClearColor(0.2f, 0.3f, 0.3f, 1.0f); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Less); GL.DepthMask(true); GL.DepthRange(scene._camera._near, scene._camera._far); // Executando o postprocessing caso a tecla P tenha sido apertada no último frame if (executepostProcessing) { postProcessing.preparePostProcessing(); } GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); // Desenhando a cena. scene.Draw(); // Desenhando o skybox skybox.Draw(scene._camera); // Executando o postprocessing caso a tecla P tenha sido apertada no último frame if (executepostProcessing) { postProcessing.executePostProcessing(); } Context.SwapBuffers(); base.OnRenderFrame(e); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); Skybox.Draw(Camera.View, Camera.Projection, Matrix.CreateScale(1000)); base.Draw(gameTime); }
private void DrawSkybox(GameTime gameTime) { RasterizerState originalRasterizerState = graphics.GraphicsDevice.RasterizerState; RasterizerState rasterizerState = new RasterizerState(); rasterizerState.CullMode = CullMode.None; graphics.GraphicsDevice.RasterizerState = rasterizerState; skybox.Draw(camera.View, camera.Projection, camera.Position); graphics.GraphicsDevice.RasterizerState = originalRasterizerState; }
private void DrawSkybox() { RasterizerState originalRasterizerState = Graphics.GraphicsDevice.RasterizerState; RasterizerState rasterizerState = new RasterizerState(); rasterizerState.CullMode = CullMode.None; Graphics.GraphicsDevice.RasterizerState = rasterizerState; skybox.Draw(View, Projection, centerPosition); Graphics.GraphicsDevice.RasterizerState = originalRasterizerState; }
/// <summary> /// Draws the scene. /// </summary> /// <param name="spriteBatch">The spriteBatch.</param> /// <param name="gameTime">The GameTime.</param> public override void Draw(SpriteBatch spriteBatch, GameTime gameTime) { _skyBox.Draw(spriteBatch, gameTime); _entityComposer.Draw(spriteBatch, gameTime); if (!_debugDisplay.Visible) { _scoreBoard.Draw(spriteBatch, gameTime); } _minimap.Draw(spriteBatch, gameTime); _debugDisplay.Draw(spriteBatch, gameTime); _blackBlend.Draw(spriteBatch, gameTime); UIManager.Draw(spriteBatch, gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); skybox.Draw(camera.View, camera.Projection, Matrix.CreateScale(200.0f)); Matrix world = Matrix.CreateScale(10.0f) * Matrix.CreateTranslation(sphere.Position); DrawModel(ref model, ref world); base.Draw(gameTime); }
void DrawSkybox() { GraphicsDevice.Clear(Color.CornflowerBlue); RasterizerState originalRasterizerState = graphics.GraphicsDevice.RasterizerState; RasterizerState rasterizerState = new RasterizerState(); rasterizerState.CullMode = CullMode.None; graphics.GraphicsDevice.RasterizerState = rasterizerState; Vector3 cameraPosition = camera.GetWorldPosition(); skybox.Draw(Matrix.CreateLookAt(cameraPosition, player.Position, Vector3.UnitY), Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, 1f, 0.1f, 4000f), cameraPosition); graphics.GraphicsDevice.RasterizerState = originalRasterizerState; }
public void Render(Skybox sky) { if (sky != null) { //detect type of skybox if (sky is Skybox) { //PROCEDURAL SKYBOX //Draw the skybox //TODO: Draw the transition based on the rotation //TODO: Draw the stars based on the rotation sky.Draw(); } else if (sky is TexturedSkybox) { //TEXTURED CUBE SKYBOX //Get the camera orientation //Draw the visible faces sky.Draw(); } else if (sky is ColorSkybox) { //COLORED CUBE SKYBOX //Draw the skybox VoxelClient.Instance.GraphicsDevice.Clear(((ColorSkybox)sky).skycolor); } else { //Default to a black skybox VoxelClient.Instance.GraphicsDevice.Clear(Color.Black); } } }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); GraphicsDevice.BlendState = BlendState.Opaque; GraphicsDevice.DepthStencilState = new DepthStencilState(); RasterizerState ras = new RasterizerState(); ras.CullMode = CullMode.None; GraphicsDevice.RasterizerState = ras; skybox.Draw(view, projection, cameraPosition); base.Draw(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); skybox.Draw(camera.View, camera.Projection, Matrix.CreateScale(ArenaSize)); //Draw player DrawModel(ref sphere, ref player.World, player.Color); //Draw enemies for (int i = 0; i < MaxEnemies; i++) { Enemy enemy = enemies[i]; DrawModel(ref sphere, ref enemy.World, enemy.Color); } base.Draw(gameTime); }
/// <summary> /// Draws the Scene. /// </summary> /// <param name="spriteBatch">The spriteBatch.</param> /// <param name="gameTime">The GameTime.</param> public override void Draw(SpriteBatch spriteBatch, GameTime gameTime) { _skyBox.Draw(spriteBatch, gameTime); _fadeableText1.Draw(spriteBatch, gameTime); if (_fadeableText1.AnimationComplete) { _fadeableText2.Draw(spriteBatch, gameTime); if (_fadeableText2.AnimationComplete) { _fadeableText3.Draw(spriteBatch, gameTime); if (_fadeableText3.AnimationComplete) { _blackBlend.Draw(spriteBatch, gameTime); } } } }
public void Render(List <ViewEntity> entities, float time, ITransformation camera) { UpdateInstancing(entities); var arrTrans = new Dictionary <Enums.EntityType, Matrix4x4[]>(); foreach (var transform in _transforms) { arrTrans.Add(transform.Key, transform.Value.ToArray()); } _renderInstanceGroup.UpdateGeometry(arrTrans); _deferred.Draw(_renderState, camera, _instanceCounts, _textures, _normalMaps, _heightMaps, _intensities, _disableBackFaceCulling, time); _directShadowMap.Draw(_renderState, camera, _instanceCounts, _deferred.Depth, _lights[0].Direction, _disableBackFaceCulling, _deferred.Position, _deferred.Normal); _blurredShadowMap.Draw(_directShadowMap.Output); _environmentMap.CreateMap(entities[2], _renderState, 0, arrTrans, _instanceCounts, _textures, _normalMaps, _heightMaps, _intensities, _disableBackFaceCulling, _lights, camera, time); _environmentMap.Draw(_renderState, _deferred.Depth); _addEnvMap.Draw(_deferred.Color, _environmentMap.Output, 0.5f); _lighting.Draw(camera, _addEnvMap.Output, _deferred.Normal, _deferred.Position, _blurredShadowMap.Output, _deferred.IntensityMap, _lights); //_addProjectileColor.Draw(_deferred.ProjectileDepth, _deferred.Depth, _deferred.ProjectileColor, _lighting.Output, _deferred.ProjectileColor, _lighting.Output, _deferred.ProjectileColor, _lighting.Output, _deferred.ProjectileColor, _lighting.Output); _sphereCut.Draw(camera, _lighting.Output, _deferred.Depth); _skybox.Draw(camera); _addSkybox.Draw(_skybox.Output, _sphereCut.Output); if (Bloom) { _bloom.Draw(_addSkybox.Output); _ssaoWithBlur.Draw(_deferred.Depth, _bloom.Output); } else { _ssaoWithBlur.Draw(_deferred.Depth, _addSkybox.Output); } TextureDrawer.Draw(_ssaoWithBlur.Output); }
/// <summary> /// Se llama cada vez que hay que refrescar la pantalla. /// Escribir aquí todo el código referido al renderizado. /// </summary> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); //Finalmente invocamos al draw del modelo. RasterizerState originalRasterizerState = Graphics.GraphicsDevice.RasterizerState; RasterizerState rasterizerState = new RasterizerState(); rasterizerState.CullMode = CullMode.None; Graphics.GraphicsDevice.RasterizerState = rasterizerState; skybox.Draw(View, Projection, position); Graphics.GraphicsDevice.RasterizerState = originalRasterizerState; VenusModel.Draw(World * Matrix.CreateScale(.05f) * Matrix.CreateRotationY(VenusRotation) * Matrix.CreateTranslation(-5f, -2f, -10), View, Projection); // SpaceShipModel.Draw(World * Matrix.CreateScale(.8f) * Matrix.CreateRotationY(RotationY), View, Projection); SpaceShipModelMK1.Draw(World * //Matrix.CreateTranslation(0,-15f,0) * Matrix.CreateScale(.15f) * Matrix.CreateFromYawPitchRoll(Rotation.X, Rotation.Y, Rotation.Z) * // Rotation * Matrix.CreateTranslation(position) , View, Projection); SpaceShipModelMK2.Draw(World * Matrix.CreateScale(.08f) * Matrix.CreateRotationY(VenusRotation) * Matrix.CreateTranslation(4f, -2f, -10), View, Projection); SpaceShipModelMK3.Draw(World * Matrix.CreateScale(.08f) * Matrix.CreateRotationY(-VenusRotation) * Matrix.CreateTranslation(3f, 2f, -10), View, Projection); base.Draw(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); // Draw Skybox First GraphicsDevice.BlendState = BlendState.Opaque; GraphicsDevice.DepthStencilState = new DepthStencilState(); RasterizerState originalRasterizerState = graphics.GraphicsDevice.RasterizerState; RasterizerState ras = new RasterizerState(); ras.CullMode = CullMode.None; GraphicsDevice.RasterizerState = ras; skybox.Draw(view, projection, cameraPosition); //Draw 3D Helicopter graphics.GraphicsDevice.RasterizerState = originalRasterizerState; DrawModelWithEffect(); base.Draw(gameTime); }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear((Color.Azure)); plane.draw(gameTime, bCamera); var originalCullState = graphics.GraphicsDevice.RasterizerState; graphics.GraphicsDevice.RasterizerState = RasterizerState.CullNone; var originalBlendState = graphics.GraphicsDevice.BlendState; graphics.GraphicsDevice.BlendState = BlendState.AlphaBlend; var originalDepthStencilState = graphics.GraphicsDevice.DepthStencilState; var originalSamplerStates = graphics.GraphicsDevice.SamplerStates[0]; if (!PLANE.adjustMode) { skybox.Draw(bCamera.View, bCamera.Projection, PLANE.position); terrain.Draw(gameTime, graphics, bCamera); floor.Draw(gameTime, bCamera, 1f); for (int i = 0; i < 12; i++) { Clouds[i].Draw(gameTime, bCamera, 0.7f); } } if (!PLANE.adjustMode) { graphics.GraphicsDevice.BlendState = originalBlendState; graphics.GraphicsDevice.RasterizerState = originalCullState; spriteBatches.Draw(spriteBatch, PLANE.showWarning, PLANE.speedReached, PLANE.position.Y - 2, PLANE.velocity); graphics.GraphicsDevice.DepthStencilState = originalDepthStencilState; graphics.GraphicsDevice.SamplerStates[0] = originalSamplerStates; } base.Draw(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); Matrix world = Matrix.CreateRotationY(MathHelper.ToRadians( 270.0f * (float)gameTime.TotalGameTime.TotalSeconds)) * Matrix.CreateTranslation(new Vector3(0, 0, -4000)); DrawModel(ref model, ref world, greyAsteroid); world = Matrix.CreateRotationY(MathHelper.ToRadians( 45.0f * (float)gameTime.TotalGameTime.TotalSeconds)) * Matrix.CreateRotationZ(MathHelper.ToRadians( 45.0f * (float)gameTime.TotalGameTime.TotalSeconds)) * Matrix.CreateTranslation(new Vector3(0, 0, 4000)); DrawModel(ref model, ref world, originalAsteroid); world = Matrix.CreateScale(5000.0f); skybox.Draw(camera.View, camera.Projection, world); base.Draw(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.Black); //graphics.GraphicsDevice.RenderState.AlphaBlendEnable = false; //graphics.GraphicsDevice.RenderState.PointSpriteEnable = false; //graphics.GraphicsDevice.RenderState.DepthBufferWriteEnable = true; GraphicsDevice.BlendState = BlendState.Additive; GraphicsDevice.DepthStencilState = DepthStencilState.Default; laserScanner.View = camera.View; laserScanner.Projection = camera.Projection; skybox.Draw(camera.View, camera.Projection, Matrix.CreateScale(5000.0f)); Matrix world = Matrix.CreateRotationY( MathHelper.ToRadians(45.0f * (float)gameTime.TotalGameTime.TotalSeconds)) * Matrix.CreateTranslation(new Vector3(0, 0, -4000)); DrawModel(ref model, ref world, texture); base.Draw(gameTime); }
protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.Black); if (!hud.huntingSystem.active) { if (gameInMainMenu) { mainMenu.Draw(); } else if (mainMenu.ifIntro) { mainMenu.intro.Draw(); } else { RasterizerState originalRasterizerState = graphics.GraphicsDevice.RasterizerState; RasterizerState rasterizerState = new RasterizerState(); rasterizerState.CullMode = CullMode.None; graphics.GraphicsDevice.RasterizerState = rasterizerState; GraphicsDevice.SamplerStates[1] = SamplerState.LinearClamp; device.SetRenderTarget(renderTarget); device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0); foreach (Wolf w in wataha.wolves) { w.Draw(camera, "ShadowMap"); } foreach (Animal rabit in rabits) { rabit.Draw(camera, "ShadowMap"); } if (QuestSystem.currentQuest is SheepQuest) { foreach (Animal sheep in ((SheepQuest)QuestSystem.currentQuest).sheeps) { sheep.Draw(camera, "ShadowMap"); } } if (QuestSystem.currentQuest is FindToolsQuest) { foreach (GameObject tool in ((FindToolsQuest)QuestSystem.currentQuest).tools) { tool.Draw(camera, "ShadowMap"); } } foreach (QuestGiver q in QuestSystem.questGivers) { q.Draw(camera, "ShadowMap"); } trees.Draw(camera, "ShadowMap"); if (!(QuestSystem.questGivers[1].actualQuest == null && QuestSystem.questGivers[1].questCompleted.Count == QuestSystem.questGivers[1].questsList.Count)) { blockade.Draw(camera, "ShadowMap"); } blockade2.Draw(camera, "ShadowMap"); croft.Draw(camera, "ShadowMap"); barrell.Draw(camera, "ShadowMap"); device.SetRenderTarget(null); foreach (Wolf w in wataha.wolves) { w.shadowMap = (Texture2D)renderTarget; } foreach (Animal rabit in rabits) { rabit.shadowMap = (Texture2D)renderTarget; } if (QuestSystem.currentQuest is SheepQuest) { foreach (Animal sheep in ((SheepQuest)QuestSystem.currentQuest).sheeps) { sheep.shadowMap = (Texture2D)renderTarget; } } if (QuestSystem.currentQuest is FindToolsQuest) { foreach (GameObject tool in ((FindToolsQuest)QuestSystem.currentQuest).tools) { tool.shadowMap = (Texture2D)renderTarget; } } foreach (QuestGiver q in QuestSystem.questGivers) { q.shadowMap = (Texture2D)renderTarget; } trees.shadowMap = (Texture2D)renderTarget; blockade.shadowMap = (Texture2D)renderTarget; blockade2.shadowMap = (Texture2D)renderTarget; croft.shadowMap = (Texture2D)renderTarget; barrell.shadowMap = (Texture2D)renderTarget; device.SetRenderTarget(renderTarget2); device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0); device.BlendState = BlendState.AlphaBlend; foreach (Wolf w in wataha.wolves) { w.Draw(camera, "ShadowedScene"); } foreach (Animal rabit in rabits) { rabit.Draw(camera, "ShadowedScene"); } if (QuestSystem.currentQuest is SheepQuest) { foreach (Animal sheep in ((SheepQuest)QuestSystem.currentQuest).sheeps) { sheep.Draw(camera, "ShadowedScene"); } } if (QuestSystem.currentQuest is FindToolsQuest) { foreach (GameObject tool in ((FindToolsQuest)QuestSystem.currentQuest).tools) { tool.Draw(camera, "ShadowedScene"); } } foreach (QuestGiver q in QuestSystem.questGivers) { q.Draw(camera, "ShadowedScene"); } trees.Draw(camera, "ShadowedScene"); if (!(QuestSystem.questGivers[1].actualQuest == null && QuestSystem.questGivers[1].questCompleted.Count == QuestSystem.questGivers[1].questsList.Count)) { blockade.Draw(camera, "ShadowedScene"); } blockade2.Draw(camera, "ShadowedScene"); croft.Draw(camera, "ShadowedScene"); barrell.Draw(camera, "ShadowedScene"); device.BlendState = BlendState.Opaque; skybox.Draw(camera); reflekt.DrawModelWithEffect(camera.View, camera.Projection, camera); foreach (QuestGiver q in QuestSystem.questGivers) { q.shadowMap = null; } foreach (Wolf w in wataha.wolves) { w.shadowMap = null; } foreach (Animal rabit in rabits) { rabit.shadowMap = null; } if (QuestSystem.currentQuest is SheepQuest) { foreach (Animal sheep in ((SheepQuest)QuestSystem.currentQuest).sheeps) { sheep.shadowMap = null; } } if (QuestSystem.currentQuest is FindToolsQuest) { foreach (GameObject tool in ((FindToolsQuest)QuestSystem.currentQuest).tools) { tool.shadowMap = null; } } trees.shadowMap = null; blockade.shadowMap = null; blockade2.shadowMap = null; croft.shadowMap = null; barrell.shadowMap = null; graphics.GraphicsDevice.RasterizerState = originalRasterizerState; billboardTest.Draw(camera.View, camera.Projection, wolf.cam.up, camera.right); billboardTest2.Draw(camera.View, camera.Projection, wolf.cam.up, camera.right); ps.Draw(camera.View, camera.Projection, wolf.cam.up, wolf.cam.right); hud.Draw(); device.SetRenderTarget(null); GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, Content.Load <Effect>("Effects/post")); spriteBatch.Draw(renderTarget2, new Rectangle(0, 0, device.PresentationParameters.BackBufferWidth, device.PresentationParameters.BackBufferHeight), Color.White); spriteBatch.End(); } } else { hud.huntingSystem.Draw(); } base.Draw(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.DepthStencilState.DepthBufferEnable = true; GraphicsDevice.DepthStencilState.DepthBufferWriteEnable = true; GraphicsDevice.DepthStencilState = new DepthStencilState(); // TODO: Add your drawing code here switch (currentState) { case GameState.Menu: GraphicsDevice.Clear(Color.Violet); break; case GameState.Play: GraphicsDevice.Clear(Color.Gray); break; case GameState.Pause: GraphicsDevice.Clear(Color.Gray); break; case GameState.End: GraphicsDevice.Clear(Color.Red); break; default: // something weird happened break; } if (currentState == GameState.Pause) { states[GameState.Play].Draw(gameTime, cameras[curCamera]); states[currentState].Draw(gameTime, cameras[curCamera]); foreach (Cannonball b in cannonballs) { b.Draw(gameTime, cameras[curCamera]); } } if (currentState.Equals(GameState.Play)) { states[currentState].Draw(gameTime, cameras[curCamera]); foreach (Cannonball b in cannonballs) { b.Draw(gameTime, cameras[curCamera]); } } else { states[currentState].Draw(gameTime, cameras[curCamera]); } skybox.Draw(cameras[curCamera].View, cameras[curCamera].Projection, cameras[curCamera].Position); graphics.GraphicsDevice.RasterizerState = new RasterizerState(); // end of 3D Drawing // start 2D Drawing spriteBatch.Begin(); states[currentState].Draw(gameTime, spriteBatch); if (currentState == GameState.Pause) { spriteBatch.DrawString(segoeFont, "GAME PAUSED", new Vector2(10, 20), Color.Black); spriteBatch.DrawString(segoeFont, "Money Left: $" + score + ".00", new Vector2(200, 20), Color.Black); Color timeColor = (gameClock.TimeLeft <= 10) ? Color.Red : Color.Black; spriteBatch.DrawString(segoeFont, "Time Left: " + gameClock.TimeLeft + " Seconds", new Vector2(200, 40), timeColor); } if (currentState == GameState.Info) { spriteBatch.DrawString(segoeFont, "How to play", new Vector2(220, 60), Color.Black); spriteBatch.DrawString(segoeFont, "Use the arrow keys to look around", new Vector2(220, 80), Color.Black); spriteBatch.DrawString(segoeFont, "Press the tab key to switch cameras", new Vector2(220, 100), Color.Black); spriteBatch.DrawString(segoeFont, "Hold the space bar to charge the cannon", new Vector2(220, 120), Color.Black); spriteBatch.DrawString(segoeFont, "realse to fire", new Vector2(220, 140), Color.Black); spriteBatch.DrawString(segoeFont, "Destroy the buildings before time runs out", new Vector2(220, 160), Color.Black); spriteBatch.DrawString(segoeFont, "Press M to Mute the music", new Vector2(220, 180), Color.Black); } if (currentState == GameState.End) { spriteBatch.DrawString(segoeFont, "GAME OVER", new Vector2(200, 0), Color.Black); spriteBatch.DrawString(segoeFont, "Money Left: $" + score + ".00", new Vector2(200, 20), Color.Black); spriteBatch.DrawString(segoeFont, " Head Designer: Jesse McIntosh" + "\n\n Head Programmer: Jordan Nguyen" + "\n\n Special Thanks:" + "\n Ravi Kamath" + "\n Ken Perlin", new Vector2(200, 80), Color.Black); } if (currentState == GameState.Menu) { spriteBatch.DrawString(segoeFont, "Block Busters!", new Vector2(15, 5), Color.Black); spriteBatch.DrawString(segoeFont, "Captain Jack Sparrowbeard was growing tired" + "\n of his life of piracy. Having grown weary of the seas he had his " + "\n ship broken down for salvage, and sold all but one of his cannons. " + "\n He is now a de-construction worker for hire that builders contract " + "\n out to go from town to town to destroy nasty condemned buildings. " + "\n The faster Captain Jack destroys the buildings the more money" + "\n they give him. If he uses too many cannonballs though the " + "\n building destruction venture may end up costing him more than " + "\n he gets paid.", new Vector2(0, 150), Color.Black); } if (currentState == GameState.Play) { spriteBatch.DrawString(segoeFont, "Money Left: $" + score + ".00", new Vector2(200, 20), Color.Black); Color timeColor = (gameClock.TimeLeft <= 10) ? Color.Red : Color.Black; spriteBatch.DrawString(segoeFont, "Time Left: " + gameClock.TimeLeft + " Seconds", new Vector2(200, 40), timeColor); spriteBatch.DrawString(segoeFont, "Cannon Power", new Vector2(0, 410), Color.Black); } spriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); // TODO: Add your drawing code here switch (effectType) { case EffectType.Default: DrawModel(model, world, view, projection); break; case EffectType.Ambient: DrawModelWithAmbientEffect(model, world, view, projection); break; case EffectType.Diffuse: DrawModelWithDiffuseEffect(model, world, view, projection); break; case EffectType.Specular: DrawModelWithSpecularEffect(model, world, view, projection); break; case EffectType.Textured: DrawModelWithTexturedEffect(model, world, view, projection); break; case EffectType.GrayScale: DrawModelWithGrayScaleEffect(model, world, view, projection); break; case EffectType.BumpMap: DrawModelWithBumpMapEffect(model, world, view, projection); break; case EffectType.SkyBox: RasterizerState originalRasterizerState = graphics.GraphicsDevice.RasterizerState; RasterizerState rasterizerState = new RasterizerState(); rasterizerState.CullMode = CullMode.None; graphics.GraphicsDevice.RasterizerState = rasterizerState; skybox.Draw(view, projection, cameraLocation); graphics.GraphicsDevice.RasterizerState = originalRasterizerState; DrawModelWithTexturedEffect(model, world, view, projection); break; case EffectType.Reflection: RasterizerState rOriginalRasterizerState = graphics.GraphicsDevice.RasterizerState; RasterizerState rRasterizerState = new RasterizerState(); rRasterizerState.CullMode = CullMode.None; graphics.GraphicsDevice.RasterizerState = rRasterizerState; skybox.Draw(view, projection, cameraLocation); graphics.GraphicsDevice.RasterizerState = rOriginalRasterizerState; DrawModelWithReflectionEffect(model, world, view, projection); break; case EffectType.Transparency: RasterizerState tOriginalRasterizerState = graphics.GraphicsDevice.RasterizerState; RasterizerState tRasterizerState = new RasterizerState(); tRasterizerState.CullMode = CullMode.None; graphics.GraphicsDevice.RasterizerState = tRasterizerState; skybox.Draw(view, projection, cameraLocation); graphics.GraphicsDevice.RasterizerState = tOriginalRasterizerState; graphics.GraphicsDevice.BlendState = BlendState.AlphaBlend; DrawModelWithTransparencyEffect(model, world, view, projection); graphics.GraphicsDevice.BlendState = BlendState.Opaque; break; } hudManager.Draw(gameTime); base.Draw(gameTime); }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); Camera.Draw(gameTime, null, ref view, ref proj); GraphicsDevice.BlendFactor = new Color(255, 255, 255, 255); GraphicsDevice.BlendState = BlendState.Opaque; GraphicsDevice.DepthStencilState = DepthStencilState.Default; GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; GraphicsDevice.SamplerStates[0] = SamplerState.PointWrap; GraphicsDevice.SetRenderTarget(RenderTargetMap); GraphicsDevice.Clear(Color.Transparent); MapVisible.DrawMeshWithoutPart(0, 3, Camera.CameraFrustum, ref view, ref proj); NonEuclideanRenderFunctions.DrawPlane(GraphicsDevice, illusion2plane, ref view, ref proj); NonEuclideanRenderFunctions.DrawPlane(GraphicsDevice, illusion3plane, ref view, ref proj); Teapot.Position = new Vector3(4.32f, 0.76f, -6.73f); Teapot.Draw(ref view, ref proj); Teapot.Position = new Vector3(-10.764509f, 0f, -19.796597f); Teapot.Draw(ref view, ref proj); Cup.Position = new Vector3(-6.42751f, 0f, -20.183052f); Cup.Draw(ref view, ref proj); for (int i = 0; i < 30; i++) { StairsVisible.Draw(ref view, ref proj); StairsVisible.Position.Y += 5.36f; } StairsVisible.Position.Y = 5.36f; GraphicsDevice.SetRenderTarget(NonEuclideanRenders[0]); GraphicsDevice.Clear(Color.Transparent); Teapot.Position = new Vector3(4.32f, 0.17f, -6.73f); Teapot.Draw(ref view, ref proj); GraphicsDevice.SetRenderTarget(NonEuclideanRenders[1]); GraphicsDevice.Clear(Color.Transparent); RoomIllusion1.DrawMeshWithoutPart(0, 3, Camera.CameraFrustum, ref view, ref proj); GraphicsDevice.SetRenderTarget(null); Skybox.Draw(gameTime, Camera.CameraFrustum, ref view, ref proj); _spriteBatch.Begin(); _spriteBatch.Draw(NonEuclideanRenders[1], new Rectangle(0, 0, 800, 480), Color.White); _spriteBatch.Draw(RenderTargetMap, new Rectangle(0, 0, 800, 480), Color.White); if (_illusion_visible) { /* * Vector3 p = Vector3.Transform(new Vector3(3.96f, 0.71f, -6.12f), view *proj); * Vector3 p2 = Vector3.Transform(new Vector3(4.67f, 0.17f, -6.12f), view * proj); * * p += Vector3.One; * p *= 0.5f; * p2 += Vector3.One; * p2 *= 0.5f; * p.X *= 800; * p2.X *= 800; * * p.Y *= 480; * p2.Y *= 480; * * _spriteBatch.Draw(NonEuclideanRenders[0], * new Rectangle((int)p.X, 0,(int) p2.X, 480), * new Rectangle((int)p.X, 0,(int) p2.X, 480), Color.White); ; * if(allowdebugging) Debugger.Break(); * _spriteBatch.DrawString(DefaultFont, "Second demonstration visible", new Vector2(10, 460), Color.White); */ } _spriteBatch.DrawString(DefaultFont, "DEBUG: Position = " + Camera.Position, Vector2.One, Color.Black); _spriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// Primary draw method. /// </summary> /// <param name="gameTime">Handeled by the framework, the passage of time is updated automagically.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); _skybox.Draw(_camera.View, _camera.Projection, _camera.Position); foreach (BasicModel model in _models) { if (_camera.BoundingVolumeIsInView(model.BoundingSphere)) { model.Draw(_camera.View, _camera.Projection, _camera.Position); } } _lineDrawer.Begin(_camera.View, _camera.Projection); _lineDrawer.DrawHexagonGrid(Vector2.One * -9930, (new Vector2(80, 40)), 200, Color.Red); _lineDrawer.DrawLine(_models[0].Position, new Vector3(_models[0].Position.X, 0, _models[0].Position.Z), Color.CornflowerBlue); ShipMovement.DrawHeading(); ShipMovement.DrawMarker(); _lineDrawer.End(); _stars.Draw(_camera.View, _camera.Projection, _camera.Up, _camera.Right); // if rendered card buffer is null, initialize it here if (_renderedCardBuffer == null) { // Choosing a random card for testing... Random r = new Random(); //Card c = _cards[r.Next(_cards.Count)]; Card c = null; foreach (Card cx in _cards) { if (cx.Title == "Patrol Drone") //if (_rulesTextFont.MeasureString(WrapText(_rulesTextFont, cx.RulesText, _cardRulesWidth)).Y > _cardRulesHeight) { c = cx; //Debug.WriteLine("{0}", _rulesTextFont.MeasureString(WrapText(_rulesTextFont, cx.RulesText, _cardRulesWidth)).Y - _cardRulesHeight); break; } } string someRandomText = c.RulesText; someRandomText = WrapText(_rulesTextFont, someRandomText, _cardRulesWidth); Vector2 textSize = _rulesTextFont.MeasureString(someRandomText); string titleString = c.Title; Vector2 titleSize = _titleFont.MeasureString(titleString); string typeString = c.Supertype.ToString(); string subtypeString = c.Subtype.ToString(); if (subtypeString != "None") { typeString = typeString + " - " + c.Subtype.ToString(); } Vector2 typeSize = _typeFont.MeasureString(typeString); string costString = (c.EnergyCostType == AmountType.Variable) ? Description.ToDescription(c.EnergyCostVar).Replace("+", string.Empty) : c.EnergyCost.ToString(); Vector2 costSize = _statFont.MeasureString(costString); Rectangle cardRect = new Rectangle( 0, 0, _cardTexture.Width, _cardTexture.Height); float titleScale = 1; if (titleSize.X > _cardTitleWidth) { titleScale = _cardTitleWidth / titleSize.X; } float typeScale = 1; if (typeSize.X > _cardTypeWidth) { typeScale = _cardTypeWidth / typeSize.X; } float costScale = 1; if (costSize.X > _cardCostWidth) { costScale = _cardCostWidth / costSize.X; } // render the title text's shadow RenderTarget2D titleShadowTarget = new RenderTarget2D(GraphicsDevice, _cardTitleWidth, _cardTitleHeight, false, GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24); GraphicsDevice.SetRenderTarget(titleShadowTarget); GraphicsDevice.Clear(Color.Transparent); _spriteBatch.Begin(); _spriteBatch.DrawString(_titleFont, titleString, new Vector2((int)((_cardTitleWidth - titleSize.X * titleScale) / 2), (int)((_cardTitleHeight - titleSize.Y * titleScale) / 2)), Color.White, 0, Vector2.Zero, titleScale, SpriteEffects.None, 0); _spriteBatch.End(); // do blur GaussianBlur gaussianBlur = new GaussianBlur(this); gaussianBlur.ComputeKernel(4, 2); int renderTargetWidth = titleShadowTarget.Width / 2; int renderTargetHeight = titleShadowTarget.Height / 2; RenderTarget2D rt1 = new RenderTarget2D(GraphicsDevice, renderTargetWidth, renderTargetHeight, false, GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.None); RenderTarget2D rt2 = new RenderTarget2D(GraphicsDevice, renderTargetWidth, renderTargetHeight, false, GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.None); gaussianBlur.ComputeOffsets(renderTargetWidth, renderTargetHeight); Texture2D titleShadowResult = gaussianBlur.PerformGaussianBlur(titleShadowTarget, rt1, rt2, _spriteBatch); // render the type text's shadow RenderTarget2D typeShadowTarget = new RenderTarget2D(GraphicsDevice, _cardTypeWidth, _cardTypeHeight, false, GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24); GraphicsDevice.SetRenderTarget(typeShadowTarget); GraphicsDevice.Clear(Color.Transparent); _spriteBatch.Begin(); _spriteBatch.DrawString(_typeFont, typeString, new Vector2((int)((_cardTypeWidth - typeSize.X * typeScale) / 2), (int)((_cardTypeHeight - typeSize.Y * typeScale) / 2)), Color.White, 0, Vector2.Zero, typeScale, SpriteEffects.None, 0); _spriteBatch.End(); // do blur renderTargetWidth = typeShadowTarget.Width / 2; renderTargetHeight = typeShadowTarget.Height / 2; rt1 = new RenderTarget2D(GraphicsDevice, renderTargetWidth, renderTargetHeight, false, GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.None); rt2 = new RenderTarget2D(GraphicsDevice, renderTargetWidth, renderTargetHeight, false, GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.None); gaussianBlur.ComputeOffsets(renderTargetWidth, renderTargetHeight); Texture2D typeShadowResult = gaussianBlur.PerformGaussianBlur(typeShadowTarget, rt1, rt2, _spriteBatch); // render the card _renderedCardBuffer = new RenderTarget2D(GraphicsDevice, _cardTexture.Width, _cardTexture.Height, false, GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24); GraphicsDevice.SetRenderTarget(_renderedCardBuffer); GraphicsDevice.Clear(Color.Transparent); _spriteBatch.Begin(); _spriteBatch.Draw(_cardTexture, cardRect, Color.White); _spriteBatch.DrawString(_rulesTextFont, someRandomText, new Vector2(_cardRulesLeftX, (int)(_cardRulesTopY + (_cardRulesHeight - textSize.Y) / 2)), Color.Black, 0, Vector2.Zero, 1, SpriteEffects.None, 0); _spriteBatch.Draw(titleShadowResult, new Rectangle((int)(_cardTitleLeftX + (_cardTitleWidth - titleShadowResult.Width * 2) / 2), (int)(_cardTitleTopY + (_cardTitleHeight - titleShadowResult.Height * 2) / 2), titleShadowResult.Width * 2, titleShadowResult.Height * 2), new Rectangle(0, 0, titleShadowResult.Width, titleShadowResult.Height), Color.White); _spriteBatch.Draw(typeShadowResult, new Rectangle((int)(_cardTypeLeftX + (_cardTypeWidth - typeShadowResult.Width * 2) / 2), (int)(_cardTypeTopY + (_cardTypeHeight - typeShadowResult.Height * 2) / 2), typeShadowResult.Width * 2, typeShadowResult.Height * 2), new Rectangle(0, 0, typeShadowResult.Width, typeShadowResult.Height), Color.White); _spriteBatch.DrawString(_titleFont, titleString, new Vector2((int)(_cardTitleLeftX + (_cardTitleWidth - titleSize.X * titleScale) / 2), (int)(_cardTitleTopY + (_cardTitleHeight - titleSize.Y * titleScale) / 2)), Color.Black, 0, Vector2.Zero, titleScale, SpriteEffects.None, 0); _spriteBatch.DrawString(_typeFont, typeString, new Vector2((int)(_cardTypeLeftX + (_cardTypeWidth - typeSize.X * typeScale) / 2), (int)(_cardTypeTopY + (_cardTypeHeight - typeSize.Y * typeScale) / 2)), Color.Black, 0, Vector2.Zero, typeScale, SpriteEffects.None, 0); _spriteBatch.DrawString(_statFont, costString, new Vector2((int)(_cardCostLeftX + (_cardCostWidth - costSize.X * costScale) / 2), (int)(_cardCostTopY + (_cardCostHeight - costSize.Y * costScale) / 2)), Color.Black, 0, Vector2.Zero, costScale, SpriteEffects.None, 0); _spriteBatch.End(); GraphicsDevice.SetRenderTarget(null); } // Draw cards *this should always appear at the end so its on top _spriteBatch.Begin(); float scale = .4f; // Note: this is arbitrary rules text for testing... Rectangle retval = new Rectangle( 0 + 10, GraphicsDevice.Viewport.Height - (int)(_cardTexture.Height * scale) - 10, (int)(_cardTexture.Width * scale), (int)(_cardTexture.Height * scale)); _spriteBatch.Draw(_renderedCardBuffer, retval, Color.White); _spriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); // Draw Skybox First GraphicsDevice.BlendState = BlendState.Opaque; GraphicsDevice.DepthStencilState = new DepthStencilState(); RasterizerState originalRasterizerState = graphics.GraphicsDevice.RasterizerState; RasterizerState ras = new RasterizerState(); ras.CullMode = CullMode.None; GraphicsDevice.RasterizerState = ras; if (skyboxID == 0) { string[] skyboxTextures = { "Colors/black", "Colors/white", "Colors/blue", "Colors/Red", "Colors/green", "Colors/orange", }; skybox = new Skybox(skyboxTextures, Content, GraphicsDevice); } else if (skyboxID == 1) { string[] skyboxTextures = { "Room/posx", "Room/negx", "Room/posy", "Room/negy", "Room/posz", "Room/negz", }; skybox = new Skybox(skyboxTextures, Content, GraphicsDevice); } else if (skyboxID == 2) { string[] skyboxTextures = { "Daytime/DaytimeX", "Daytime/Daytime-X", "Daytime/DaytimeY", "Daytime/Daytime-Y", "Daytime/DaytimeZ", "Daytime/Daytime-Z", }; skybox = new Skybox(skyboxTextures, Content, GraphicsDevice); } else if (skyboxID == 3) { string[] skyboxTextures = { "Forest/forestX", "Forest/forest-X", "Forest/forestY", "Forest/forest-Y", "Forest/forestZ", "Forest/forest-Z", }; skybox = new Skybox(skyboxTextures, Content, GraphicsDevice); } //string[] skyboxTextures = //{ // "Room/posx", "Room/negx", // "Room/posy", "Room/negy", // "Room/posz", "Room/negz", //}; skybox.Draw(view, projection, cameraPosition); //Draw 3D Helicopter graphics.GraphicsDevice.RasterizerState = originalRasterizerState; DrawModelWithEffect(); spriteBatch.Begin(); if (showMenu) { showHelp(); } if (showValue) { showInfo(); } spriteBatch.End(); base.Draw(gameTime); }