我正在使用Silverlight 5.0开发3D应用程序。
对我而言,System.Windows.Graphics.GraphicsDeviceManager.Current.GraphicsDevice
始终显示null
。
这是我的代码
private void DrawingSurface_Loaded(object sender, RoutedEventArgs e)
{
if (GraphicsDeviceManager.Current.RenderMode != RenderMode.Hardware)
{
if (GraphicsDeviceManager.Current.RenderModeReason == RenderModeReason.SecurityBlocked)
{
throw new Exception();
}
}
GraphicsDevice device = System.Windows.Graphics.GraphicsDeviceManager.Current.GraphicsDevice;
_vertexBuffer = StreamHelper.ToMesh(device, "cube.obj");
_effect = new BasicEffect(GraphicsDeviceManager.Current.GraphicsDevice);
_effect.Texture = StreamHelper.ToTexture2D(device, "Tulips.jpg");
_effect.TextureEnabled = true;
_effect.World = Matrix.Identity;
_effect.View = Matrix.CreateLookAt(new Vector3(5.0f, 5.0f, 5.0f), Vector3.Zero, Vector3.Up);
_effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, 1.667f, 1.0f, 10.0f);
}
任何人都可以帮助我。
答案 0 :(得分:1)
您是否允许使用3D图形?如果没有运行Silverlight.Configuration.exe(对我而言,它位于“C:\ Program Files(x86)\ Microsoft Silverlight \ 5.0.61118.0 \”)并选择权限选项卡。允许3D图形。
答案 1 :(得分:0)
您可能想要检查一些其他GraphicsDeviceManager.Current.RenderModeReason值。正如本文中所讨论的更多:http://blogs.msdn.com/b/eternalcoding/archive/2011/10/18/some-reasons-why-my-3d-is-not-working-with-silverlight-5.aspx