Forum
Contact





DirectX using C#
DirectX using C++
DirectX using Visual Basic



Latest Forum posts

 No download link for 2d series: shooter
  Posted by: zaboleq
  When: 07/05/2013 at 15:46:28

 Collision Class?
  Posted by: Anonymous
  When: 05/05/2013 at 19:03:59

 stack overflow
  Posted by: cityguy
  When: 07/04/2013 at 01:58:38

 Meshes looks strange.
  Posted by: ab_saratov
  When: 01/04/2013 at 04:31:08

 Lamppost Not loaded
  Posted by: Anonymous
  When: 22/03/2013 at 06:43:52

 Collision Class?
  Posted by: Da_Boom
  When: 21/03/2013 at 01:23:09

 Math boggles me
  Posted by: cityguy
  When: 17/03/2013 at 03:44:48

 Collision Class?
  Posted by: Da_Boom
  When: 16/03/2013 at 03:44:42

 Tree update
  Posted by: Anonymous
  When: 15/03/2013 at 21:11:22

 XNA 4.0
  Posted by: Anonymous
  When: 15/03/2013 at 19:43:57

 Error when I try to run.
  Posted by: Anonymous
  When: 15/03/2013 at 19:21:06

 Error With the Effect File
  Posted by: Anonymous
  When: 15/03/2013 at 18:21:01

 Can only get shadowmap
  Posted by: Anonymous
  When: 15/03/2013 at 15:48:52

 Vertex and Pixel Shader Versions?
  Posted by: Anonymous
  When: 15/03/2013 at 15:07:16

 Unsupported properties
  Posted by: Anonymous
  When: 15/03/2013 at 14:23:00

 Problem Loading Skybox
  Posted by: Rana
  When: 15/03/2013 at 10:34:45

 Black Screen Of Death - Help!
  Posted by: Anonymous
  When: 15/03/2013 at 03:43:43

 2.0 anyone?
  Posted by: Anonymous
  When: 15/03/2013 at 02:19:48

 Defitinition of tha rotation axis
  Posted by: Anonymous
  When: 15/03/2013 at 00:55:14

 Typo / Inconsistancy for 360 deployment.
  Posted by: Anonymous
  When: 14/03/2013 at 19:48:23




Topic: XNA 2.0 Strugglers



  
Goto parent category
  
Create a new user account


   XNA 2.0 Strugglers
 Poster : cpyburn
 Posts: 29
 Country : UnitedStats
 City: Memphis

  
Posted by cpyburn on 28/05/2008 at 16:00:45
//XNA 2.0 -Triangle Strip- Make sure you added streettexture.dds from last chapter to your content folder
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace XNAtutorialSeries3
    // Altered for XNA 2.0 using Series 1 Your first triangle as Starting Point and Making Changes for Series 3
    // Everything added by me is // Added and ended with // Ended.  This follows everything up to this point.
    // I will continue to update these and post on the forums as I complete them in my free time.
    // This tutorial assumes you made a FX file named OurHLSLfile.fx.  If you need help, go to content, right click, add, new item, effects file
    // Cut and paiste this code in below. Alteration By: Cpyburn
    /* DONT INCLUDE THE COMMENT CODE AKA /**/
/* //DONT INCLUDE THIS LINE
struct VertexToPixel
{
    float4 Position     : POSITION;


     float2 TexCoords    : TEXCOORD0;


};

struct PixelToFrame
{
    float4 Color : COLOR0;
};

float4x4 xViewProjection;



Texture xColoredTexture;

sampler ColoredTextureSampler = sampler_state { texture = <xColoredTexture> ; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = mirror; AddressV = mirror;};



VertexToPixel SimplestVertexShader( float4 inPos : POSITION, float2 inTexCoords : TEXCOORD0)


{
    VertexToPixel Output = (VertexToPixel)0;
    
    Output.Position = mul(inPos, xViewProjection);


     Output.TexCoords = inTexCoords;


    
    return Output;    
}

PixelToFrame OurFirstPixelShader(VertexToPixel PSIn)
{
    PixelToFrame Output = (PixelToFrame)0;



     Output.Color = tex2D(ColoredTextureSampler, PSIn.TexCoords);



    return Output;
}

technique Simplest
{
    pass Pass0
    {        
        VertexShader = compile vs_1_1 SimplestVertexShader();
        PixelShader = compile ps_1_1 OurFirstPixelShader();
    }
}

*/
//DONT INCLUDE THIS LINE
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        // Added
        private struct myownvertexformat
        {
            private Vector3 position;
            //private Color color; // Removed
            private Vector2 TexCoord; // Added

            public myownvertexformat(Vector3 position, Vector2 TexCoord) // Removed Color color parameter
            {
                this.position = position;
                //this.color = color; // Removed
                this.TexCoord = TexCoord; // Added
            }

            public static VertexElement[] Elements =
             {
                 new VertexElement(0, 0, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Position, 0),
                 new VertexElement(0, sizeof(float)*3, VertexElementFormat.Vector2, VertexElementMethod.Default, VertexElementUsage.TextureCoordinate, 0), // Fog
             };
            public static int SizeInBytes = sizeof(float) * (3 + 2); // Altered (3 + 1) because vector2 uses 2 floats, color only used one
        }// End Added

        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        GraphicsDevice device;
        Effect effect;

        // Added
        //VertexPositionColor[] vertices;
        VertexBuffer vb;
        VertexDeclaration myVertexDeclaration;
        Matrix viewMatrix;
        Matrix projectionMatrix;
        Texture2D StreetTexture;
        // End Added

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            graphics.PreferredBackBufferWidth = 500;
            graphics.PreferredBackBufferHeight = 500;
            graphics.IsFullScreen = false;
            graphics.ApplyChanges();
            Window.Title = "Riemers series 3 altered by cpyburn to xna 2.0";

            base.Initialize();
        }

        // Added
        private void SetUpVertices()
        {
            myownvertexformat[] vertices = new myownvertexformat[12];

            vertices[0] = new myownvertexformat(new Vector3(-20, -10, 0), new Vector2(-0.25f, 25.0f));
            vertices[1] = new myownvertexformat(new Vector3(-20, 100, 0), new Vector2(-0.25f, 0.0f));
            vertices[2] = new myownvertexformat(new Vector3(2, -10, 0), new Vector2(0.25f, 25.0f));
            vertices[3] = new myownvertexformat(new Vector3(2, 100, 0), new Vector2(0.25f, 0.0f));
            vertices[4] = new myownvertexformat(new Vector3(2, -10, 1), new Vector2(0.375f, 25.0f));
            vertices[5] = new myownvertexformat(new Vector3(2, 100, 1), new Vector2(0.375f, 0.0f));
            vertices[6] = new myownvertexformat(new Vector3(3, -10, 1), new Vector2(0.5f, 25.0f));
            vertices[7] = new myownvertexformat(new Vector3(3, 100, 1), new Vector2(0.5f, 0.0f));
            vertices[8] = new myownvertexformat(new Vector3(13, -10, 1), new Vector2(0.75f, 25.0f));
            vertices[9] = new myownvertexformat(new Vector3(13, 100, 1), new Vector2(0.75f, 0.0f));
            vertices[10] = new myownvertexformat(new Vector3(13, -10, 21), new Vector2(1.25f, 25.0f));
            vertices[11] = new myownvertexformat(new Vector3(13, 100, 21), new Vector2(1.25f, 0.0f));

            vb = new VertexBuffer(device, myownvertexformat.SizeInBytes * 12, BufferUsage.WriteOnly);
            vb.SetData(vertices);
            myVertexDeclaration = new VertexDeclaration(device, myownvertexformat.Elements);
            // End Added
        }// End Added


        protected override void LoadContent()
        {
            device = graphics.GraphicsDevice;
            spriteBatch = new SpriteBatch(GraphicsDevice);

            effect = Content.Load<Effect>("OurHLSLfile");
            // Added
            StreetTexture = Content.Load<Texture2D>("streettexture");
            SetUpVertices();
            SetUpCamera();
            // End Added
        }

        protected override void UnloadContent()
        {
        }

        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            device.Clear(Color.DarkSlateBlue);

            // Added
            effect.CurrentTechnique = effect.Techniques["Simplest"];
            //effect.Parameters["xView"].SetValue(viewMatrix);
            effect.Parameters["xViewProjection"].SetValue(viewMatrix * projectionMatrix);
            effect.Parameters["xColoredTexture"].SetValue(StreetTexture); // Added to send texture to the .FX file
            //effect.Parameters["xWorld"].SetValue(Matrix.Identity);
            // End Added
            effect.Begin();
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();

                // Added
                device.VertexDeclaration = myVertexDeclaration;
                device.Vertices[0].SetSource(vb, 0, myownvertexformat.SizeInBytes); // Make sure to pur the correct size!!!
                device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 10);
                // End Added
                pass.End();
            }
            effect.End();

            base.Draw(gameTime);
        }

        // Added
        private void SetUpCamera()
        {
            viewMatrix = Matrix.CreateLookAt(new Vector3(-25, -18, 13), new Vector3(0, 12, 2), new Vector3(0, 0, 1)); // Grrrr I hate when Z is up?
            projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, device.Viewport.AspectRatio, 1.0f, 300.0f);
        }// End Added
    }
}

  
Post a new reply
 





Google
 
Web www.riemers.net
If you appreciate the amount of time I spend creating and updating
these pages, feel free to donate -- any amount is welcome !
- Website design & DirectX code : Riemer Grootjans -
©2006 Riemer Grootjans


News
Home
Forum
XNA 2.0 Recipes Book (8)
XNA 3.0 Recipes Book (8)
Downloads
Extra Reading (3)
Matrices: geometrical
Matrix Mathematics
Homogenous matrices
Community Projects (1)
Tutorials (160)
XNA 4.0 using C# (89)
DirectX using C# (54)
Series 1:Terrain (14)
Opening a window
Linking to the Device
Drawing a triangle
Camera
Rotation - Translation
Indices
Terrain creation
Terrain from file
DirectInput
Importing bmp files
Colored vertices
DirectX Light basics
Mesh creation
Mesh lighting
Series 2: Flightsim (19)
Series 3: HLSL (19)
Short Tuts (2)
Resizing problem
Checking Device caps
DirectX using C++ (15)
DirectX using VB (2)