<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:10px"><div style="margin-bottom: 1em; border: 0px; font-size: 15px; clear: both; color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; line-height: 13px;" class="">All:</div><div style="margin-bottom: 1em; border: 0px; font-size: 15px; clear: both; color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; line-height: 13px;" class="">I am developing a VTK 5.10-based medical application under Mac OS X 10.10.</div><div style="margin-bottom: 1em; border: 0px; font-size: 15px; clear: both; color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; line-height: 13px;" class="" id="yui_3_16_0_1_1427845536538_2980">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".</div><div style="margin-bottom: 1em; border: 0px; font-size: 15px; clear: both; color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; line-height: 13px;" class="" id="yui_3_16_0_1_1427845536538_2987">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.</div><div style="margin-bottom: 1em; border: 0px; font-size: 15px; clear: both; color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; line-height: 13px;" class="" id="yui_3_16_0_1_1427845536538_2979">The small demo app follows:</div><pre style="margin-top: 0px; padding: 5px; border: 0px; font-size: 13px; overflow: auto; width: auto; max-height: 600px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; word-wrap: normal; color: rgb(34, 34, 34); background-color: rgb(238, 238, 238);" class="" id="yui_3_16_0_1_1427845536538_3012"><code style="margin-top: 0px; margin-bottom: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;" class="" id="yui_3_16_0_1_1427845536538_3011">#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());
}</code></pre><pre style="margin-top: 0px; padding: 5px; border: 0px; font-size: 13px; overflow: auto; width: auto; max-height: 600px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; word-wrap: normal; color: rgb(34, 34, 34); background-color: rgb(238, 238, 238);" class="" id="yui_3_16_0_1_1427845536538_3012"><code style="margin-top: 0px; margin-bottom: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;" class="" id="yui_3_16_0_1_1427845536538_3109"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 13px; white-space: normal; background-color: rgb(255, 255, 255);" class="" id="yui_3_16_0_1_1427845536538_3108">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?</span><br></code></pre><pre style="margin-top: 0px; padding: 5px; border: 0px; font-size: 13px; overflow: auto; width: auto; max-height: 600px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; word-wrap: normal; color: rgb(34, 34, 34); background-color: rgb(238, 238, 238);" class="" id="yui_3_16_0_1_1427845536538_3012"><code style="margin-top: 0px; margin-bottom: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;" class="">Thank you,</code></pre><pre style="margin-top: 0px; padding: 5px; border: 0px; font-size: 13px; overflow: auto; width: auto; max-height: 600px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; word-wrap: normal; color: rgb(34, 34, 34); background-color: rgb(238, 238, 238);" class="" id="yui_3_16_0_1_1427845536538_3012"><code style="margin-top: 0px; margin-bottom: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;" class="">Eric.</code></pre></div></body></html>