Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: ___ CG ___

  1. #1
    Junior Member Regular Contributor
    Join Date
    Dec 2002
    Location
    Poland
    Posts
    234

    ___ CG ___

    Hello

    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.

    Thanx

  2. #2
    Member Regular Contributor
    Join Date
    Apr 2002
    Location
    Austria
    Posts
    328

    Re: ___ CG ___

    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.
    There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.

    There is another theory which states that this has already happened...

  3. #3
    Junior Member Regular Contributor
    Join Date
    Nov 2002
    Location
    Kiev, Ukraine
    Posts
    130

    Re: ___ CG ___

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

  4. #4
    Junior Member Regular Contributor
    Join Date
    Dec 2002
    Location
    Poland
    Posts
    234

    Re: ___ CG ___

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

  5. #5
    Junior Member Regular Contributor
    Join Date
    Dec 2002
    Location
    Poland
    Posts
    234

    Re: ___ CG ___

    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

  6. #6
    Junior Member Regular Contributor
    Join Date
    Nov 2002
    Location
    Kiev, Ukraine
    Posts
    130

    Re: ___ CG ___

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

  7. #7
    Junior Member Newbie
    Join Date
    Jul 2003
    Location
    New Hope, MN
    Posts
    12

    Re: ___ CG ___

    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.

  8. #8
    Junior Member Newbie
    Join Date
    Nov 2003
    Location
    Switzerland
    Posts
    12

    Re: ___ CG ___

    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.

    --Martin

  9. #9
    Junior Member Regular Contributor
    Join Date
    Dec 2002
    Location
    Poland
    Posts
    234

    Re: ___ CG ___

    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!

  10. #10
    Member Regular Contributor
    Join Date
    Apr 2002
    Location
    Austria
    Posts
    328

    Re: ___ CG ___

    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... :-)
    There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.

    There is another theory which states that this has already happened...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •