Cg Help

Started by
3 comments, last by dawidjoubert 17 years, 12 months ago
Hi, I am trying lesson 47 and I have done everything I think but i get this error. Here is the applicable code:

// Load And Compile The Vertex Shader From File
cgWaterSurface = cgCreateProgramFromFile(cgContext, CG_SOURCE,"Wave.Cg", cgVertexProfile, "main", 0);

// Validate Success
if (cgWaterSurface == NULL)
{
	// We Need To Determine What Went Wrong
	CGerror Error = cgGetError();

	// Show A Message Box Explaining What Went Wrong
MessageBox(NULL, cgGetErrorString(Error), "Error", MB_OK);
....
...
..

I get the MessageBox that pops up and it says "CG ERROR: The compile returned an error" Here is my Cg Script

// Water Wave Cg Program

// Input structure
struct appdata 
{
	float4 position : POSITION;			// Position is always required
	float4 color: COLOR0;
	float3 wave: COLOR1;
};

// Output structure
struct vfconn
{
	float4 HPos: POSITION;
	float4 Col0: COLOR0;
};

// Our actual CG script
vfconn main(appdata IN,uniform float4x4 ModelViewProj)
{
	vfconn OUT;				// Variable To Handle Our Output From The Vertex
							// Shader (Goes To A Fragment Shader If Available)
							
	// Change The Y Position Of The Vertex Based On Sine Waves
	IN.position.y = ( sin(IN.wave.x + (IN.position.z / 4.0) ) + sin(IN.wave.x + (IN.position.x / 5.0) ) ) * 2.5f;							
	
	// Transform The Vertex Position Into Homogenous Clip-Space (Required)
	OUT.HPos = mul(ModelViewProj, IN.position);

	// Set The Color To The Value Specified In IN.color
	OUT.Col0.xyz = IN.color.xyz;
	
	return OUT;
};

Now How can i test my cg scripts for syntaxing and all of that?
----------------------------

http://djoubert.co.uk
Advertisement
What happens if you try set the last 0 to "NULL" in the following part:

cgWaterSurface = cgCreateProgramFromFile(cgContext, CG_SOURCE,"Wave.Cg", cgVertexProfile, "main", 0);

Also have you verified the cg file is called Wave.Cg, should'nt it be ".cg" instead?
Quote:Original post by AlphaDude
What happens if you try set the last 0 to "NULL" in the following part:

cgWaterSurface = cgCreateProgramFromFile(cgContext, CG_SOURCE,"Wave.Cg", cgVertexProfile, "main", 0);

Also have you verified the cg file is called Wave.Cg, should'nt it be ".cg" instead?


I doubt either of those would make a difference. In every compiler I've used, NULL is just #defined as 0 anyway.

Edit: Nothing stands out to me in your code (though I'm not familiar with Cg). What version of the Cg compiler are you using? Are you sure that is functioning correctly (Does it work for other shaders)?
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
I have no idea if it works for other shaders, the code comes from nehe tutorial 47. The Cg version is 1.1 the one that Nehe said I should download.

Anyhow this is my first attempt at Cg so I don't know what I am doing wrong. Maybe this is irrelevant but when I tried to compile earlier it said it can't locate the cg.dll so i copied all the dll files found in "program files\Nvidia\Cg\" and that solved that error message.

Anyhow thanks in advance
----------------------------

http://djoubert.co.uk
Quote:Original post by Sr_Guapo
Quote:Original post by AlphaDude
What happens if you try set the last 0 to "NULL" in the following part:

cgWaterSurface = cgCreateProgramFromFile(cgContext, CG_SOURCE,"Wave.Cg", cgVertexProfile, "main", 0);

Also have you verified the cg file is called Wave.Cg, should'nt it be ".cg" instead?


I doubt either of those would make a difference. In every compiler I've used, NULL is just #defined as 0 anyway.

Edit: Nothing stands out to me in your code (though I'm not familiar with Cg). What version of the Cg compiler are you using? Are you sure that is functioning correctly (Does it work for other shaders)?



Thanks i looked into other documentation and guess what the solution is/was?
HPOS and COL0 needed to be upper-case

----------------------------

http://djoubert.co.uk

This topic is closed to new replies.

Advertisement