本文整理汇总了C#中GraphicsDevice类的典型用法代码示例。如果您正苦于以下问题:C# GraphicsDevice类的具体用法?C# GraphicsDevice怎么用?C# GraphicsDevice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GraphicsDevice类属于命名空间,在下文中一共展示了GraphicsDevice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadingScreen
/// <summary>
/// The constructor is private: loading screens should
/// be activated via the static Load method instead.
/// </summary>
private LoadingScreen (ScreenManager screenManager,bool loadingIsSlow,
GameScreen[] screensToLoad)
{
this.loadingIsSlow = loadingIsSlow;
this.screensToLoad = screensToLoad;
TransitionOnTime = TimeSpan.FromSeconds (0.5);
// If this is going to be a slow load operation, create a background
// thread that will update the network session and draw the load screen
// animation while the load is taking place.
if (loadingIsSlow) {
backgroundThread = new Thread (BackgroundWorkerThread);
backgroundThreadExit = new ManualResetEvent (false);
graphicsDevice = screenManager.GraphicsDevice;
// Look up some services that will be used by the background thread.
IServiceProvider services = screenManager.Game.Services;
networkSession = (NetworkSession)services.GetService (
typeof(NetworkSession));
messageDisplay = (IMessageDisplay)services.GetService (
typeof(IMessageDisplay));
}
}
示例2: getMouseWorldPosition
/// <summary>
/// Checks the mouse's position set in the in-game world plane.
/// </summary>
/// <param name="mousePosition">Mouse's position on screen</param>
/// <param name="camera">Camera object</param>
/// <param name="device">Graphics device used in rendering</param>
/// <returns></returns>
public static Vector3 getMouseWorldPosition(Vector2 mousePosition,CameraAndLights camera,GraphicsDevice device)
{
Vector3 nearsource = new Vector3(mousePosition,0f);
Vector3 farsource = new Vector3(mousePosition,CameraAndLights.nearClip);
Vector3 nearPoint = device.Viewport.Unproject(nearsource,
camera.projectionMatrix,
camera.viewMatrix,
Matrix.Identity);
Vector3 farPoint = device.Viewport.Unproject(farsource,
camera.projectionMatrix,
camera.viewMatrix,
Matrix.Identity);
// Create a ray from the near clip plane to the far clip plane.
Vector3 direction = farPoint - nearPoint;
direction.Normalize();
Ray pickRay = new Ray(nearPoint,direction);
Plane floor = new Plane(new Vector3(0f,1f,0f),0f);
float denominator = Vector3.Dot(floor.Normal,pickRay.Direction);
float numerator = Vector3.Dot(floor.Normal,pickRay.Position) + floor.D;
float dist = -(numerator / denominator);
Vector3 mouseWorldPos = nearPoint + direction * dist;
return mouseWorldPos * new Vector3(1f,0f,1f);
}
示例3: Player
/// <summary>
/// Player constructor.
/// </summary>
/// <param name="color"></param>
public Player(Alliance alliance, Color color, Point startLocation)
{
Game1.GetInstance().players.AddLast(this);
this.device = Game1.GetInstance().GraphicsDevice;
this.alliance = alliance;
this.startLocation = startLocation;
if (!this.alliance.members.Contains(this)) this.alliance.members.AddLast(this);
this.color = color;
selectionTex = Game1.GetInstance().Content.Load<Texture2D>("Selection");
selectedTex = Game1.GetInstance().Content.Load<Texture2D>("Selected");
units = new CustomArrayList<Unit>();
buildings = new CustomArrayList<Building>();
hud = new HUD(this, color);
resources = 100000;
meleeStore = new MeleeStore(this);
rangedStore = new RangedStore(this);
fastStore = new FastStore(this);
arrowManager = new ArrowManager();
lightTexture = Game1.GetInstance().Content.Load<Texture2D>("Fog/Light");
MouseManager.GetInstance().mouseClickedListeners += ((MouseClickListener)this).OnMouseClick;
MouseManager.GetInstance().mouseReleasedListeners += ((MouseClickListener)this).OnMouseRelease;
MouseManager.GetInstance().mouseMotionListeners += ((MouseMotionListener)this).OnMouseMotion;
MouseManager.GetInstance().mouseDragListeners += ((MouseMotionListener)this).OnMouseDrag;
}
示例4: APNGFrame
internal APNGFrame(GraphicsDevice graphicsDevice, Frame frame)
{
if (frame.fcTLChunk != null)
{
X = (int) frame.fcTLChunk.XOffset;
Y = (int) frame.fcTLChunk.YOffset;
Width = (int) frame.fcTLChunk.Width;
Height = (int) frame.fcTLChunk.Height;
BlendOp = frame.fcTLChunk.BlendOp;
DisposeOp = frame.fcTLChunk.DisposeOp;
DelayTime = new TimeSpan(
TimeSpan.TicksPerSecond*frame.fcTLChunk.DelayNum/frame.fcTLChunk.DelayDen);
}
else
{
X = 0;
Y = 0;
Width = frame.IHDRChunk.Width;
Height = frame.IHDRChunk.Height;
BlendOp = BlendOps.APNGBlendOpSource;
DisposeOp = DisposeOps.APNGDisposeOpNone;
DelayTime = TimeSpan.Zero;
}
// frame.GetStream() is not seekable, so we build a new MemoryStream.
FrameTexture = Texture2D.FromStream(
graphicsDevice, new MemoryStream(frame.GetStream().ToArray()));
MultiplyAlpha(FrameTexture);
}
示例5: DrawObjects
public override void DrawObjects(GraphicsDevice graphicDevice, SpriteBatch spriteBatch, ContentManager content)
{
graphicDevice.Clear(Color.CornflowerBlue);
SpriteFont newFont = content.Load<SpriteFont>(@"Fonts/Text");
spriteBatch.Begin();
this.controlScreenBackgroundPosition = new Vector2(0, 0);
spriteBatch.Draw(this.controlScreenBackgroundTexture, this.controlScreenBackgroundPosition, Color.White);
if (this.controlScreenItems.Count < 1)
{
// Back planket and text;
this.buttonPosition = new Vector2(840, 660);
this.controlScreenItems.Add(new MenuItems(this.button, this.buttonPosition, "Back", newFont, false));
}
this.controlScreenItems[this.selectedEntry].Selected = true;
foreach (var item in this.controlScreenItems)
{
item.DrawMenuItems(spriteBatch, new Color(248, 218, 127));
}
this.DrawCursor(spriteBatch);
spriteBatch.End();
}
示例6: CreateWhitePixel
private static Texture2D CreateWhitePixel(GraphicsDevice graphicsDevice)
{
whitePixel = new Texture2D(graphicsDevice, 1, 1);
whitePixel.SetData(new[] { Color.White });
return whitePixel;
}
示例7: Draw
public void Draw(GraphicsDevice gd)
{
drawEffect.World = Matrix.CreateTranslation(Position);
drawEffect.DiffuseColor = new Vector3(1f, 1f - hitAlpha, 1f - hitAlpha);
foreach (EffectPass pass in drawEffect.CurrentTechnique.Passes)
{
pass.Apply();
AnimChunk c = shipSprite.AnimChunks[0];
if (c == null) continue;
if (c == null || c.VertexArray == null || c.VertexArray.Length == 0) continue;
gd.DrawUserIndexedPrimitives<VertexPositionNormalColor>(PrimitiveType.TriangleList, c.VertexArray, 0, c.VertexArray.Length, c.IndexArray, 0, c.VertexArray.Length / 2);
}
drawEffect.World = Matrix.CreateScale(0.75f) * (Matrix.CreateRotationX(orbRotation.X) * Matrix.CreateRotationY(orbRotation.Y) * Matrix.CreateRotationZ(orbRotation.Z)) * Matrix.CreateTranslation(orbPosition);
drawEffect.DiffuseColor = Color.White.ToVector3();
foreach (EffectPass pass in drawEffect.CurrentTechnique.Passes)
{
pass.Apply();
AnimChunk c = shipSprite.AnimChunks[1];
if (c == null) continue;
if (c == null || c.VertexArray == null || c.VertexArray.Length == 0) continue;
gd.DrawUserIndexedPrimitives<VertexPositionNormalColor>(PrimitiveType.TriangleList, c.VertexArray, 0, c.VertexArray.Length, c.IndexArray, 0, c.VertexArray.Length / 2);
}
}
示例8: CylinderPrimitive
/// <summary>
/// Constructs a new cylinder primitive,
/// with the specified size and tessellation level.
/// </summary>
public CylinderPrimitive(GraphicsDevice graphicsDevice,
float height, float radius, int tessellation)
{
if (tessellation < 3)
throw new ArgumentOutOfRangeException("tessellation");
height /= 2;
// Create a ring of triangles around the outside of the cylinder.
for (int i = 0; i < tessellation; i++)
{
Vector3 normal = GetCircleVector(i, tessellation);
AddVertex(normal * radius + Vector3.Up * height, normal);
AddVertex(normal * radius + Vector3.Down * height, normal);
AddIndex(i * 2);
AddIndex(i * 2 + 1);
AddIndex((i * 2 + 2) % (tessellation * 2));
AddIndex(i * 2 + 1);
AddIndex((i * 2 + 3) % (tessellation * 2));
AddIndex((i * 2 + 2) % (tessellation * 2));
}
// Create flat triangle fan caps to seal the top and bottom.
CreateCap(tessellation, height, radius, Vector3.Up);
CreateCap(tessellation, height, radius, Vector3.Down);
InitializePrimitive(graphicsDevice);
}
示例9: Event
public Event(SpriteBatch _s, GraphicsDevice _g,SpriteFont _font)
{
s = _s;
g = _g;
font = _font;
posBGI.X = 0;
posBGI.Y = 0;
posLeft0.X = 0;
posLeft0.Y = 10;
posLeft1.X = 60;
posLeft1.Y = 10;
posRight0.X = 480;
posRight0.Y = 10;
posRight1.X = 520;
posRight1.Y = 10;
posFrame.X = 10;
posFrame.Y = 340;
posName.X = 100;
posName.Y = 355;
posTalk.X = 50;
posTalk.Y = 400;
serif = new List<string>();
Stream stream;
stream = File.OpenRead("images/hb1.png");
imgBGI = Texture2D.FromStream(g, stream);
stream = File.OpenRead("images/sowaku.png");
imgFrame = Texture2D.FromStream(g, stream);
}
示例10: ColorVertex
public virtual void ColorVertex(GraphicsDevice gd, int index, Vector2 texturePosition)
{
VertexPositionNormalTexture v = vertices[index];
v.TextureCoordinate = texturePosition;
vertices[index] = v;
InitializeVertexBuffer(gd);
}
示例11: LightmapDrawBuffer
/// <summary>
/// Initializes a new instance of the <see cref="LightmapDrawBuffer"/> class.
/// </summary>
/// <param name="device">The graphics device.</param>
public LightmapDrawBuffer(GraphicsDevice device)
{
this.device = device;
// this.indices = new List<int>();
this.vertices = new List<HullVertex>();
}
示例12: Draw
public override void Draw(GraphicsDevice device, Camera camera)
{
game.GraphicsDevice.BlendState = BlendState.AlphaBlend;
Matrix[] transforms = new Matrix[model.Bones.Count];
model.CopyAbsoluteBoneTransformsTo(transforms);
game.GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead;
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.World = mesh.ParentBone.Transform * GetWorld();
effect.View = camera.view;
effect.Projection = camera.projection;
effect.TextureEnabled = true;
effect.Texture = tex;
effect.Alpha = alpha;
//trying to get lighting to work, but so far the model just shows up as pure black - it was exported with a green blinn shader
//effect.EnableDefaultLighting(); //did not work
effect.LightingEnabled = true;
}
mesh.Draw();
}
}
示例13: Draw
public override void Draw(double elapsedSeconds, GraphicsDevice device)
{
sb.Begin();
gui.Draw(device, sb, elapsedSeconds);
sb.End();
base.Draw(elapsedSeconds, device);
}
示例14: AutoInitialize
//===========================================================
// Structures and Variables
//===========================================================
//===========================================================
// Overridden Particle System Functions
//===========================================================
//===========================================================
// Initialization Functions
//===========================================================
public override void AutoInitialize(GraphicsDevice cGraphicsDevice, ContentManager cContentManager, SpriteBatch cSpriteBatch)
{
InitializeSpriteParticleSystem(cGraphicsDevice, cContentManager, 1000, 50000, "Textures/Smoke");
LoadParticleSystem();
Emitter.ParticlesPerSecond = 200;
Name = "Dot";
}
示例15: TrophyScreen
public TrophyScreen(GameWorld3D game)
{
_game = game.Game;
_graphicsDevice = game.GraphicsDevice;
_gameWorld3D = game;
Initialize();
}