I can't use even the simplest shader. I always get exceptions.

Hello guys,

I hope you can help me. I developped a small application using MonoGame’s BasicEffect. Now, I want to learn about effects, but I can’t even run a simple example. First, I though I misunderstood something or made some mistakes in my code, but then, I downloaded the XNA Tutorial from Riemer source code in a new, empty MonoGame Windows project. I also downloaded the *.fx effect and converted it into a *.mgfxo file by using your 2MGFX tool. I load the effect with

System.IO.BinaryReader Reader = new System.IO.BinaryReader(System.IO.File.Open("C:\\Users\\Benjamin\\Desktop\\test123.mgfxo", System.IO.FileMode.Open));
this.effect = new Effect(graphics.GraphicsDevice, Reader.ReadBytes((int)Reader.BaseStream.Length));

Everything seems to work fine until the Draw function, which gets me an exception:

Zusätzliche Informationen: HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: Falscher Parameter.

Translated: Wrong parameter.

Please tell me, what I did wrong. I used exactly the same code as in Riemer’s Tutorial. I only changed the effect loading as explained earlier and I changed the vs_2_0 and ps_2_0 to make your 2MGFX happy.

Please help me! :slight_smile:

Hello again,

can someone pleasehelp me? I highly assume, that all you are able to use shaders - otherwise the engine would be pretty useless. Has no one an idea what’s going wrong?

This is how I load my effect, try it out:

effect = new Effect(this.GraphicsDevice, (byte[])File.ReadAllBytes(Content.RootDirectory + "\\Brightener.mgfx"));

And since your problem is in the draw section, you should show us how you begin your spriteBatch and how you apply your effect to the spriteBatch.

Hello thecrow34,

I am using exactly the same source code as Riemer in his XNA tutorial. I only exchanged the loading of the *.mgfxo file and created the *.mgfxo using the official converter tool 2MGFX.

Used tutorial: Riemer’s Pixel Shader tutorial

I am using Microsoft Visual Studio 2010 Professional, Windows 8 and MonoGame 3.2.

I did a test yesterday to get shaders working in a project, basically I used this example https://github.com/mono/MonoGame/wiki/Effects-And-Shaders and compiled the shader manually (there’s a bat in a directory)

I uploaded a minimal project here:


I hope it helps

By the way,

this issue refers to your problem https://github.com/mono/MonoGame/issues/3235
and this PR fixed this problem 5 days ago https://github.com/mono/MonoGame/pull/3487

if you use the latest GIT repository you may probably get a more verbose error message (if the problem is caused by a vertex format mismatch)