[vtkusers] Direct use GLSL in VTK : I had can loadExtention, But could not see anything?

Francois Bertel francois.bertel at kitware.com
Mon Jan 15 09:20:35 EST 2007


Hi Patrik,

In the case your GLSL code is only about changing some material properties of your mesh, forget what I said before and use the material mechanism instead of coding the OpenGL calls yourself:

There is an example in the VTK source tree:

VTK/Utilities/MaterialLibrary/Materials/GLSLTwisted.xml
VTK/Utilities/MaterialLibrary/GLSLShaders/Twisted.glsl

More information here:
http://www.vtk.org/Wiki/Shader_In_VTK
http://www.vtk.org/Wiki/VTK_Shaders

There is a tcl test here: VTL/Rendering/Testing/Tcl/TestGLSLShader.tcl
In this test, there are 3 key lines:

# Load the material. Here, we are loading a material
# defined in the Vtk Library. One can also specify
# a filename to a material description xml.
[actor GetProperty] LoadMaterial "GLSLTwisted"

# Turn shading on. Otherwise, shaders are not used.
[actor GetProperty] ShadingOn

# Pass a shader variable need by GLSLTwisted.
[actor GetProperty] AddShaderVariable "Rate" 1.0


The C++ version would be:

vtkActor *actor;
vtkProperty *property=actor->GetProperty();

property->LoadMaterial("GLSLTwisted");
property->ShadingOn();
property->AddShaderVariable("Rate",1.0);


Now, you may still want to know why your code is not working. There is probably some rendering code somewhere between vtkProperty, vtkActor and their OpenGL subclasses that reset the shader program.


-- 
François Bertel, PhD  | Kitware Inc. Suite 204
1 (518) 371 3971 x113 | 28 Corporate Drive
                      | Clifton Park NY 12065, USA



More information about the vtkusers mailing list