Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: can i write glsl code in .cg/.cgfx file?

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2010
    Posts
    3

    can i write glsl code in .cg/.cgfx file?

    hi, all
    I see the following code in Cg Refercence Manual -> cg Profile -> glslv :
    glslv void main(float4 position : POSITION,
    out float4 opos : POSITION)
    {
    opos = mul(gl_ModelViewMatrix, position);
    }


    My question is, does it mean that I can wirte glsl code in .cg/.cgfx file?

    Then I write the following code in my .cgfx file:
    glslv void main(
    uniform float pointRadius,
    uniform float pointScale,
    uniform vec4 eyePos
    )
    {
    vec4 wpos = vec4(gl_Vertex.xyz, 1.0);
    gl_Position = gl_ModelViewProjectionMatrix * wpos;

    // calculate window-space point size
    vec4 eyeSpacePos = gl_ModelViewMatrix * wpos;
    float dist = length(eyeSpacePos.xyz);
    gl_PointSize = pointRadius * (pointScale / dist);

    gl_TexCoord[0] = gl_MultiTexCoord0;
    gl_TexCoord[1] = eyeSpacePos;

    gl_FrontColor = gl_Color;
    }

    But there are serveal errors when i compile this code in FxComposer.
    Error error C5059 stdlib "gl_" variables are not accessible
    Error error C5059 stdlib "gl_" variables are not accessible


    It seems that the variables which contain prefix "gl_" are not recognised by the compiler.

    so, can I wirte glsl code in .cg/.cgfx file?

    Thank you.

  2. #2
    Junior Member Newbie
    Join Date
    Feb 2010
    Posts
    25

    Re: can i write glsl code in .cg/.cgfx file?

    I don't know about mixing GLSL and Cg/CgFX, though it certainly seems like it's possible if the compiler isn't throwing a huge fit.

    However, the error messages you're seeing may be unrelated. Most of the built-in gl_* variables (including the ones you're using in the sample above) are now deprecated as of GLSL 1.30. FxComposer may be adhering to a more recent version of the GLSL standard, in which case the use of those variables is indeed an error. All GL state variables (e.g. gl_ModelViewMatrix) must now be explicitly declared passed in as normal uniform variables, and all vertex attributes (e.g. gl_Vertex, gl_MultiTexCoord0) must be explicitly mapped using glBindAttribLocation() and friends.

    Alternatively, there may be some way to force FxComposer into compatibility mode...

  3. #3
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,892

    Re: can i write glsl code in .cg/.cgfx file?

    Quote Originally Posted by yaoyansi
    I see the following code in Cg Refercence Manual -> cg Profile -> glslv ...

    My question is, does it mean that I can [write] glsl code in .cg/.cgfx file?
    Check out this post by Ilian Dinev. This speaks to using GLSL in Cg, and gives examples. Also potentially useful: this

    But there are [several] errors when i compile this code in FxComposer. ... It seems that the variables which contain prefix "gl_" are not [recognized] by the compiler.
    They work for me, cross-compiling GLSL to asm for checking dead code elimination and such. Try a command-line like this:

    Code :
    cgc -oglsl -strict -glslWerror -profile gpu_vp vert.glsl
    cgc -oglsl -strict -glslWerror -profile gpu_fp frag.glsl

Posting Permissions

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