Scale line-width to match zoom.

This commit is contained in:
Paul Chote
2011-07-22 21:13:14 +12:00
parent fc783ddf80
commit 6183621a72
6 changed files with 24 additions and 0 deletions

View File

@@ -48,6 +48,7 @@ namespace OpenRA.FileFormats.Graphics
void DrawPrimitives( PrimitiveType type, int firstVertex, int numVertices );
void SetLineWidth( float width );
void EnableScissor( int left, int top, int width, int height );
void DisableScissor();
}

View File

@@ -15,6 +15,8 @@ namespace OpenRA.Graphics
{
public class LineRenderer : Renderer.IBatchRenderer
{
public float LineWidth = 1f;
Renderer renderer;
IShader shader;
@@ -35,6 +37,7 @@ namespace OpenRA.Graphics
{
var vb = renderer.GetTempVertexBuffer();
vb.SetData( vertices, nv );
renderer.SetLineWidth(LineWidth);
renderer.DrawBatch( vb, 0, nv, PrimitiveType.LineList );
} );

View File

@@ -77,9 +77,11 @@ namespace OpenRA.Graphics
{
device.Clear(Color.Black);
WorldLineRenderer.LineWidth = zoom;
float2 r1 = new float2(2f/Resolution.Width, -2f/Resolution.Height);
float2 r2 = new float2(-1, 1);
var zr1 = zoom*r1;
SetShaderParams( WorldSpriteShader, zr1, r2, scroll );
SetShaderParams( WorldLineShader, zr1, r2, scroll );
SetShaderParams( LineShader, r1, r2, scroll );
@@ -116,6 +118,11 @@ namespace OpenRA.Graphics
CurrentBatchRenderer = null;
}
public void SetLineWidth(float width)
{
device.SetLineWidth(width);
}
static IGraphicsDevice device;
public static Size Resolution { get { return device.WindowSize; } }

View File

@@ -135,6 +135,12 @@ namespace OpenRA.Renderer.Cg
throw new NotImplementedException();
}
public void SetLineWidth( float width )
{
Gl.glLineWidth(width);
ErrorHandler.CheckGlError();
}
public IVertexBuffer<Vertex> CreateVertexBuffer( int size ) { return new VertexBuffer<Vertex>( size ); }
public ITexture CreateTexture() { return new Texture(); }
public ITexture CreateTexture( Bitmap bitmap ) { return new Texture( bitmap ); }

View File

@@ -115,6 +115,12 @@ namespace OpenRA.Renderer.Glsl
throw new NotImplementedException();
}
public void SetLineWidth( float width )
{
Gl.glLineWidth(width);
ErrorHandler.CheckGlError();
}
public IVertexBuffer<Vertex> CreateVertexBuffer( int size ) { return new VertexBuffer<Vertex>( size ); }
public ITexture CreateTexture() { return new Texture(); }
public ITexture CreateTexture( Bitmap bitmap ) { return new Texture( bitmap ); }

View File

@@ -48,6 +48,7 @@ namespace OpenRA.Renderer.Null
}
public void DrawPrimitives(PrimitiveType pt, int firstVertex, int numVertices) { }
public void SetLineWidth( float width ) { }
public IVertexBuffer<Vertex> CreateVertexBuffer(int size) { return new NullVertexBuffer<Vertex>(); }
public ITexture CreateTexture() { return new NullTexture(); }