Jump to content
  • Advertisement
Sign in to follow this  
jbb

OpenGL Getting started with ARB_VERTEX_PROGRAM and Cg

This topic is 5051 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

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?

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!