• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
TScrypter

Can't render sprite in SlimDX using SlimDX.Direct3D10

2 posts in this topic

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]
0

Share this post


Link to post
Share on other sites
Couple of issues:
[list]
[*]You clear your render target view, but don't set it as render target in the output merger stage.
[*]Neither do you set a viewport in the rasterizer stage.
[*]You don't set a rasterizer state explicitly. The default has culling enabled, which might cull your quad, depending on the transformation. For now I'd disable it altogether.
[*]The SpriteInstance constructors second and third argument are in texture space, which is normalized (goes from 0 to 1 in both dimensions). E.g. use something like (0,0) and (1,1) respectively.
[*]The SpriteInstances transformation means the world transformation. This has to play along with your projection and view. Since you are currently using a ortho projection in pixel/screen space, a scaling of (1,1,1) will result in a 1x1 pixel, unlikely what you want.
[/list]

I hope that helps.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0