# I got a completely black window，when I run example.

**URL:** <https://discourse.vtk.org/t/i-got-a-completely-black-window-when-i-run-example/14282>\
**Category:** Development\
**Created:** [July 23, 2024, 8:19am UTC](https://discourse.vtk.org/t/i-got-a-completely-black-window-when-i-run-example/14282 "2024-07-23T08:19:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![LItterBoy-GB](https://discourse.vtk.org/user_avatar/discourse.vtk.org/litterboy-gb/32/9093_2.png) [@LItterBoy-GB](https://discourse.vtk.org/u/LItterBoy-GB)\
**Post date:** [July 23, 2024, 8:19am UTC](https://discourse.vtk.org/t/i-got-a-completely-black-window-when-i-run-example/14282/1 "2024-07-23T08:19:48Z")

</div>

```auto
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkCellArray.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkRotationalExtrusionFilter.h>
#include <vtkStripper.h>
#include <vtkTubeFilter.h>
#include <vtkSmartPointer.h>
#include <vtkAutoInit.h>

VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);

int main(int, char* [])
{
	// Create the RenderWindow, Renderer and both Actors
	vtkNew<vtkNamedColors> colors;

	vtkNew<vtkRenderer> renderer;
	vtkNew<vtkRenderWindow> renWin;
	renWin->AddRenderer(renderer.GetPointer());

	vtkNew<vtkRenderWindowInteractor> iren;
	iren->SetRenderWindow(renWin.GetPointer());

	// create bottle profile
	//
	vtkNew<vtkPoints> points;
	points->InsertPoint(0, 0.01, 0.0, 0.0);
	points->InsertPoint(1, 1.5, 0.0, 0.0);
	points->InsertPoint(2, 1.5, 0.0, 3.5);
	points->InsertPoint(3, 1.25, 0.0, 3.75);
	points->InsertPoint(4, 0.75, 0.0, 4.00);
	points->InsertPoint(5, 0.6, 0.0, 4.35);
	points->InsertPoint(6, 0.7, 0.0, 4.65);
	points->InsertPoint(7, 1.0, 0.0, 4.75);
	points->InsertPoint(8, 1.0, 0.0, 5.0);
	points->InsertPoint(9, 0.2, 0.0, 5.0);

	vtkNew<vtkCellArray> lines;
	lines->InsertNextCell(10); // number of points
	lines->InsertCellPoint(0);
	lines->InsertCellPoint(1);
	lines->InsertCellPoint(2);
	lines->InsertCellPoint(3);
	lines->InsertCellPoint(4);
	lines->InsertCellPoint(5);
	lines->InsertCellPoint(6);
	lines->InsertCellPoint(7);
	lines->InsertCellPoint(8);
	lines->InsertCellPoint(9);

	vtkNew<vtkPolyData> profile;
	profile->SetPoints(points.GetPointer());
	profile->SetLines(lines.GetPointer());

	// extrude profile to make bottle
	//
	vtkNew<vtkRotationalExtrusionFilter> extrude;
	extrude->SetInputData(profile.GetPointer());
	extrude->SetResolution(60);

	vtkNew<vtkPolyDataMapper> map;
	map->SetInputConnection(extrude->GetOutputPort());

	vtkNew<vtkActor> bottle;
	bottle->SetMapper(map.GetPointer());
	bottle->GetProperty()->SetColor(colors->GetColor3d("Mint").GetData());

	// display the profile
	vtkNew<vtkStripper> stripper;
	stripper->SetInputData(profile.GetPointer());

	vtkNew<vtkTubeFilter> tubes;
	tubes->SetInputConnection(stripper->GetOutputPort());
	tubes->SetNumberOfSides(11);
	tubes->SetRadius(0.05);

	vtkNew<vtkPolyDataMapper> profileMapper;
	profileMapper->SetInputConnection(tubes->GetOutputPort());

	vtkNew<vtkActor> profileActor;
	profileActor->SetMapper(profileMapper.GetPointer());
	profileActor->GetProperty()->SetColor(colors->GetColor3d("Tomato").GetData());

	// Add the actors to the renderer, set the background and size
	//
	renderer->AddActor(bottle.GetPointer());
	renderer->AddActor(profileActor.GetPointer());
	renderer->SetBackground(colors->GetColor3d("Burlywood").GetData());

	renWin->SetSize(640, 480);
	renWin->SetWindowName("Bottle");
	renWin->Render();

	renderer->GetActiveCamera()->SetPosition(1, 0, 0);
	renderer->GetActiveCamera()->SetFocalPoint(0, 0, 0);
	renderer->GetActiveCamera()->SetViewUp(0, 0, 1);
	renderer->ResetCamera();
	renderer->GetActiveCamera()->Azimuth(30);
	renderer->GetActiveCamera()->Elevation(30);

	// render the image
	//
	iren->Start();

	return EXIT_SUCCESS;
}

```

 ![image](https://discourse.vtk.org/uploads/default/original/2X/6/6148afab23cc023d912180f8c4b57ceef817d316.png)

---

<div class="post-metadata">

**Author:** ![sankhesh](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sankhesh/32/73_2.png) [@sankhesh](https://discourse.vtk.org/u/sankhesh)\
**Post date:** [July 23, 2024, 2:15pm UTC](https://discourse.vtk.org/t/i-got-a-completely-black-window-when-i-run-example/14282/2 "2024-07-23T14:15:43Z")

</div>

My guess is that your camera is not looking at the data or the data is being clipped away.

Just before `iren->Start`, add

```auto
renderer->ResetCameraClippingRange();
renWin->Render()

```

---

<div class="post-metadata">

**Author:** ![LItterBoy-GB](https://discourse.vtk.org/user_avatar/discourse.vtk.org/litterboy-gb/32/9093_2.png) [@LItterBoy-GB](https://discourse.vtk.org/u/LItterBoy-GB)\
**Post date:** [July 24, 2024, 1:25am UTC](https://discourse.vtk.org/t/i-got-a-completely-black-window-when-i-run-example/14282/3 "2024-07-24T01:25:59Z")

</div>

> [@sankhesh](#):
>
> ```auto
> renderer->ResetCameraClippingRange();
> renWin->Render()
> 
> ```

These two pieces of code exist.

> [@LItterBoy-GB](#):
>
> ```auto
> renWin->SetSize(640, 480);
> renWin->SetWindowName("Bottle");
> renWin->Render();
> 
> renderer->GetActiveCamera()->SetPosition(1, 0, 0);
> renderer->GetActiveCamera()->SetFocalPoint(0, 0, 0);
> renderer->GetActiveCamera()->SetViewUp(0, 0, 1);
> renderer->ResetCamera();
> renderer->GetActiveCamera()->Azimuth(30);
> renderer->GetActiveCamera()->Elevation(30);
> 
> ```

But I found that I am unable to use vtkNamedFors.  
I got an exception “Microsoft C++ Exception: std::length\_error”, when i use the code `GetColor3d("Mint")`.

```auto
vtkNew<vtkNamedColors> colors;
vtkColor3d color = colors->GetColor3d("Mint");
double* a = color.GetData();

```

Sometime no exception, but a is [0.0f,0.0f,0.0f] when no exception.

Here is my solution.

> [@LItterBoy-GB](#):
>
> `bottle->GetProperty()->SetColor(colors->GetColor3d("Mint").GetData());`

Change to

```auto
bottle->GetProperty()->SetColor(0,0,1);

```

> [@LItterBoy-GB](#):
>
> `profileActor->GetProperty()->SetColor(colors->GetColor3d("Tomato").GetData());`

Change to

```auto
profileActor->GetProperty()->SetColor(1,0,0);

```

> [@LItterBoy-GB](#):
>
> `renderer->SetBackground(colors->GetColor3d("Burlywood").GetData());`

Change to

```auto
renderer->SetBackground(1,1,1);

```

But I want to know why. why can not use `vtkNamedColors`?

---

<div class="post-metadata">

**Author:** ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)\
**Post date:** [July 24, 2024, 9:14am UTC](https://discourse.vtk.org/t/i-got-a-completely-black-window-when-i-run-example/14282/4 "2024-07-24T09:14:18Z")

</div>

Have a look at [Bottle](https://examples.vtk.org/site/Cxx/Modelling/Bottle/). Check your CMakeLists.txt files against the one there. Also ensure that if you built VTK as Release make sure your build is also Release.
