Getting started with ARB_VERTEX_PROGRAM and Cg

Started by
2 comments, last by Lutz 19 years, 7 months ago
I wrote a simple opengl program to display two trangles to make a square with a view slightly from above. I wanted to convert it to use ARB_VERTEX_PROGRAM as a learning excercise so I wrote a simple thing using the Cg compiler. struct in_s { float4 position : POSITION; }; struct out_s { float4 HPos : POSITION; float4 Col0 : COLOR0; }; out_s main(in_s IN, uniform float4x4 ModelViewProj) { out_s OUT; OUT.HPos = mul(ModelViewProj, IN.position); // Set the vertex color to RED OUT.Col0.r = 1.0; OUT.Col0.g = 0.0; OUT.Col0.b = 0.0; return OUT; } I convert it to a program using the Cg compiler and load it but I never get any output. Is this program going to work at all? Or is it likely correct and I need to look at my c++ code?
Advertisement
The program looks correct at first sight, but I would STRONGLY recommend you to intercept possible CG compiler errors. Look into the error handling tools as explained in the CG toolkit (from NVidia IIRC).

As far as I remember, the compiler doesn't just cancel the execution of the whole program if it can't compile the CG part. So the CG part just doesn't work and you don't know why. There can be many reasons why it doesn't work:

1) There's a syntax error in the program which I don't see at the moment
2) You didn't initialize the CG profile correctly
3) You forgot to bind the parameters
4) You forgot to set the parameters
5) You didn't load or bind the program

The CG compiler tells you all those things (except maybe 4) if you ask for it.

You seem to be using a float4 for the colour, but aren't setting the alpha. I don't know how Cg handles uninitialised parameters, but it could just be setting it to zero, which is why you aren't seeing anything...
If at first you don't succeed, redefine success.
Uninitialized parameters are not changed at all AFAIK. Every variable that is bound to a GPU register by the binding semantics (... : COLOR) keeps the value of this register in a CG program. So it's the alpha value coincides with the alpha of the last glColor4f(...) call.

This topic is closed to new replies.

Advertisement