Re: Help request on Effect.FromFile



I thank you very much for your reply. Changing the path to the absolute path
did not change the error message. In case of DX debugger, I am not quite
sure how I can set it. I am sorry, but I am quite new to DX.

However, I am including both the .fx file and program file below. The files
can help to find out what the problem might be. This program is a blue copy
from T. Miller's book(chapter 11, op.193-205). I have slightly modified it
with
respect to the April release .

Again I thank you very much for your consideration.


// EFFECT FILE
// simple.fx

// World, View and Projection Matrices
float4x4 WorldViewProj : WORLDVIEWPROJECTION;
float Time = 1.0f;

struct VS_OUPUT
{
float4 pos : POSITION;
float4 diff : COLOR0;
}

// Transform coordinates to World space

VS_OUTPUT Transform(float4 Pos : POSITION)
{
VS_OUTPUT Out = (VS_OUTPUT)0;
Out.pos = mul(Pos, WorldViewProj);
Out.diff.r = 1 - Time;
Out.diff.b = Time * WorldViewProj[2].yz;
Out.diff.ga = Time * WorldViewProj[0].xy;

return Out;
}

technique TransformDiffuse
{
pass P0
{
CullMode = None;

VertexShader = compile vs_1_1 Transform();
PixelShader = NULL;
}
}

// END OF EFFECT FILE

// MAIN PROGRAM

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Direct3D = Microsoft.DirectX.Direct3D;

namespace BasicHLSL
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{

private Device device = null;
private VertexBuffer vb = null;
private Effect effect = null;
private VertexDeclaration decl = null;

private Matrix worldMatrix;
private Matrix viewMatrix;
private Matrix projMatrix;
private float angle = 0.0f;

/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(448, 318);
this.Name = "Form1";
this.Text = "Form1";

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
///
public bool InitializeGraphics()
{
PresentParameters pParameters = new PresentParameters();
pParameters.Windowed = true;
pParameters.SwapEffect = SwapEffect.Discard;
pParameters.AutoDepthStencilFormat = DepthFormat.D16;
pParameters.EnableAutoDepthStencil = true;

int ordinalAdapter = Manager.Adapters.Default.Adapter;

bool canDoShaders = true;
// Do we have HW support?
Caps hardware = Manager.GetDeviceCaps(0, DeviceType.Hardware);

if (hardware.VertexShaderVersion >= new Version(1,1)) // Yes!!
{
CreateFlags flags = CreateFlags.SoftwareVertexProcessing;

if (hardware.DeviceCaps.SupportsHardwareTransformAndLight)
flags = CreateFlags.HardwareVertexProcessing;

if (hardware.DeviceCaps.SupportsPureDevice)
flags |= CreateFlags.PureDevice;

// We have pure hardware device & hardware support
device = new Device(ordinalAdapter, DeviceType.Hardware, this, flags,
pParameters);

try
{
effect = Effect.FromFile(device, @"C:\DirectX\C#\BasicHLSL\simple.fx",
null, ShaderFlags.None, null);
effect.Technique = "TransformDiffuse";
}
catch (DirectXException exep)
{
// Houston we have a problem!!
MessageBox.Show(exep.ToString());
}

}
else
{
canDoShaders = false;
device = new Device(ordinalAdapter, DeviceType.Reference, this,
CreateFlags.SoftwareVertexProcessing, pParameters);
}

vb = new VertexBuffer(typeof(CustomVertex.PositionOnly), 3, device,
Usage.Dynamic | Usage.WriteOnly,
CustomVertex.PositionOnly.Format, Pool.Default);

vb.Created += new EventHandler(this.onVertexBufferCreate);
onVertexBufferCreate(vb, null);
// Matrices
projMatrix = Matrix.PerspectiveFovLH((float)Math.PI/4.0f,
(float)(this.Width / this.Height), 1.0f, 100.0f);
viewMatrix = Matrix.LookAtLH(new Vector3(0, 0, 5.0f), new Vector3(), new
Vector3(0, 1, 0));
// Vertex Declaration
VertexElement[] elements = new VertexElement[]
{
new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default,
DeclarationUsage.Position, 0),
VertexElement.VertexDeclarationEnd
};

decl = new VertexDeclaration(device, elements);
return canDoShaders;
}

private void onVertexBufferCreate(object sender, EventArgs e)
{
VertexBuffer buffer = (VertexBuffer)sender;
CustomVertex.PositionOnly [] verts = new CustomVertex.PositionOnly[3];
verts[0].Position = new Vector3(0.0f, 1.0f, 1.0f); // April SDK
verts[1].Position = new Vector3(-1.0f, -1.0f, 1.0f); // April SDK
verts[2].Position = new Vector3(1.0f, -1.0f, 1.0f); // April SDK

buffer.SetData(verts, 0, LockFlags.None);
}

protected override void OnPaint(PaintEventArgs e)
{
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer,
Color.CornflowerBlue, 1.0f, 0);
UpdateWorld();
device.BeginScene();
device.SetStreamSource(0, vb, 0);
device.VertexDeclaration = decl;
int numPasses = effect.Begin(0);
for (int i = 0; i < numPasses; i++)
{
effect.BeginPass(i); // April SDK
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
effect.EndPass(); // April SDK
}
effect.End();
device.EndScene();
device.Present();
this.Invalidate();
}

private void UpdateWorld()
{
worldMatrix = Matrix.RotationAxis(new Vector3(angle / ((float)Math.PI *
2.0f),
angle / ((float)Math.PI * 4.0f), angle / ((float)Math.PI * 6.0f)),
angle / (float)Math.PI);
angle += 0.1f;

Matrix worldViewProj = worldMatrix * viewMatrix * projMatrix;
effect.SetValue("Time", (float)Math.Sin(angle / 5.0f));
effect.SetValue("WorldViewProj", worldViewProj);
}


[STAThread]
static void Main()
{
using (Form1 frm = new Form1())
{
frm.Show();
if (!frm.InitializeGraphics())
MessageBox.Show("No shader support. Running in Ref Mode!");
Application.Run(frm);
}
}
}
}

// END OF FILE

"ZMan" wrote:

> #1 Remove the possibility of a path error by hard coding an explicit path
> c:\......\simple.fx
> #2 TUrn on directX debugging - do you get any other output.
>
> --
> ZMan (zman@xxxxxxxxxxxxxx)
> http://www.thezbuffer.com
> News and Information for Managed DirectX
>
>
> "Millennium Falcon" <MillenniumFalcon@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
> message news:E8F6CADB-9012-4759-9950-06DACE5C0E11@xxxxxxxxxxxxxxxx
> > Hi!
> >
> > When I use the following statement
> >
> > effect = Effect.FromFile(device, "simple.fx", null, ShaderFlags.None,
> > null);
> >
> > in the program, I get the following exception :
> >
> > Error in the application.
> >
> > -2147467259(E_FAIL) at
> > (.... two references to the two overloads of the method Effect.FromFile)
> >
> > Would it be possible to encode this message? If it's a path error, I will
> > be completely dissappointed because I have a copy of this file in almost
> > every
> > subfolder in the directory.
> >
> > Thanks for any help and/or links.
> > Best regards
>
>
>
.



Relevant Pages

  • Re: blue screen error - Symbols can not be loaded...
    ... this error condition means that a kernel-mode ... You receive a "Stop 0x0000000A" error message in Windows XP ... Your debugger is not using the correct symbols ...
    (microsoft.public.windowsxp.general)
  • Re: blue screen error - Symbols can not be loaded...
    ... this error condition means that a kernel-mode ... You receive a "Stop 0x0000000A" error message in Windows XP ... Your debugger is not using the correct symbols ...
    (microsoft.public.windowsxp.general)
  • Re: Help with error message 80040241
    ... see suggested by others is to reinstall DirectX on that system. ... Get Instant WMP Answers ... > I've encountered error message 80040241 while using Windows Media ...
    (microsoft.public.windowsmedia.player)
  • Re: Delayed input from joystick
    ... Have you by chance enabled a debugger or running a debug install of DirectX? ... The only time I have seen lagged input is during debugging when the debugger ...
    (microsoft.public.windowsxp.games)
  • Re: aspnet_wp.exe stopped unexpectedly
    ... Havent tried to use the debugger; ... be displayed when I call this page from the browser. ... An error message detailing the cause of this specific ... request failure can ne found in the system event log of the web server. ...
    (microsoft.public.dotnet.general)