git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1135 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
@@ -21,6 +21,7 @@ namespace OpenRa.Game
|
|||||||
string TileSuffix;
|
string TileSuffix;
|
||||||
|
|
||||||
const string mapName = "scm12ea.ini";
|
const string mapName = "scm12ea.ini";
|
||||||
|
const string shaderName = "diffuse.fx";
|
||||||
|
|
||||||
Dictionary<TileReference, SheetRectangle<Sheet>> tileMapping =
|
Dictionary<TileReference, SheetRectangle<Sheet>> tileMapping =
|
||||||
new Dictionary<TileReference, SheetRectangle<Sheet>>();
|
new Dictionary<TileReference, SheetRectangle<Sheet>>();
|
||||||
@@ -29,6 +30,11 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
Dictionary<Sheet, IndexBuffer> drawBatches = new Dictionary<Sheet, IndexBuffer>();
|
Dictionary<Sheet, IndexBuffer> drawBatches = new Dictionary<Sheet, IndexBuffer>();
|
||||||
|
|
||||||
|
Effect effect;
|
||||||
|
IntPtr textureParameter;
|
||||||
|
SpriteHelper spriteHelper;
|
||||||
|
FontHelper fontHelper;
|
||||||
|
|
||||||
void LoadTextures()
|
void LoadTextures()
|
||||||
{
|
{
|
||||||
List<Sheet> tempSheets = new List<Sheet>();
|
List<Sheet> tempSheets = new List<Sheet>();
|
||||||
@@ -62,6 +68,22 @@ namespace OpenRa.Game
|
|||||||
s.LoadTexture(device);
|
s.LoadTexture(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float U(SheetRectangle<Sheet> s, float u)
|
||||||
|
{
|
||||||
|
float u0 = (float)s.origin.X / (float)s.sheet.bitmap.Width;
|
||||||
|
float u1 = (float)(s.origin.X + s.size.Width) / (float)s.sheet.bitmap.Width;
|
||||||
|
|
||||||
|
return (1 - u) * u0 + u * u1;
|
||||||
|
}
|
||||||
|
|
||||||
|
float V(SheetRectangle<Sheet> s, float v)
|
||||||
|
{
|
||||||
|
float v0 = (float)s.origin.Y / (float)s.sheet.bitmap.Height;
|
||||||
|
float v1 = (float)(s.origin.Y + s.size.Height) / (float)s.sheet.bitmap.Height;
|
||||||
|
|
||||||
|
return (1 - v) * v0 + v * v1;
|
||||||
|
}
|
||||||
|
|
||||||
void LoadVertexBuffer()
|
void LoadVertexBuffer()
|
||||||
{
|
{
|
||||||
Dictionary<Sheet, List<ushort>> indexMap = new Dictionary<Sheet, List<ushort>>();
|
Dictionary<Sheet, List<ushort>> indexMap = new Dictionary<Sheet, List<ushort>>();
|
||||||
@@ -74,10 +96,10 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
ushort offset = (ushort)(4 * (i * 128 + j));
|
ushort offset = (ushort)(4 * (i * 128 + j));
|
||||||
|
|
||||||
vertices[offset] = new Vertex(24 * i, 24 * j, 0, 0, 0);
|
vertices[offset] = new Vertex(24 * i, 24 * j, 0, U(tile,0), V(tile,0));
|
||||||
vertices[offset + 1] = new Vertex(24 + 24 * i, 24 * j, 0, 1, 0);
|
vertices[offset + 1] = new Vertex(24 + 24 * i, 24 * j, 0, U(tile,1), V(tile,0));
|
||||||
vertices[offset + 2] = new Vertex(24 * i, 24 + 24 * j, 0, 0, 1);
|
vertices[offset + 2] = new Vertex(24 * i, 24 + 24 * j, 0, U(tile,0), V(tile,1));
|
||||||
vertices[offset + 3] = new Vertex(24 + 24 * i, 24 + 24 * j, 0, 1, 1);
|
vertices[offset + 3] = new Vertex(24 + 24 * i, 24 + 24 * j, 0, U(tile,1), V(tile,1));
|
||||||
|
|
||||||
List<ushort> indexList;
|
List<ushort> indexList;
|
||||||
if (!indexMap.TryGetValue(tile.sheet, out indexList))
|
if (!indexMap.TryGetValue(tile.sheet, out indexList))
|
||||||
@@ -120,6 +142,12 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
LoadTextures();
|
LoadTextures();
|
||||||
LoadVertexBuffer();
|
LoadVertexBuffer();
|
||||||
|
|
||||||
|
effect = new Effect(device, File.OpenRead("../../../" + shaderName));
|
||||||
|
textureParameter = effect.GetHandle("DiffuseTexture");
|
||||||
|
|
||||||
|
spriteHelper = new SpriteHelper(device);
|
||||||
|
fontHelper = new FontHelper(device, "Tahoma", 10, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Run()
|
internal void Run()
|
||||||
@@ -134,21 +162,32 @@ namespace OpenRa.Game
|
|||||||
void Frame()
|
void Frame()
|
||||||
{
|
{
|
||||||
device.Begin();
|
device.Begin();
|
||||||
device.Clear(0);
|
device.Clear( Color.Red.ToArgb(), Surfaces.Color );
|
||||||
|
|
||||||
// render something :)
|
|
||||||
|
|
||||||
vertexBuffer.Bind(0);
|
vertexBuffer.Bind(0);
|
||||||
|
|
||||||
|
effect.Quality = ShaderQuality.Low;
|
||||||
|
effect.Begin();
|
||||||
|
effect.BeginPass(0);
|
||||||
|
|
||||||
foreach (KeyValuePair<Sheet, IndexBuffer> batch in drawBatches)
|
foreach (KeyValuePair<Sheet, IndexBuffer> batch in drawBatches)
|
||||||
{
|
{
|
||||||
//todo: bind texture!
|
effect.SetTexture(textureParameter, batch.Key.texture);
|
||||||
|
effect.Commit();
|
||||||
|
|
||||||
batch.Value.Bind();
|
batch.Value.Bind();
|
||||||
|
|
||||||
device.DrawIndexedPrimitives(PrimitiveType.TriangleList,
|
device.DrawIndexedPrimitives(PrimitiveType.TriangleList,
|
||||||
vertexBuffer.Size, batch.Value.Size / 3);
|
vertexBuffer.Size, batch.Value.Size / 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
effect.EndPass();
|
||||||
|
effect.End();
|
||||||
|
|
||||||
|
spriteHelper.Begin();
|
||||||
|
fontHelper.Draw(spriteHelper, "fps: 1337", 0, 0, Color.White.ToArgb());
|
||||||
|
spriteHelper.End();
|
||||||
|
|
||||||
device.End();
|
device.End();
|
||||||
device.Present();
|
device.Present();
|
||||||
}
|
}
|
||||||
|
|||||||
53
diffuse.fx
Normal file
53
diffuse.fx
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
// OpenRA test shader
|
||||||
|
// Author: C. Forbes
|
||||||
|
//--------------------------------------------------------
|
||||||
|
|
||||||
|
shared texture DiffuseTexture;
|
||||||
|
|
||||||
|
sampler s_DiffuseTexture = sampler_state {
|
||||||
|
Texture = <DiffuseTexture>;
|
||||||
|
MinFilter = None;
|
||||||
|
MagFilter = None;
|
||||||
|
MipFilter = None;
|
||||||
|
|
||||||
|
AddressU = Wrap;
|
||||||
|
AddressV = Wrap;
|
||||||
|
AddressW = Wrap;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VertexIn {
|
||||||
|
float4 Position: POSITION;
|
||||||
|
float2 Tex0: TEXCOORD0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VertexOut {
|
||||||
|
float4 Position: POSITION;
|
||||||
|
float2 Tex0: TEXCOORD0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FragmentIn {
|
||||||
|
float2 Tex0: TEXCOORD0;
|
||||||
|
};
|
||||||
|
|
||||||
|
VertexOut Simple_vp(VertexIn v) {
|
||||||
|
VertexOut o;
|
||||||
|
o.Position = float4( v.Position.x / 320.0f - 0.5f - 2, 5-v.Position.y / 240.0f, 0, 1 );
|
||||||
|
o.Tex0 = v.Tex0;
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
float4 Simple_fp(FragmentIn f) : COLOR0 {
|
||||||
|
float4 color = tex2D(s_DiffuseTexture, f.Tex0);
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
technique low_quality {
|
||||||
|
pass p0 {
|
||||||
|
AlphaBlendEnable = false;
|
||||||
|
ZWriteEnable = true;
|
||||||
|
ZEnable = false;
|
||||||
|
CullMode = None;
|
||||||
|
VertexShader = compile vs_2_0 Simple_vp();
|
||||||
|
PixelShader = compile ps_2_0 Simple_fp();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user