diff --git a/BluntDx.dll b/BluntDx.dll index cf1f0d1ce2..0644a43f5d 100644 Binary files a/BluntDx.dll and b/BluntDx.dll differ diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index 3c9b0ec143..2b7ab13e0b 100644 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -6,6 +6,7 @@ using System.Drawing; using BluntDirectX.Direct3D; using OpenRa.FileFormats; using System.IO; +using System.Runtime.InteropServices; namespace OpenRa.Game { @@ -21,6 +22,58 @@ namespace OpenRa.Game const string mapName = "scm12ea.ini"; + Dictionary> tileMapping = + new Dictionary>(); + + FvfVertexBuffer vertexBuffer; + IndexBuffer indexBuffer; + + void LoadTextures() + { + List tempSheets = new List(); + + Provider sheetProvider = delegate + { + Sheet t = new Sheet( new Bitmap(256, 256)); + tempSheets.Add(t); + return t; + }; + + TileSheetBuilder builder = new TileSheetBuilder( new Size(256,256), sheetProvider ); + + for( int i = 0; i < 128; i++ ) + for (int j = 0; j < 128; j++) + { + TileReference tileRef = map.MapTiles[i, j]; + + if (!tileMapping.ContainsKey(tileRef)) + { + SheetRectangle rect = builder.AddImage(new Size(24, 24)); + Bitmap srcImage = tileSet.tiles[ tileRef.tile ].GetTile( tileRef.image ); + using (Graphics g = Graphics.FromImage(rect.sheet.bitmap)) + g.DrawImage(srcImage, rect.origin); + + tileMapping.Add(tileRef, rect); + } + } + + foreach (Sheet s in tempSheets) + s.LoadTexture(device); + } + + void LoadVertexBuffer() + { + Vertex[] vertices = new Vertex[4 * map.Width * map.Height]; + + vertexBuffer = new FvfVertexBuffer(device, vertices.Length, Vertex.Format); + vertexBuffer.SetData(vertices); + + ushort[] indices = new ushort[6 * map.Width * map.Height]; + + indexBuffer = new IndexBuffer(device, indices.Length); + indexBuffer.SetData(indices); + } + public MainWindow() { ClientSize = new Size(640, 480); @@ -35,6 +88,9 @@ namespace OpenRa.Game Text = string.Format("OpenRA - {0} - {1}", map.Title, mapName); tileSet = LoadTileSet(map); + + LoadTextures(); + LoadVertexBuffer(); } internal void Run() @@ -53,6 +109,11 @@ namespace OpenRa.Game // render something :) + //vertexBuffer.Bind(0); + //indexBuffer.Bind(); + + //device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 2 * map.Width * map.Height); + device.End(); device.Present(); } @@ -81,5 +142,7 @@ namespace OpenRa.Game } return new TileSet(TileMix, TileSuffix, pal); } + + } } diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index 31029a5c52..72ccc8e056 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -44,6 +44,8 @@ + + diff --git a/OpenRa.Game/Sheet.cs b/OpenRa.Game/Sheet.cs new file mode 100644 index 0000000000..a7f68558e7 --- /dev/null +++ b/OpenRa.Game/Sheet.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Drawing; +using BluntDirectX.Direct3D; +using System.IO; +using System.Drawing.Imaging; + +namespace OpenRa.Game +{ + class Sheet + { + public readonly Bitmap bitmap; + public Texture texture; + + public Sheet(Bitmap b) { bitmap = b; } + + public void LoadTexture(GraphicsDevice device) + { + string tempFile = string.Format("../../../block-cache-{0}.bmp", suffix++); + bitmap.Save(tempFile); + + using( Stream s = File.OpenRead(tempFile) ) + texture = Texture.Create(s, device); + } + + static int suffix = 0; + } +} diff --git a/OpenRa.Game/Vertex.cs b/OpenRa.Game/Vertex.cs new file mode 100644 index 0000000000..140025efd3 --- /dev/null +++ b/OpenRa.Game/Vertex.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; +using BluntDirectX.Direct3D; + +namespace OpenRa.Game +{ + [StructLayout(LayoutKind.Sequential)] + struct Vertex + { + public float x, y, z, u, v; + + public Vertex(float x, float y, float z, float u, float v) + { + this.x = x; this.y = y; this.z = z; + this.u = u; + this.v = v; + } + + public const VertexFormat Format = VertexFormat.Position | VertexFormat.Texture; + } +}