Jump to content
  • Advertisement
Sign in to follow this  
CloudSeven

[SlimDx] Sample Code Not Running

This topic is 2493 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! EveryOne!smile.gif
I Am New To SlimDx..
Previously I Was Working On XNA!!

I Tried And Learned The 1st Two Tutorials Available On Slimdx.org
But Third One Always Gives Me This Errorsad.gif
Code Is Exactly The Same As In Third Tutorial




using (var bytecode = ShaderBytecode.CompileFromFile("Effect.fx", "VShader", "vs_4_0", ShaderFlags.None, EffectFlags.None))
vertexShader = new VertexShader(device, bytecode);



Here Is Snapshot !
Untitled-3.png


Effect.fx File Contains This
float4 VShader(float4 position : POSITION) : SV_POSITION
{
return position;
}
float4 PShader(float4 position : SV_POSITION) : SV_Target
{
return float4(1.0f, 1.0f, 0.0f, 1.0f);
}



I Need SlimDx For One Of My Projects!!

Any Help Would Be Great!!cool.gif
Thanks!

Share this post


Link to post
Share on other sites
Advertisement
There are many tools available for you to use to debug your application, such as PIX, the Direct3D debug runtimes, SlimDX error information, hell even a page of tips for you to follow. You're going to have to do some of the work on your own though, because scientists have yet to discover how to let people unlock their innate psychic debugging powers.

Share this post


Link to post
Share on other sites
Erm, welcome to the forum.

Yup, as you can see, that exception is as helpful as "does not compute". At least create your device with DeviceCreationFlags.Debug and (hopefully) get some additional info. Mikes other hints apply, too, of course. If you then still can't figure out what's going wrong on your own, come back and tell us exactly what your tried and what info you collected. Currently I don't see anything blatantly done wrong yet, but it's really very little to work with.

And, I for one, rather prefer descriptions and (compilable) code than screenshots, screenshots can't be copy-pasted and show too little of the context. For communicating rendering artifacts, of course, screenshots are mostly better.

Share this post


Link to post
Share on other sites

Erm, welcome to the forum.

Yup, as you can see, that exception is as helpful as "does not compute". At least create your device with DeviceCreationFlags.Debug and (hopefully) get some additional info. Mikes other hints apply, too, of course. If you then still can't figure out what's going wrong on your own, come back and tell us exactly what your tried and what info you collected. Currently I don't see anything blatantly done wrong yet, but it's really very little to work with.

And, I for one, rather prefer descriptions and (compilable) code than screenshots, screenshots can't be copy-pasted and show too little of the context. For communicating rendering artifacts, of course, screenshots are mostly better.


if i create device with DeviceCreationFlags.Debug it gives this error
Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug, description, out device, out swapChain);
E_FAIL: An undetermined error occurred (-2147467259)

Is it something wrong with Device

I Have Pentium D!
Do'nt Have External Graphics Card.
I am Using Default VGA!

just i thought it might be?

Also Here Is Complete Filecode That i'm Trying To RUN!

using System.Windows.Forms;
using SlimDX;
using SlimDX.D3DCompiler;
using SlimDX.Direct3D11;
using SlimDX.DXGI;
using SlimDX.Windows;
using Device = SlimDX.Direct3D11.Device;
using Resource = SlimDX.Direct3D11.Resource;

namespace SimpleTriangle
{
static class Program
{
static void Main()
{
Device device;
SwapChain swapChain;
ShaderSignature inputSignature;
VertexShader vertexShader;
PixelShader pixelShader;

var form = new RenderForm("Tutorial 3: Simple Triangle");
var description = new SwapChainDescription()
{
BufferCount = 2,
Usage = Usage.RenderTargetOutput,
OutputHandle = form.Handle,
IsWindowed = true,
ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm),
SampleDescription = new SampleDescription(1, 0),
Flags = SwapChainFlags.AllowModeSwitch,
SwapEffect = SwapEffect.Discard
};

Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug, description, out device, out swapChain)
;

// create a view of our render target, which is the backbuffer of the swap chain we just created
RenderTargetView renderTarget;
using (var resource = Resource.FromSwapChain<Texture2D>(swapChain, 0))
renderTarget = new RenderTargetView(device, resource);

// setting a viewport is required if you want to actually see anything
var context = device.ImmediateContext;
var viewport = new Viewport(0.0f, 0.0f, form.ClientSize.Width, form.ClientSize.Height);
context.OutputMerger.SetTargets(renderTarget);
context.Rasterizer.SetViewports(viewport);

// load and compile the vertex shader
using (var bytecode = ShaderBytecode.CompileFromFile("triangle.fx", "VShader", "vs_4_0", ShaderFlags.None, EffectFlags.None))
{

//MessageBox.Show(bytecode);
inputSignature = ShaderSignature.GetInputSignature(bytecode);
vertexShader = new VertexShader(device, bytecode);
}

// load and compile the pixel shader
using (var bytecode = ShaderBytecode.CompileFromFile("triangle.fx", "PShader", "ps_4_0", ShaderFlags.None, EffectFlags.None))
pixelShader = new PixelShader(device, bytecode);

// create test vertex data, making sure to rewind the stream afterward
var vertices = new DataStream(12 * 3, true, true);
vertices.Write(new Vector3(0.0f, 0.5f, 0.5f));
vertices.Write(new Vector3(0.5f, -0.5f, 0.5f));
vertices.Write(new Vector3(-0.5f, -0.5f, 0.5f));
vertices.Position = 0;

// create the vertex layout and buffer
var elements = new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0) };
var layout = new InputLayout(device, inputSignature, elements);
var vertexBuffer = new Buffer(device, vertices, 12 * 3, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

// configure the Input Assembler portion of the pipeline with the vertex data
context.InputAssembler.InputLayout = layout;
context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, 12, 0));

// set the shaders
context.VertexShader.Set(vertexShader);
context.PixelShader.Set(pixelShader);

// prevent DXGI handling of alt+enter, which doesn't work properly with Winforms
using (var factory = swapChain.GetParent<Factory>())
factory.SetWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAltEnter);

// handle alt+enter ourselves
form.KeyDown += (o, e) =>
{
if (e.Alt && e.KeyCode == Keys.Enter)
swapChain.IsFullScreen = !swapChain.IsFullScreen;
};

// handle form size changes
form.UserResized += (o, e) =>
{
renderTarget.Dispose();

swapChain.ResizeBuffers(2, 0, 0, Format.R8G8B8A8_UNorm, SwapChainFlags.AllowModeSwitch);
using (var resource = Resource.FromSwapChain<Texture2D>(swapChain, 0))
renderTarget = new RenderTargetView(device, resource);

context.OutputMerger.SetTargets(renderTarget);
};

MessagePump.Run(form, () =>
{
// clear the render target to a soothing blue
context.ClearRenderTargetView(renderTarget, new Color4(0.5f, 0.5f, 1.0f));

// draw the triangle
context.Draw(3, 0);
swapChain.Present(0, PresentFlags.None);
});

// clean up all resources
// anything we missed will show up in the debug output
vertices.Close();
vertexBuffer.Dispose();
layout.Dispose();
inputSignature.Dispose();
vertexShader.Dispose();
pixelShader.Dispose();
renderTarget.Dispose();
swapChain.Dispose();
device.Dispose();
}
}
}

Share this post


Link to post
Share on other sites
As you have no 3d hardware, you could try using the software renderer - Drivertype.WARP

See http://www.gamedev.net/topic/569465-slimdx-initialise-direct3d101-with-warp-driver/

Share this post


Link to post
Share on other sites
That code runs for me. I see a big yellow triangle :) It's using shader model 4.0, that wont compile on your computer. You'll need to invest in a direct X 10 video card to get that code working. Buy a video card !

Share this post


Link to post
Share on other sites
I have the exact problem discussed above.

I have, I believe, the latest versions of the DirectX SDK, C# Express and SlimDK. The laptop I am running on is a Sony running Windows7 with a DirectX 11 capable graphics board.

Things went silent on this thread back in November, and I am wondering if this means a solution to the problem has been found, or if everyone just got interested in other things.

Any help in solving this for me would be greatly appreciated. In fact, I would gladly pay someone to get on my machine with teamviewer and fix this for me.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!