[vtkusers] vtkShader2 and Samplers
me at guillaumedumont.com
Tue Sep 23 19:15:23 EDT 2014
I am currently trying to use shaders with VTK (GLSL) and I have managed so
far to run a vertex & fragment shader using the vtkShader2 and
vtkShaderProgram2 classes. However, I am now trying to set the sampler2D of
my shader but I haven't been very successful at all and it has been bugging
me for a while.
In order to use shaders, I based myself on the code snippet given in this
Here is my shader:
uniform sampler2D tex;
out vec4 color;
color = texture(tex, vec2(100, 100));
color = 1;
This is very simple test that I use to verify that I get a color from the
texture. And here is the C++ code to set the sampler2D "tex", that comes
after the snippet mentioned above:
// load the texture
vtkSmartPointer<vtkJPEGReader> jpegReader =
vtkSmartPointer<vtkOpenGLTexture> texture =
// try to set the sampler2D here
int index = texture->GetIndex();
vtkSmartPointer<vtkUniformVariables> uniformVariables =
uniformVariables->SetUniformi("tex", 1, &index);
With this code, I get a black texture. So my guess was that the uniforms
weren't actually copied onto the GPU, so I tried:
But the Build() fails with the linking error: "no program".
At this point, I would really appreciate any help/indication/snippet.
Thanks a lot in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the vtkusers