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 6174301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:43:47+00:00 2026-05-23T23:43:47+00:00

I was messing around with some triangles and made this. At first, I thought,

  • 0

I was messing around with some triangles and made this. At first, I thought, all the “methods” I wrote were instantiated but those “methods” : device, content and effect; are actually all nulls. The code is almost fine, what was I supposed to write instead of those?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Learning_Test1
{
class Triangle
{
    GraphicsDevice device;
    ContentManager content;
    Effect effect;

    VertexPositionColor[] vertices;

    public void bob()
    {
        content.RootDirectory = "Content";
        content.Load<Effect>("effects");
    }

    public void Initialize()
    {
        vertices = new VertexPositionColor[3];

        vertices[0].Position = new Vector3(1, 0, 0);
        vertices[0].Color = Color.Red;

        vertices[1].Position = new Vector3(0, 0, 1);
        vertices[1].Color = Color.Green;

        vertices[1].Position = new Vector3(-1, 0, 0);
        vertices[1].Color = Color.Blue;
    }

    public void Update()
    {
    }

    public void Draw()
    {
        effect.CurrentTechnique = effect.Techniques["PretransformedPS"];

        foreach (EffectPass pass in effect.CurrentTechnique.Passes)
        {
            pass.Apply();
        }

        device.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1, VertexPositionColor.VertexDeclaration);
    }
}

}

  • 1 1 Answer
  • 0 Views
  • 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-23T23:43:48+00:00Added an answer on May 23, 2026 at 11:43 pm

    Well the only thing that you are actually initializing is your “vertices” array. I dont see where you actually attempt to initialize the other variables, unless you didnt include some code in your question, for example where you actually call your

    Triangle testTriangle =  new Triangle();
    

    You should initialize the rest of your class variables, device, content, and effect in your class’s initialize function unless you plan on setting them elsewhere. It’s been a little while since I last used XNA but if I remember correctly Device and Content might be initialized for you when you create a new game template so all you would have to do is set them equal to testTriangle.Device and testTriangle.Content. If not I would highly recommend looking at the tutorials on the XNA site as they are fantastic and I am 100% sure that you will be able to figure out how to initialize them from there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm messing around with SQLite for the first time by working through some of
I've been messing around with randomizing in python for awhile now but for some
Hey all, I've been messing around with this awesome library on my *nix box,
I've been messing around with this for some time. I recently started using the
I'm messing around with some C code using floats, and I'm getting 1.#INF00, -1.#IND00
I am currently messing around with some stuff for an idea for a site
I'm messing around with some windows functions using p/invoke. Occasionally, I get an error
The situation is that I've spent some time messing around with some experimental code.
I have finally started messing around with creating some apps that work with RESTful
I have been messing around with writing some stored procedures in .NET code with

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.