/// <summary> /// Renders this segment to an image buffer to speed up rendering. /// </summary> public void PreRenderSegment() { // Create an image to render to and set it as the render target. _preRenderedImage = new Image(_width * 16, _height * 16, ImageFlags.Dynamic); IRenderTarget previousTarget = GraphicsManager.RenderTarget; GraphicsManager.RenderTarget = (IRenderTarget)_preRenderedImage[0]; GraphicsManager.BeginScene(); GraphicsManager.ClearColor = unchecked ((int)0xFFFF00FF); GraphicsManager.ClearScene(); // Go through each tile and render it to this image. for (int tileX = 0; tileX < _width; tileX++) { for (int tileY = 0; tileY < _height; tileY++) { if (_tileData[tileX, tileY] == null) { continue; } _tileData[tileX, tileY].Render(new Transformation(0, 0, 0, 0, 0, 0, 1, 1, 1), null, 0); } } // Go back to rendering on the window. GraphicsManager.FinishScene(); GraphicsManager.PresentScene(); GraphicsManager.RenderTarget = previousTarget; }
/// <summary> /// Renders a preview of the image to the preview panel. /// </summary> private void RenderPreview() { if (Visible == false) { return; } lock (_imageLock) { IRenderTarget previousTarget = GraphicsManager.RenderTarget; GraphicsManager.RenderTarget = _canvas; GraphicsManager.Viewport = new Rectangle(0, 0, previewPanel.Width, previewPanel.Height); GraphicsManager.SetResolution(previewPanel.Width, previewPanel.Height, false); GraphicsManager.BeginScene(); GraphicsManager.ClearColor = unchecked ((int)0xFFD3D3D3); GraphicsManager.VertexColors.AllVertexs = unchecked ((int)0xFFFFFFFF); GraphicsManager.ClearScene(); if (_reloadImage == true) { ReloadImage(); _reloadImage = false; } if (_image != null) { int imageX = (int)((GraphicsManager.Viewport.Width / 2.0f) - (_image.Width / 2.0f)); int imageY = (int)((GraphicsManager.Viewport.Height / 2.0f) - (_image.Height / 2.0f)); int cellWidth = (int)cellWidthBox.Value; int cellHeight = (int)cellHeightBox.Value; int cellSpacingX = (int)cellSpaceXBox.Value; int cellSpacingY = (int)cellSpaceYBox.Value; GraphicsManager.VertexColors.AllVertexs = unchecked ((int)0xFFFFFFFF); GraphicsManager.RenderImage(_image, imageX, imageY, 0); if (cellWidth != 0 && cellHeight != 0) { GraphicsManager.BlendMode = BlendMode.Invert; GraphicsManager.VertexColors.AllVertexs = unchecked ((int)0xFF666666); int cellsH = (_image.Width / (cellWidth + cellSpacingX)); int cellsV = (_image.Height / (cellHeight + cellSpacingY)); for (int i = 0; i < (cellsH * cellsV); i++) { int px = (i % cellsH) * cellWidth; int py = (i / cellsH) * cellHeight; GraphicsManager.RenderDashedRectangle(imageX + px + ((i % cellsH) * cellSpacingX), imageY + py + ((i / cellsH) * cellSpacingY), 0, cellWidth, cellHeight, 1); } GraphicsManager.BlendMode = BlendMode.Alpha; GraphicsManager.VertexColors.AllVertexs = unchecked ((int)0xFFFFFFFF); } } else if (_loadImageThread != null) { GraphicsManager.RenderText("Loading...", 5, 5, 0); } GraphicsManager.FinishScene(); GraphicsManager.PresentScene(); GraphicsManager.RenderTarget = previousTarget; } }
/// <summary> /// Renders a preview of the image to the preview panel. /// </summary> private void RenderPreview() { if (Visible == false) { return; } lock (_fontLock) { IRenderTarget previousTarget = GraphicsManager.RenderTarget; GraphicsManager.RenderTarget = _canvas; GraphicsManager.BeginScene(); GraphicsManager.ClearColor = unchecked ((int)0xFFD3D3D3); GraphicsManager.VertexColors.AllVertexs = unchecked ((int)0xFFFFFFFF); GraphicsManager.ClearScene(); if (_fontImage != null) { int imageX = (int)((GraphicsManager.Viewport.Width / 2.0f) - (_fontImage.Width / 2.0f)); int imageY = (int)((GraphicsManager.Viewport.Height / 2.0f) - (_fontImage.Height / 2.0f)); GraphicsManager.VertexColors.AllVertexs = unchecked ((int)0xFFFFFFFF); GraphicsManager.RenderImage(_fontImage, imageX, imageY, 0); } else if (_loadFontThread != null) { GraphicsManager.RenderText("Loading...", 5, 5, 0); } GraphicsManager.FinishScene(); GraphicsManager.PresentScene(); GraphicsManager.RenderTarget = previousTarget; } }
protected override void OnPaint(PaintEventArgs e) { //e.Graphics.Clear(this.BackColor); if (Manager.Room != null) { // Clear the screen. GraphicsManager.DrawClear(this.BackColor); // Begin drawing the scene. GraphicsManager.BeginScene(); DrawBackground(); //GraphicsManager.DrawRectangle(new Rectangle(Offset.X, Offset.Y, Math.Min(Manager.Room.Width, this.Width) + 1, Math.Min(Manager.Room.Height, this.Height) + 1), Color.Orange, false); GraphicsManager.Scissor = new Rectangle(0, 0, this.Width, this.Height); // draw instances DrawInstances(); // draw grid and higlights DrawGrid(); OpenGL.glTexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR); if (_drawMousePosition) { drawRectangleAroundMouseOnGrid(new Rectangle(_mouseX, _mouseY, _gridX / _zoom, _gridY / _zoom)); } // Disable scissor testing. OpenGL.glDisable(GLOption.ScissorTest); // End drawing the scene. GraphicsManager.EndScene(); //e.Graphics.Clear(this.BackColor); //foreach (PlaceableInstance instance in Manager.Room.Instances) //{ // e.Graphics.DrawString( pointDistance(instance.XCenter, instance.YCenter, _mx, _my).ToString(), Manager.MainWindow.Font, Brushes.Black, instance.X, instance.Y); //} } else { e.Graphics.Clear(this.BackColor); } }
/// <summary> /// Invoked when the canvas needs to be rendered. /// </summary> public void Render() { if (Visible == false) { return; } GraphicsManager.RenderTarget = (IRenderTarget)_canvas; GraphicsManager.BeginScene(); GraphicsManager.ClearColor = unchecked ((int)0xFFACACAC); GraphicsManager.ClearScene(); GraphicsManager.VertexColors.AllVertexs = _color; if (_tileset != null) { // Work out the offset based on the slider values. int hOffset = -(tilesetHScrollBar.Value * (_tileset.Image.Width + _tileset.Image.HorizontalSpacing)); int vOffset = -(tilesetVScrollBar.Value * (_tileset.Image.Height + _tileset.Image.VerticalSpacing)); // Render the current tileset. GraphicsManager.VertexColors.AllVertexs = _color; GraphicsManager.RenderImage(_tileset.FullImage, hOffset, vOffset, 0, 0); GraphicsManager.DepthBufferEnabled = false; // Render the selection cursor to if something has been selected. if (_selectedTiles == true || _selectingTiles == true) { int x = ((_selection.X) * (_tileset.Image.Width + _tileset.Image.HorizontalSpacing)) + hOffset; int y = ((_selection.Y) * (_tileset.Image.Height + _tileset.Image.VerticalSpacing)) + vOffset; int w = (_selection.Width * (_tileset.Image.Width + _tileset.Image.HorizontalSpacing)); int h = (_selection.Height * (_tileset.Image.Height + _tileset.Image.VerticalSpacing)); GraphicsManager.VertexColors.AllVertexs = unchecked ((int)0xFFFFFFFF); GraphicsManager.RenderRectangle(x, y, 0, w, h, false); GraphicsManager.RenderRectangle(x + 2, y + 2, 0, w - 4, h - 4, false); GraphicsManager.VertexColors.AllVertexs = unchecked ((int)0xFFFF0000); GraphicsManager.RenderRectangle(x + 1, y + 1, 0, w - 2, h - 2, false); GraphicsManager.VertexColors.AllVertexs = unchecked ((int)0x6600AAFF); GraphicsManager.RenderRectangle(x + 3, y + 3, 0, w - 6, h - 6, true); } // Render the tile cursor. int mouseX = Input.InputManager.MouseX, mouseY = Input.InputManager.MouseY; bool mouseInPanel = !(mouseX <0 || mouseY <0 || mouseX> canvasPanel.ClientSize.Width || mouseY> canvasPanel.ClientSize.Height); int tileX = (mouseX / (_tileset.Image.Width + _tileset.Image.HorizontalSpacing)) + tilesetHScrollBar.Value; int tileY = (mouseY / (_tileset.Image.Height + _tileset.Image.VerticalSpacing)) + tilesetVScrollBar.Value; int rx = (tileX * _tileset.Image.Width) + hOffset + (_tileset.Image.HorizontalSpacing * tileX); int ry = (tileY * _tileset.Image.Height) + vOffset + (_tileset.Image.VerticalSpacing * tileY); int rw = _tileset.Image.Width; int rh = _tileset.Image.Height; GraphicsManager.VertexColors.AllVertexs = unchecked ((int)0xFFFFFFFF); GraphicsManager.RenderRectangle(rx, ry, 0, rw, rh, false); GraphicsManager.RenderRectangle(rx + 2, ry + 2, 0, rw - 4, rh - 4, false); GraphicsManager.VertexColors.AllVertexs = unchecked ((int)0xFFFF0000); GraphicsManager.RenderRectangle(rx + 1, ry + 1, 0, rw - 2, rh - 2, false); } GraphicsManager.FinishScene(); GraphicsManager.PresentScene(); GraphicsManager.RenderTarget = null; }
public void BeginScene(ScriptThread thread) { GraphicsManager.BeginScene(); }
/// <summary> /// Called when the preview panel needs rendering. /// </summary> private void Render() { if (Visible == false) { return; } IRenderTarget previousRenderTarget = GraphicsManager.RenderTarget; // Render the preview. GraphicsManager.RenderTarget = _canvas; GraphicsManager.BeginScene(); GraphicsManager.ClearColor = unchecked ((int)0xFFACACAC); GraphicsManager.VertexColors.AllVertexs = unchecked ((int)0xFFFFFFFF); GraphicsManager.SetResolution(previewPanel.ClientSize.Width, previewPanel.ClientSize.Height, false); GraphicsManager.Viewport = new Rectangle(0, 0, previewPanel.ClientSize.Width, previewPanel.ClientSize.Height); GraphicsManager.ClearScene(); // Render the origin. if (_showOrigin == true) { GraphicsManager.VertexColors.AllVertexs = unchecked ((int)0xFFFFFFFF); GraphicsManager.RenderLine(0, _cameraTransformation.Y + (_canvas.RenderControl.ClientSize.Height / 2), 0, _canvas.RenderControl.ClientSize.Width, _cameraTransformation.Y + (_canvas.RenderControl.ClientSize.Height / 2), 0); GraphicsManager.RenderLine(_cameraTransformation.X + (_canvas.RenderControl.ClientSize.Width / 2), 0, 0, _cameraTransformation.X + (_canvas.RenderControl.ClientSize.Width / 2), _canvas.RenderControl.ClientSize.Height, 0); } // Render the emitter node in the middle. if (_emitterNode != null) { _emitterNode.Think(1.0f); // Allow it some thinking time as well. _emitterNode.IsBoundingBoxVisible = _showBoundingBox; _emitterNode.IsCollisionBoxVisible = false; _emitterNode.IsEventLinesVisible = false; _emitterNode.IsSizingPointsVisible = false; _emitterNode.Transformation = _cameraTransformation; _emitterNode.Render(new Transformation((previewPanel.ClientSize.Width - _emitterNode.BoundingRectangle.Width) / 2.0f, (previewPanel.ClientSize.Height - _emitterNode.BoundingRectangle.Height) / 2.0f, 0, 0, 0, 0, 1, 1, 1), null, 0); } GraphicsManager.FinishScene(); GraphicsManager.PresentScene(); // Set the status strips. fpsToolStripStatusLabel.Text = "FPS: " + Editor.GlobalInstance.CurrentFPS; particleCountToolStripStatusLabel.Text = "Particles: " + _emitterNode.Particles.Count + "/" + _emitterNode.MaximumParticles; // Move the camera around if we have been asked to. if (InputManager.KeyDown(KeyCodes.LeftMouse) || InputManager.KeyDown(KeyCodes.RightMouse)) { if (_cameraMoving == true) { _cameraTransformation.X += (InputManager.MouseX - _cameraMoveX); _cameraTransformation.Y += (InputManager.MouseY - _cameraMoveY); _cameraMoveX = InputManager.MouseX; _cameraMoveY = InputManager.MouseY; } else if (InputManager.MouseX >= 0 && InputManager.MouseY >= 0 && InputManager.MouseX < previewPanel.ClientSize.Width && InputManager.MouseY < previewPanel.ClientSize.Height) { if (InputManager.KeyPressed(KeyCodes.LeftMouse) || InputManager.KeyPressed(KeyCodes.RightMouse)) { _cameraMoving = true; _cameraMoveX = InputManager.MouseX; _cameraMoveY = InputManager.MouseY; } } } else { _cameraMoving = false; } GraphicsManager.RenderTarget = previousRenderTarget; }
/// <summary> /// Renders the game in all its glory! /// </summary> public void Render() { /* GraphicsManager.BeginScene(); * GraphicsManager.ClearRenderState(); * GraphicsManager.Viewport = new Rectangle(0, 0, GraphicsManager.Resolution[0], GraphicsManager.Resolution[1]); * GraphicsManager.ClearColor = unchecked((int)0xFFFF0000); * GraphicsManager.ClearScene(); * * GraphicsManager.VertexColors[0] = unchecked((int)0xFFFFFFFF); * GraphicsManager.VertexColors[1] = unchecked((int)0xFF00FF00); * GraphicsManager.VertexColors[2] = unchecked((int)0xFFFF00FF); * GraphicsManager.VertexColors[3] = unchecked((int)0xFF0000FF); * GraphicsManager.RenderRectangle(5, 5, 0, 16, 16, true); * GraphicsManager.RenderRectangle(5, 37, 0, 16, 16, false); * * GraphicsManager.RenderOval(37, 5, 0, 16, 16, true); * GraphicsManager.RenderOval(37, 37, 0, 16, 16, false); * * GraphicsManager.RenderLine(74, 5, 0, 74 + 16, 5 + 16, 0); * GraphicsManager.RenderLine(74, 37, 0, 74 + 16, 37 + 16, 0); * * GraphicsManager.FinishScene(); * GraphicsManager.PresentScene(); * * return;*/ //HighPreformanceTimer timer = new HighPreformanceTimer(); // Don't try and render if we don't have a loading function. if (_renderLoadingScreen == true && (Fusion.GlobalInstance.GameScriptProcess == null || Fusion.GlobalInstance.GameScriptProcess.Process == null || Fusion.GlobalInstance.GameScriptProcess.Process.SymbolExists("OnLoadingRender") == false)) { return; } // Begin rendering. GraphicsManager.PushRenderState(); GraphicsManager.BeginScene(); GraphicsManager.ClearRenderState(); // GraphicsManager.ClearColor = unchecked((int)0xFFFF0000); GraphicsManager.ClearScene(); GraphicsManager.Viewport = new Rectangle(0, 0, GraphicsManager.Resolution[0], GraphicsManager.Resolution[1]); if (_renderThisFrame == true) { // Render the current scene graph. if (_renderSceneGraph == true) { GraphicsManager.PushRenderState(); Engine.GlobalInstance.Map.SceneGraph.Render(); GraphicsManager.PopRenderState(); } // Do we have a game script render function? if (_gameScriptRenderFunction != null) { GraphicsManager.PushRenderState(); Fusion.GlobalInstance.GameScriptProcess.Process[0].InvokeFunction(_gameScriptRenderFunction, true, true, true); GraphicsManager.PopRenderState(); } // Do we have a map script render function? if (_mapScriptRenderFunction != null) { GraphicsManager.PushRenderState(); Fusion.GlobalInstance.MapScriptProcess.Process[0].InvokeFunction(_mapScriptRenderFunction, true, true, true); GraphicsManager.PopRenderState(); } } else { _renderThisFrame = true; } // Render the loading screen if we have been asked to. if (_renderLoadingScreen == true && Fusion.GlobalInstance.GameScriptProcess != null && Fusion.GlobalInstance.GameScriptProcess.Process != null && Fusion.GlobalInstance.GameScriptProcess.Process.SymbolExists("OnLoadingRender")) { GraphicsManager.PushRenderState(); Fusion.GlobalInstance.GameScriptProcess.Process[0].InvokeFunction("OnLoadingRender", true, true, true); GraphicsManager.PopRenderState(); } // Tell plugins to render. Plugin.CallPluginMethod("Render"); // Render the console. GraphicsManager.Resolution = new int[] { ClientSize.Width, ClientSize.Height }; GraphicsManager.ResolutionOffset = new float[] { 0, 0 }; GraphicsManager.ResolutionScale = new float[] { 1.0f, 1.0f }; GraphicalConsole.Render(); GraphicsManager.FinishScene(); GraphicsManager.PresentScene(); GraphicsManager.PopRenderState(); //System.Console.WriteLine("R: " + (float)timer.DurationMillisecond); //System.Console.WriteLine("Spent " + Graphics.Image._tileTime); //Graphics.Image._tileTime = 0; }