Skip to main content
gamedev.net
🔒 Locked

Loading cg program from file

Started by Garret 5 replies 1.1k views
Original Post
Garret
Garret
Hi, I'm trying to get Cg working in my app using code from sample:

context = cgCreateContext();

    if (vertexProfile == CG_PROFILE_UNKNOWN || fragmentProfile == CG_PROFILE_UNKNOWN) {
        vertexProfile   = cgGLGetLatestProfile(CG_GL_VERTEX);
        fragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
    }
    cgGLSetOptimalOptions(vertexProfile);
    cgGLSetOptimalOptions(fragmentProfile);
	cgGLEnableProfile(vertexProfile);
	cgGLEnableProfile(fragmentProfile);

    vertexProg = cgCreateProgramFromFile(context,
		CG_SOURCE,
		"c:\\Vertex.cg",//"BlinnVertex.cg",
        vertexProfile, 
		"main",
		NULL);
The shader compiles fine with cgc, but when I use

error = cgGetFirstError();
const char* error_text = cgGetErrorString(error);
to figure out why shader doesn't work, I get the following: "CG ERROR : Invalid program handle." Where can be the problem and why my program handle could be invalid? Sample, from which I got this code compiles and runs fine. Thanks for everything that can help, Peter.
MARS_999
MARS_999
vertexProg = cgCreateProgramFromFile(context,
CG_SOURCE,
"c:\\Vertex.cg",//"BlinnVertex.cg",
vertexProfile,
"main",
NULL);

Well I don't use Cg, but this looks wrong. //"BlinnVertex.cg" Should that be

"\\BlinnVertex.cg" or "/BlinnVertex.cg"

depending on where you are going!!!
Garret
Garret
Quote:
Original post by MARS_999
vertexProg = cgCreateProgramFromFile(context,
CG_SOURCE,
"c:\\Vertex.cg",//"BlinnVertex.cg",
vertexProfile,
"main",
NULL);

Well I don't use Cg, but this looks wrong. //"BlinnVertex.cg" Should that be

"\\BlinnVertex.cg" or "/BlinnVertex.cg"

depending on where you are going!!!

It is a comment string ;) Rewriting program in such way:
context = cgCreateContext();  if (vertexProfile == CG_PROFILE_UNKNOWN || fragmentProfile == CG_PROFILE_UNKNOWN)   {    vertexProfile   = cgGLGetLatestProfile(CG_GL_VERTEX);    fragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);  }  cgGLSetOptimalOptions(vertexProfile);  cgGLSetOptimalOptions(fragmentProfile);	cgGLEnableProfile(vertexProfile);	cgGLEnableProfile(fragmentProfile);    vertexProg = cgCreateProgramFromFile(context,		CG_SOURCE,		"c:\\Vertex.cg",        vertexProfile, 		"main",		NULL);

changes nothing (I tried it).
Winegums
Winegums
"c:\\Vertex.cg",

shouldn't that be a single backslash?


incidentally, i advise you to try to avoid using paths like this.

what happens if you submit this application as a demo to someone? instead you can do things like...

"CG/VertexTerrain.cg",

asuming you have a folder called CG in the same directory as your program. it makes your application far more contained


EDIT: actually...have you tried

"c:/Vertex.cg",

? could be that, certainly i'm sure double forwardslash is wrong.
Garret
Garret
Quote:
Original post by Winegums
"c:\\Vertex.cg",

shouldn't that be a single backslash?


incidentally, i advise you to try to avoid using paths like this.

what happens if you submit this application as a demo to someone? instead you can do things like...

"CG/VertexTerrain.cg",

asuming you have a folder called CG in the same directory as your program. it makes your application far more contained


EDIT: actually...have you tried

"c:/Vertex.cg",

? could be that, certainly i'm sure double forwardslash is wrong.

Actually, it seems that the problem was in paths to libs and includes of Cg - I might use .h's from one version and .lib's from anothers :)
Winegums
Winegums
oh, well there ya go, shows what i know ;)

glad you got it fixed anyway!
Garret
Garret
Quote:
Original post by Winegums
oh, well there ya go, shows what i know ;)

glad you got it fixed anyway!


Thanks for assistance anyway - it is more convenient to use CG/..., than C:\\.. ;)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.