# Rendering tubes and spheres and QVTKOpenGLNativeWidget

**URL:** https://discourse.vtk.org/t/rendering-tubes-and-spheres-and-qvtkopenglnativewidget/12168
**Category:** Support
**Tags:** rendering
**Created:** [August 18, 2023, 5:21pm UTC](https://discourse.vtk.org/t/rendering-tubes-and-spheres-and-qvtkopenglnativewidget/12168 "2023-08-18T17:21:02Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![totte\_karlsson](https://discourse.vtk.org/user_avatar/discourse.vtk.org/totte_karlsson/32/4281_2.png) [@totte\_karlsson](https://discourse.vtk.org/u/totte_karlsson)
#### Post date: [August 18, 2023, 5:21pm UTC](https://discourse.vtk.org/t/rendering-tubes-and-spheres-and-qvtkopenglnativewidget/12168/1 "2023-08-18T17:21:02Z")

</div>

Hello,  
We are rendering polylines and are using the technique described [here](https://www.kitware.com/rendering-tubes-and-spheres-in-vtk/) to render points as spheres, pixels and wire vs tubes.

I found that when using a console application, points are rendered as ‘pixels’ (squares), by setting

```auto
 anActor->GetProperty()->SetRenderPointsAsSpheres(false);

```

However, the same code don’t do the same thing when rendered using a QVTKOpenGLNativeWidget. In this case, the points are always rendered as spheres (when doing **SetRenderPointsAsSpheres(false)**) and not rendered at all when **SetRenderPointsAsSpheres(true)**

Is there a way to enable the ‘console app behavior’ when using a QVTKOpenGLNativeWidget ?

 ![image](https://discourse.vtk.org/uploads/default/original/2X/c/c73f1f65e609f8e0162f8925f962ea36402175b5.png)  
In a console application: SetRenderPointsAsSpheres(false);

![image](https://discourse.vtk.org/uploads/default/original/2X/1/18e2cdb511db91dce7bf5ded28c294bc4cb36977.png)  
In a QT application, using QVTKOpenGLNativeWidget: SetRenderPointsAsSpheres(true);

![image](https://discourse.vtk.org/uploads/default/original/2X/9/95e6dc8af08fc8821ad3ed8fc7452c51b2c143a9.png)  
In a QT application, using QVTKOpenGLNativeWidget: SetRenderPointsAsSpheres(false);

We are using VTK 9.1 and QT 6.5.

Regards  
Totte K.

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [August 18, 2023, 8:08pm UTC](https://discourse.vtk.org/t/rendering-tubes-and-spheres-and-qvtkopenglnativewidget/12168/2 "2023-08-18T20:08:56Z")

</div>

Hello @totte_karlsson!

When you execute the Qt application and request the actor to render points as spheres, do you observe any errors or shader warnings in the console? It’s worth noting that opengl errors are turned off by default in VTK release builds. If you encounter this issue, you might need to include these CMake arguments during the configuration of VTK.

```auto
-DVTK_REPORT_OPENGL_ERRORS=ON
-DVTK_REPORT_OPENGL_ERRORS_IN_RELEASE_BUILDS=ON

```

If you’re on windows, console output is generally disabled for Qt gui apps, so run your app this way in powershell to view console output:

```auto
& "my.exe" 2>&1 | Out-String

```

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [August 24, 2023, 12:49pm UTC](https://discourse.vtk.org/t/rendering-tubes-and-spheres-and-qvtkopenglnativewidget/12168/3 "2023-08-24T12:49:37Z")

</div>

Hello,

If you build your Qt application with qmake, then enable the console with a `CONFIG += console` in your `.pro` file. If you build with CMake, make sure the executable target (`add_executable(...)`) doesn’t have a `WIN32` modifier in it and/or you don’t have a `set_property(TARGET <your exe target> PROPERTY WIN32_EXECUTABLE true)`. By default, CMake builds “console applications” in Windows.

best,

PC

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [August 24, 2023, 3:28pm UTC](https://discourse.vtk.org/t/rendering-tubes-and-spheres-and-qvtkopenglnativewidget/12168/4 "2023-08-24T15:28:20Z")

</div>

@Paulo_Carvalho

Do Qt console apps on windows get a limited subset of OpenGL?

---

<div class="post-metadata">

### Author: ![totte\_karlsson](https://discourse.vtk.org/user_avatar/discourse.vtk.org/totte_karlsson/32/4281_2.png) [@totte\_karlsson](https://discourse.vtk.org/u/totte_karlsson)
#### Post date: [August 24, 2023, 10:51pm UTC](https://discourse.vtk.org/t/rendering-tubes-and-spheres-and-qvtkopenglnativewidget/12168/5 "2023-08-24T22:51:38Z")

</div>

Hello Jaswant,

Here is my configs related to CMake VTK and OpenGL

 ![image](https://discourse.vtk.org/uploads/default/original/2X/5/5f14c0b827a4ac53a1bbd3331aa9ea2e893b9aff.png)

When running my QT application, I don’t see any OpenGL errors in the console, and behavior is described as in the question.

So, there seem to be something different using a renderwindow in the QT widget, than one spawned from a console application.

Weird?

---

<div class="post-metadata">

### Author: ![totte\_karlsson](https://discourse.vtk.org/user_avatar/discourse.vtk.org/totte_karlsson/32/4281_2.png) [@totte\_karlsson](https://discourse.vtk.org/u/totte_karlsson)
#### Post date: [August 24, 2023, 11:04pm UTC](https://discourse.vtk.org/t/rendering-tubes-and-spheres-and-qvtkopenglnativewidget/12168/6 "2023-08-24T23:04:50Z")

</div>

Hello Paulo,

I get console output when I’m running my QT application. We turn on/off the console using CMake. This is the CMake file for the application

```auto
cmake_minimum_required(VERSION 3.16.0)
set(target arboreta)
project(${target} VERSION 1.0.0 LANGUAGES CXX)
OPTION(SHOW_ARBORETA_CONSOLE "Show Arboreta Console" OFF)

include_directories(
    ../../foundation
    ../../foundation/common
    ../../foundation/math
    ../../foundation/graphics
    ../../foundation/volume_manager
    ${CMAKE_INSTALL_PREFIX}/include
)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

set_property(GLOBAL PROPERTY AUTOGEN_SOURCE_GROUP "Qt Generated")

#Find boost
find_package(Boost ${BOOST_VERSION} EXACT COMPONENTS system filesystem REQUIRED)
link_directories(${Boost_LIBRARY_DIRS})

find_package(Qt6 COMPONENTS Widgets REQUIRED)

file(GLOB_RECURSE UI_FILES *.ui)
file(GLOB_RECURSE HPP_FILES *.h)
file(GLOB_RECURSE CPP_FILES *.cpp)
file(GLOB_RECURSE QRC_FILES *.qrc)

qt_add_executable(${target}
    ../app/main.cpp
)

target_sources(${target}     
PUBLIC
        ${UI_FILES}
        ${HPP_FILES}
        ${CPP_FILES}
        ${QRC_FILES}
        ../../resources/arboreta_rs.qrc
)

source_group("UI" REGULAR_EXPRESSION ".*\\.ui?")
source_group("QRC" REGULAR_EXPRESSION ".*\\.qrc?")
# source_group("QRC" REGULAR_EXPRESSION ".*\\.qrc?") # *.qrc | *_rs.cpp 
# source_group("QRC" REGULAR_EXPRESSION ".*\(\.qrc?|_rs\.cpp?)")
#set_target_properties(${target} PROPERTIES VS_GLOBAL_KEYWORD "QtVS_v304")

target_link_libraries(${target} PRIVATE 
Qt6::Widgets 
arbFoundation
)

install(    
    TARGETS ${target} 
    RUNTIME DESTINATION bin COMPONENT core
    LIBRARY DESTINATION lib COMPONENT core
    ARCHIVE DESTINATION lib COMPONENT core
)       

if(NOT ${SHOW_ARBORETA_CONSOLE})
	set_property(TARGET ${target} PROPERTY WIN32_EXECUTABLE true)
endif()

```

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [August 25, 2023, 1:36pm UTC](https://discourse.vtk.org/t/rendering-tubes-and-spheres-and-qvtkopenglnativewidget/12168/7 "2023-08-25T13:36:43Z")

</div>

> [@jaswantp](#):
>
> Do Qt console apps on windows get a limited subset of OpenGL?

None that I know of. The real difference between a “console app” and a “Win32 app” is that the former starts at the `void main()` and the latter, at the `WinMain()` function. If you app starts at the `WinMain()`, a console does not appear when the program loads. So, a “console app” can have graphics in it.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [August 25, 2023, 1:48pm UTC](https://discourse.vtk.org/t/rendering-tubes-and-spheres-and-qvtkopenglnativewidget/12168/8 "2023-08-25T13:48:59Z")

</div>

Please, try to link against Qt’s winmain static library when configuring the “Win32 app” mode. This enrures you’re using Qt’s `WinMain()`. Maybe your program is finding some one else or the compiler is making one for you.

```plaintext
if(NOT ${SHOW_ARBORETA_CONSOLE})
	set_property(TARGET ${target} PROPERTY WIN32_EXECUTABLE true)
    target_link_libraries(${target} PUBLIC Qt::WinMain)
endif()

```

take care,

PC

---

<div class="post-metadata">

### Author: ![Ren](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/r/ed655f/32.png) [@Ren](https://discourse.vtk.org/u/Ren)
#### Post date: [October 12, 2023, 6:56am UTC](https://discourse.vtk.org/t/rendering-tubes-and-spheres-and-qvtkopenglnativewidget/12168/9 "2023-10-12T06:56:28Z")

</div>

Hello Totte K, have you resolved the problem? I met with the same thing

---

<div class="post-metadata">

### Author: ![totte\_karlsson](https://discourse.vtk.org/user_avatar/discourse.vtk.org/totte_karlsson/32/4281_2.png) [@totte\_karlsson](https://discourse.vtk.org/u/totte_karlsson)
#### Post date: [October 12, 2023, 1:43pm UTC](https://discourse.vtk.org/t/rendering-tubes-and-spheres-and-qvtkopenglnativewidget/12168/10 "2023-10-12T13:43:52Z")

</div>

Hello Liang,

Nope, we are still observing this issue for now.

Totte

---

<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: [October 12, 2023, 2:09pm UTC](https://discourse.vtk.org/t/rendering-tubes-and-spheres-and-qvtkopenglnativewidget/12168/11 "2023-10-12T14:09:38Z")

</div>

@totte_karlsson In your application, do you ensure that the correct surface format is initialized for Qt? See [VTK: QVTKOpenGLNativeWidget Class Reference](https://vtk.org/doc/nightly/html/classQVTKOpenGLNativeWidget.html#details)

ParaView uses `QVTKOpenGLNativeWidget` and can render lines as tubes and points as spheres on Windows.
