[vtkusers] X, vtkXOpenGLRenderWindow and vtkXRenderWindowInteractor

Kall, Bruce A. kall at mayo.edu
Tue Apr 14 13:59:29 EDT 2009


What is the correct way in X Windows (Xlib) to map my own X window and
have all rendering and interaction happen with this window?
I've modified the code for Example2.cxx (see below).

The renWin->Render() works in the window I create, but the interactor seems
to create another window on the Start() command and then immediately dies
with a GLXBadDrawable error:
Major opcode 128 (GLX)
Minor opcode: 11 (X_GLXSwapBuffers)

Any suggestions, corrections? Sure seems like this must have come up
before, but I haven't found any code that does this in pure Xlib.

If I comment out the renwin->Render() just before creating the 
interactor, the
interactor does create and pop up its own window (with no error) and 
then all rendering and
interaction does go into the window the interactor creates, but not my 
window.

Thanks,
Bruce


The code:

/*=========================================================================

  Program:   Visualization Toolkit
  Module:    $RCSfile: Example2.cxx,v $

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
// include OS specific include file to mix in X code

#include "vtkActor.h"
#include "vtkConeSource.h"
#include "vtkGlyph3D.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderer.h"
#include "vtkSphereSource.h"
#include "vtkXOpenGLRenderWindow.h"
#include "vtkXRenderWindowInteractor.h"

#include <X11/Xlib.h>


void quit_cb(Widget,XtPointer,XtPointer);

int main (int argc, char *argv[])
{
  // X window stuff
  int depth;
  Visual *vis;
  Display *display;
  Window window;
 
  Colormap col;
 
  unsigned long white_pixel,black_pixel;
  XColor color_value;
 
  // do the xwindow ui stuff
  // get the display connection and give it to the renderer
  display = XOpenDisplay(NULL);
  /* Turn X Synchronization on so errors happen right away, rather than 
getting buffered */
  XSynchronize(display,true);
 
  // VTK stuff
  vtkXOpenGLRenderWindow *renWin;
  vtkRenderer *ren1;
  vtkActor *sphereActor1, *spikeActor1;
  vtkSphereSource *sphere;
  vtkConeSource *cone;
  vtkGlyph3D *glyph;
  vtkPolyDataMapper *sphereMapper, *spikeMapper;
  vtkXRenderWindowInteractor *iren;

 
  renWin = vtkXOpenGLRenderWindow::New();

  renWin->SetDisplayId(display);
  depth = renWin->GetDesiredDepth();
  vis = renWin->GetDesiredVisual();
  col = renWin->GetDesiredColormap();

  /* get a couple of colors */
  white_pixel = 0;
  black_pixel = 0;
  if(XParseColor(display, col, "white", &color_value))
    white_pixel = color_value.pixel;

  if(XParseColor(display, col, "black", &color_value))
    black_pixel = color_value.pixel;

  window = 
XCreateSimpleWindow(display,DefaultRootWindow(display),512,512,256,256,1,white_pixel,black_pixel);
  XMapRaised(display,window);
  XFlush(display);
  XClearWindow(display,window);
  XFlush(display);
  renWin->SetDisplayId(display);
  renWin->SetWindowId(window);

  ren1 = vtkRenderer::New();
  renWin->AddRenderer(ren1);

  sphere = vtkSphereSource::New();
  sphereMapper = vtkPolyDataMapper::New();
  sphereMapper->SetInputConnection(sphere->GetOutputPort());
  sphereActor1 = vtkActor::New();
  sphereActor1->SetMapper(sphereMapper);
  cone = vtkConeSource::New();
  glyph = vtkGlyph3D::New();
  glyph->SetInputConnection(sphere->GetOutputPort());
  glyph->SetSourceConnection(cone->GetOutputPort());
  glyph->SetVectorModeToUseNormal();
  glyph->SetScaleModeToScaleByVector();
  glyph->SetScaleFactor(0.25);
  spikeMapper = vtkPolyDataMapper::New();
  spikeMapper->SetInputConnection(glyph->GetOutputPort());
  spikeActor1 = vtkActor::New();
  spikeActor1->SetMapper(spikeMapper);
  ren1->AddActor(sphereActor1);
  ren1->AddActor(spikeActor1);
  ren1->SetBackground(0.4,0.1,0.2);

  renWin->Render();
  // We use an X specific interactor
  // since we have decided to make this an X program
  iren = vtkXRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);

  iren->Start();

  return 0;
}




More information about the vtkusers mailing list