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

MOUSSAUD David 244079 David.MOUSSAUD at cea.fr
Mon Jan 18 12:45:55 EST 2016


Hi,



I have finally found how to display my colored points.



Instead of using

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

I have used

    points->InsertNextPoint(0.1, 0.0, 0.0);



and it works like a charm !



Could someone explain me(us) why, calling this API, it does not make appear the 2 warning messages below ?



Best regards,

David.

________________________________
De : vtkusers [vtkusers-bounces at vtk.org] de la part de MOUSSAUD David 244079
Envoyé : jeudi 14 janvier 2016 09:51
À : vtkusers at vtk.org
Objet : [PROVENANCE INTERNET] [vtkusers] opengl2 : set the RGB color to a vertex with vtkPolyData and vtkPolyDataMapper


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/20160118/34cb5ebb/attachment.html>


More information about the vtkusers mailing list