___ CG ___


I have a stupid question. At least I hope that I choosed a right forum to ask it. So… what is the difference between CG and OpenGL shaders? Are they something similiar and do they have the same purpose? I don’t really know anything about it so I’ll appreciate any help.


The main difference between CG and GLslang is that the high shading language compiler of GLslang is included in the OpenGL driver of the implementation. So there are A LOT of optimization possibilities.

cg - developed by NVidia, GLSlang - by 3Dlabs (and became to be official HL language for OpenGL, when cg was restricted).

Ow, I see. Now it seems to be clear for me. Thanks guys!

Hmmm… I thought of another question (if you don’t mind). Is it possible to use CG with OpenGL? Does a graphics API has to provide some additional feedback for managing CG code? I’m just curious. Thanx

>>Is it possible to use CG with OpenGL?
ARB_profile & NV20/nv30 profile(Win32/Linux, but not a FreeBSD/MacOS X).

The CG compiler emits fragment program code so OpenGL is not required to provide additional shader management functionality and neither are you forced to use the CG runtime library. There has to be some way to bind variables to certain API constructs, but thats really about it for CG.

>>Does a graphics API has to provide some additional feedback for managing CG code? I’m just curious.

The most important advantage of OpenGL Shading language is the integration into OpenGL, you can access OpenGL states with built-in uniforms. For example you set lighting with:

glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_amb);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_dif);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_spec);

and then access your values inside the shader with gl_LightSource[0].ambient etc.

The benefit is better portability and compatibility between shaders of different authors. In CG everyone used his own uniform variables and it resulted in a complete lack of portability between different C++ programs.

Imagine someone writes a OGLSL phong lighting fragment shader using built-in uniforms only, it is a matter of a few minutes to integrate this shader into someones existing OpenGL program… And if the end-user doesn’t have a video card with shader support he will still see standard OpenGL (per vertex) lighting.


Thank you for your help.

To sum up, I think you’ve answered a question I wanted to ask now… I mean what is better? I see that for OpenGL GLslang is the best option, right? If so I don’t have anything more I’d like to ask for now.

Thanks once again!

Yes, GLslang is the best option but it is supported by 3DLabs and ATI (inofficial) only. And I noticed that ATI’s implementation has some major bugs… :slight_smile:

As I know, NVidia GLSlang implementaion will be very soon(looks like in the same time with official ATI implementation). Cg also will be updated.

nVidia and GLslang? Very soon?
This is the first time I heard something like this. But I hope it is true!

Hmmm… I thought it would be nice if you knew some tutorials about GLslang. Do you know any? It is rather hard to learn from technical specifications.

Thanx in advance!

Hi, i have a proponsal to all of yours: The only source of glslang examples are the ASHLI, form ATI, and ogl2sdk, form 3DLabs. I Propose to create a web related to GLSLang. I can provide the site (a subdomain of my site www.typhoonlabs.com, in construction, and with no accupation for now) with all the glslang community contributions, source code, demos, tutorials, etc.
One site for all people that want to learn GLSLang, but i need all your colaborations

P.D: forgive my bad english please

Originally posted by ayaromenok:
Cg also will be updated.

I thought thay dropped it in favour of glSlang. It wouldn’t make much sence to continue it, anyway.

I recently created a webpage with some OGLSL examples, located at: http://www.clockworkcoders.com/oglsl/

Right now, it only contains very simple tutorials, current OGLSL implementations are just not as advanced (or even have bugs).

If you created some shaders I can add some links to your site, or you can send them to me.


Ey, cool site!!
Especially the VS.NET GLslang coloring!! Thank you, guy!

PS: Which GLslang implementation do u use?

PS: Which GLslang implementation do u use?

Shader Spec 1.051

I tested everything with ATI ‘cod hotfix’ driver and 3Dlabs current driver.


Well , i promise send my “experiments” with glslang to your web

Originally posted by mchristen:
I recently created a webpage with some OGLSL examples, located at: http://www.clockworkcoders.com/oglsl/

That’s just what I’ve been looking for. Thanks.

[This message has been edited by Orzech (edited 12-15-2003).]