[vtkusers] Cg compile erro in VTK

Cory Quammen cquammen at cs.unc.edu
Tue Mar 4 08:41:35 EST 2008


Hi,

You might be running into a bug I've reported here:
http://www.vtk.org/Bug/view.php?id=4725

Basically, when the Cg program is read into a buffer containing your
shader code, the vtkXMLShader class allocates an array that is the
reported size of the file + 1. The size of the file is reported by
ifstream.tellg(). After reading the Cg program, a string terminator
gets placed at the last element in the array. The problem is that the
reported size of the file is larger than the number of characters, at
least in Windows. This is because line endings in Windows ('/r/n') are
counted as two characters as reported by ifstream.tellg(), but are
read as single-character line endings. As a result, your shader winds
up with junk characters right after your Cg code but before the string
terminator, and this is what causes your compiler error.

I've posted a patch with the bug report above. It simply puts the
string terminator in the correct place.

Hope that helps,
Cory

On Mon, Mar 3, 2008 at 11:55 PM, 捷 冯 <conan0316 at yahoo.com.cn> wrote:
> Hi everyone,
>   Recently, I have been working on shaders in VTK. I use
> vtkProperty::LoadMaterial() to load the xml file successfully. But an error
> comes out while compiling the code.
> It says:
> ERROR: In ..\..\VTK\Rendering\vtkCgShader.cxx, line 303
> vtkCgShader (032BB718): CG ERROR : The compile returned an error.
> ERROR: In ..\..\VTK\Rendering\vtkCgShader.cxx, line 306
> vtkCgShader (032BB718): (51) : error C0000: syntax error, unexpected
> $undefined at token "<undefined>"
> (51) : error C0501: type name expected at token "<undefined>"
>
> ERROR: In ..\..\VTK\Rendering\vtkCgShader.cxx, line 265
> vtkCgShader (032BB718): Failed to create Cg program.
>
> I don't know why and want your help. Thanks.
>
> My shader code is:
> vertex shader:
> struct C2E1v_Output {
>   float4 position : POSITION;
>   float4 color    : COLOR;
> };
> C2E1v_Output main(uniform float2 position : POSITION)
> {
>   C2E1v_Output OUT;
>   OUT.position = float4(position, 0, 1);
>   OUT.color    = float4(0, 1, 0, 1);  // RGBA green
>   return OUT;
> }
>
> fragment shader:
> struct C2E2f_Output {
>   float4 color : COLOR;
> };
> C2E2f_Output main(uniform float4 color : COLOR)
> {
>   C2E2f_Output OUT;
>   OUT.color = color;
>   return OUT;
> }
>
> xml file is:
> <?xml version="1.0" encoding="UTF-8"?>
> <Material name="Mat1" NumberOfProperties="1" NumberOfVertexShaders="1"
> NumberOfFragmentShaders="1">>
>   <Shader scope="Vertex" name="Vertex" location="Vertex.cg" language="Cg"
> entry="main" args="-DVERTEX_PROGRAM">
>   </Shader>
>   <Shader scope="Fragment" name="TestCgStructureFrag"
> location="StructureFragmentTest.cg" language="Cg" entry="fragment_program"
> args="-DFRAGMENT_PROGRAM">
>   </Shader>
> </Material>
> It's very simple.
>
> I hope you guys can help me.
> Thanks again.
>
>  ________________________________
> 雅虎邮箱传递新年祝福,个性贺卡送亲朋!
> _______________________________________________
>  This is the private VTK discussion list.
>  Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>  Follow this link to subscribe/unsubscribe:
>  http://www.vtk.org/mailman/listinfo/vtkusers
>
>



-- 
Cory Quammen
Department of Computer Science
University of North Carolina at Chapel Hill
http://www.cs.unc.edu/~cquammen


More information about the vtkusers mailing list