[vtkusers] vtkShader2 and Samplers
Guillaume DUMONT
me at guillaumedumont.com
Tue Sep 23 19:15:23 EDT 2014
Hi everyone,
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
answer (
http://vtk.1045678.n5.nabble.com/GLSL-Shader-on-a-vtkActor-VTK-6-1-and-Qt-5-2-1-tt5727788.html#a5728023
).
Here is my shader:
#version 130
uniform sampler2D tex;
out vec4 color;
void propFuncFS(void)
{
color = texture(tex, vec2(100, 100));
color[3] = 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<vtkJPEGReader>::New();
jpegReader->SetFileName("path/to/image");
jpegReader->Update();
vtkSmartPointer<vtkOpenGLTexture> texture =
vtkSmartPointer<vtkOpenGLTexture>::New();
texture->SetInputConnection(jpegReader->GetOutputPort());
// try to set the sampler2D here
int index = texture->GetIndex();
vtkSmartPointer<vtkUniformVariables> uniformVariables =
vtkSmartPointer<vtkUniformVariables>::New();
uniformVariables->SetUniformi("tex", 1, &index);
program->SetUniformVariables(uniformVariables);
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:
program->SetContext(m_renderWindow);
program->Build();
program->SendUniforms();
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.
--
Guillaume
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20140923/c5d8e89f/attachment.html>
More information about the vtkusers
mailing list