Exemple #1
0
Window::Window(QScreen *screen) :
    QWindow (screen),
    scene_  (new BasicUsageScene)
{
    setSurfaceType(OpenGLSurface);

    QSurfaceFormat format;
    format.setDepthBufferSize(24);
    format.setMajorVersion(3);
    format.setMinorVersion(3);
    format.setSamples(4);
    format.setProfile(QSurfaceFormat::CoreProfile);

    resize(800, 600);
    setFormat(format);
    create();

    context_ = new QOpenGLContext();
    context_->setFormat(format);
    context_->create();

    scene_->setContext(context_);
    initializeGl();

    connect(this, SIGNAL(widthChanged(int)), this, SLOT(resizeGl()));
    connect(this, SIGNAL(heightChanged(int)), this, SLOT(resizeGl()));
    resizeGl();

    QTimer* timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(updateScene()));
    timer->start(16);
}
Exemple #2
0
int pxMain(int argc, char* argv[])
{
  myWindow win;
  
  win.init(10, 64, 250, 250);
  win.setTitle("Simple OpenGL");
  initializeGl();

  win.setVisibility(true);
  
  win.setAnimationFPS(60);

  eventLoop.run();
  
  return 0;
}
	SceneManager::SceneManager() :
			sceneWidth(500),
			sceneHeight(500),
			fps(START_FPS),
			fpsForDisplay(START_FPS)
	{
		//initialize GL
		initializeGl();

		//initialize fps
		previousFps.fill(START_FPS);
        indexFps = previousFps.size();
		previousTime = std::chrono::high_resolution_clock::now();

		//renderer
		for (auto &activeRenderer : activeRenderers)
		{
			activeRenderer = nullptr;
		}
	}
bool AppImplMswRendererGl::initialize( HWND wnd, HDC dc, RendererRef sharedRenderer )
{
	mWnd = wnd;
	mDC = dc;

	RendererGl *sharedRendererGl = dynamic_cast<RendererGl*>( sharedRenderer.get() );
	HGLRC sharedRC = ( sharedRenderer ) ? sharedRendererGl->mImpl->mRC : NULL;

	if( ! initializeGl( wnd, dc, sharedRC, mRenderer->getOptions(), &mRC ) ) {
		return false;
	}

	gl::Environment::setCore();
	auto platformData = std::shared_ptr<gl::Context::PlatformData>( new gl::PlatformDataMsw( mRC, mDC ) );
	platformData->mDebug = mRenderer->getOptions().getDebug();
	platformData->mDebugLogSeverity = mRenderer->getOptions().getDebugLogSeverity();
	platformData->mDebugBreakSeverity = mRenderer->getOptions().getDebugBreakSeverity();
	platformData->mObjectTracking = mRenderer->getOptions().getObjectTracking();
	mCinderContext = gl::Context::createFromExisting( platformData );
	mCinderContext->makeCurrent();

	return true;
}
Exemple #5
0
int Game::run() {
  // Initialize
  if (!initializeGlfw()) {
    return 1;
  }
  if (GLEW_OK != initializeGlew()) {
    return 2;
  }
  initializeGl();
  tileManager_->initialize(currentPos_);
  options_ = tileManager_->getOptions();
  ImGui_ImplGlfwGL3_Init(window_, true);

  deltaTime_ = 0.0f; // Time between current and last frame
  lastFrame_ = 0.0f; // Time at last frame
  lastTime_ = 0.0f;  // Time since last fps-"second"
  frameCount_ = 0;

  // Game loop
  while (!glfwWindowShouldClose(window_)) {
    // Calculate deltatime of current frame
    GLfloat currentTime = glfwGetTime();
    deltaTime_ = currentTime - lastFrame_;
    lastFrame_ = currentTime;

    // Check for events
    glfwPollEvents();

    // GUI
    showGui();

    // Move
    do_movement(deltaTime_);

    // Get current camera position
    getCurrentPosition();

    // Clear color- and depth buffer
    glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Update and render tiles
    tileManager_->update(currentPos_);
    tileManager_->renderAll(deltaTime_, camera_.getViewMatrix());

    // Render GUI
    if (!guiClosed_) {
      // ignore wireframe setting for gui
      glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
      ImGui::Render();
      glPolygonMode(GL_FRONT_AND_BACK, fillmode_);
    }

    // Swap the screen buffers
    glfwSwapBuffers(window_);
  }

  // Clean up imgui
  ImGui_ImplGlfwGL3_Shutdown();

  // Clean up tiles
  tileManager_->cleanUp();

  // Terminate GLFW, clearing any resources allocated by GLFW.
  glfwDestroyWindow(window_);
  glfwTerminate();
  return 0;
}