Hello, I’m new here.
I am trying to get a model exported from blender to display correctly in monogame (latest development build as of yesterday). The model shows, but is all black. I have also tried using .x models from tutorials, and they also appear black. I was able to draw a quad with texture on it in code (so I know the texture is loading correctly), but displaying a textured and/or lighted model is a roadblock.
Quick introduction…
- Experienced C++ coder, intermediate C#
- Experienced OpenGL
- Experienced with several game engines, except XNA
- No XNA experience, or really even DirectX
I know the tools for diagnosing “black model” issues in other game engines/OpenGL, but I am clueless with how to diagnose this in monogame, and I am having trouble finding information via Google. Is there a way for me to inspect a loaded model’s vertices, normals, UV coords, etc.? How do I examine the state of the system?
If you know why the model is black, that’s a fine answer, but I’m really even more interested in the approach to diagnose the issue here. How do I debug in monogame?
I tried setting a breakpoint in VS 2010 and inspecting the members of the Model class, but I cannot see anything so low-level as actual vertex coordinates, or even whether normals are in use, or how a vertex buffer is configured.
For completeness, I will paste the code I am using. Again, the model displays, but it is black. I have tried enabling and disabling lighting and texturing. This is using the Windows OpenGL template, running in Windows 7.
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace Game1
{
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Model model;
Texture2D texture;
public Game1()
: base()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
texture = Content.Load<Texture2D>("metal_0");
model = Content.Load<Model>("ship2");
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
Matrix[] transforms = new Matrix[model.Bones.Count];
model.CopyAbsoluteBoneTransformsTo(transforms);
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.World = transforms[mesh.ParentBone.Index];
effect.View = Matrix.CreateLookAt(new Vector3(5, 8, 30), new Vector3(0, 1, 0), Vector3.UnitY);
effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 800f / 480f, 1f, 10000f);
effect.TextureEnabled = true;
effect.Texture = texture;
}
mesh.Draw();
}
base.Draw(gameTime);
}
}
}