using
System;
using
System.Collections.Generic;
using
Microsoft.Xna.Framework;
using
Microsoft.Xna.Framework.Content;
using
Microsoft.Xna.Framework.GamerServices;
using
Microsoft.Xna.Framework.Graphics;
using
Microsoft.Xna.Framework.Input;
public
class GameClass
: Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
// ** TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
// ** TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
Texture2D testImage;
public GameClass()
{
graphics =
new
GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override
void LoadContent()
{
// ** TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
// ** TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
testImage
= Content.Load<Texture2D>("myImage");
}
// ** TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
// ** TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
// ** TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
public void
DrawQuad(Texture2D tex,
float x, float
y, float w, float
h)
{
VertexPositionTexture[]
verts ={new
VertexPositionTexture(new
Vector3(x, y, 0),
new Vector2(0.0f,
0.0f)),
new
VertexPositionTexture(new
Vector3(x+w, y, 0),
new Vector2(1.0f,
0.0f)),
new
VertexPositionTexture(new
Vector3(x+w, y+h, 0),
new Vector2(1.0f,
1.0f)),
new
VertexPositionTexture(new
Vector3(x, y+h, 0),
new Vector2(0.0f,
1.0f))};
VertexDeclaration
basicEffectVertexDeclaration
=
new
VertexDeclaration(graphics.GraphicsDevice,
VertexPositionTexture.VertexElements);
BasicEffect basicEffect;
basicEffect = new
BasicEffect(graphics.GraphicsDevice,
null);
basicEffect.Alpha = 1.0f;
basicEffect.VertexColorEnabled = false;
basicEffect.TextureEnabled = true;
basicEffect.Texture = tex;
basicEffect.EnableDefaultLighting();
basicEffect.LightingEnabled = false;
basicEffect.Projection = Matrix.CreateOrthographicOffCenter(0.0F,
graphics.GraphicsDevice.Viewport.Width,
graphics.GraphicsDevice.Viewport.Height, 0.0f,
0.0F, -1.0F);
basicEffect.View = Matrix.Identity;
basicEffect.World = Matrix.Identity;
graphics.GraphicsDevice.SamplerStates[0].AddressU =
TextureAddressMode.Wrap;
graphics.GraphicsDevice.SamplerStates[0].AddressV =
TextureAddressMode.Wrap;
graphics.GraphicsDevice.RenderState.CullMode =
CullMode.None;
graphics.GraphicsDevice.VertexDeclaration = basicEffectVertexDeclaration;
basicEffect.Begin();
foreach (EffectPass
pass in basicEffect.CurrentTechnique.Passes)
{
pass.Begin();
graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>(
PrimitiveType.TriangleFan,
verts, 0, 2);
pass.End();
}
basicEffect.End();
}//
End DrawQuad(..)
// ** TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
// ** TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
// ** TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
protected override
void Update(GameTime
gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back
== ButtonState.Pressed)
this.Exit();
base.Update(gameTime);
}
protected override
void Draw(GameTime
gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// ** TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
// ** TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
TEXTURE2D ** TEXTURE2D ** TEXTURE2D **
DrawQuad(testImage, 40, 40, 300, 300);
base.Draw(gameTime);
}
}
//
Program Entry Point
static
class Program
{
static void
Main(string[] args)
{
using (GameClass
game = new
GameClass())
{
game.Run();
}
}
} |