Sign in to follow this  

Cg Help

This topic is 4256 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, 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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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)?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 4256 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.

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