Shaders

Started by
14 comments, last by biovenger 20 years, 7 months ago
Cg isn't C or C++. It's a language developed by NVIDIA which just happens to use the C/C++ specification to aid developers. Cg shaders work like textures. You don't load a texture every frame using glTexImage2D(). You create a texture object, bind it, then load the texture into it. The same is true for a Cg shader. You create a shader object, bind it, then load in the shader from a text file. It's compiled as it's loaded. Then, when you want to use a shader, you bind it again, just like a texture, and render your scene.

A note: I'm not 100% about the above. It might apply to ARB_fragment_program, not Cg. However, I think this is the way it's done...


Coding Stuff ->  [ iNsAn1tY Games | DarkVertex | How To Do CSG | Direct3D Vs. OpenGL | Google ]
Fun Stuff    ->  [ Evil T-Shirts | Stick-Based Comedy | You're Already Here | The Best Film Reviews ]

[edited by - iNsAn1tY on September 4, 2003 8:22:31 AM]
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]
Advertisement
I understand the semantics of Cg and that it is a programming language that compiles to GPU instructions, etc... That was not my question, sorry for not being clear.

What I need to know, is after compiling a shader, how do I use it from any language that can access OpenGL? Do I execute the shader binary from my program or do I load in a procedure or somewhat? That is the only part that is very unclear and ironically, seemingly impossible to get any information about. There are tons of articles and tutorials about Cg, but none that tell one how to use the shaders from some other API (such as OGL).
-----------------------------Final Frontier Trader
I''m pretty sure the Cg docs say...

There''s an extra library for using Cg with OpenGL which allows you to load/compile Cg source into shaders then use them while you''re using OpenGL.

I can''t remember the exact workings of it, but the docs are all there.

Why you shouldn''t use iostream.h - ever! | A Good free online C++ book
An interesting article appeared in the GameDev articles today: Cg Shadow Volumes. This linked to a document I was quite unaware of, and which I'll be using to understand Cg a bit more. It's an introduction to Cg, using bumpmapping as an example, and it's here: Cg Bumpmapping. It shows exactly how to initialize Cg and load shaders, and will come in very handy, I'm sure...


Coding Stuff ->  [ iNsAn1tY Games | DarkVertex | How To Do CSG | Direct3D Vs. OpenGL | Google ]
Fun Stuff    ->  [ Evil T-Shirts | Stick-Based Comedy | You're Already Here | The Best Film Reviews ]

[edited by - iNsAn1tY on September 5, 2003 6:32:38 AM]
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]
Yes, it seems that the article will be very useful, thank you all!
-----------------------------Final Frontier Trader
quote:Original post by iNsAn1tY
I believe that you''ll need a GeforceFX or a Radeon 5900 to run some of Humus''s demos. They really are the very latest stuff. Most of the demos on the main page don''t work on my Geforce 3. You need support for ARB_fragment_shader.



Yes you will need a GeForce FX (any) or Radeon 9500 or higher (9000/9100/9200 are DirectX 8.1 cards) for Fragement programs.

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"
Member of the Shove Pouya Off A Cliff club, SPOAC. (If you wish to join, add this line to your signature.)Member of "Un-Ban nes8bit" association, UNA (to join put this in your sig)"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

This topic is closed to new replies.

Advertisement