TScrypter

Members
  • Content count

    2
  • Joined

  • Last visited

Community Reputation

108 Neutral

About TScrypter

  • Rank
    Newbie
  1. I'm attempting to build a Sprite animation creator for the artists on a project I'm currently working on. I am using SlimDX for rendering to a Panel which serves as a viewport on a form. The application does not throw an error, but I cannot get the sprite I'm attempting to load to be rendered. I know the device and swapchain are set up correctly because I can clear the backbuffer and present. I feel like I'm missing one crucial step, but I can't figure out what it is. I'm basing a lot off this off of an example from [u]Beginning DirectX 10 Game Programming[/u] by Wendy Jones. I've attached a screenshot to show the result that I'm getting. All I'm asking is that someone can help me figure out what I'm missing to get my sprite to be rendered to the screen. [source lang="csharp"]using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using SlimDX; using SlimDX.Direct3D10; using SlimDX.DXGI; using Device = SlimDX.Direct3D10.Device; using Resource = SlimDX.Direct3D10.Resource; using SlimDX.Windows; namespace Editor { public partial class Form1 : Form { #region DirectX Fields /// <summary> /// Properties to represent objects necessary just get Direct3D running /// </summary> Device device; SwapChainDescription swapChainDescription; SwapChain swapChain; RenderTargetView BackBuffer; /// <summary> /// Properties to represent drawing a sprite /// </summary> Sprite sprite; List<SpriteInstance> sprites = new List<SpriteInstance>(); #endregion public Form1() { InitializeComponent(); } /// <summary> /// Load this form, then create all /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Form1_Load(object sender, EventArgs e) { // Initialize the SwapChainDescription swapChainDescription = new SwapChainDescription() { BufferCount = 1, IsWindowed = true, Flags = SwapChainFlags.AllowModeSwitch, ModeDescription = new ModeDescription(0,0, new Rational(60,1), Format.R8G8B8A8_UNorm), OutputHandle = pnlOutput.Handle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; // Create a Device instance and a SwapChain instance Device.CreateWithSwapChain(null, DriverType.Hardware, DeviceCreationFlags.Debug, swapChainDescription, out device, out swapChain); // Get a reference to the BackBuffer using (var resource = Resource.FromSwapChain<Texture2D>(swapChain, 0)) { BackBuffer = new RenderTargetView(device, resource); }; InitializeSpriteObject(); // Run the renderer on its own thread using the MessagePump class MessagePump.Run(this, Render); } /// <summary> /// Render the current frame to the backbuffer and present it /// </summary> private void Render() { device.ClearRenderTargetView(BackBuffer, new Color4(0.5f, 0.0f, 0.75f)); if (sprites.Count > 0) { sprite.Begin(SpriteFlags.SortBackToFront); sprite.DrawImmediate(sprites.ToArray()); sprite.End(); } swapChain.Present(0, PresentFlags.None); } /// <summary> /// Initialize the SpriteObject (acts similarly to a SpriteBatch in XNA) /// </summary> private void InitializeSpriteObject() { sprite = new Sprite(device, 0); sprite.ProjectionTransform = Matrix.OrthoOffCenterLH(0.0f, 600.0f, 400.0f, 0.0f, 0.1f, 10.0f); sprite.ViewTransform = Matrix.Scaling(1.0f,1.0f,1.0f) * Matrix.Translation(0.0f, 0.0f, 0.0f); } /// <summary> /// Get an image for the sprite and render it /// </summary> private void LoadTexture(string ImagePath) { // MessageBox.Show(ImagePath); Texture2D texture = Texture2D.FromFile(device, ImagePath); Texture2DDescription textureDesc = texture.Description; ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { Dimension = ShaderResourceViewDimension.Texture2D, Format = Format.R8G8B8A8_UNorm, MipLevels = textureDesc.MipLevels }; ShaderResourceView srv = new ShaderResourceView(device, texture, srvd); SpriteInstance instance = new SpriteInstance(srv, new Vector2(300, 200), new Vector2(600, 400)); instance.Transform = Matrix.Scaling(1.0f, 1.0f, 1.0f) * Matrix.Translation(300, 200, 0.1f); sprites.Add(instance); } /// <summary> /// Open a new item (a texture) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void openToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (dialog.FileName.EndsWith("png") || dialog.FileName.EndsWith("bmp")) { LoadTexture(dialog.FileName); } } } } }[/source]
  2. XNA 4.0 near broke me spirit!

    I'm currently attempting to write a game for the 360 in 4.0 with VS 2010, however I'd like to remove some of the code/objects into a library for future games(First person camera, a debugging text display, etc...). VS 2010 throws an error regarding the library that requires a .config file to be added to the game application to tell it to use the library.