Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Phone

Developing for Windows Phone 7 and Xbox 360 : Drawing with a Custom Effect

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
6/19/2011 4:19:51 PM
So you have your first custom effect file but nothing to show for it on the screen. Let’s get started by drawing a quad with the new effect file.

Define the following two member variables to hold the Effect and the array of vertices make up the two triangles in the quad.

Effect customEffect;
VertexPositionColor[] userPrimitives;

The Effect type is used with custom effects and is the base type of the five built-in effects. There are a number of built-in vertex types. The VertexPositionColor contains both the vertex position and the color for the vertex. All built-in vertex types implement the IVertexType interface that requires the vertex type to specify the VertexDeclaration. As we discussed before, the VertexDeclaration is used to tell the graphics hardware how the fields of the vertex should be used, such as position and color.

Next, in the games LoadContent method, load the Effect and define each of the vertices.

// Load custom effect and set parameters
customEffect = Content.Load<Effect>("CustomEffect");
customEffect.Parameters["World"].SetValue(Matrix.Identity);
customEffect.Parameters["View"].SetValue(Matrix.CreateLookAt(new Vector3(0, 0, 3), new
Vector3(0, 0, 0), new Vector3(0, 1, 0)));
customEffect.Parameters["Projection"].SetValue(Matrix.CreatePerspectiveFieldOfView (MathHel
per.PiOver4, GraphicsDevice.Viewport.AspectRatio, 0.1f, 100.0f));

// Create the verticies for our triangle
userPrimitives = new VertexPositionColor[4];
userPrimitives[0] = new VertexPositionColor();
userPrimitives[0].Position = new Vector3(-1, 1, 0);
userPrimitives[0].Color = Color.Red;
userPrimitives[1] = new VertexPositionColor();
userPrimitives[1].Position = new Vector3(1, 1, 0);
userPrimitives[1].Color = Color.Green;
userPrimitives[2] = new VertexPositionColor();
userPrimitives[2].Position = new Vector3(-1, -1, 0);
userPrimitives[2].Color = Color.Blue;
userPrimitives[3] = new VertexPositionColor();
userPrimitives[3].Position = new Vector3(1, -1, 0);
userPrimitives[3].Color = Color.Yellow;


Notice that the Effect is loaded through the content pipeline. After loading the effect, set three properties for the World, View, and Project matrices. Although the built-in effects expose these as properties in the API surface, your Effect can’t because there is no guarantee that the Effect will use those global variables. Instead, use the Parameters collection and specify the parameter by string name.

Finally, in the games Draw method, tell the graphics card that you are using this specific effect and to draw the two triangles.

// Start using the BasicEffect
customEffect.CurrentTechnique.Passes[0].Apply();
// Draw the primitives
GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleStrip,
userPrimitives, 0, 2);


Before using an Effect, call Apply on the specific EffectPass you plan to use. In this case, you know there is only one EffectTechnique, so use the CurrentTechniqueEffectPass, so use index 0. and there is only one

Now you are ready to draw. Press F5 and see the glory that is your first effect. Figure 1 shows an example of what you should see.

Figure 1. Drawing a quad with your first custom effect


Well that’s not too exciting, but it draws a pure red quad to the screen. Notice that the colors that were defined for each vertex are not used because the template pixel shader just outputs the single red color and does not use the vertex color. Don’t worry about it—it gets better looking from here.

Other -----------------
- Developing for Windows Phone 7 and Xbox 360 : Creating Your First Custom Effect & Parts of an Effect File
- Developing for Windows Phone and Xbox Live : SamplerStates
- Windows Phone 7 Development : Understanding Device Physical Security & Meeting Certification Requirements
- Windows Phone 7 Development : Implementing Data Security (part 2) - Using Rfc2898DeriveBytes and AES to Encrypt Data
- Windows Phone 7 Development : Implementing Data Security (part 1) - Using HMACSHA1 and HMACHSHA256
- Developing for Windows Phone and Xbox Live : Back to Device States (part 2) - RasterizerState
- Developing for Windows Phone and Xbox Live : Back to Device States (part 1) - The Stencil Buffer
- Developing for Windows Phone and Xbox Live : Render Targets (part 2) - Faking a Shadow with a Depth Buffer and Render Targets
- Developing for Windows Phone and Xbox Live : Render Targets (part 1)
- Windows Phone 7 Development : Implementing Network Security
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server