[vtkusers] using openGL 4.1 on mac os X under vtk 5.10

eric lamar ec_lamar at yahoo.com
Tue Mar 31 19:57:34 EDT 2015


All:I am developing a VTK 5.10-based medical application under Mac OS X 10.10.I am extending VTK with a volume rendering engine that needs opengl 3.1 (specifically, glRestartPrimitive). When I do a glGetString(GL_VERSION), the system reports "2.1 NVIDIA-10.0.43 310.41.05f01". When I request OpenGL 3.2 (I've modified the routine "vtkCocoaRenderWindow::CreateGLContext" in vtkCocoaRenderWindow.mm; I've added "NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core" to the attributes list.), the system responds with "4.1 NVIDIA-10.0.43 310.41.05f01".That is fine; however, in a small demo app that works fine under Opengl 2.1 but I get a blank screen under Opengl 4.1. This small demo app is a distillation of the larger medial application.The small demo app follows:#include <iostream>
#include <OpenGL/GL3.h>

//#include <vtkRenderer.h>
#include <QtGui/qapplication.h>
#include <QVTKWidget.h>
#include <QtGui/qmainwindow.h>
#include "vtkRenderWindow.h"
#include "vtkSmartPointer.h"
#include "vtkSphereSource.h"
#include "vtkRenderer.h"

#include <vtkVersion.h>
#include <vtkSmartPointer.h>
#include <vtkSphere.h>
#include <vtkSampleFunction.h>
#include <vtkSmartVolumeMapper.h>
#include <vtkColorTransferFunction.h>
#include <vtkPiecewiseFunction.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkVolumeProperty.h>
#include <vtkCamera.h>
#include <vtkImageShiftScale.h>
#include <vtkImageData.h>
#include <vtkPointData.h>
#include <vtkDataArray.h>
#include <vtkXMLImageDataReader.h>


static void CreateImageData(vtkImageData* im);

int main(int argc, char * argv[])
{
    // app and window
    QApplication app(argc, argv);
    QMainWindow* wnd = new QMainWindow;
    wnd->setFixedSize(500, 500);

    // vtk widget
    QVTKWidget* w = new QVTKWidget();
    wnd->setCentralWidget(w);
    // renderer with red background
    vtkRenderer* rend = vtkRenderer::New();
    rend->SetBackground(0.8, 0.8, 0.8);
    // render-window to connect renderer -> widget
    vtkRenderWindow* window = vtkRenderWindow::New();
    window->AddRenderer(rend);
    w->SetRenderWindow(window);

    vtkSmartPointer<vtkImageData> imageData = vtkSmartPointer<vtkImageData>::New();
    CreateImageData(imageData);

    vtkSmartPointer<vtkSmartVolumeMapper> volumeMapper =
    vtkSmartPointer<vtkSmartVolumeMapper>::New();
    volumeMapper->SetBlendModeToComposite(); // composite first
    volumeMapper->SetInput(imageData);//SetInputData(imageData);
    vtkSmartPointer<vtkVolumeProperty> volumeProperty =
    vtkSmartPointer<vtkVolumeProperty>::New();
    volumeProperty->ShadeOff();
    volumeProperty->SetInterpolationType(VTK_LINEAR_INTERPOLATION);

    vtkSmartPointer<vtkPiecewiseFunction> compositeOpacity =
    vtkSmartPointer<vtkPiecewiseFunction>::New();
    compositeOpacity->AddPoint(0.0,0.0);
    compositeOpacity->AddPoint(80.0,1.0);
    compositeOpacity->AddPoint(80.1,1.0);
    compositeOpacity->AddPoint(255.0,0.0);
    volumeProperty->SetScalarOpacity(compositeOpacity); // composite first.

    vtkSmartPointer<vtkColorTransferFunction> color =
    vtkSmartPointer<vtkColorTransferFunction>::New();
    color->AddRGBPoint(0.0  ,0.0,0.0,1.0);
    color->AddRGBPoint(40.0  ,1.0,0.0,0.0);
    color->AddRGBPoint(255.0,1.0,1.0,1.0);
    volumeProperty->SetColor(color);

    vtkSmartPointer<vtkVolume> volume =
    vtkSmartPointer<vtkVolume>::New();
    volume->SetMapper(volumeMapper);
    volume->SetProperty(volumeProperty);
    rend->AddViewProp(volume);
    rend->ResetCamera();

    wnd->show();

    cout << "OpenGL Version=" << glGetString(GL_VERSION) << endl;

    return app.exec();
}



void CreateImageData(vtkImageData* imageData)
{
    // Create a spherical implicit function.
    vtkSmartPointer<vtkSphere> sphere =
    vtkSmartPointer<vtkSphere>::New();
    sphere->SetRadius(0.1);
    sphere->SetCenter(0.0,0.0,0.0);

    vtkSmartPointer<vtkSampleFunction> sampleFunction =
    vtkSmartPointer<vtkSampleFunction>::New();
    sampleFunction->SetImplicitFunction(sphere);
    sampleFunction->SetOutputScalarTypeToDouble();
    sampleFunction->SetSampleDimensions(127,127,127); // intentional NPOT dimensions.
    sampleFunction->SetModelBounds(-1.0,1.0,-1.0,1.0,-1.0,1.0);
    sampleFunction->SetCapping(false);
    sampleFunction->SetComputeNormals(false);
    sampleFunction->SetScalarArrayName("values");
    sampleFunction->Update();

    vtkDataArray* a = sampleFunction->GetOutput()->GetPointData()->GetScalars("values");
    double range[2];
    a->GetRange(range);

    vtkSmartPointer<vtkImageShiftScale> t =
    vtkSmartPointer<vtkImageShiftScale>::New();
    t->SetInputConnection(sampleFunction->GetOutputPort());

    t->SetShift(-range[0]);
    double magnitude=range[1]-range[0];
    if(magnitude==0.0)
    {
        magnitude=1.0;
    }
    t->SetScale(255.0/magnitude);
    t->SetOutputScalarTypeToUnsignedChar();

    t->Update();

    imageData->ShallowCopy(t->GetOutput());
}My question is (1) why is the screen blank? (2) do I need to have vertex and fragment programs enabled (given I've received a OpenGL 4.1 context)? (3) does enabling OpenGL >2.1 break VTK? (4) What do I need to change to get output?
Thank you,Eric.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150331/b6687f9b/attachment.html>


More information about the vtkusers mailing list