[vtkusers] opengl2 : set the RGB color to a vertex with vtkPolyData and vtkPolyDataMapper

MOUSSAUD David 244079 David.MOUSSAUD at cea.fr
Thu Jan 14 03:51:32 EST 2016


Dear all,



I'm trying to use the opengl2 backend rendering. I am with the 6.3 release version.



I have a working code to display 3 colored vertex that works with opengl1 (cf below and attached file).





    // Setup points

    points = vtkSmartPointer<vtkPoints>::New();


     // Setup the colors array

    colors = vtkSmartPointer<vtkUnsignedCharArray>::New();

    colors->SetNumberOfComponents(3);

    colors->SetName("Colors");


    // create a vertex

    vertex = vtkSmartPointer<vtkVertex>::New();


    // list of all the vertices

    vertices= vtkSmartPointer<vtkCellArray>::New();


    nb_points = 3;

    points->Resize(nb_points);

    vertices->Initialize();

    colors->Initialize();


    points->SetPoint(0, 0.1, 0.0, 0.0);

    vertex->GetPointIds()->SetId(0,0);

    vertices->InsertNextCell(vertex);

    colors->InsertNextTuple3(255,0,0);


    points->SetPoint(1, 0, 0.1, 0.0);

    vertex->GetPointIds()->SetId(0,1);

    vertices->InsertNextCell(vertex);

    colors->InsertNextTuple3(0,255,0);


    points->SetPoint(2, 0, 0.0, 0.1);

    vertex->GetPointIds()->SetId(0,2);

    vertices->InsertNextCell(vertex);

    colors->InsertNextTuple3(0,0,255);


    // Create a polydata object and add everything to it

    polydata = vtkSmartPointer<vtkPolyData>::New();

    polydata->SetPoints(points);

    polydata->SetVerts(vertices);

    polydata->GetPointData()->SetScalars(colors);


    mapper = vtkSmartPointer<vtkPolyDataMapper>::New();


    mapper->SetInputData(polydata);


    actor = vtkSmartPointer<vtkActor>::New();

    actor->SetMapper(mapper);

    actor->GetProperty()->SetPointSize(5);


    // Setup window

    renderWindow = vtkSmartPointer<vtkRenderWindow>::New();


    // Setup renderer

    renderer = vtkSmartPointer<vtkRenderer>::New();

    renderWindow->AddRenderer(renderer);


    renderer->AddActor(actor);

    renderer->ResetCamera();


    this->SetRenderWindow(renderWindow);



When I compile the same project with my vtk library compiled with the opengl2 backend rendering,



I have this error :



ERROR: In C:\work\lib\vtk\VTK-6.3.0\VTK-6.3.0\Rendering\OpenGL2\vtkOpenGLPolyDataMapper.cxx, line 1223
vtkOpenGLPolyDataMapper (0000000000501B90): Error setting 'vertexMC' in shader VAO.

ERROR: In C:\work\lib\vtk\VTK-6.3.0\VTK-6.3.0\Rendering\OpenGL2\vtkOpenGLPolyDataMapper.cxx, line 1250
vtkOpenGLPolyDataMapper (0000000000501B90): Error setting 'scalarColor' in shader VAO.



For information, I've tried the same with a vtkPlyReader based project and I've succeed to render it with opengl2 backend (and it works very much better !)



Best Regards,

David.




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160114/2933a50f/attachment.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: qvtkwidgetrendu3d.cpp
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160114/2933a50f/attachment.ksh>


More information about the vtkusers mailing list