[vtkusers] Rendering in the existing window!

Alex Malyushytskyy alexmalvtk at gmail.com
Thu May 23 13:43:41 EDT 2013


You will have more chances to get help if you post/reply to mailing list,
so I am forwarding this to it.
As for your problem, look at the code I recommended to look above.
As far as I can tell your code at every paint event creates pipeline then
deletes it.


Alex


On Wed, May 22, 2013 at 9:16 PM, Le Minh Nhat <nhatleminh10 at gmail.com>wrote:

> Hi Alex,
> Yes, I tried what u said adding the function SetParentId(handler).
> However, when I ran the program, it was hang and nothing happened! Do u
> have any idea? Is it because of the place I called the function
> drawSphere(handler) in the WinProc?
> Looking forward to hearing from you!
> Thanks.
>
>
>
> On Thu, May 23, 2013 at 2:06 AM, Alex Malyushytskyy <alexmalvtk at gmail.com>wrote:
>
>> try  add
>>
>> renWin->SetParentId(handler);
>>
>> to
>> drawSphere(HWND handler)
>>
>> vtk source has Win32Cone.cxx example which might be useful
>>
>> Alex
>>
>>
>>
>> On Wed, May 22, 2013 at 2:36 AM, Le Minh Nhat <nhatleminh10 at gmail.com>wrote:
>>
>>> Hi everyone,
>>> I am quite new to Vtk, and I have tried to create a sphere using Vtk.
>>> However, the rendering window is separated from my existing window. Here is
>>> my source code:
>>>
>>> #include <windows.h>
>>>
>>> #include "vtkSphereSource.h"
>>> #include "vtkPolyDataMapper.h"
>>> #include "vtkProperty.h"
>>> #include "vtkActor.h"
>>> #include "vtkRenderWindow.h"
>>> #include "vtkRenderer.h"
>>> #include "vtkRenderWindowInteractor.h"
>>> #include "vtkWin32OpenGLRenderWindow.h"
>>> #include "vtkNew.h"
>>> #include "vtkCamera.h"
>>> //
>>> //
>>> void drawSphere(HWND handler)
>>> {
>>>   // create sphere geometry
>>>   vtkSphereSource *sphere = vtkSphereSource::New();
>>>   sphere->SetRadius(1.0);
>>>   sphere->SetThetaResolution(18);
>>>   sphere->SetPhiResolution(18);
>>>
>>>   // map to graphics library
>>>   vtkPolyDataMapper *map = vtkPolyDataMapper::New();
>>>   map->SetInput(sphere->GetOutput());
>>>
>>>   // actor coordinates geometry, properties, transformation
>>>   vtkActor *aSphere = vtkActor::New();
>>>   aSphere->SetMapper(map);
>>>   aSphere->GetProperty()->SetColor(0,0,1); // sphere color blue
>>>
>>>   // a renderer and render window
>>>   vtkRenderer *ren1 = vtkRenderer::New();
>>>   vtkRenderWindow *renWin = vtkRenderWindow::New();
>>>
>>>   renWin->AddRenderer(ren1);
>>>
>>>   // an interactor
>>>   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
>>>   iren->SetRenderWindow(renWin);
>>>
>>>   // add the actor to the scene
>>>   ren1->AddActor(aSphere);
>>>   ren1->SetBackground(1,1,1); // Background color white
>>>
>>>   // render an image (lights and cameras are created automatically)
>>>   //renWin->InitializeFromCurrentContext();
>>>   renWin->Render();
>>>
>>>
>>>   // begin mouse interaction
>>>   iren->Start();
>>>
>>>   // release memory and return
>>>   sphere->Delete();
>>>   map->Delete();
>>>   aSphere->Delete();
>>>   ren1->Delete();
>>>   renWin->Delete();
>>>   iren->Delete();
>>>
>>> }
>>>
>>> LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
>>> lParam)
>>> {
>>>     switch(msg)
>>>     {
>>>
>>>
>>>         case WM_CLOSE:
>>>             DestroyWindow(hwnd);
>>>         break;
>>>
>>>         case WM_DESTROY:
>>>             PostQuitMessage(0);
>>>         break;
>>>
>>>         case WM_PAINT:
>>>             drawSphere(hwnd);
>>>         break;
>>>
>>>         default:
>>>             return DefWindowProc(hwnd, msg, wParam, lParam);
>>>     }
>>>     return 0;
>>> }
>>>
>>> int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
>>> lpCmdLine, int nCmdShow)
>>> {
>>>     WNDCLASSEX wc;
>>>     HWND hwnd;
>>>     MSG Msg;
>>>
>>>     wc.cbSize            = sizeof(WNDCLASSEX);
>>>     wc.style            = 0;
>>>     wc.lpfnWndProc        = WndProc;
>>>     wc.cbClsExtra        = 0;
>>>     wc.cbWndExtra        = 0;
>>>     wc.hInstance        = hInstance;
>>>     wc.hIcon            = LoadIcon(NULL, IDI_APPLICATION);
>>>     wc.hCursor            = LoadCursor(NULL, IDC_ARROW);
>>>     wc.hbrBackground    = (HBRUSH)(COLOR_WINDOW+1);
>>>     wc.lpszMenuName        = NULL;
>>>     wc.lpszClassName    = "mySphere";
>>>     wc.hIconSm            = LoadIcon(NULL, IDI_APPLICATION);
>>>
>>>     if(!RegisterClassEx(&wc))
>>>     {
>>>         MessageBox(NULL, "Window Registration Failed!", "Error!",
>>> MB_ICONEXCLAMATION | MB_OK);
>>>         return 0;
>>>     }
>>>
>>>     hwnd = CreateWindowEx(
>>>         WS_EX_CLIENTEDGE,
>>>         "mySphere",
>>>         "Sphere",
>>>         WS_OVERLAPPEDWINDOW,
>>>         CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
>>>         NULL, NULL, hInstance, NULL);
>>>
>>>     if(hwnd == NULL)
>>>     {
>>>         MessageBox(NULL, "Window Creation Failed!", "Error!",
>>>             MB_ICONEXCLAMATION | MB_OK);
>>>         return 0;
>>>     }
>>>
>>>     ShowWindow(hwnd, nCmdShow);
>>>     UpdateWindow(hwnd);
>>>
>>>     while(GetMessage(&Msg, NULL, 0, 0) > 0)
>>>     {
>>>         TranslateMessage(&Msg);
>>>         DispatchMessage(&Msg);
>>>     }
>>>     return Msg.wParam;
>>> }
>>>
>>> Anyone has any idea how to set the rendering window and the existing
>>> window to be one! Any response will be appreciated.
>>> Best regards,
>>> Bent
>>>
>>> _______________________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the VTK FAQ at:
>>> http://www.vtk.org/Wiki/VTK_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130523/1950ceb5/attachment.htm>


More information about the vtkusers mailing list