Discussion:
[Opensg-users] VTK rendering in an OpenGL context created by OpenSG
Christian Bar
2015-12-03 14:33:22 UTC
Permalink
Dear All,
I am trying to create an OpenSG application that renders some OpenSG noded
and, in addition, also renders VTK data.
I am aware of the ContribVTK lib, but I'd like to do a different thing,
which is to render a vtk scene in an OpenGL context created by OpenSG. This
can be accomplished by the *ExternalVTKWidget *and
*vtkExternalOpenGLRenderWindow*, which should do just like what I want.
I successfully ran the VTK example that demonstrate the two classes above
and render some vtk actors and some plain GL code inside a glut window (
*TestGLUTRenderWindow*).
Then, I tried to copy the code and put it inside the basic OpenSG example
(01hello).

What I get is a crash when I call
*externalVTKWidget->GetRenderWindow()->Render()
*during the first render (called in the glut display function). Such crash
do no happen when I use vtk and glut, withouth OpenSG.
The crash is caused because vtk internally calls *glGetString(GL_VERSION)*,
and this returns null, which obviously is an error. BTW, if I call
*glGetString(GL_VERSION)
*BEFORE *GLUTWindow->init()*, it returns the correct string ("4.5.0 NVIDIA
348.07"). Is glew somehow related to this? I thought that *GLUTWindow *already
calls the *wglMakeCurrent* (and related stuff), so I should already have a
valid OpenGL context...
BTW (again), *glGetString(GL_VERSION) *always return null after a
*GLUTWindow->init()*, even if I do not use VTK.

Now, the real question is: do I have to build OpenSG and VTK in a way that
makes them compatible? What are the CMAKE options that manage this?
Has anyone ever tried to mix OpenSG and VTK?

My machine runs Windows 8 and I am building the application with Visual
Studio 2010 x64.
VTK version is 6.3 and OpenSG 2.0 (updated from git)

Many thanks to anyone that could give me some advice :)
Kind regards,
Christian Bar
Carsten Neumann
2015-12-03 17:19:02 UTC
Permalink
Hello Christian,
Post by Christian Bar
What I get is a crash when I call
/externalVTKWidget->GetRenderWindow()->Render() /during the first render
(called in the glut display function). Such crash do no happen when I
use vtk and glut, withouth OpenSG.
The crash is caused because vtk internally calls
/glGetString(GL_VERSION)/, and this returns null, which obviously is an
error. BTW, if I call /glGetString(GL_VERSION) /BEFORE
/GLUTWindow->init()/, it returns the correct string ("4.5.0 NVIDIA
348.07"). Is glew somehow related to this? I thought that /GLUTWindow
/already calls the /wglMakeCurrent/ (and related stuff), so I should
already have a valid OpenGL context...
BTW (again), /glGetString(GL_VERSION) /always return null after a
/GLUTWindow->init()/, even if I do not use VTK.
the OpenSG windows only activate the GL context for the duration of the
rendering and deactivate it when done, so anything outside of
Window::render() typically does not have an active GL context.
You should be able to surround your additional rendering with
GLUTWindow::activate()/deactivate() calls to get access to the context.
Post by Christian Bar
Now, the real question is: do I have to build OpenSG and VTK in a way
that makes them compatible? What are the CMAKE options that manage this?
Has anyone ever tried to mix OpenSG and VTK?
My machine runs Windows 8 and I am building the application with Visual
Studio 2010 x64.
I don't think any additional care beyond the normal windows requirement
not to mix debug/release libs is needed - but I haven't tried it.

Cheers,
Carsten
Christian Bar
2015-12-04 17:18:45 UTC
Permalink
Thank you Carsten!

I managed to render a VTK cube in a OpenSG Window!

A lot of work has still to be done, but it's a good start :)


Thank you,

Regards,

Christian




----------------------------------------------

Hello Christian,
Post by Christian Bar
What I get is a crash when I call
/externalVTKWidget->GetRenderWindow()->Render() /during the first render
(called in the glut display function). Such crash do no happen when I
use vtk and glut, withouth OpenSG.
The crash is caused because vtk internally calls
/glGetString(GL_VERSION)/, and this returns null, which obviously is an
error. BTW, if I call /glGetString(GL_VERSION) /BEFORE
/GLUTWindow->init()/, it returns the correct string ("4.5.0 NVIDIA
348.07"). Is glew somehow related to this? I thought that /GLUTWindow
/already calls the /wglMakeCurrent/ (and related stuff), so I should
already have a valid OpenGL context...
BTW (again), /glGetString(GL_VERSION) /always return null after a
/GLUTWindow->init()/, even if I do not use VTK.
the OpenSG windows only activate the GL context for the duration of the
rendering and deactivate it when done, so anything outside of
Window::render() typically does not have an active GL context.
You should be able to surround your additional rendering with
GLUTWindow::activate()/deactivate() calls to get access to the context.
Post by Christian Bar
Now, the real question is: do I have to build OpenSG and VTK in a way
that makes them compatible? What are the CMAKE options that manage this?
Has anyone ever tried to mix OpenSG and VTK?
My machine runs Windows 8 and I am building the application with Visual
Studio 2010 x64.
I don't think any additional care beyond the normal windows requirement
not to mix debug/release libs is needed - but I haven't tried it.

Cheers,
Carsten
Christian Bar
2015-12-04 17:23:10 UTC
Permalink
Thank you Carsten!

I managed to render a VTK cube in a OpenSG Window!

A lot of work has still to be done, but it's a good start :)


Thank you,

Regards,

Christian




----------------------------------------------

Hello Christian,
Post by Christian Bar
What I get is a crash when I call
/externalVTKWidget->GetRenderWindow()->Render() /during the first render
(called in the glut display function). Such crash do no happen when I
use vtk and glut, withouth OpenSG.
The crash is caused because vtk internally calls
/glGetString(GL_VERSION)/, and this returns null, which obviously is an
error. BTW, if I call /glGetString(GL_VERSION) /BEFORE
/GLUTWindow->init()/, it returns the correct string ("4.5.0 NVIDIA
348.07"). Is glew somehow related to this? I thought that /GLUTWindow
/already calls the /wglMakeCurrent/ (and related stuff), so I should
already have a valid OpenGL context...
BTW (again), /glGetString(GL_VERSION) /always return null after a
/GLUTWindow->init()/, even if I do not use VTK.
the OpenSG windows only activate the GL context for the duration of the
rendering and deactivate it when done, so anything outside of
Window::render() typically does not have an active GL context.
You should be able to surround your additional rendering with
GLUTWindow::activate()/deactivate() calls to get access to the context.
Post by Christian Bar
Now, the real question is: do I have to build OpenSG and VTK in a way
that makes them compatible? What are the CMAKE options that manage this?
Has anyone ever tried to mix OpenSG and VTK?
My machine runs Windows 8 and I am building the application with Visual
Studio 2010 x64.
I don't think any additional care beyond the normal windows requirement
not to mix debug/release libs is needed - but I haven't tried it.

Cheers,
Carsten

Loading...