Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1091183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:29:07+00:00 2026-05-16T23:29:07+00:00

I’m currently trying to make a simple square by combining two triangles, like in

  • 0

I’m currently trying to make a simple square by combining two triangles, like in the tutorials by Riemer (Link to tutorial), but since a lot has changed from 3.x to 4.0, I find it difficult.
I would also like to know how to texture this “square”, so if anyone could help me by giving some example or whatsoever, I would appreciate it 🙂

Thanks!

  • Basic
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:29:08+00:00Added an answer on May 16, 2026 at 11:29 pm

    Here is an example XNA 4.0 program that draws a simple textured square. It requires the Green-gel-x texture (from wiki-commons – link in code) added to the content project (or replaced with your own texture). After the textured square is drawn, a wireframe square is drawn over the top so you can see the triangles. This example uses an orthographic projection and a BasicEffect instead of an effect file but is otherwise similar to the Riemer tutorial you linked to.

    To perform the texturing each vertex requires a texture coordinate. For a texture that tiles once across the surface of the square the texture coordinates are (0, 0) for the top left vertex and (1, 1) for the bottom right vertex and so on. If you wanted to tile the texture across the square twice, you could set all the bottom right texture coordinates to 2, instead of 1.

    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Graphics;
    using Microsoft.Xna.Framework.Input;
    
    namespace WindowsGame
    {
        public class Game1 : Microsoft.Xna.Framework.Game
        {
            const string TEXTURE_NAME = "Green-gel-x";  // http://upload.wikimedia.org/wikipedia/commons/9/99/Green-gel-x.png
            const int TOP_LEFT = 0;
            const int TOP_RIGHT = 1;
            const int BOTTOM_RIGHT = 2;
            const int BOTTOM_LEFT = 3;
            RasterizerState WIREFRAME_RASTERIZER_STATE = new RasterizerState() { CullMode = CullMode.None, FillMode = FillMode.WireFrame };
    
            GraphicsDeviceManager graphics;
            BasicEffect effect;
            Texture2D texture;
            VertexPositionColorTexture[] vertexData;
            int[] indexData;
            Matrix viewMatrix;
            Matrix projectionMatrix;
    
            public Game1()
            {
                graphics = new GraphicsDeviceManager(this);
                Content.RootDirectory = "Content";
            }
    
            protected override void Initialize()
            {
                effect = new BasicEffect(graphics.GraphicsDevice);
    
                SetUpVertices(Color.White);
                SetUpCamera();
                SetUpIndices();
    
                base.Initialize();
            }
    
            private void SetUpVertices(Color color)
            {
                const float HALF_SIDE = 200.0f;
                const float Z = 0.0f;
    
                vertexData = new VertexPositionColorTexture[4];
                vertexData[TOP_LEFT] = new VertexPositionColorTexture(new Vector3(-HALF_SIDE, HALF_SIDE, Z), color, new Vector2(0, 0));
                vertexData[TOP_RIGHT] = new VertexPositionColorTexture(new Vector3(HALF_SIDE, HALF_SIDE, Z), color, new Vector2(1, 0));
                vertexData[BOTTOM_RIGHT] = new VertexPositionColorTexture(new Vector3(HALF_SIDE, -HALF_SIDE, Z), color, new Vector2(1, 1));
                vertexData[BOTTOM_LEFT] = new VertexPositionColorTexture(new Vector3(-HALF_SIDE, -HALF_SIDE, Z), color, new Vector2(0, 1));
            }
    
            private void SetUpIndices()
            {
                indexData = new int[6];
                indexData[0] = TOP_LEFT;
                indexData[1] = BOTTOM_RIGHT;
                indexData[2] = BOTTOM_LEFT;
    
                indexData[3] = TOP_LEFT;
                indexData[4] = TOP_RIGHT;
                indexData[5] = BOTTOM_RIGHT;
            }
    
            private void SetUpCamera()
            {
                viewMatrix = Matrix.Identity;
                projectionMatrix = Matrix.CreateOrthographic(Window.ClientBounds.Width, Window.ClientBounds.Height, -1.0f, 1.0f);
            }
    
            protected override void LoadContent()
            {
                texture = Content.Load<Texture2D>(TEXTURE_NAME);
            }
    
            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)
            {
                GraphicsDevice.Clear(Color.CornflowerBlue);
    
                // Draw textured box
                GraphicsDevice.RasterizerState = RasterizerState.CullNone;  // vertex order doesn't matter
                GraphicsDevice.BlendState = BlendState.NonPremultiplied;    // use alpha blending
                GraphicsDevice.DepthStencilState = DepthStencilState.None;  // don't bother with the depth/stencil buffer
    
                effect.View = viewMatrix;
                effect.Projection = projectionMatrix;
                effect.Texture = texture;
                effect.TextureEnabled = true;
                effect.DiffuseColor = Color.White.ToVector3();
                effect.CurrentTechnique.Passes[0].Apply();
    
                GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertexData, 0, 4, indexData, 0, 2);
    
                // Draw wireframe box
                GraphicsDevice.RasterizerState = WIREFRAME_RASTERIZER_STATE;    // draw in wireframe
                GraphicsDevice.BlendState = BlendState.Opaque;                  // no alpha this time
    
                effect.TextureEnabled = false;
                effect.DiffuseColor = Color.Black.ToVector3();
                effect.CurrentTechnique.Passes[0].Apply();
    
                GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertexData, 0, 4, indexData, 0, 2);
    
                base.Draw(gameTime);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.