[vtkusers] Direct use GLSL in VTK : I had can loadExtention, But could not see anything?

Patrik Spring patrikspring at yahoo.com.cn
Mon Jan 15 04:41:47 EST 2007


By good guy help , I run  understand VTK only through vtkOpenGLExtensionManager to support OpenGL 1.5 or 2.0!
  
  So I do it , my program could loadExtention and run , but I could not  see anything? I should see a red cube, if program run correct!
  
  why? there  were something  error?  who can give some guide?
  
  thanks ! Following is my code !
  
  ==========================================================
  
  int shader()
  {
  
      vtkCubeSource* sphere = vtkCubeSource::New();
  
  
      vtkPolyDataMapper*  sphereMapper = vtkPolyDataMapper::New();
      sphereMapper->SetInputConnection(sphere->GetOutputPort());
      
      vtkActor* sphereActor = vtkActor::New();
      sphereActor->SetMapper(sphereMapper);
  
  
      vtkRenderWindow *renWin = vtkRenderWindow::New();
  
      vtkOpenGLExtensionManager *extensions=vtkOpenGLExtensionManager::New();
      extensions->SetRenderWindow(renWin);
  
      int supports_GL_VERSION_2_0=extensions->ExtensionSupported("GL_VERSION_2_0");
  
  
      if(supports_GL_VERSION_2_0)
      {
          extensions->LoadExtension("GL_VERSION_2_0");
          vertShader = vtkgl::CreateShader(vtkgl::VERTEX_SHADER) ;    
          fragShader = vtkgl::CreateShader(vtkgl::FRAGMENT_SHADER);
          std::cout << "Ok, Graphic Card  supports GL_VERSION_2_0!" << std::endl;
      }
  
      const vtkgl::GLchar* vs = "void main(){ gl_Position = ftransform(); } ";
      const vtkgl::GLchar* fs = "void main(){ gl_FragColor = vec4(1.0,0.0,0.0,0.0); }";
  
  
      const char * vv = vs;
      const char * ff = fs;
  
      vtkgl::ShaderSource( vertShader, 1, &vs, NULL );
      vtkgl::ShaderSource( fragShader, 1, &fs, NULL );
  
      vtkgl::CompileShader(vertShader);
      vtkgl::CompileShader(fragShader);
  
      programHandle = static_cast<GLuint>(vtkgl::CreateProgram());
      vtkgl::AttachShader(programHandle,vertShader);
      vtkgl::AttachShader(programHandle,fragShader);
  
      vtkgl::LinkProgram(programHandle);
    
      int maxLength  = 1024;
      vtkgl::GLchar* info = new vtkgl::GLchar[maxLength];
    GLsizei charsWritten = 0;
  
    vtkgl::GetShaderInfoLog( vertShader, maxLength, &charsWritten, info );
  
    if( info )
      {
      cout << "Log message: " << (char *)info << endl;
      }
  
    vtkgl::GetShaderInfoLog( fragShader, maxLength, &charsWritten, info );
  
    if( info )
      {
      cout << "Log message: " << (char *)info << endl;
      }
  
      vtkgl::UseProgram(programHandle);
  
  
      vtkRenderer* ren1 = vtkRenderer::New();
      renWin->AddRenderer(ren1);
      vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
      iren->SetRenderWindow(renWin);
  
      ren1->AddActor(sphereActor);
  
      ren1->SetBackground(0.1,0.2,0.4);
      renWin->SetSize(300,300);
      renWin->Render();
  
      iren->Initialize();
      iren->Start();
  
      return 0;
  }
  
  
  
  
 		
---------------------------------
 Mp3疯狂搜-新歌热歌高速下   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070115/8ed4a668/attachment.htm>


More information about the vtkusers mailing list