Esempio n. 1
0
void EngineActions::ExitPlayMode()
{
	QProgressDialog dialog(0,0);
	Utils::ShowProgressBar(&dialog, "Exiting play mode");

	// Stop the animation system.
	m_treenityMain->GetAnimationSystem()->Synch();
	m_treenityMain->GetAnimationSystem()->Terminate();

	// Clear whatever happened within the game session.
	ClearScene();
	g_engineContext.m_physics->RemoveAll();
	g_networkEntityMap.clear();
	RootForce::Network::NetworkComponent::ResetSequenceForUser(0);
	m_treenityMain->ProcessWorldMessages();

	// Restore the old world state.
	std::map<ECS::Entity*, std::string> entityNames;
	std::stringstream ss(m_editorLevelState);
	m_world->GetEntityImporter()->Import(ss, &entityNames);
	m_treenityMain->GetProjectManager()->SetEntityNames(entityNames);
	AddDefaultEntities();
	InitializeScene();

	//SDL_SetRelativeMouseMode(SDL_FALSE);
	g_engineContext.m_inputSys->LockMouseToCenter(false);
	m_editorMode = EditorMode::EDITOR;

	g_engineContext.m_logger->LogText(LogTag::TOOLS, LogLevel::DEBUG_PRINT, "Exited play mode");
}
Esempio n. 2
0
/*!
 * Creates a new document object.
 */
Document::Document()
:
  m_scene(0),
  m_isModified( false )
{
    InitializeScene();
}
Esempio n. 3
0
int main (int argc, char ** argv) {
    // Initialize the window:
    glutInit(&argc, argv);
    glutInitWindowPosition(-1, -1);
    glutInitWindowSize(WindowWidth, WindowHeight);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    int window = glutCreateWindow("Computer Graphics: Practice 1");

    // Setting the events:
    glutDisplayFunc(OnRender);
    glutReshapeFunc(OnResize);
    glutKeyboardFunc(OnKeyboard);
    glutSpecialFunc(OnSpecial);

    // Initialize OpenGL and the scene:
    InitializeGL();
    InitializeScene();

    // Run the main loop:
    glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
    glutMainLoop();

    // Finish the execution:
    UseTimer = false;
    EarthTexture.Release();
    MoonTexture.Release();
    glutDestroyWindow(window);
    return 0;
}
Esempio n. 4
0
// Keyboard press event handler
void OnKeyPress(GLFWwindow* /* window */, int key, int /* scancode */, int action, int /* mods */) {
  scene.keyboard[key] = action;

  // Reset
  if (key == GLFW_KEY_R && action == GLFW_PRESS) {
    InitializeScene();
  }
}
Esempio n. 5
0
void EngineActions::LoadScene( const QString& p_filePath )
{
	QFileInfo fileInfo(p_filePath);
	QProgressDialog dialog(0,0);
	Utils::ShowProgressBar(&dialog, "Level: " + fileInfo.completeBaseName());

	ClearScene();
	//Utils::RunWithProgressBar(QtConcurrent::run(m_treenityMain->GetProjectManager(), &ProjectManager::Import, p_filePath));
	m_treenityMain->GetProjectManager()->Import(p_filePath);
	AddDefaultEntities();
	InitializeScene();
	m_treenityMain->GetEditor()->GetUi().statusBar->showMessage("Level loaded: " + p_filePath, 5000);
}
Esempio n. 6
0
void Scene::Initialize(uint32_t uID, std::string * name)
{
	_name = *name;
	_uID = uID;

	Texture* blankDiff = new Texture(Color32(0xFFFFFFFF));
	Texture* blankNrm = new Texture(Color32((uint8_t)255, (uint8_t)127, (uint8_t)127, (uint8_t)255));
	_defaultMaterial = new Material
	(
		blankDiff,
		blankNrm
	);

	InitializeScene();
}
Esempio n. 7
0
int main(int argc, char* argv[]) 
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    glutInitWindowSize(800, 600);
    glutCreateWindow("Excercise 4 - Gouraud Shader");
    glutReshapeFunc(ChangeSize);
    glutDisplayFunc(RenderScene);

    GLenum err = glewInit();
    if (GLEW_OK != err) {
        fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
        return 1;
    }

    SetupRC();
	InitializeScene();

    glutMainLoop();
    return 0;
}
Esempio n. 8
0
int main() {
  // Initialize GLFW
  if (!glfwInit()) {
    std::cerr << "Failed to initialize GLFW!" << std::endl;
    return EXIT_FAILURE;
  }

  // Setup OpenGL context
  glfwWindowHint(GLFW_SAMPLES, 4);
  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
  glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
  glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

  // Try to create a window
  auto window = glfwCreateWindow(SIZE, SIZE, "PPGSO gl_scene", nullptr, nullptr);
  if (!window) {
    std::cerr << "Failed to open GLFW window, your graphics card is probably only capable of OpenGL 2.1" << std::endl;
    glfwTerminate();
    return EXIT_FAILURE;
  }

  // Finalize window setup
  glfwMakeContextCurrent(window);

  // Initialize GLEW
  glewExperimental = GL_TRUE;
  glewInit();
  if (!glewIsSupported("GL_VERSION_3_3")) {
    std::cerr << "Failed to initialize GLEW with OpenGL 3.3!" << std::endl;
    glfwTerminate();
    return EXIT_FAILURE;
  }

  // Add keyboard and mouse handlers
  glfwSetKeyCallback(window, OnKeyPress);
  glfwSetCursorPosCallback(window, OnMouseMove);
  glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); // Hide mouse cursor
  glfwSetInputMode(window, GLFW_STICKY_KEYS, 1);

  // Initialize OpenGL state
  // Enable Z-buffer
  glEnable(GL_DEPTH_TEST);
  glDepthFunc(GL_LEQUAL);

  // Enable polygon culling
  glEnable(GL_CULL_FACE);
  glFrontFace(GL_CCW);
  glCullFace(GL_BACK);

  InitializeScene();

  // Track time
  float time = (float)glfwGetTime();

  // Main execution loop
  while (!glfwWindowShouldClose(window)) {
    // Compute time delta
    float dt = (float)glfwGetTime() - time;
    time = (float)glfwGetTime();

    // Set gray background
    glClearColor(.5f,.5f,.5f,0);
    // Clear depth and color buffers
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Update and render all objects
    scene.Update(dt);
    scene.Render();

    // Display result
    glfwSwapBuffers(window);
    glfwPollEvents();
  }

  // Clean up
  glfwTerminate();

  return EXIT_SUCCESS;
}
Esempio n. 9
0
void tRenderer::Render()
{    
    if (m_xRenderSystem != 0)
    {
        if (m_RenderSystemInitialized == false)
        {
            InitializeScene();
        }

        m_xRenderSystem->BeginScene();

    #ifdef DEBUG_RENDER_TIMING
        DbgPrintf("Time to execute m_xRenderSystem->BeginScene():  %lf", timer.ElapsedMs());
        timer.Reset();
    #endif

        // Render the Scene.
        m_xRenderSystem->SetViewport(m_pRenderTarget->x(), m_pRenderTarget->y(), m_pRenderTarget->width(), m_pRenderTarget->height());

        RenderScene();
    
        // Render Cursor
        if (m_CursorRenderFunction != 0)
        {
            m_CursorRenderFunction();

        #ifdef DEBUG_RENDER_TIMING
            m_xRenderSystem->Flush();
            DbgPrintf("Time to Render Cursor:  %lf", timer.ElapsedMs());
            timer.Reset();
        #endif
        }

        if (m_OverlaysUpdated == true)
        {
            UpdateSceneOverlays();
        }

        // Draw Overlays
        if (m_Overlays.size() > 0)
        {
            m_xRenderSystem->SetOrthographicProjection(m_pRenderTarget->x(), m_pRenderTarget->y(), m_pRenderTarget->width(), m_pRenderTarget->height());

            unsigned long numRenderables = static_cast<unsigned long>(m_Overlays.size());

            for (unsigned long renderIndex = 0; renderIndex < numRenderables; ++renderIndex)
            {
                RenderOverlay(m_Overlays[renderIndex]);
                
            #ifdef DEBUG_RENDER_TIMING
                m_xRenderSystem->Flush();
                DbgPrintf("Time to Render Overlay #%d:  %lf", renderIndex, timer.ElapsedMs());
                timer.Reset();
            #endif
            }
        }

        m_xRenderSystem->EndScene();
    }

    emit RenderCompleted();
}
Esempio n. 10
0
/****************************************************************************
 SetupWindow()

 Creates a window and the device and rendering contexts for it.
*****************************************************************************/
BOOL SetupWindow(char *title, int width, int height, int bits, bool isFullscreen)
{
  // set the global flag
  g_isFullScreen = isFullscreen;

  // get our instance handle
  g_hInstance	= GetModuleHandle(NULL);

  WNDCLASSEX  wc;    // window class

  // fill out the window class structure
  wc.cbSize         = sizeof(WNDCLASSEX);
  wc.style          = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  wc.lpfnWndProc    = WndProc;
  wc.cbClsExtra     = 0;
  wc.cbWndExtra     = 0;
  wc.hInstance      = g_hInstance;
  wc.hIcon          = LoadIcon(NULL, IDI_APPLICATION);	// default icon
  wc.hIconSm        = LoadIcon(NULL, IDI_WINLOGO);		  // windows logo small icon
  wc.hCursor        = LoadCursor(NULL, IDC_ARROW);		  // default arrow
  wc.hbrBackground  = NULL; //(HBRUSH) GetStockObject(BLACK_BRUSH);   // black background
  wc.lpszMenuName   = NULL;     // no menu
  wc.lpszClassName  = WND_CLASS_NAME;
  
  // register the windows class
  if (!RegisterClassEx(&wc))
  {
    MessageBox(NULL,"Unable to register the window class", "Error", MB_OK | MB_ICONEXCLAMATION);
    return FALSE;							// Exit And Return FALSE
  }

  // if we're in fullscreen mode, set the display up for it
  if (g_isFullScreen)
  {
    // set up the device mode structure
    DEVMODE screenSettings;
    memset(&screenSettings,0,sizeof(screenSettings));

    screenSettings.dmSize       = sizeof(screenSettings);	
    screenSettings.dmPelsWidth  = width;			// screen width
    screenSettings.dmPelsHeight = height;			// screen height
    screenSettings.dmBitsPerPel = bits;				// bits per pixel
    screenSettings.dmFields     = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

    // attempt to switch to the resolution and bit depth we've selected
    if (ChangeDisplaySettings(&screenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
    { 
        g_isFullScreen = FALSE;	
    }
  }

  DWORD dwExStyle;
  DWORD dwStyle;

  // if we're still in fullscreen mode, set the window style appropriately
  if (g_isFullScreen)
  {
		dwExStyle = WS_EX_APPWINDOW;
		dwStyle = WS_POPUP;			  // simple window with no borders or title bar
		ShowCursor(FALSE);            // hide the cursor for now
  }
  else
  {
		dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
		dwStyle = WS_OVERLAPPEDWINDOW;
  }

  // set up the window we're rendering to so that the top left corner is at (0,0)
  // and the bottom right corner is (height,width)
  RECT  windowRect;
  windowRect.left = 0;
  windowRect.right = (LONG) width;
  windowRect.top = 0;
  windowRect.bottom = (LONG) height;

  // change the size of the rect to account for borders, etc. set by the style
  AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);

  // class registered, so now create our window
  g_hwnd = CreateWindowEx(dwExStyle,          // extended style
                          WND_CLASS_NAME,     // class name
                          title,              // app name
                          dwStyle |           // window style
                          WS_CLIPCHILDREN |   // required for
                          WS_CLIPSIBLINGS,    // using OpenGL
                          0, 0,               // x,y coordinate
                          windowRect.right - windowRect.left, // width
                          windowRect.bottom - windowRect.top, // height
                          NULL,               // handle to parent
                          NULL,               // handle to menu
                          g_hInstance,        // application instance
                          NULL);              // no extra params

  // see if our window handle is valid
  if (!g_hwnd)
	{
    // reset the display
		KillWindow();
		MessageBox(NULL, "Unable to create window", "Error", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

  // get a device context
	if (!(g_HDC = GetDC(g_hwnd)))
	{
    // reset the display
		KillWindow();
		MessageBox(NULL,"Unable to create device context", "Error", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

  // set the pixel format we want (p55)
  PIXELFORMATDESCRIPTOR pfd = {
    sizeof(PIXELFORMATDESCRIPTOR),	// size of structure
    1,                              // default version
    PFD_DRAW_TO_WINDOW |            // window drawing support
    PFD_SUPPORT_OPENGL |            // OpenGL support
    PFD_DOUBLEBUFFER,               // double buffering support
    PFD_TYPE_RGBA,                  // RGBA color mode
    bits,                           // 32 bit color mode
    0, 0, 0, 0, 0, 0,               // ignore color bits, non-palettized mode
    0,                              // no alpha buffer
    0,                              // ignore shift bit
    0,                              // no accumulation buffer
    0, 0, 0, 0,                     // ignore accumulation bits
    16,                             // 16 bit z-buffer size
    0,                              // no stencil buffer
    0,                              // no auxiliary buffer
    PFD_MAIN_PLANE,                 // main drawing plane
    0,                              // reserved
    0, 0, 0 };                      // layer masks ignored
      
	GLuint  pixelFormat;

	// choose best matching pixel format
	if (!(pixelFormat = ChoosePixelFormat(g_HDC, &pfd)))
	{
    // reset the display
		KillWindow();
		MessageBox(NULL, "Can't find an appropriate pixel format", "Error", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

	// set pixel format to device context
  if(!SetPixelFormat(g_HDC, pixelFormat,&pfd))
	{
    // reset the display
		KillWindow();
		MessageBox(NULL, "Unable to set pixel format", "Error", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
  }

  // create the OpenGL rendering context
  if (!(g_HRC = wglCreateContext(g_HDC)))
	{
    // reset the display
		KillWindow();
		MessageBox(NULL, "Unable to create OpenGL rendering context", "Error",MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

  // now make the rendering context the active one
  if(!wglMakeCurrent(g_HDC, g_HRC))
	{
    // reset the display
		KillWindow();
		MessageBox(NULL,"Unable to activate OpenGL rendering context", "ERROR", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

  // show the window in the forground, and set the keyboard focus to it
  ShowWindow(g_hwnd, SW_SHOW);
  SetForegroundWindow(g_hwnd);
  SetFocus(g_hwnd);

  // set up the perspective for the current screen size
  ResizeScene(width, height);

  // do one-time initialization
  
  if (!InitializeScene())
  {
    // reset the display
	  KillWindow();
	  MessageBox(NULL, "Initialization failed", "Error", MB_OK | MB_ICONEXCLAMATION);
	  return FALSE;
  }
  
  return TRUE;
} // end SetupWindow()
Esempio n. 11
0
/*!
 * Initializes the document with a empty scene.
 */
void Document::New()
{
    InitializeScene();
	m_isModified = false;
}