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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:24:15+00:00 2026-06-12T22:24:15+00:00

I am just getting into XNA programming and have been unable to figure out

  • 0

I am just getting into XNA programming and have been unable to figure out how can I access the texture from a “.x” model. I am using a custom shader to display my model (just a cube with a texture mapped on it) with the filters set to point. To do this I needed to pass the effect my texture file which needed to be imported separately from my model or else it would complain since it is included in my model as well. This works perfectly how I want it, however this isn’t really an agreeable method when I have many different models with their own textures.

My question is:

How am I able to access the texture included in my model directly from it and send that to my shader? Or am I able to access it directly with HLSL?

What I have tried:

I have found posts saying that it can assigned to a texture variable with:

Texture2d texture = ((BasicEffect)model.Meshes[0].Effects[0]).Texture

When I tried this the game runs but the cubes are just black. I can see that the texture variable is holding info and has the right dimensions but I can’t tell if it is correctly holding the actual image. When I used just the BasicEffect they rendered just fine with their texture.

Update:

I have managed to get this to work after a little bit of fiddling. My game loads in a few hundred of the same cube and upon creation of each it would try save the texture of the model using the code above and then go through the mesh parts and change the effects to my custom effect. I discovered that the first cube created would save the texture okay but any subsequent cubes created would complain that they can’t be cast as a BasicEffect. This resulted in one textured cube and then a lot of black ones. I am guessing that when it reuses the same model over and over like that it will just use the one that was modified to use my custom effect which was done on the first instance of the cube. Is this normal? I have got them all to render as textured by changing the texture variable to static.

  • 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-06-12T22:24:16+00:00Added an answer on June 12, 2026 at 10:24 pm

    If anyone else is wondering about this as I was then saving the texture using:

    Texture2d texture = ((BasicEffect)model.Meshes[0].Effects[0]).Texture
    

    This does work but there is one thing to watch for which is what was causing me problems. If you change the effect of the model from the default BasicEffect for one instance it will be changed for every instance of the model created thereafter. So you will only be able to use the above code before you change the effect for the first time on a particular model.

    I later found this book which describes exactly how to extract the texture and other information from a model: 3D Graphics with XNA Game Studio 4.0 by Sean James – Specifically chapter 2

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

Sidebar

Related Questions

I'm just getting into LESS and am trying to figure out how I can
I just started getting into iPhone development. I have been mish-mashing tutorials and material
I'm just getting into advanced C++ programming (object orientation), and I've been looking for
Can someone please help me out, I am just getting into Spring3, Spring3 MVC
I'm just getting into functional programming and i'm in the try out some non-trivial
I'm just getting into Android development. I'm trying to figure out if its possible
I'm just getting into using REST and have started building my first app following
We're just getting into MVVM in WPF. We have implemented our ViewModels with 'strongly
I am just getting into Sharepoint, and I have a question about having a
My little brother is just getting into programming, and for his Science Fair project,

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.