public void Initialize() { var positions = new List <Vector3>(); var indices = new List <int>(); _vd = VertexDescriptor.GetDescriptor <VertexP>(); // new VertexDescriptor(new VertexDeclaration(GGraphicDeviceFactory.Device, VertexP.Elements)); _BuildGeoSphere(_subdivitions, 1, positions, indices); _vertices = new VertexP[positions.Count]; for (int i = 0; i < positions.Count; i++) { _vertices[i] = new VertexP(positions[i]); } this._indices = new ushort[indices.Count]; for (int i = 0; i < indices.Count; i++) { this._indices[i] = (ushort)indices[i]; } if (_vb != null) { _vb.Dispose(); } _vb = GraphicDeviceFactory.Device.CreateVertexBuffer(data: _vertices); if (_ib != null) { _ib.Dispose(); } _ib = GraphicDeviceFactory.Device.CreateIndexBuffer(data: this._indices); }
protected override void Draw(GraphicBuffer buffer) { base.Draw(buffer); buffer.DrawRectangle('#', Coordinate.Origin, new Size(15, 10), true); buffer.DrawRectangle('#', new Coordinate(0, 11), new Size(15, 10), false); }
/// <summary> /// Updates the control if <see cref="IsVisible"/> is set to true. /// </summary> /// <param name="buffer">The <see cref="GraphicBuffer"/> to draw on.</param> public virtual void Update(GraphicBuffer buffer) { if (this.IsVisible) { this.Draw(buffer); } }
/// <summary> /// Draws a filled rectangle. /// </summary> /// <param name="buffer">The <see cref="GraphicBuffer"/> to draw on.</param> private void DrawFilledRectangle(GraphicBuffer buffer) { for (int y = this.Location.Y - 1; y < this.Location.Y + this.Size.Height - 1; y++) { buffer.DrawLine(this.Token, this.Location + new Coordinate(0, y + 1), this.Location + new Coordinate(this.Size.Width - 1, 0)); } }
/// <summary> /// Draws the control. /// </summary> protected override void Draw(GraphicBuffer buffer) { buffer.BackgroundDrawingColor = this.BackgroundColor; buffer.ForegroundDrawingColor = this.ForegroundColor; buffer.DrawRectangle(' ', Coordinate.Origin, this.Size, true); }
protected override void Draw(GraphicBuffer buffer) { base.Draw(buffer); buffer.DrawLine('#', new Coordinate(0, 2), new Coordinate(15, 2)); buffer.DrawLine('#', new Coordinate(0, 6), new Coordinate(0, 15)); buffer.DrawLine('#', new Coordinate(0, 19), new Coordinate(13, 36)); }
/// <summary> /// Draws a unfilled rectangle. /// </summary> /// <param name="buffer">The <see cref="GraphicBuffer"/> to draw on.</param> private void DrawUnfilledRectangle(GraphicBuffer buffer) { buffer.DrawLine(this.Token, this.Location, new Coordinate(this.Location.X + this.Size.Width - 1, this.Location.Y)); buffer.DrawLine(this.Token, new Coordinate(this.Location.X, this.Location.Y + this.Size.Height), new Coordinate(this.Location.X + this.Size.Width - 1, this.Location.Y)); buffer.DrawLine(this.Token, this.Location, new Coordinate(this.Location.X, this.Location.Y + this.Size.Height)); buffer.DrawLine(this.Token, new Coordinate(this.Location.X + this.Size.Width - 1, this.Location.Y), new Coordinate(this.Location.X + this.Size.Width - 1, this.Location.Y + this.Size.Height)); }
/// <summary> /// Draws the control. /// </summary> /// <param name="buffer">The <see cref="GraphicBuffer"/> to draw on.</param> protected override void Draw(GraphicBuffer buffer) { buffer.ForegroundDrawingColor = this.ForegroundColor; buffer.BackgroundDrawingColor = this.BackgroundColor; buffer.DrawRectangle(' ', Coordinate.Origin, this.Size, true); var words = new List <string>(); words.AddRange(this.Text.Split(' ')); //Split text into words var lines = new List <string>(); // If there is only one word, draw it immediately. // This fixes a bug, which caues a cut-off at the end of a line // (the cut-off for only one word is desired) if (words.Count == 1) { lines.Add(words[0]); } else { do { string line = String.Empty; bool first = true; for (int i = 0; i < words.Count; i++) { if (line.Length + words[0].Length < this.Size.Width) //check if the line fits into the label { string space = first ? String.Empty : " "; first = false; line += space + words[0]; words.Remove(words[0]); i--; } else { break; } } lines.Add(line); }while (words.Count > 0 && lines.Count < this.Size.Height); } for (int i = 0; i < lines.Count; i++) { buffer.DrawLine(lines[i], new Coordinate(0, i)); } }
public void CreateIndexBuffer(Array indices, IndexFormat format = IndexFormat.Index16, ResourceUsage usage = ResourceUsage.Default, CpuAccessFlags cpuAccess = CpuAccessFlags.ReadWrite) { _is16BitIndices = format == IndexFormat.Index16; _faceCount = indices.Length / (_is16BitIndices ? 2 : 4) / 3; if (_ib != null) { _ib.Dispose(); } _ib = GraphicDeviceFactory.Device.CreateIndexBuffer(indices.Length, indices, format, usage, cpuAccess); }
/// <summary> /// Draws the shape. /// </summary> /// <param name="buffer">The <see cref="GraphicBuffer"/> to draw on.</param> public override void Draw(GraphicBuffer buffer) { if (this.IsFilled) { this.DrawFilledRectangle(buffer); } else { this.DrawUnfilledRectangle(buffer); } }
public void CreateIndexBuffer <T>(T[] indices, ResourceUsage usage = ResourceUsage.Default, CpuAccessFlags cpuAccess = CpuAccessFlags.ReadWrite) where T : struct { _faceCount = indices.Length / 3; _is16BitIndices = ClrRuntime.Runtime.SizeOf <T>() == 2; if (_ib != null) { _ib.Dispose(); } _ib = GraphicDeviceFactory.Device.CreateIndexBuffer <T>(usage, cpuAccess, indices); }
public void CreateVertexBuffer(Array vertexes, int vertexCount, ResourceUsage usage = ResourceUsage.Default, CpuAccessFlags cpuAccess = CpuAccessFlags.ReadWrite) { if (_vb != null) { _vb.Dispose(); } this._vertexCount = vertexCount; int size = vertexCount * _vd.Size; _vb = GraphicDeviceFactory.Device.CreateVertexBuffer(size, _vd.Size, vertexes, usage, cpuAccess); }
/// <summary> /// Draws the control. /// </summary> /// <param name="buffer">The <see cref="GraphicBuffer"/> to draw on.</param> protected override void Draw(GraphicBuffer buffer) { buffer.BackgroundDrawingColor = this.BackgroundColor; buffer.ForegroundDrawingColor = this.ForegroundColor; string background = String.Empty; background = background.PadRight(this.Size.Width, ' '); buffer.DrawLine(background, Coordinate.Origin); buffer.DrawLine(this.Text, Coordinate.Origin); }
public void CreateVertexBuffer <T>(T[] vertexes, ResourceUsage usage = ResourceUsage.Default, CpuAccessFlags cpuAccess = CpuAccessFlags.ReadWrite) where T : struct { if (_vb != null) { _vb.Dispose(); } int size = ClrRuntime.Runtime.SizeOf <T>(); _vertexCount = (vertexes.Length * size) / _vd.Size; _vb = GraphicDeviceFactory.Device.CreateVertexBuffer <T>(_vd.Size, usage, cpuAccess, data: vertexes); }
/// <summary> /// Draws the control. /// </summary> /// <param name="buffer">The <see cref="GraphicBuffer"/> to draw on.</param> protected override void Draw(GraphicBuffer buffer) { buffer.ForegroundDrawingColor = this.ForegroundColor; buffer.BackgroundDrawingColor = this.BackgroundColor; buffer.DrawRectangle(' ', Coordinate.Origin, this.Size, true); for (int i = 0; i < this.items.Count && i < this.Size.Height; i++) { string bulletString = this.DisplayBullets ? this.Bullet + " " : String.Empty; buffer.DrawLine(bulletString + this.items[i], new Coordinate(0, i)); } }
public BoxMesh() { _builder = new BoxBuilder(10, 10, 10); _mat = BasicMaterial.CreateDefaultMaterial("boxMaterial"); //VertexPositionColor[] vertexes = new VertexPositionColor[_builder.Vertices.Length]; //for (int i = 0; i < vertexes.Length; i++) //{ // vertexes[i] = new VertexPositionColor(_builder.Vertices[i].Position, new Color4(1, 1, 0, 0)); //} var device = GraphicDeviceFactory.Device; _vb = device.CreateVertexBuffer(data: _builder.Vertices); _ib = device.CreateIndexBuffer(data: _builder.Indices); _mat.Diffuse = new Vector3(1, 1, 1); _mat.DiffuseMap = device.CreateTexture2DFromFile(@"I:\Pictures\lufy.png"); _mat.SpecularIntensity = 0; _mat.EmisiveIntensity = 0; _mat.Alpha = 1f; IsTransparent = _mat.ContainsTrasparency; SetRender <DefaultTechnique, BasicMeshEffect>((box, render) => { var effect = render.Effect; //effect.Constants.gId = new Vector4(1, 1, 0, 0); //effect.U.World = Matrix.Identity; //map.World = Matrix.Identity; device.PrimitiveTopology = IAPrimitive.TriangleList; device.SetVertexBuffer(0, _vb, 0); device.SetIndexBuffer(_ib, 0); render.Bind(_mat); foreach (var pass in effect.Passes(0)) { effect.Apply(pass); device.DrawIndexed(_builder.Indices.Length, 0, 0); } effect.EndPasses(); }); //.BindWith(new CameraBinding()) //.BindWith(new MeshMaterialBinding()) //.BindWith(new LightBinding()) //.BindWith(new AmbientLightBinding()) //.BindWith(new PixelClippingBinding()); }
/// <summary> /// Updates the control if <see cref="Control.IsVisible"/> is set to true. /// </summary> /// <param name="buffer">The <see cref="GraphicBuffer"/> to draw on.</param> public override void Update(GraphicBuffer buffer) { base.Update(buffer); if (this.IsVisible) { foreach (Control control in this.controls) { var localBuffer = new GraphicBuffer(control.Size); control.Update(localBuffer); buffer.Merge(localBuffer, control.RelativeLocation); } } }
private void CreateTriangle() { //Creates a triangle with position and color data var data = new TriangleVertex[] { new TriangleVertex(new Vector3(0, 1, 0), Color4.Blue), new TriangleVertex(new Vector3(1, -1, 0), Color4.Green), new TriangleVertex(new Vector3(-1, -1, 0), Color4.Red) }; //Create the vertex buffer for olding the data in the device, passing data will feed the vertex buffer //with the provided array vertexBuffer = device.CreateVertexBuffer(data: data); //Create transformation matrices world = Matrix.Identity; view = Matrix.LookAt(new Vector3(0, 0, -1), new Vector3(0, 0, 1), Vector3.UnitY); projection = Matrix.PerspectiveFovLh((float)Width / (float)Height, Igneel.Numerics.PIover6, 1, 1000); }
private void InitParticles() { IsTransparent = true; _nbQuads = _particlesBuffer.Length; for (int i = 0; i < _particlesBuffer.Length; i++) { _particlesBuffer[i].Life = -1; _particlesBuffer[i].InvMass = 1f; _particlesBuffer[i].Mass = 1f; _particlesBuffer[i].Color = 0xFFFFFFFF; _particlesBuffer[i].Alpha = 0; } float size = 1; _quads = new ParticleVertex[_nbQuads * 4]; _vd = VertexDescriptor.GetDescriptor <ParticleVertex>(); short[] indices = new short[_nbQuads * 6];; for (int i = 0; i < _nbQuads; i++) { // P0----P1 // | / | // | / | // P3----P2 _quads[4 * i] = new ParticleVertex(-0.5f * size, 0.5f * size, 0, 0, 0); //P0 _quads[4 * i + 1] = new ParticleVertex(0.5f * size, 0.5f * size, 0, 1, 0); //P1 _quads[4 * i + 2] = new ParticleVertex(-0.5f * size, -0.5f * size, 0, 0, 1); //P3 _quads[4 * i + 3] = new ParticleVertex(0.5f * size, -0.5f * size, 0, 1, 1); //P2 indices[6 * i] = (short)(4 * i); indices[6 * i + 1] = (short)(4 * i + 1); indices[6 * i + 2] = (short)(4 * i + 2); indices[6 * i + 3] = (short)(4 * i + 2); indices[6 * i + 4] = (short)(4 * i + 1); indices[6 * i + 5] = (short)(4 * i + 3); } _vb = GraphicDeviceFactory.Device.CreateVertexBuffer(ResourceUsage.Dynamic, CpuAccessFlags.Write, data: _quads); _ib = GraphicDeviceFactory.Device.CreateIndexBuffer(data: indices); }
public BillBoardRender() : base() { _vd = VertexDescriptor.GetDescriptor <VertexPTx>(); _vb = GraphicDeviceFactory.Device.CreateVertexBuffer(data: Vertices); if (this.Effect != null) { _map = Effect.Map <IMap>(); //hWorldViewProj = this.effect.TryGetGlobalSematic(ShaderSemantics.WORLDVIEWPROJ); //hColor = this.effect.TryGetGlobalSematic(ShaderSemantics.COLOR); //hWorld = this.effect.TryGetGlobalSematic(ShaderSemantics.World); //hViewProj = this.effect.TryGetGlobalSematic(ShaderSemantics.VIEWPROJ); } _rastState = GraphicDeviceFactory.Device.CreateRasterizerState(new RasterizerDesc { Cull = CullMode.None }); }
/// <summary> /// Draws the control. /// </summary> /// <param name="buffer">The <see cref="GraphicBuffer"/> to draw on.</param> protected override void Draw(GraphicBuffer buffer) { for (int i = 0; i < this.Items.Count; i++) { buffer.ForegroundDrawingColor = this.ForegroundColor; buffer.BackgroundDrawingColor = this.BackgroundColor; if (this.SelectedIndex == i) { buffer.ForegroundDrawingColor = this.SelectionForegroundColor; buffer.BackgroundDrawingColor = this.SelectionBackgroundColor; } string bulletString = this.DisplayBullets ? this.Bullet + " " : String.Empty; buffer.DrawLine(bulletString + this.items[i].Name, new Coordinate(0, i)); buffer.ResetColor(); } }
public Sprite(RectangleF rect) { var device = GraphicDeviceFactory.Device; var viewport = device.ViewPort; var vertexes = new VertexPTxH[4]; vertexes[0].Position = new Vector4(rect.X, rect.Y, 0.5f, 1.0f); vertexes[0].TexCoord = new Vector2(0, 0); vertexes[1].Position = new Vector4(rect.X + rect.Width, rect.Y, 0.5f, 1.0f); vertexes[1].TexCoord = new Vector2(1, 0); vertexes[2].Position = new Vector4(rect.X, rect.Y + rect.Height, 0.5f, 1.0f); vertexes[2].TexCoord = new Vector2(0, 1); vertexes[3].Position = new Vector4(rect.X + rect.Width, rect.Y + rect.Height, 0.5f, 1.0f); vertexes[3].TexCoord = new Vector2(1, 1); _vb = device.CreateVertexBuffer(usage: ResourceUsage.Immutable, cpuAcces: CpuAccessFlags.None, data: vertexes); _state = device.CreateDepthStencilState(new DepthStencilStateDesc(depthEnable: false, writeEnable: false, depthFunc: Comparison.LessEqual)); }
private void CreateSphere() { var stacks = 128; var slices = 128; var radius = 10; var vertices = new SphereVertex[(stacks - 1) * (slices + 1) + 2]; var indices = new ushort[(stacks - 2) * slices * 6 + slices * 6]; float phiStep = Numerics.PI / stacks; float thetaStep = Numerics.TwoPI / slices; // do not count the poles as rings int numRings = stacks - 1; // Compute vertices for each stack ring. int k = 0; var v = new SphereVertex(); for (int i = 1; i <= numRings; ++i) { float phi = i * phiStep; // vertices of ring for (int j = 0; j <= slices; ++j) { float theta = j * thetaStep; // spherical to cartesian v.Position = Vector3.SphericalToCartesian(phi, theta, radius); v.Normal = Vector3.Normalize(v.Position); v.TexCoord = new Vector2(theta / (-2.0f * (float)Math.PI), phi / (float)Math.PI); // partial derivative of P with respect to theta v.Tangent = new Vector3(-radius * (float)Math.Sin(phi) * (float)Math.Sin(theta), 0, radius * (float)Math.Sin(phi) * (float)Math.Cos(theta)); vertices[k++] = v; } } // poles: note that there will be texture coordinate distortion vertices[vertices.Length - 2] = new SphereVertex(new Vector3(0.0f, -radius, 0.0f), new Vector3(0.0f, -1.0f, 0.0f), Vector3.Zero, new Vector2(0.0f, 1.0f)); vertices[vertices.Length - 1] = new SphereVertex(new Vector3(0.0f, radius, 0.0f), new Vector3(0.0f, 1.0f, 0.0f), Vector3.Zero, new Vector2(0.0f, 0.0f)); int northPoleIndex = vertices.Length - 1; int southPoleIndex = vertices.Length - 2; int numRingVertices = slices + 1; // Compute indices for inner stacks (not connected to poles). k = 0; for (int i = 0; i < stacks - 2; ++i) { for (int j = 0; j < slices; ++j) { indices[k++] = (ushort)((i + 1) * numRingVertices + j); indices[k++] = (ushort)(i * numRingVertices + j + 1); indices[k++] = (ushort)(i * numRingVertices + j); indices[k++] = (ushort)((i + 1) * numRingVertices + j + 1); indices[k++] = (ushort)(i * numRingVertices + j + 1); indices[k++] = (ushort)((i + 1) * numRingVertices + j); } } // Compute indices for top stack. The top stack was written // first to the vertex buffer. for (int i = 0; i < slices; ++i) { indices[k++] = (ushort)i; indices[k++] = (ushort)(i + 1); indices[k++] = (ushort)northPoleIndex; } // Compute indices for bottom stack. The bottom stack was written // last to the vertex buffer, so we need to offset to the index // of first vertex in the last ring. int baseIndex = (numRings - 1) * numRingVertices; for (int i = 0; i < slices; ++i) { indices[k++] = (ushort)(baseIndex + i + 1); indices[k++] = (ushort)(baseIndex + i); indices[k++] = (ushort)southPoleIndex; } vertexBuffer = device.CreateVertexBuffer(data: vertices); indexBuffer = device.CreateIndexBuffer(data: indices); }
/// <summary> /// Draws the shape. /// </summary> /// <param name="buffer">The <see cref="GraphicBuffer"/> to draw on.</param> public abstract void Draw(GraphicBuffer buffer);
/// <summary> /// Draws the control. /// </summary> /// <param name="buffer">The <see cref="GraphicBuffer"/> to draw on.</param> protected abstract void Draw(GraphicBuffer buffer);
private void InitializeEnviroment3D() { if (Axis == null) { Axis = new VertexPositionColor[6]; } //X axis Axis[0] = new VertexPositionColor(Vector3.UnitX * _size, new Color4(Color.Red.ToArgb())); Axis[1] = new VertexPositionColor(Vector3.UnitX * -_size, new Color4(Color.Red.ToArgb())); //Y axis Axis[2] = new VertexPositionColor(Vector3.UnitY * _size, new Color4(Color.Green.ToArgb())); Axis[3] = new VertexPositionColor(Vector3.UnitY * -_size, new Color4(Color.Green.ToArgb())); //Z axis Axis[4] = new VertexPositionColor(Vector3.UnitZ * _size, new Color4(Color.Blue.ToArgb())); Axis[5] = new VertexPositionColor(Vector3.UnitZ * -_size, new Color4(Color.Blue.ToArgb())); float left = -_size; float right = _size; float top = _size; float bottom = -_size; int sizeH = (int)(2 * _size / _scale); int sizeV = sizeH; Color4 color = new Color4(Color.DarkGray.ToArgb()); Lines = new VertexPositionColor[(sizeH + sizeV) * 2 + 4]; int k = 0; //horizontal Lines for (int i = 0; i <= sizeH; i++) { float z = top - _scale * i; Lines[k++] = new VertexPositionColor(new Vector3(left, 0, z), color); Lines[k++] = new VertexPositionColor(new Vector3(right, 0, z), color); } //Vertical Lines for (int i = 0; i <= sizeV; i++) { float x = left + _scale * i; Lines[k++] = new VertexPositionColor(new Vector3(x, 0, top), color); Lines[k++] = new VertexPositionColor(new Vector3(x, 0, bottom), color); } VertexPositionColor[] vbData = new VertexPositionColor[Axis.Length + Lines.Length]; Array.ConstrainedCopy(Axis, 0, vbData, 0, Axis.Length); Array.ConstrainedCopy(Lines, 0, vbData, Axis.Length, Lines.Length); int vertexSize = Marshal.SizeOf(typeof(VertexPositionColor)); _vb = GraphicDeviceFactory.Device.CreateVertexBuffer(vbData.Length * vertexSize, vertexSize, vbData, usage: ResourceUsage.Default, cpuAcces: CpuAccessFlags.ReadWrite); //unsafe{ // VertexPositionColor* pter = (VertexPositionColor*)vb.Map(MapType.ReadWrite); // for (int i = 0; i < vbData.Length; i++) // { // var pos = pter[i].Position; // pter[i].Color = new Color4(1, 1, 1, 1); // } // vb.Unmap(); // } //vb.Write(axis,0, false); //vb.Write(lines, vertexSize * axis.Length, false); }
/// <summary> /// Updates the control if <see cref="Control.IsVisible"/> is set to true. /// </summary> /// <param name="buffer">The <see cref="GraphicBuffer"/> to draw on.</param> public override void Update(GraphicBuffer buffer) { base.Update(buffer); buffer.DrawToScreen(this.AbsoluteLocation); }
protected override void IASetIndexBufferImpl(GraphicBuffer indexBuffer, int offset) { throw new NotImplementedException(); }
protected override void IASetVertexBufferImpl(int slot, GraphicBuffer vertexBuffer, int offset, int stride) { throw new NotImplementedException(); }
public override void UpdateBuffer(GraphicBuffer buffer, int offset, IntPtr pterData, int dataSize) { throw new NotImplementedException(); }