void runGUI(const vl::String& title, BaseDemo* program, vl::OpenGLContextFormat /*format*/, int x, int y, int width, int height, vl::fvec4 bk_color, vl::vec3 eye, vl::vec3 center)
  {
    program->setAppletName(title);

    // WX_GL_RGBA:            Use true colour
    // WX_GL_BUFFER_SIZE:     Bits for buffer if not WX_GL_RGBA
    // WX_GL_LEVEL:           0 for main buffer, >0 for overlay, <0 for underlay
    // WX_GL_DOUBLEBUFFER:    Use doublebuffer
    // WX_GL_STEREO:          Use stereoscopic display
    // WX_GL_AUX_BUFFERS:     Number of auxiliary buffers (not all implementation support this option)
    // WX_GL_MIN_RED:         Use red buffer with most bits (> MIN_RED bits)
    // WX_GL_MIN_GREEN:       Use green buffer with most bits (> MIN_GREEN bits)
    // WX_GL_MIN_BLUE:        Use blue buffer with most bits (> MIN_BLUE bits)
    // WX_GL_MIN_ALPHA:       Use alpha buffer with most bits (> MIN_ALPHA bits)
    // WX_GL_DEPTH_SIZE:      Bits for Z-buffer (0,16,32)
    // WX_GL_STENCIL_SIZE:    Bits for stencil buffer
    // WX_GL_MIN_ACCUM_RED:   Use red accum buffer with most bits (> MIN_ACCUM_RED bits)
    // WX_GL_MIN_ACCUM_GREEN: Use green buffer with most bits (> MIN_ACCUM_GREEN bits)
    // WX_GL_MIN_ACCUM_BLUE:  Use blue buffer with most bits (> MIN_ACCUM_BLUE bits)
    // WX_GL_MIN_ACCUM_ALPHA: Use blue buffer with most bits (> MIN_ACCUM_ALPHA bits)
    int context_format[] =
    {
      WX_GL_RGBA,
      WX_GL_DOUBLEBUFFER,
      WX_GL_MIN_RED, 8,
      WX_GL_MIN_GREEN, 8,
      WX_GL_MIN_BLUE, 8,
      WX_GL_MIN_ALPHA, 8,
      WX_GL_DEPTH_SIZE, 24,
      WX_GL_STENCIL_SIZE, 8,
      /*WX_GL_LEVEL, 0,
      WX_GL_AUX_BUFFERS, 0*/
      0
    };
    MyFrame *frame = new MyFrame(NULL, L"WXGLCanvas", wxPoint(x,y), wxSize(width, height));
    mWXWin = new WXGLCanvas( frame, NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE, context_format );

    /* needed before accessing OpenGL */
    frame->Show();

    /* common test setup */
    setupApplet(program, mWXWin, bk_color, eye, center);

    /* initialize OpenGL context */
    mWXWin->initGLContext();

    /* call initEvent() to initialize the test */
    mWXWin->dispatchInitEvent();

    /* these must be done after the window is visible and the applet is initialized */
    frame->SetPosition( wxPoint(x,y) );
    frame->SetClientSize( wxSize(width,height) );
    frame->SetLabel(wxT("Visualization Library on wxWindows"));
  }
예제 #2
0
파일: main.cpp 프로젝트: zulman/qutemol
// `Main program' equivalent, creating windows and returning main app frame
bool MyApp::OnInit()
{
    hardSettings.OnStart();
    
    cgSettings.SetDefaults(); // <-- quick hack (solves wrong constructor order): 
      
    //if (!wxApp::OnInit()) return false;

    // questo per caricare salvare PNG...
    wxImage::AddHandler(new wxPNGHandler);
    wxImage::AddHandler(new wxJPEGHandler);
    
    // Create the main frame window
    MyFrame *frame = new MyFrame(NULL, wxT("QuteMol"),
//        wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE //wxRESIZE_BORDER
#ifdef __DARWIN__
        wxDefaultPosition, wxDefaultSize,wxDEFAULT_FRAME_STYLE| wxRESIZE_BORDER
#else
        wxDefaultPosition, wxDefaultSize,wxRESIZE_BORDER
#endif
        );
        
    /* Make a menubar */
    
    /*
    // ...or, maybe NOT
    wxMenu *fileMenu = new wxMenu;

    fileMenu->Append(wxID_EXIT, wxT("E&xit"));
    fileMenu->Append(wxID_ABOUT, wxT("A&bout"));
    fileMenu->Append(wxID_OPEN, wxT("O&pen"));
    
    wxMenuBar *menuBar = new wxMenuBar;
    menuBar->Append(fileMenu, wxT("&File"));
    
    frame->SetMenuBar(menuBar);
    */

    frame->SetCanvas( 
      new TestGLCanvas(
        frame, wxID_ANY, wxPoint(0,0), wxSize( winx, winy ),   wxNO_BORDER //wxSUNKEN_BORDER
      )
    );

    // onle TestGLCanvas to process idles...
    wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED);
    frame->SetExtraStyle(wxWS_EX_PROCESS_IDLE );
    
    MyTab::frame2redraw=frame->GetCanvas();
    
    frame->SetToolbar(  
      new MyToolbar(
        frame, wxID_ANY, wxPoint(winx,0), wxDefaultSize,   
       // wxNO_BORDER //wxSUNKEN_BORDER
        wxDEFAULT_FRAME_STYLE 
       |
//                      wxNO_FULL_REPAINT_ON_RESIZE |
                      wxCLIP_CHILDREN |
                      wxTAB_TRAVERSAL
      )
    );
    
    wxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
    sizer->Add(frame->GetCanvas(),      1, wxGROW|wxSHAPED); 
    sizer->Add(frame->GetToolbar(),      0, wxGROW);
    frame->SetSizer(sizer);

    int tbsize=frame->GetToolbar()->GetBestFittingSize().x;
    frame->GetToolbar()->SetSize(tbsize,winy);
    frame->GetToolbar()->Layout();
   
    //frame->SetMinSize(wxSize(tbsize+200,200));
    frame->SetClientSize(wxSize(winx+tbsize,winy));

    static const wxCmdLineEntryDesc cmdLineDesc[] =
    {
      { 
        wxCMD_LINE_PARAM,_T(""),_T(""),_T("filename.pdb:(molecule to be drawn)"), 
        wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL 
      },
      { 
        wxCMD_LINE_OPTION,_T("a"),_T(""),_T("filename.art: optional Atom Render Table"), 
        wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL 
      },
      { 
        wxCMD_LINE_SWITCH,_T("v"),_T(""),_T("don't start, show version name"), 
        wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL 
      },
      { wxCMD_LINE_NONE }
    };
    
    wxCmdLineParser parser(cmdLineDesc, argc, argv);
    
    parser.Parse();

    InitQuteMol( NULL );

    wxString artFilename;
    if (parser.Found(_T("v"))>0) {
      FILE *f=fopen("output.txt", "wt");
      if (f) { 
        fprintf(f,"ver 0.4.1");
        fclose(f);
      }
      exit(0);
    }
    
    if (parser.Found(_T("a"),&artFilename)>0) {
      if (!readArtFile(artFilename.ToAscii())) {
        wxMessageBox(
          wxString(_T("Error reading art file \"") + artFilename +"\""), 
          _T("Error reading art file"), 
          wxOK | wxICON_EXCLAMATION, frame);
        exit(0);
        return false;
      }
    }
       
    if (parser.GetParamCount()>0)  frame->OnReadFile(parser.GetParam(0));
/*      InitQuteMol( parser.GetParam(0).mb_str(wxConvUTF8) );
    } else {
      InitQuteMol( NULL );
    }*/
  
    /* Show the frame */

    frame->Center();    
    frame->SetDropTarget( new MyDropTarget(frame) );
    frame->Show(true);
    
    return true;
}
//-----------------------------------------------------------------------------
bool MyApp::OnInit()
{
  /* open a console so we can see the applet's output on stdout */
  showWin32Console();

  /* init Visualization Library */
  VisualizationLibrary::init();

  MyFrame *frame = new MyFrame(NULL, L"WXGLCanvas", wxDefaultPosition, wxSize(400, 300));

  /* Initialize the OpenGL context and window properties */
  // WX_GL_RGBA:            Use true colour
  // WX_GL_BUFFER_SIZE:     Bits for buffer if not WX_GL_RGBA
  // WX_GL_LEVEL:           0 for main buffer, >0 for overlay, <0 for underlay
  // WX_GL_DOUBLEBUFFER:    Use doublebuffer
  // WX_GL_STEREO:          Use stereoscopic display
  // WX_GL_AUX_BUFFERS:     Number of auxiliary buffers (not all implementation support this option)
  // WX_GL_MIN_RED:         Use red buffer with most bits (> MIN_RED bits)
  // WX_GL_MIN_GREEN:       Use green buffer with most bits (> MIN_GREEN bits)
  // WX_GL_MIN_BLUE:        Use blue buffer with most bits (> MIN_BLUE bits)
  // WX_GL_MIN_ALPHA:       Use alpha buffer with most bits (> MIN_ALPHA bits)
  // WX_GL_DEPTH_SIZE:      Bits for Z-buffer (0,16,32)
  // WX_GL_STENCIL_SIZE:    Bits for stencil buffer
  // WX_GL_MIN_ACCUM_RED:   Use red accum buffer with most bits (> MIN_ACCUM_RED bits)
  // WX_GL_MIN_ACCUM_GREEN: Use green buffer with most bits (> MIN_ACCUM_GREEN bits)
  // WX_GL_MIN_ACCUM_BLUE:  Use blue buffer with most bits (> MIN_ACCUM_BLUE bits)
  // WX_GL_MIN_ACCUM_ALPHA: Use blue buffer with most bits (> MIN_ACCUM_ALPHA bits)
  int context_format[] =
  {
    WX_GL_RGBA,
    WX_GL_DOUBLEBUFFER,
    WX_GL_MIN_RED, 8,
    WX_GL_MIN_GREEN, 8,
    WX_GL_MIN_BLUE, 8,
    WX_GL_MIN_ALPHA, 8,
    WX_GL_DEPTH_SIZE, 24,
    WX_GL_STENCIL_SIZE, 8,
    /*WX_GL_LEVEL, 0,
    WX_GL_AUX_BUFFERS, 0*/
    0
  };
  ref<WXGLCanvas> vl_gl_canvas = new WXGLCanvas( frame, NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE, context_format );

  /* create the applet to be run */
  ref<Applet> applet = new App_RotatingCube;

  applet->initialize();

  /* target the window so we can render on it */
  applet->rendering()->as<Rendering>()->renderer()->setFramebuffer( vl_gl_canvas->framebuffer() );
  
  /* black background */
  applet->rendering()->as<Rendering>()->camera()->viewport()->setClearColor( black );
  
  /* define the camera position and orientation */
  vec3 eye    = vec3(0,10,35); // camera position
  vec3 center = vec3(0,0,0);   // point the camera is looking at
  vec3 up     = vec3(0,1,0);   // up direction
  mat4 view_mat = mat4::getLookAt(eye, center, up);
  applet->rendering()->as<Rendering>()->camera()->setViewMatrix( view_mat );
  
  /* show the window */
  frame->Show();
  
  /* THE ORDER IS IMPORTANT IMPORTANT */
  vl_gl_canvas->initGLContext();
  
  /* bind the applet so it receives all the GUI events related to the OpenGLContext */
  vl_gl_canvas->addEventListener(applet.get());

  /* these must be done after the window is visible */
  int x = 0;
  int y = 0;
  int width = 512;
  int height= 512;
  frame->SetPosition( wxPoint(x,y) );
  frame->SetClientSize( wxSize(width,height) );
  frame->SetLabel(wxT("Visualization Library on wxWindows - Rotating Cube"));

  return true;
}