コード例 #1
0
ファイル: Application.cpp プロジェクト: JamesLinus/nui3
void Application::OnInit()
{
  nuiInit(NULL);

  uint Width = 0, Height = 0;
  bool HasSize = false;
  bool IsFullScreen = false;
  bool DebugObject = false;
  bool DebugInfo = false;
  bool ShowFPS = false;

  
  nuiRenderer Renderer = eOpenGL;
//  nuiRenderer Renderer = eSoftware;
//  nuiRenderer Renderer = eDirect3D;

  // Accept NGL default options
  ParseDefaultArgs();

  GetLog().UseConsole(true);
  GetLog().SetLevel(_T("font"), 100);

  // Manual
  if ( (GetArgCount() == 1) &&
       ((!GetArg(0).Compare(_T("-h"))) || (!GetArg(0).Compare(_T("--help")))) )
  {
    NGL_OUT(_T("no params\n"));
    Quit (0);
    return;
  }
  
  // Parse args
  int i = 0;
  while (i < GetArgCount())
  {
    nglString arg = GetArg(i);
    if ((!arg.Compare(_T("--size")) || !arg.Compare(_T("-s"))) && ((i+1) < GetArgCount()))
    {
      int w, h;

      std::string str(GetArg(i+1).GetStdString());
      sscanf(str.c_str(), "%dx%d", &w, &h);
      if (w > 0) Width  = w;
      if (h > 0) Height = h;
      HasSize = true;
      i++;
    }
    else if (!arg.Compare(_T("--showfps")) || !arg.Compare(_T("-fps"))) ShowFPS = true;
    else if (!arg.Compare(_T("--fullscreen")) || !arg.Compare(_T("-f"))) IsFullScreen = true;
    else if (!arg.Compare(_T("--debugobject")) || !arg.Compare(_T("-d"))) DebugObject = true;
    else if (!arg.Compare(_T("--debuginfo")) || !arg.Compare(_T("-i"))) DebugInfo = true;
    else if (!arg.Compare(_T("--renderer")) || !arg.Compare(_T("-r"))) 
    {
      arg = GetArg(i+1);
      if (!arg.Compare(_T("opengl"))) Renderer = eOpenGL;
      else if (!arg.Compare(_T("direct3d"))) Renderer = eDirect3D;
      else if (!arg.Compare(_T("software"))) Renderer = eSoftware;
      i++;
    }
    i++;
  }
  
  nuiMainWindow::SetRenderer(Renderer);

  if (!HasSize)
  {
    if (IsFullScreen)
    {
      nglVideoMode current_mode;

      Width = current_mode.GetWidth();
      Height = current_mode.GetHeight();
    }
    else
    {
#ifdef NUI_IPHONE
      Width = 320;
      Height = 480;
#else
      Width = 800;
      Height = 600;
#endif
    }
  }


  /* Create the nglWindow (and thus a GL context, don't even try to
   *   instantiate the gui (or nglFont) before the nuiWin !)
   */
  nuiContextInfo ContextInfo(nuiContextInfo::StandardContext3D);
  nglWindowInfo Info;

  Info.Flags = IsFullScreen ? nglWindow::FullScreen : 0;
  Info.Width = Width;
  Info.Height = Height;
  Info.Pos = nglWindowInfo::ePosCenter;
  Info.Title = APPLICATION_TITLE;
  Info.XPos = 0;
  Info.YPos = 0;
        
  mpMainWindow = new MainWindow(ContextInfo,Info, ShowFPS);
  if ((!mpMainWindow) || (mpMainWindow->GetError()))
  {
    if (mpMainWindow) 
      NGL_OUT(_T("Error: cannot create window (%s)\n"), mpMainWindow->GetErrorStr());
    Quit (1);
    return;
  }
  mpMainWindow->Acquire();
  mpMainWindow->DBG_SetMouseOverInfo(DebugInfo);  mpMainWindow->DBG_SetMouseOverObject(DebugObject);
  mpMainWindow->SetState(nglWindow::eShow);

}
コード例 #2
0
bool nuiInitMinimal(void* OSHandle = NULL, nuiKernel* pKernel)
{
  bool res = nuiInit(OSHandle, pKernel);
  return res;
}
コード例 #3
0
ファイル: my_native_code.cpp プロジェクト: JamesLinus/nui3
/**
  * This is the main entry point of a native application that is using
  * android_native_app_glue.  It runs in its own thread, with its own
  * event loop for receiving input events and doing other things.
  */
void android_main(struct android_app* state) 
{ 
  LOGI("nuiInit");
  nuiInit(state);
  LOGI("nuiInit OK");
  
  // Create the NUI bridge which also serves as the main window/widget tree:
  LOGI("create Android Bridge");
  gpBridge = new nuiAndroidBridge();
  LOGI("create Android Bridge OK");
  
  struct engine engine;
  
  // Make sure glue isn't stripped.
  app_dummy();
  
  memset(&engine, 0, sizeof(engine));
  state->userData = &engine;
  state->onAppCmd = engine_handle_cmd;
  state->onInputEvent = engine_handle_input;
  engine.app = state;
  
  // Prepare to monitor accelerometer
  engine.sensorManager = ASensorManager_getInstance();
  engine.accelerometerSensor = ASensorManager_getDefaultSensor(engine.sensorManager,
                                                               ASENSOR_TYPE_ACCELEROMETER);
  engine.sensorEventQueue = ASensorManager_createEventQueue(engine.sensorManager,
                                                            state->looper, LOOPER_ID_USER, NULL, NULL);
  
  if (state->savedState != NULL) 
  {
    // We are starting with a previous saved state; restore from it.
    engine.state = *(struct saved_state*)state->savedState;
  }
  
  // loop waiting for stuff to do.

  
  while (1) 
  {
    // Read all pending events.
    int ident;
    int events;
    struct android_poll_source* source;
    
    // If not animating, we will block forever waiting for events.
    // If animating, we loop until all events are read, then continue
    // to draw the next frame of animation.
    while ((ident=ALooper_pollAll(engine.animating ? 0 : -1, NULL, &events,
                                  (void**)&source)) >= 0) 
    {
      
      // Process this event.
      if (source != NULL) 
      {
        source->process(state, source);
      }
      
      // If a sensor has data, process it now.
      if (ident == LOOPER_ID_USER) 
      {
        if (engine.accelerometerSensor != NULL) 
        {
          ASensorEvent event;
          while (ASensorEventQueue_getEvents(engine.sensorEventQueue,
                                             &event, 1) > 0) 
          {
//            LOGI("accelerometer: x=%f y=%f z=%f",
//                 event.acceleration.x, event.acceleration.y,
//                 event.acceleration.z);
          }
        }
      }
      
      // Check if we are exiting.
      if (state->destroyRequested != 0) 
      {
        engine_term_display(&engine);
        return;
      }
    }
    
    if (engine.animating) 
    {
      // Done with events; draw next animation frame.
      engine.state.angle += .01f;
      if (engine.state.angle > 1) 
      {
        engine.state.angle = 0;
      }
      
      // Drawing is throttled to the screen update rate, so there
      // is no need to do timing here.
      engine_draw_frame(&engine);
    }
  }
}
コード例 #4
0
ファイル: nuiApp.cpp プロジェクト: JamesLinus/nui3
void nuiApp::OnInit()
{
  nuiInit(NULL);

  nuiRenderer Renderer = eOpenGL;

// Accept NGL default options
  ParseDefaultArgs();

  uint Width = 0, Height = 0;
  uint Angle = 0;
//Angle = 90;
//Angle = 180;
  Angle = 0;

  bool HasSize = false;
  bool IsFullScreen = false;
  bool DebugObject = false;
  bool DebugInfo = false;
  bool ShowFPS = false;
  bool PartialRedraw = false;
//  bool PartialRedraw = true;

  nuiMainWindow::SetRenderer(Renderer);

  nuiContextInfo ContextInfo(nuiContextInfo::StandardContext3D);
  ContextInfo.FrameBitsR = 5;
  ContextInfo.FrameBitsG = 6;
  ContextInfo.FrameBitsB = 5;
  ContextInfo.FrameBitsA = 0;
  ContextInfo.DepthBits = 0;

///< If false partial redraw cannot be achieved
  ContextInfo.CopyOnSwap = PartialRedraw;
 

  nglWindowInfo Info;

  Info.Flags = IsFullScreen ? nglWindow::FullScreen : 0;
  Info.Width = Width;
  Info.Height = Height;
  Info.Rotate = Angle;
  Info.Pos = nglWindowInfo::ePosCenter;
  Info.Title = _T("nuiApp");
  Info.XPos = 0;
  Info.YPos = 0;

  nuiWin* pWin = new nuiWin(ContextInfo, Info);

  if ((!pWin) || (pWin->GetError()))
  {
    if (pWin) {
      NGL_OUT(_T("[nuiApp] Error: cannot create window (%s)\n"), pWin->GetErrorStr());
    }
    Quit (1);
    return;
  }

  pWin->SetState(nglWindow::eShow);
  pWin->EnablePartialRedraw(PartialRedraw);
//  mpWindow->SetFrameRateLimit(20.f);
}