本文整理汇总了C#中RenderOptions类的典型用法代码示例。如果您正苦于以下问题:C# RenderOptions类的具体用法?C# RenderOptions怎么用?C# RenderOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RenderOptions类属于命名空间,在下文中一共展示了RenderOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: renderSprite
internal static new void renderSprite( dfRenderData renderData, RenderOptions options )
{
#if UNITY_EDITOR
var atlas = options.atlas;
if( atlas == null )
throw new NullReferenceException( "The Texture Atlas cannot be null" );
if( atlas.Texture == null )
throw new NullReferenceException( "The Texture Altas has no texture assigned or the texture was deleted" );
if( options.spriteInfo == null )
throw new ArgumentNullException( "The Sprite cannot be null" );
#endif
options.baseIndex = renderData.Vertices.Count;
rebuildTriangles( renderData, options );
rebuildVertices( renderData, options );
rebuildUV( renderData, options );
rebuildColors( renderData, options );
if( options.fillAmount < 1f )
{
doFill( renderData, options );
}
}
示例2: DrawBitmap
/// <summary>
/// Draws bitmap.
/// </summary>
/// <param name="data">
/// Image pixel data.
/// </param>
/// <param name="width">
/// Output image width.
/// </param>
/// <param name="height">
/// Output image height.
/// </param>
/// <param name="options">
/// More rendering options.
/// </param>
/// <returns>
/// Drawn bitmap.
/// </returns>
public static Bitmap DrawBitmap(byte[] data, int width, int height, RenderOptions options)
{
ImagePalette palette = options.Palette;
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
ColorPalette pal = bmp.Palette;
palette.CopyTo(pal.Entries, 0);
if(options.TransparentIndex >= 0)pal.Entries[options.TransparentIndex] = Color.Transparent;
bmp.Palette = pal;
BitmapData bmpdata = bmp.LockBits(new Rectangle(0,0,width,height), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
if(data.Length == 0){}
else if(width%4 == 0)
{
Marshal.Copy(data, 0, bmpdata.Scan0, Math.Min(bmpdata.Stride*bmpdata.Height, data.Length));
}else{
for(int y = 0; y < height; y++)
{
if(y == height-1)
{
Marshal.Copy(data, width*y, bmpdata.Scan0+bmpdata.Stride*y, data.Length-width*y);
}else{
Marshal.Copy(data, width*y, bmpdata.Scan0+bmpdata.Stride*y, width);
}
}
}
bmp.UnlockBits(bmpdata);
return bmp;
}
示例3: BlendDemo
public BlendDemo(IntPtr hInstance)
: base(hInstance) {
_waterTexOffset = new Vector2();
_eyePosW = new Vector3();
_renderOptions = RenderOptions.TexturesAndFog;
_theta = 1.3f * MathF.PI;
_phi = 0.4f * MathF.PI;
_radius = 80;
MainWindowCaption = "Blend Demo";
Enable4XMsaa = false;
_landWorld = Matrix.Identity;
_wavesWorld = Matrix.Translation(0, -3.0f, 0);
_view = Matrix.Identity;
_proj = Matrix.Identity;
_boxWorld = Matrix.Scaling(15.0f, 15.0f, 15.0f) * Matrix.Translation(8.0f, 5.0f, -15.0f);
_grassTexTransform = Matrix.Scaling(5.0f, 5.0f, 0.0f);
_dirLights = new[] {
new DirectionalLight {
Ambient = new Color4(0.2f, 0.2f, 0.2f),
Diffuse = new Color4(0.5f, 0.5f, 0.5f),
Specular = new Color4(0.5f, 0.5f, 0.5f),
Direction = new Vector3(0.57735f, -0.57735f, 0.57735f)
},
new DirectionalLight {
Ambient = Color.Black,
Diffuse = new Color4(0.2f, 0.2f, 0.2f),
Specular = new Color4(0.25f, 0.25f, 0.25f),
Direction = new Vector3(-0.57735f, -0.57735f, 0.57735f)
},
new DirectionalLight {
Ambient = Color.Black,
Diffuse = new Color4(0.2f, 0.2f, 0.2f),
Specular = Color.Black,
Direction = new Vector3(0.0f, -0.707f, -0.707f)
}
};
_landMat = new Material {
Ambient = new Color4(0.5f, 0.5f, 0.5f),
Diffuse = Color.White,
Specular = new Color4(16.0f, 0.2f, 0.2f, 0.2f)
};
_wavesMat = new Material {
Ambient = new Color4(0.5f, 0.5f, 0.5f),
Diffuse = new Color4(0.6f, 1.0f, 1.0f, 1.0f),
Specular = new Color4(32.0f, 0.8f, 0.8f, 0.8f)
};
_boxMat = new Material {
Ambient = new Color4(0.5f, 0.5f, 0.5f),
Diffuse = Color.White,
Specular = new Color4(16.0f, 0.4f, 0.4f, 0.4f)
};
}
示例4: RenderControls
public RenderControls(RenderOptions parent)
{
InitializeComponent();
_Parent = parent;
RenderSliders();
PopulateCombos();
}
示例5: Renderer
public Renderer(int passes, ViewportPolicy viewportPolicy, RenderOptions renderOptions)
{
this.Passes = passes;
this.Policy = viewportPolicy;
this.Options = renderOptions;
this.sortMode = Renderer.ToSortMode(renderOptions);
this.blendState = Renderer.ToBlendState(renderOptions);
// Doing a GlobalRenderLock because Renderer objects might be constructed in different threads.
lock (PhantomGame.Game.GlobalRenderLock)
{
if ((renderOptions & RenderOptions.Canvas) == RenderOptions.Canvas)
this.canvas = new Canvas(PhantomGame.Game.GraphicsDevice);
this.batch = new SpriteBatch(PhantomGame.Game.GraphicsDevice);
}
if (this.sortMode == SpriteSortMode.Immediate)
this.activeRenderPass = this.RenderPassFullLock;
else
this.activeRenderPass = this.RenderPassEndLock;
}
示例6: CreatePatternBrush
void CreatePatternBrush(float pixelSize)
{
// Determine adjusted pixel size of the brush to create.
const float MAX_PATTERN_SIZE = 80;
const float MIN_PATTERN_SIZE = 10;
if (pixelSize < patternWidth / MAX_PATTERN_SIZE)
pixelSize = patternWidth / MAX_PATTERN_SIZE;
if (pixelSize < patternHeight / MAX_PATTERN_SIZE)
pixelSize = patternHeight / MAX_PATTERN_SIZE;
if (pixelSize > patternWidth / MIN_PATTERN_SIZE)
pixelSize = patternWidth / MIN_PATTERN_SIZE;
if (pixelSize > patternHeight / MIN_PATTERN_SIZE)
pixelSize = patternHeight / MIN_PATTERN_SIZE;
if (patternBrushes != null && Math.Abs(pixelSize - pixelSizeCached) / pixelSize < 0.01)
return; // the pattern brush is already OK size.
// Get size of bitmap to create with the image of the pattern.
float width = (float) Math.Round(patternWidth / pixelSize);
float height = (float) Math.Round(patternHeight / pixelSize);
// Create dictionary to hold brushes for each color.
patternBrushes = new Dictionary<SymColor, Brush>(2);
pixelSizeCached = pixelSize;
RenderOptions renderOpts = new RenderOptions();
renderOpts.minResolution = pixelSize;
renderOpts.usePatternBitmaps = false;
foreach (SymColor color in map.colors) {
if (!patternGlyph.HasColor(color))
continue;
// Create a new bitmap and fill it transparent.
Bitmap bitmap = new Bitmap((int) width, (int) (offsetRows ? height * 2 : height));
Graphics g = Graphics.FromImage(bitmap);
g.CompositingMode = CompositingMode.SourceCopy;
g.SmoothingMode = SmoothingMode.HighQuality;
g.FillRectangle(new SolidBrush(Color.Transparent), 0, 0, bitmap.Width, bitmap.Height);
// Set the center of the bitmap to 0,0, and scale to mm (each pixel is 0.01 mm).
g.TranslateTransform(width / 2.0F, height / 2.0F);
g.ScaleTransform(width / patternWidth, height / patternHeight);
// Draw the pattern into the bitmap.
GraphicsTarget grTarget = new GraphicsTarget(g);
patternGlyph.Draw(grTarget, new PointF(0F, 0F), -patternAngle, GraphicsUtil.IdentityMatrix, null, color, renderOpts);
if (offsetRows) {
patternGlyph.Draw(grTarget, new PointF(patternWidth / 2, patternHeight), -patternAngle, GraphicsUtil.IdentityMatrix, null, color, renderOpts);
patternGlyph.Draw(grTarget, new PointF(-patternWidth / 2, patternHeight), -patternAngle, GraphicsUtil.IdentityMatrix, null, color, renderOpts);
}
// Create a TextureBrush on the bitmap.
TextureBrush brush = new TextureBrush(bitmap);
// Scale and the texture brush.
brush.RotateTransform(patternAngle);
brush.ScaleTransform(patternWidth / width, patternHeight / height);
brush.TranslateTransform(-width / 2.0F, -height / 2.0F);
// Dispose of the graphics.
g.Dispose();
// Add it to the collection of brushes.
patternBrushes.Add(color, brush);
}
}
示例7: DrawPatternWithTexBrush
// Draw the pattern using the texture brush.
void DrawPatternWithTexBrush(GraphicsTarget g, SymPathWithHoles path, float angle, SymColor color, RenderOptions renderOpts)
{
Brush brush = (Brush) patternBrushes[color];
Debug.Assert(brush != null);
if (angle != 0.0F) {
object graphicsState = g.Save();
try {
// Set the clipping region to draw only inside the area.
g.SetClip(path);
// use a transform to rotate.
Matrix matrix = GraphicsUtil.RotationMatrix(angle, new PointF(0, 0));
g.Transform(matrix);
// Get the correct bounding rect.
RectangleF bounding = Util.BoundsOfRotatedRectangle(path.BoundingBox, new PointF(), -angle);
g.FillRectangle(brush, bounding);
}
finally {
// restore the clip region and the transform
g.Restore(graphicsState);
}
}
else {
path.Fill(g, brush);
}
}
示例8: DrawPattern
// Draw the pattern (at the given angle) inside the path.
void DrawPattern(GraphicsTarget g, SymPathWithHoles path, float angle, SymColor color, RenderOptions renderOpts)
{
object graphicsState = g.Save();
try {
// Set the clipping region to draw only inside the area.
g.SetClip(path);
// use a transform to rotate
Matrix matrix = GraphicsUtil.RotationMatrix(patternAngle + angle, new PointF(0, 0));
g.Transform(matrix);
// Get the correct bounding rect.
RectangleF bounding = Util.BoundsOfRotatedRectangle(path.BoundingBox, new PointF(), -(patternAngle + angle));
DrawPatternRows(g, bounding, color, renderOpts);
}
finally {
// restore the clip region and the transform
g.Restore(graphicsState);
}
}
示例9: DrawHatching
// Draw the hatching into the interior of the SymPath.
void DrawHatching(GraphicsTarget g, SymPathWithHoles path, float angle, RenderOptions renderOpts)
{
object graphicsState = g.Save();
try {
// Set the clipping region to draw only inside the area.
g.SetClip(path);
// use a transform to rotate and then draw hatching.
Matrix matrix = GraphicsUtil.RotationMatrix(hatchAngle1 + angle, new PointF(0, 0));
g.Transform(matrix);
// Get the correct bounding rect.
RectangleF bounding = Util.BoundsOfRotatedRectangle(path.BoundingBox, new PointF(), -(hatchAngle1 + angle));
DrawHatchLines(g, hatchPen, hatchSpacing, bounding, renderOpts);
// and again for the second bound of hatching
if (hatchMode == 2) {
// Get the correct bounding rect.
bounding = Util.BoundsOfRotatedRectangle(path.BoundingBox, new PointF(), -(hatchAngle2 + angle));
matrix = GraphicsUtil.RotationMatrix(hatchAngle2 - hatchAngle1, new PointF(0, 0));
g.Transform(matrix);
DrawHatchLines(g, hatchPen, hatchSpacing, bounding, renderOpts);
}
}
finally {
// restore the clip region and the transform
g.Restore(graphicsState);
}
}
示例10: DrawTextOnPath
// Draw this text symbol along a path.
internal void DrawTextOnPath(GraphicsTarget g, SymPath path, string text, SymColor color, RenderOptions renderOpts)
{
if (color == null)
return;
if (color != fontColor && (framing.framingStyle == FramingStyle.None || color != framing.framingColor))
return;
if (!objectsCreated)
CreateObjects();
// Get the location of each grapheme to print.
List<GraphemePlacement> graphemeList = GetLineTextGraphemePlacement(path, text);
PointF topAscentPoint = new PointF(0, -FontAscent); // Drawing is relative to top of char, we want to draw at baseline.
foreach (GraphemePlacement grapheme in graphemeList) {
object graphicsState;
graphicsState = g.Save();
try {
// Move location to draw at to the origin, set angle for drawing text.
Matrix matrix = GraphicsUtil.TranslationMatrix(grapheme.pointStart.X, grapheme.pointStart.Y);
matrix = GraphicsUtil.Multiply(GraphicsUtil.ScalingMatrix(1, -1), matrix); // Reverse Y so text is correct way aroun
matrix = GraphicsUtil.Multiply(GraphicsUtil.RotationMatrix(-grapheme.angle, new PointF(0,0)), matrix);
g.Transform(matrix);
DrawStringWithEffects(g, color, grapheme.grapheme, topAscentPoint);
}
finally {
g.Restore(graphicsState); // restore transform
}
}
}
示例11: Draw
// Draw this point symbol at point pt with angle ang in this graphics (given color only).
internal void Draw(GraphicsTarget g, PointF pt, float angle, float[] gaps, SymColor color, RenderOptions renderOpts)
{
glyph.Draw(g, pt, angle, GraphicsUtil.IdentityMatrix, gaps, color, renderOpts);
}
示例12: OnRebuildRenderData
protected override void OnRebuildRenderData()
{
if( Atlas == null )
return;
var spriteInfo = SpriteInfo;
if( spriteInfo == null )
{
return;
}
renderData.Material = Atlas.Material;
if( spriteInfo.border.horizontal == 0 || spriteInfo.border.vertical == 0 )
{
base.OnRebuildRenderData();
return;
}
var color = ApplyOpacity( IsEnabled ? this.color : this.disabledColor );
var options = new RenderOptions()
{
atlas = atlas,
color = color,
fillAmount = fillAmount,
fillDirection = fillDirection,
flip = flip,
invertFill = invertFill,
offset = pivot.TransformToUpperLeft( Size ),
pixelsToUnits = PixelsToUnits(),
size = Size,
spriteInfo = SpriteInfo
};
renderSprite( renderData, options );
}
示例13: rebuildVertices
private static void rebuildVertices( dfRenderData renderData, RenderOptions options )
{
float meshLeft = 0;
float meshTop = 0;
float meshRight = Mathf.Ceil( options.size.x );
float meshBottom = Mathf.Ceil( -options.size.y );
#region Borders
var spriteInfo = options.spriteInfo;
float borderLeft = spriteInfo.border.left;
float borderTop = spriteInfo.border.top;
float borderRight = spriteInfo.border.right;
float borderBottom = spriteInfo.border.bottom;
if( options.flip.IsSet( dfSpriteFlip.FlipHorizontal ) )
{
float temp = borderRight;
borderRight = borderLeft;
borderLeft = temp;
}
if( options.flip.IsSet( dfSpriteFlip.FlipVertical ) )
{
float temp = borderBottom;
borderBottom = borderTop;
borderTop = temp;
}
#endregion
// Top left corner
verts[ 0 ] = new Vector3( meshLeft, meshTop, 0 ) + options.offset;
verts[ 1 ] = verts[ 0 ] + new Vector3( borderLeft, 0, 0 );
verts[ 2 ] = verts[ 0 ] + new Vector3( borderLeft, -borderTop, 0 );
verts[ 3 ] = verts[ 0 ] + new Vector3( 0, -borderTop, 0 );
// Top right corner
verts[ 4 ] = new Vector3( meshRight - borderRight, meshTop, 0 ) + options.offset;
verts[ 5 ] = verts[ 4 ] + new Vector3( borderRight, 0, 0 );
verts[ 6 ] = verts[ 4 ] + new Vector3( borderRight, -borderTop, 0 );
verts[ 7 ] = verts[ 4 ] + new Vector3( 0, -borderTop, 0 );
// Bottom left corner
verts[ 8 ] = new Vector3( meshLeft, meshBottom + borderBottom, 0 ) + options.offset;
verts[ 9 ] = verts[ 8 ] + new Vector3( borderLeft, 0, 0 );
verts[ 10 ] = verts[ 8 ] + new Vector3( borderLeft, -borderBottom, 0 );
verts[ 11 ] = verts[ 8 ] + new Vector3( 0, -borderBottom, 0 );
// Bottom right corner
verts[ 12 ] = new Vector3( meshRight - borderRight, meshBottom + borderBottom, 0 ) + options.offset;
verts[ 13 ] = verts[ 12 ] + new Vector3( borderRight, 0, 0 );
verts[ 14 ] = verts[ 12 ] + new Vector3( borderRight, -borderBottom, 0 );
verts[ 15 ] = verts[ 12 ] + new Vector3( 0, -borderBottom, 0 );
for( int i = 0; i < verts.Length; i++ )
{
renderData.Vertices.Add( ( verts[ i ] * options.pixelsToUnits ).Quantize( options.pixelsToUnits ) );
}
}
示例14: rebuildUV
private static void rebuildUV( dfRenderData renderData, RenderOptions options )
{
var atlas = options.atlas;
var textureSize = new Vector2( atlas.Texture.width, atlas.Texture.height );
var spriteInfo = options.spriteInfo;
float offsetTop = spriteInfo.border.top / textureSize.y;
float offsetBottom = spriteInfo.border.bottom / textureSize.y;
float offsetLeft = spriteInfo.border.left / textureSize.x;
float offsetRight = spriteInfo.border.right / textureSize.x;
var rect = spriteInfo.region;
// Top left corner
uv[ 0 ] = new Vector2( rect.x, rect.yMax );
uv[ 1 ] = new Vector2( rect.x + offsetLeft, rect.yMax );
uv[ 2 ] = new Vector2( rect.x + offsetLeft, rect.yMax - offsetTop );
uv[ 3 ] = new Vector2( rect.x, rect.yMax - offsetTop );
// Top right corner
uv[ 4 ] = new Vector2( rect.xMax - offsetRight, rect.yMax );
uv[ 5 ] = new Vector2( rect.xMax, rect.yMax );
uv[ 6 ] = new Vector2( rect.xMax, rect.yMax - offsetTop );
uv[ 7 ] = new Vector2( rect.xMax - offsetRight, rect.yMax - offsetTop );
// Bottom left corner
uv[ 8 ] = new Vector2( rect.x, rect.y + offsetBottom );
uv[ 9 ] = new Vector2( rect.x + offsetLeft, rect.y + offsetBottom );
uv[ 10 ] = new Vector2( rect.x + offsetLeft, rect.y );
uv[ 11 ] = new Vector2( rect.x, rect.y );
// Bottom right corner
uv[ 12 ] = new Vector2( rect.xMax - offsetRight, rect.y + offsetBottom );
uv[ 13 ] = new Vector2( rect.xMax, rect.y + offsetBottom );
uv[ 14 ] = new Vector2( rect.xMax, rect.y );
uv[ 15 ] = new Vector2( rect.xMax - offsetRight, rect.y );
#region Flip UV if requested
if( options.flip != dfSpriteFlip.None )
{
for( int i = 0; i < uv.Length; i += 4 )
{
Vector2 temp = Vector2.zero;
if( options.flip.IsSet( dfSpriteFlip.FlipHorizontal ) )
{
temp = uv[ i + 0 ]; uv[ i + 0 ] = uv[ i + 1 ]; uv[ i + 1 ] = temp;
temp = uv[ i + 2 ]; uv[ i + 2 ] = uv[ i + 3 ]; uv[ i + 3 ] = temp;
}
if( options.flip.IsSet( dfSpriteFlip.FlipVertical ) )
{
temp = uv[ i + 0 ]; uv[ i + 0 ] = uv[ i + 3 ]; uv[ i + 3 ] = temp;
temp = uv[ i + 1 ]; uv[ i + 1 ] = uv[ i + 2 ]; uv[ i + 2 ] = temp;
}
}
if( options.flip.IsSet( dfSpriteFlip.FlipHorizontal ) )
{
var th = new Vector2[ uv.Length ];
Array.Copy( uv, th, uv.Length );
// Swap top-left and top-right corners
Array.Copy( uv, 0, uv, 4, 4 );
Array.Copy( th, 4, uv, 0, 4 );
// Swap bottom-left and bottom-right corners
Array.Copy( uv, 8, uv, 12, 4 );
Array.Copy( th, 12, uv, 8, 4 );
}
if( options.flip.IsSet( dfSpriteFlip.FlipVertical ) )
{
var tv = new Vector2[ uv.Length ];
Array.Copy( uv, tv, uv.Length );
// Swap top-left and bottom-left corners
Array.Copy( uv, 0, uv, 8, 4 );
Array.Copy( tv, 8, uv, 0, 4 );
// Swap top-right and bottom-right corners
Array.Copy( uv, 4, uv, 12, 4 );
Array.Copy( tv, 12, uv, 4, 4 );
}
}
#endregion
for( int i = 0; i < uv.Length; i++ )
{
renderData.UV.Add( uv[ i ] );
//.........这里部分代码省略.........
示例15: rebuildTriangles
private static void rebuildTriangles( dfRenderData renderData, RenderOptions options )
{
var baseIndex = options.baseIndex;
var triangles = renderData.Triangles;
for( int i = 0; i < triangleIndices.Length; i++ )
{
triangles.Add( baseIndex + triangleIndices[ i ] );
}
}