void loop(GLFWwindow* window, const std::function<void(int, int, float&, void*)>& loop) {
    while (!glfwWindowShouldClose(window)) {
        window_context_t* context = (window_context_t*)glfwGetWindowUserPointer(window);
        glViewport(0, 0, context->texture_width, context->texture_height);

        ImGui_ImplGlfwGL3_NewFrame();

        glClearColor(0, 0, 0, 1);
        glClear(GL_COLOR_BUFFER_BIT);

        glBindBuffer(GL_PIXEL_UNPACK_BUFFER, context->pixel_buffer_id);
        void* pointer = glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);

        float scale = 0.0f;

        if (pointer) {
            loop(context->texture_width, context->texture_height, scale, pointer);
            glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
        }

        glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);

        draw_fullscreen_quad(window, std::vector<glm::vec4>(), scale);

        ImGui::Render();
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
}
示例#2
0
void GLApplication::Run()
{
	InitializeOpenGL();
	Initialize();
	Input::CreateSingleton();
	Gizmos::create();

	if (m_bDrawGUI)
	{
		ImGui_ImplGlfwGL3_Init(m_pWindow, true);
		ImGuiIO& io = ImGui::GetIO();
		io.DisplaySize.x = GetScreenWidth();
		io.DisplaySize.y = GetScreenHeight();
	}

	m_bRunning = true;
	while (!glfwWindowShouldClose(m_pWindow) && m_bRunning)
	{
		m_lastTime = m_currentTime;
		m_currentTime = (float)glfwGetTime();
		m_deltaTime = m_currentTime - m_lastTime;

		glClearColor(m_clearColour.r, m_clearColour.g, m_clearColour.b, 1);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glEnable(GL_CULL_FACE);
		glCullFace(GL_BACK);
		Gizmos::clear();

		if(m_bDrawGUI) ImGui_ImplGlfwGL3_NewFrame();

		Update(m_deltaTime);
		UpdateFPS(m_deltaTime);

		if (m_pCamera)
		{
			m_pCamera->Update(m_deltaTime);

			Render();

			Gizmos::draw(m_pCamera->GetProjectionView());

			if (m_bDrawGUI) ImGui::Render();

		}

		glfwSwapBuffers(m_pWindow);
		glfwPollEvents();
	}
	
	if (m_bDrawGUI)
	{
		ImGui_ImplGlfwGL3_Shutdown();
	}

	
	Gizmos::destroy();
	glfwDestroyWindow(m_pWindow);
	glfwTerminate();
}
示例#3
0
文件: main.cpp 项目: opensgct/sgct
void myDrawFun()
{
	glEnable( GL_DEPTH_TEST );
	glEnable( GL_CULL_FACE );
    gEngine->setClearColor(clear_color.x, clear_color.y, clear_color.z, 1.0f);

	//create scene transform (animation)
	glm::mat4 scene_mat = glm::translate( glm::mat4(1.0f), glm::vec3( 0.0f, 0.0f, -3.0f) );
	scene_mat = glm::rotate( scene_mat, static_cast<float>( curr_time.getVal() * speed ), glm::vec3(0.0f, -1.0f, 0.0f));
	scene_mat = glm::rotate( scene_mat, static_cast<float>( curr_time.getVal() * (speed/2.0) ), glm::vec3(1.0f, 0.0f, 0.0f));

	glm::mat4 MVP = gEngine->getCurrentModelViewProjectionMatrix() * scene_mat;

	glActiveTexture(GL_TEXTURE0);
    glBindTexture( GL_TEXTURE_2D, (use_texture ? sgct::TextureManager::instance()->getTextureId("box") : NULL));

	sgct::ShaderManager::instance()->bindShaderProgram( "xform" );

	glUniformMatrix4fv(Matrix_Loc, 1, GL_FALSE, &MVP[0][0]);

	//draw the box
	myBox->draw();

	sgct::ShaderManager::instance()->unBindShaderProgram();

	glDisable( GL_CULL_FACE );
	glDisable( GL_DEPTH_TEST );
    
    if( gEngine->isMaster() )
    {
		ImGui_ImplGlfwGL3_NewFrame(gEngine->getCurrentWindowPtr()->getXFramebufferResolution(), gEngine->getCurrentWindowPtr()->getYFramebufferResolution());

        // Show a settings window custom made for this application
        // Toggle this windows with the 'W' key.
        if(show_settings_window)
        {
            ImGui::SetNextWindowSize(ImVec2(300, 200), ImGuiSetCond_FirstUseEver);
            ImGui::Begin("Settings");
            ImGui::SliderFloat("Rotation Speed", &(speed), 0.0f, 1.0f);
            ImGui::Checkbox("Texture On/Off", &use_texture);
            ImGui::ColorEdit3("Clear Color", (float*)&clear_color);
            if (ImGui::Button("Toggle Test Window")) show_test_window ^= 1;
            ImGui::End();
        }
        
        // Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
        if (show_test_window)
        {
            ImGui::SetNextWindowPos(ImVec2(100, 20), ImGuiSetCond_FirstUseEver);
            ImGui::ShowTestWindow(&show_test_window);
        }
        
        ImGui::Render();
    }
}
示例#4
0
void GLFWOSPRayWindow::mainLoop()
{
  // continue until the user closes the window
  while (!glfwWindowShouldClose(glfwWindow)) {
    ImGui_ImplGlfwGL3_NewFrame();

    display();

    // poll and process events
    glfwPollEvents();
  }
}
示例#5
0
int main(int, char**)
{
    // Setup window
    glfwSetErrorCallback(error_callback);
    if (!glfwInit())
        exit(1);

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    GLFWwindow* window = glfwCreateWindow(1280, 720, "Empty imgui program", NULL, NULL);
    glfwMakeContextCurrent(window);
    
    gl3wInit();

    // Setup ImGui binding
    ImGui_ImplGlfwGL3_Init(window, true);

    ImVec4 clear_color = ImColor(114, 144, 154);
    
    // Main loop
    while (!glfwWindowShouldClose(window))
    {
        
        ImGuiIO& io = ImGui::GetIO();
       
        glfwPollEvents();
       
        ImGui_ImplGlfwGL3_NewFrame();

        make_gui();

        // Rendering
        glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
        
        glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        ImGui::Render();
        
        glfwSwapBuffers(window);
        
    }

    // Cleanup
    ImGui_ImplGlfwGL3_Shutdown();
    glfwTerminate();

    return 0;
}
示例#6
0
void Window::run()
{
   if(currentScene != nullptr)
   {
      currentScene->initPrograms();
      currentScene->compilePrograms();
      if(currentScene->canRenderScene())
      {
         currentScene->initialBind();
         //currentScene->initGlobalUniforms();
      }
      //While not esc pressed
      while(!glfwWindowShouldClose(currentWindow))
      {
         ImGui_ImplGlfwGL3_NewFrame();
       
         //Check for any file changes
         FileSystem::ReloadLocator::getService()->processEvents();

         //Poll and update any callbacks
         glfwPollEvents();
         //Update the input handler
         GLFWHandler::update();

         if(currentScene->shouldReloadScene())
         {
            if(currentScene->compilePrograms())
            {
               currentScene->initialBind();
               //currentScene->initGlobalUniforms();
            }
         }
         if(currentScene->canRenderScene())
         {
            //currentScene->updateGlobalUniforms();
            currentScene->update();
            currentScene->render();
         }
         //ImGui::ShowTestWindow();
         ImGui::Render();
         glfwSwapBuffers(currentWindow);
      }
   }
   else
   {
      LOG(ERROR) << "No scene loaded in window, exiting...";
   }

}
示例#7
0
MainWindow::MainWindow() {
    // Setup window
    glfwSetErrorCallback(on_error);
    if (!glfwInit())
        exit(1);

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    GLFWwindow* window = glfwCreateWindow(1280, 720, "xds", NULL, NULL);

	if (window)
	{

		glfwMakeContextCurrent(window);
		gl3wInit();

		ImGui_ImplGlfwGL3_Init(window, true);


		while (!glfwWindowShouldClose(window))
		{
			ImGuiIO& io = ImGui::GetIO();
			glfwPollEvents();
			ImGui_ImplGlfwGL3_NewFrame();

			ImGui::SetNextWindowSize(ImVec2(400, 100), ImGuiSetCond_FirstUseEver);
			ImGui::Begin("Test Window");
			ImGui::Text("TODO: Move this to new thread so xds can run in the background.");
			ImGui::Text("Close the window to continue xds execution.");
			ImGui::End();

			// Rendering
			glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
			ImVec4 clear_color = ImColor(114, 144, 154);
			glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
			glClear(GL_COLOR_BUFFER_BIT);
			ImGui::Render();

			glfwSwapBuffers(window);
		}

		// Cleanup
		ImGui_ImplGlfwGL3_Shutdown();
		glfwTerminate();

	}
}
示例#8
0
		void DebugLayer::update(GLfloat delta)
		{
			if (m_visible)
			{
				ImGui_ImplGlfwGL3_NewFrame();

				GLfloat framerate = ImGui::GetIO().Framerate;

				ImGui::Begin("Debug Menu", &m_visible);
				ImGui::Text("Application average: %.3f ms/frame (%.1f FPS)", 1000.0f / framerate, framerate);
				if (ImGui::Button("Reload shaders"))
					graphics::reloadShaders();
				ImGui::End();
			}
		}
        void Subsystem::Update()
        {
            bool show_test_window = true;
            // bool show_another_window = false;
            ImGui_ImplGlfwGL3_NewFrame();

            Support::Allocator* alloc = Support::Globals::Instance()->Allocator;
             // Memory
            ImGui::Text("Memory: %i bytes / %i bytes (%i)", alloc->GetUsedMemory(), alloc->GetSize(), alloc->GetAllocationCount() );

            // FPS
            ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);

            if(mUICallback != nullptr)
                (*mUICallback)(mMetadata);


            // Show Widgets

            // 1. Show a simple window
            // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"

            // // 2. Show another simple window, this time using an explicit Begin/End pair
            // if (show_another_window)
            // {
            //     ImGui::SetNextWindowSize(ImVec2(200,100), ImGuiSetCond_FirstUseEver);
            //     ImGui::Begin("Another Window", &show_another_window);
            //     ImGui::Text("Hello");
            //     ImGui::End();
            // }

            // // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
            // if (show_test_window)
            // {
            //     ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver);
            // ImGui::ShowTestWindow(&show_test_window);
            // }
            ImGui::Render();

        }
示例#10
0
文件: main.cpp 项目: heroboy/imgui
int main(int, char**)
{
    // Setup window
    glfwSetErrorCallback(error_callback);
    if (!glfwInit())
        exit(1);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui OpenGL3 example", NULL, NULL);
    glfwMakeContextCurrent(window);
    gl3wInit();

    // Setup ImGui binding
    ImGui_ImplGlfwGL3_Init(window, true);
    //ImGuiIO& io = ImGui::GetIO();
    //ImFont* my_font0 = io.Fonts->AddFontDefault();
    //ImFont* my_font1 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
    //ImFont* my_font2 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/Karla-Regular.ttf", 16.0f);
    //ImFont* my_font3 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f); my_font3->DisplayOffset.y += 1;
    //ImFont* my_font4 = io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); my_font4->DisplayOffset.y += 1;
    //ImFont* my_font5 = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, io.Fonts->GetGlyphRangesJapanese());

    bool show_test_window = true;
    bool show_another_window = false;
    ImVec4 clear_color = ImColor(114, 144, 154);

    // Main loop
    while (!glfwWindowShouldClose(window))
    {
        ImGuiIO& io = ImGui::GetIO();
        glfwPollEvents();
        ImGui_ImplGlfwGL3_NewFrame();

        // 1. Show a simple window
        // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
        {
            static float f;
            ImGui::Text("Hello, world!");
            ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
            ImGui::ColorEdit3("clear color", (float*)&clear_color);
            if (ImGui::Button("Test Window")) show_test_window ^= 1;
            if (ImGui::Button("Another Window")) show_another_window ^= 1;
            ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
        }

        // 2. Show another simple window, this time using an explicit Begin/End pair
        if (show_another_window)
        {
            ImGui::SetNextWindowSize(ImVec2(200,100), ImGuiSetCond_FirstUseEver);
            ImGui::Begin("Another Window", &show_another_window);
            ImGui::Text("Hello");
            ImGui::End();
        }

        // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
        if (show_test_window)
        {
            ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver);
            ImGui::ShowTestWindow(&show_test_window);
        }
        
        // Rendering
        glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
        glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
        glClear(GL_COLOR_BUFFER_BIT);
        ImGui::Render();
        glfwSwapBuffers(window);
    }

    // Cleanup
    ImGui_ImplGlfwGL3_Shutdown();
    glfwTerminate();

    return 0;
}
示例#11
0
文件: main.cpp 项目: wose/Strixel
int main(int argc, char** argv)
{
    if(argc != 2) {
        std::cout << "Usage:\n\t" << argv[0] << " IMAGE" << std::endl;
        return 1;
    }
    // Setup window
    glfwSetErrorCallback(error_callback);
    if (!glfwInit())
        return 1;
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#if __APPLE__
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
    GLFWwindow* window = glfwCreateWindow(1280, 720, "HBVisionGraphEditor", NULL, NULL);
    glfwMakeContextCurrent(window);
    gl3wInit();

    // Setup ImGui binding
    ImGui_ImplGlfwGL3_Init(window, true);

    ImVec4 clear_color = ImColor(39, 40, 34);

    cv::Mat image = cv::imread(argv[1]);

    Solution solution(image);
    AlgSimple simple;
    Preview preview{solution};
    Preview preview2{solution};

    while (!glfwWindowShouldClose(window)) {
        if(!glfwGetWindowAttrib(window, GLFW_ICONIFIED) && glfwGetWindowAttrib(window, GLFW_VISIBLE)) {
            glfwPollEvents();
            ImGui_ImplGlfwGL3_NewFrame();

            // Settings
            ImGui::BeginMainMenuBar();
            int menuHeight = ImGui::GetTextLineHeightWithSpacing();
            if(ImGui::BeginMenu("File")) {
                if(ImGui::MenuItem("Quit")) {
                    glfwSetWindowShouldClose(window, GL_TRUE);
                }
                ImGui::EndMenu();
            }
            ImGui::EndMainMenuBar();

            bool open = false;
            ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0);
            ImGui::SetNextWindowPos(ImVec2(0, menuHeight));
            ImGui::SetNextWindowSize(ImVec2(400, ImGui::GetIO().DisplaySize.y - menuHeight));
            if (ImGui::Begin("###main", &open, ImVec2(0, 0), 0.5f,
                             ImGuiWindowFlags_NoTitleBar |
                             ImGuiWindowFlags_NoResize |
                             ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus |
                             ImGuiWindowFlags_NoSavedSettings))
            {
                if (ImGui::TreeNodeEx("Solution", ImGuiTreeNodeFlags_DefaultOpen)) {
                    solution.draw();
                    ImGui::TreePop();
                }
                if (ImGui::TreeNodeEx("Algorithm", ImGuiTreeNodeFlags_DefaultOpen)) {
                    static int currentAlgorithm = 0;
                    ImGui::Combo("###AlgorithmCombo", &currentAlgorithm, "simple\0empty\0\0");
                    simple.draw();
                    ImGui::TreePop();
                }
                ImGui::Spacing();
                ImGui::Separator();
                ImGui::Spacing();
                if (ImGui::Button("Calculate Pattern", ImVec2(ImGui::GetContentRegionAvailWidth(), 20))) {
                    simple.calculate(solution);
                }
            }
            ImGui::End();
            ImGui::PopStyleVar();

            // Preview
            preview.draw(solution);
            preview2.draw(solution);

            // Rendering
            int display_w, display_h;
            glfwGetFramebufferSize(window, &display_w, &display_h);
            glViewport(0, 0, display_w, display_h);
            glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
            glClear(GL_COLOR_BUFFER_BIT);
            ImGui::Render();
            glfwSwapBuffers(window);
        } else {
            glfwWaitEvents();
        }
    }

    // Cleanup
    ImGui_ImplGlfwGL3_Shutdown();
    glfwTerminate();

    return 0;
}
示例#12
0
int main(int argc, char** argv) {
  glfwSetErrorCallback(glfwError);

  if (!glfwInit()) return 1;

  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
  glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

  GLFWmonitor* monitor = glfwGetPrimaryMonitor();
  const GLFWvidmode* mode = glfwGetVideoMode(monitor);

  GLFWwindow* window =
      glfwCreateWindow(mode->width, mode->height, "HumanDetection", NULL, NULL);
  glfwMakeContextCurrent(window);
  glewExperimental = GL_TRUE;
  glewInit();

  fhd_context detector;
  fhd_context_init(&detector, 512, 424, 8, 8);

  ImGui_ImplGlfwGL3_Init(window, true);
  ImGui::GetStyle().WindowRounding = 0.f;
  bool show_window = true;

  fhd_ui ui(&detector);

  if (argc > 1) {
    const char* train_database = argv[1];
    ui.train_mode = true;
    fhd_candidate_db_init(&ui.candidate_db, train_database);
  }

  ImVec4 clear_color = ImColor(218, 223, 225);
  while (!glfwWindowShouldClose(window)) {
    glfwPollEvents();

    if (ImGui::IsKeyPressed(GLFW_KEY_ESCAPE)) break;

    if (ui.train_mode) {
      if (ImGui::IsKeyPressed(GLFW_KEY_X)) {
        fhd_ui_clear_candidate_selection(&ui);
        ui.depth_frame = ui.frame_source->get_frame();
      }

      if (ImGui::IsKeyPressed(GLFW_KEY_SPACE)) {
        fhd_ui_commit_candidates(&ui);
      }
    } else {
      if (ui.update_enabled) {
        ui.depth_frame = ui.frame_source->get_frame();
      }
    }

    if (ui.depth_frame) {
      auto t1 = std::chrono::high_resolution_clock::now();
      fhd_run_pass(&detector, ui.depth_frame);
      auto t2 = std::chrono::high_resolution_clock::now();
      auto duration =
          std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1);
      ui.detection_pass_time_ms = double(duration.count()) / 1000.0;
      fhd_ui_update(&ui, ui.depth_frame);
    }

    ImGui_ImplGlfwGL3_NewFrame();
    int display_w, display_h;
    glfwGetFramebufferSize(window, &display_w, &display_h);

    ImGui::SetNextWindowPos(ImVec2(0, 0));

    ImGuiWindowFlags flags = ImGuiWindowFlags_NoMove |
                             ImGuiWindowFlags_NoResize |
                             ImGuiWindowFlags_NoTitleBar;

    ImGui::Begin("foo", &show_window,
                 ImVec2(float(display_w), float(display_h)), -1.f, flags);

    ImGui::BeginChild("toolbar", ImVec2(300.f, float(display_h)));
    render_db_selection(&ui);
    render_classifier_selection(&ui);

    if (ui.train_mode) {
      ImGui::Text("*** TRAINING DB: %s ***", argv[1]);
    }

    ImGui::Text("detection pass time %.3f ms", ui.detection_pass_time_ms);
    ImGui::Text("frame source: %s", ui.database_name.c_str());
    ImGui::Text("frame %d/%d", ui.frame_source->current_frame(),
                ui.frame_source->total_frames());
    ImGui::Text("classifier: %s", ui.classifier_name.c_str());
    ImGui::Checkbox("update enabled", &ui.update_enabled);
    ImGui::SliderFloat("##det_thresh", &ui.detection_threshold, 0.f, 1.f,
                       "detection threshold %.3f");
    ImGui::InputFloat("seg k depth", &ui.fhd->depth_segmentation_threshold);
    ImGui::InputFloat("seg k normals", &ui.fhd->normal_segmentation_threshold);
    ImGui::SliderFloat("##min_reg_dim", &ui.fhd->min_region_size, 8.f, 100.f,
                       "min region dimension %.1f");
    ImGui::SliderFloat("##merge_dist_x", &ui.fhd->max_merge_distance, 0.1f, 2.f,
                       "max h merge dist (m) %.2f");
    ImGui::SliderFloat("##merge_dist_y", &ui.fhd->max_vertical_merge_distance,
                       0.1f, 3.f, "max v merge dist (m) %.2f");
    ImGui::SliderFloat("##min_inlier", &ui.fhd->min_inlier_fraction, 0.5f, 1.f,
                       "RANSAC min inlier ratio %.2f");
    ImGui::SliderFloat("##max_plane_dist", &ui.fhd->ransac_max_plane_distance,
                       0.01f, 1.f, "RANSAC max plane dist %.2f");
    ImGui::SliderFloat("##reg_height_min", &ui.fhd->min_region_height, 0.1f,
                       3.f, "min region height (m) %.2f");
    ImGui::SliderFloat("##reg_height_max", &ui.fhd->max_region_height, 0.1f,
                       3.f, "max region height (m) %.2f");
    ImGui::SliderFloat("##reg_width_min", &ui.fhd->min_region_width, 0.1f, 1.f,
                       "min region width (m) %.2f");
    ImGui::SliderFloat("##reg_width_max", &ui.fhd->max_region_height, 0.1f,
                       1.5f, "max region width (m) %.2f");
    ImGui::SliderInt("##min_depth_seg_size", &ui.fhd->min_depth_segment_size, 4,
                     200, "min depth seg size");
    ImGui::SliderInt("##min_normal_seg_size", &ui.fhd->min_normal_segment_size,
                     4, 200, "min normal seg size");
    ImGui::EndChild();

    ImGui::SameLine();

    ImGui::BeginGroup();

    ImDrawList* draw_list = ImGui::GetWindowDrawList();

    ImVec2 p = ImGui::GetCursorScreenPos();
    ImGui::Image((void*)intptr_t(ui.depth_texture.handle), ImVec2(512, 424));


    ImU32 rect_color = ImColor(240, 240, 20);
    for (int i = 0; i < detector.candidates_len; i++) {
      const fhd_candidate* candidate = &detector.candidates[i];
      if (candidate->weight >= 1.f) {
        const fhd_image_region region = candidate->depth_position;

        const float x = p.x + float(region.x);
        const float y = p.y + float(region.y);
        const float w = float(region.width);
        const float h = float(region.height);
        ImVec2 points[4] = {
          ImVec2(x, y),
          ImVec2(x + w, y),
          ImVec2(x + w, y + h),
          ImVec2(x, y + h)
        };
        draw_list->AddPolyline(points, 4, rect_color, true, 4.f, true);
      }
    }

    ImGui::BeginGroup();
    ImGui::Image((void*)intptr_t(ui.normals_texture.handle), ImVec2(256, 212));
    ImGui::SameLine();
    ImGui::Image((void*)intptr_t(ui.normals_seg_texture.handle),
                 ImVec2(256, 212));
    ImGui::EndGroup();

    ImGui::BeginGroup();
    ImGui::Image((void*)intptr_t(ui.downscaled_depth.handle), ImVec2(256, 212));
    ImGui::SameLine();
    ImGui::Image((void*)intptr_t(ui.depth_segmentation.handle),
                 ImVec2(256, 212));
    ImGui::EndGroup();

    ImGui::Image((void*)intptr_t(ui.filtered_regions.handle), ImVec2(256, 212));

    ImGui::EndGroup();

    ImGui::SameLine();

    ImGui::BeginGroup();

    if (ui.train_mode) {
      fhd_candidate_selection_grid(&ui, FHD_HOG_WIDTH * 2, FHD_HOG_HEIGHT * 2);
    } else {
      for (int i = 0; i < detector.candidates_len; i++) {
        fhd_texture* t = &ui.textures[i];
        ImGui::Image((void*)intptr_t(t->handle),
                     ImVec2(t->width * 2, t->height * 2));
        if (i % 7 < 6) ImGui::SameLine();
      }
    }

    ImGui::EndGroup();
    ImGui::End();

    glViewport(0, 0, display_w, display_h);
    glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
    glClear(GL_COLOR_BUFFER_BIT);

    ImGui::Render();
    glfwSwapBuffers(window);
  }

  if (ui.train_mode) {
    fhd_candidate_db_close(&ui.candidate_db);
  }

  fhd_texture_destroy(&ui.depth_texture);
  fhd_classifier_destroy(detector.classifier);
  ImGui_ImplGlfwGL3_Shutdown();
  glfwTerminate();

  return 0;
}
		void Window::clear() const
		{
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
			ImGui_ImplGlfwGL3_NewFrame();
		}
示例#14
0
int main()
{
	DEBUGLOG->setAutoPrint(true);

	//////////////////////////////////////////////////////////////////////////////
	/////////////////////// INIT //////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////

	// create window and opengl context
	auto window = generateWindow(800,800);

	//////////////////////////////////////////////////////////////////////////////
	/////////////////////////////// RENDERING  ///////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////
	
	/////////////////////     Scene / View Settings     //////////////////////////
	glm::mat4 model = glm::mat4(1.0f);
	glm::vec4 eye(0.0f, 0.0f, 3.0f, 1.0f);
	glm::vec4 center(0.0f,0.0f,0.0f,1.0f);
	glm::mat4 view = glm::lookAt(glm::vec3(eye), glm::vec3(center), glm::vec3(0,1,0));

	// glm::mat4 perspective = glm::ortho(-2.0f, 2.0f, -2.0f, 2.0f, -1.0f, 6.0f);
	/// perspective projection is experimental; yields weird warping effects due to vertex interpolation of uv-coordinates
	glm::mat4 perspective = glm::perspective(glm::radians(65.f), getRatio(window), 0.1f, 10.f);

	// create object
	// Sphere grid;
	Grid grid(10,10,0.1f,0.1f,true);
	// Volume grid;

	// load grass texture
	s_texHandle = TextureTools::loadTexture(RESOURCES_PATH +  std::string( "/grass.png"));
	glBindTexture(GL_TEXTURE_2D, s_texHandle);

	/////////////////////// 	Renderpass     ///////////////////////////
	DEBUGLOG->log("Shader Compilation: volume uvw coords"); DEBUGLOG->indent();
	ShaderProgram shaderProgram("/modelSpace/GBuffer.vert", "/modelSpace/GBuffer.frag"); DEBUGLOG->outdent();
	shaderProgram.update("model", model);
	shaderProgram.update("view", view);
	shaderProgram.update("projection", perspective);
	shaderProgram.update("color", glm::vec4(1.0f,0.0f,0.0f,1.0f));

	DEBUGLOG->log("FrameBufferObject Creation: volume uvw coords"); DEBUGLOG->indent();
	FrameBufferObject fbo(getResolution(window).x, getResolution(window).y);
	FrameBufferObject::s_internalFormat  = GL_RGBA32F; // to allow arbitrary values in G-Buffer
	fbo.addColorAttachments(4); DEBUGLOG->outdent();   // G-Buffer
	FrameBufferObject::s_internalFormat  = GL_RGBA;	   // restore default

	RenderPass renderPass(&shaderProgram, &fbo);
	renderPass.addEnable(GL_DEPTH_TEST);
	renderPass.addClearBit(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
	renderPass.addRenderable(&grid);

	ShaderProgram compShader("/screenSpace/fullscreen.vert", "/screenSpace/finalCompositing.frag");
	// ShaderProgram compShader("/screenSpace/fullscreen.vert", "/screenSpace/simpleAlphaTexture.frag");

	Quad quad;
	RenderPass compositing(&compShader, 0);
	compositing.addClearBit(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
	compositing.addRenderable(&quad);

	// Geometry test shader
	ShaderProgram geomShader("/modelSpace/geometry.vert", "/modelSpace/simpleLighting.frag", "/geometry/simpleGeom.geom");
	RenderPass geom(&geomShader, 0);
	geom.addClearBit(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
	geom.addRenderable(&grid);
	geom.addEnable(GL_DEPTH_TEST);
	geom.addEnable(GL_ALPHA_TEST);
	geom.addEnable(GL_BLEND);

	glAlphaFunc(GL_GREATER, 0);

	geomShader.update("projection", perspective);


	//////////////////////////////////////////////////////////////////////////////
	///////////////////////    GUI / USER INPUT   ////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////

	// Setup ImGui binding
    ImGui_ImplGlfwGL3_Init(window, true);

	Turntable turntable;
	double old_x;
    double old_y;
	glfwGetCursorPos(window, &old_x, &old_y);
	
	auto cursorPosCB = [&](double x, double y)
	{
		ImGuiIO& io = ImGui::GetIO();
		if ( io.WantCaptureMouse )
		{ return; } // ImGUI is handling this

		double d_x = x - old_x;
		double d_y = y - old_y;

		if ( turntable.getDragActive() )
		{
			turntable.dragBy(d_x, d_y, view);
		}

		old_x = x;
		old_y = y;
	};

	auto mouseButtonCB = [&](int b, int a, int m)
	{
		if (b == GLFW_MOUSE_BUTTON_LEFT && a == GLFW_PRESS)
		{
			turntable.setDragActive(true);
		}
		if (b == GLFW_MOUSE_BUTTON_LEFT && a == GLFW_RELEASE)
		{
			turntable.setDragActive(false);
		}

		ImGui_ImplGlfwGL3_MouseButtonCallback(window, b, a, m);
	};

	auto keyboardCB = [&](int k, int s, int a, int m)
	{
		if (a == GLFW_RELEASE) {return;} 
		switch (k)
		{
			case GLFW_KEY_W:
				eye += glm::inverse(view)    * glm::vec4(0.0f,0.0f,-0.1f,0.0f);
				center += glm::inverse(view) * glm::vec4(0.0f,0.0f,-0.1f,0.0f);
				break;
			case GLFW_KEY_A:
				eye += glm::inverse(view)	 * glm::vec4(-0.1f,0.0f,0.0f,0.0f);
				center += glm::inverse(view) * glm::vec4(-0.1f,0.0f,0.0f,0.0f);
				break;
			case GLFW_KEY_S:
				eye += glm::inverse(view)    * glm::vec4(0.0f,0.0f,0.1f,0.0f);
				center += glm::inverse(view) * glm::vec4(0.0f,0.0f,0.1f,0.0f);
				break;
			case GLFW_KEY_D:
				eye += glm::inverse(view)    * glm::vec4(0.1f,0.0f,0.0f,0.0f);
				center += glm::inverse(view) * glm::vec4(0.1f,0.0f,0.0f,0.0f);
				break;
			default:
				break;
		}
		ImGui_ImplGlfwGL3_KeyCallback(window,k,s,a,m);
	};

	setCursorPosCallback(window, cursorPosCB);
	setMouseButtonCallback(window, mouseButtonCB);
	setKeyCallback(window, keyboardCB);

	//////////////////////////////////////////////////////////////////////////////
	//////////////////////////////// RENDER LOOP /////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////

	double elapsedTime = 0.0;
	render(window, [&](double dt)
	{
		elapsedTime += dt;
		std::string window_header = "Volume Renderer - " + std::to_string( 1.0 / dt ) + " FPS";
		glfwSetWindowTitle(window, window_header.c_str() );

		////////////////////////////////     GUI      ////////////////////////////////
        ImGuiIO& io = ImGui::GetIO();
		ImGui_ImplGlfwGL3_NewFrame(); // tell ImGui a new frame is being rendered
		
		ImGui::PushItemWidth(-100);
		if (ImGui::CollapsingHeader("Geometry Shader Settings"))
    	{
    		ImGui::ColorEdit4( "color", glm::value_ptr( s_color)); // color mixed at max distance
	        ImGui::SliderFloat("strength", &s_strength, 0.0f, 2.0f); // influence of color shift
        }
        
		ImGui::Checkbox("auto-rotate", &s_isRotating); // enable/disable rotating volume
		ImGui::PopItemWidth();
        //////////////////////////////////////////////////////////////////////////////

		///////////////////////////// MATRIX UPDATING ///////////////////////////////
		if (s_isRotating) // update view matrix
		{
			model = glm::rotate(glm::mat4(1.0f), (float) dt, glm::vec3(0.0f, 1.0f, 0.0f) ) * model;
		}

		view = glm::lookAt(glm::vec3(eye), glm::vec3(center), glm::vec3(0.0f, 1.0f, 0.0f));
		//////////////////////////////////////////////////////////////////////////////
				
		////////////////////////  SHADER / UNIFORM UPDATING //////////////////////////
		// update view related uniforms
		shaderProgram.update(   "view", view);
		shaderProgram.update(   "model", turntable.getRotationMatrix() * model);

		geomShader.update(   "view", view);
		geomShader.update(   "model", turntable.getRotationMatrix() * model);
		compShader.update(   "vLightPos", view * turntable.getRotationMatrix() * s_lightPos);

		updateVectorTexture(elapsedTime);

		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, s_vectorTexture);

	//	glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); // this is altered by ImGui::Render(), so reset it every frame
		glActiveTexture(GL_TEXTURE1);
		glBindTexture(GL_TEXTURE_2D, s_texHandle);
		geomShader.update("tex", 1);
		geomShader.update("blendColor", 2.0);
		geomShader.update("color", s_color);
		geomShader.update("strength", s_strength);
		//////////////////////////////////////////////////////////////////////////////
		
		////////////////////////////////  RENDERING //// /////////////////////////////
		// glActiveTexture(GL_TEXTURE0);
		// glBindTexture(GL_TEXTURE_2D, fbo.getColorAttachmentTextureHandle(GL_COLOR_ATTACHMENT0)); // color
		// glActiveTexture(GL_TEXTURE1);
		// glBindTexture(GL_TEXTURE_2D, fbo.getColorAttachmeHntTextureHandle(GL_COLOR_ATTACHMENT1)); // normal
		// glActiveTexture(GL_TEXTURE2);
		// glBindTexture(GL_TEXTURE_2D, fbo.getColorAttachmentTextureHandle(GL_COLOR_ATTACHMENT2)); // position
		// glActiveTexture(GL_TEXTURE0);

		// compShader.update("colorMap",    0);
		// compShader.update("normalMap",   1);
		// compShader.update("positionMap", 2);

		// renderPass.render();
		// compositing.render();

		geom.render();

		ImGui::Render();
		glDisable(GL_BLEND);
		glBlendFunc(GL_ONE, GL_ZERO); // this is altered by ImGui::Render(), so reset it every frame
		//////////////////////////////////////////////////////////////////////////////

	});

	destroyWindow(window);

	return 0;
}
示例#15
0
文件: Main.cpp 项目: hmkum/HMKEngine
int main()
{
	hmk::Logger::get_instance().initialize("engine.txt");
	if (glfwInit() == GL_FALSE)
	{
		HMK_LOG_ERROR("failed glfwInit")
		hmk::Logger::get_instance().shutdown();
		return -1;
	}

	glfwSetErrorCallback(ErrorCallback);

	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
	glfwWindowHint(GLFW_SAMPLES, 8);

	GLFWwindow* window = glfwCreateWindow(800, 600, "HMK", nullptr, nullptr);
	if (window == nullptr)
	{
		HMK_LOG_ERROR("failed glfwCreateWindow")
		hmk::Logger::get_instance().shutdown();
		glfwTerminate();
		return -1;
	}
	glfwSetWindowPos(window, 500, 30);
	glfwMakeContextCurrent(window);

	if (gl3wInit() == -1) // 0 success
	{
		HMK_LOG_ERROR("failed gl3wInit")
		hmk::Logger::get_instance().shutdown();
		glfwTerminate();
		return -1;
	}

	if (!gl3wIsSupported(3, 3))
	{
		HMK_LOG_ERROR("Upgrade your graphic card!")
		hmk::Logger::get_instance().shutdown();
		glfwTerminate();
		return -1;
	}

#if _DEBUG
	if (glDebugMessageCallback)
	{
		glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
		glDebugMessageCallback(glErrorCallback, nullptr);
		GLuint unused = 0;
		glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, &unused, true);
	}
#endif

	ImGui_ImplGlfwGL3_Init(window, false);

	Game *game = new Game();
	game->initialize();

	glfwSetKeyCallback(window, KeyCallback);
	glfwSetCursorPosCallback(window, CursorPosCallback);
	glfwSetMouseButtonCallback(window, MouseButtonCallback);
	glfwSetDropCallback(window, DropCallback);

	keyCallback = HMK_CALLBACK_4(Game::key_input, game);
	cursorPosCallback = HMK_CALLBACK_2(Game::cursor_pos_input, game);
	mouseButtonCallback = HMK_CALLBACK_3(Game::mouse_button_input, game);
	dropCallback = HMK_CALLBACK_2(Game::drop_files_callback, game);

	double lastTime = glfwGetTime();

	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_TRUE);
	glDepthFunc(GL_LEQUAL);
	glDepthRange(0.0f, 1.0f);
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glFrontFace(GL_CW);
	glEnable(GL_FRAMEBUFFER_SRGB);
	glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); // https://www.opengl.org/wiki/Cubemap_Texture#Seamless_cubemap
	glEnable(GL_MULTISAMPLE);
	glClearColor(0.2f, 0.3f, 0.2f, 1.0f);

	double fps = 0.0;
	double acc = 0.0;
	while (!glfwWindowShouldClose(window))
	{
		glfwPollEvents();
		ImGui_ImplGlfwGL3_NewFrame();

		double now = glfwGetTime();
		double delta = now - lastTime;
		lastTime = now;

		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		game->update((float)delta);
		game->render();

		fps++;
		acc += delta;
		if (acc > 1.0)
		{
			acc = 0.0;
			fps = 0.0;
		}

		ImGui::Render();
		glfwSwapBuffers(window);
	}

	delete game;
	hmk::Logger::get_instance().shutdown();
	glfwDestroyWindow(window);
	ImGui_ImplGlfwGL3_Shutdown();
	glfwTerminate();
	return 0;
}
示例#16
0
void ImGui_ImplGlfwGL3_NewFrame()
{
	int fboW, fboH;
	glfwGetFramebufferSize(g_Window, &fboW, &fboH);
	ImGui_ImplGlfwGL3_NewFrame(fboW, fboH);
}
示例#17
0
文件: game.cpp 项目: sgelb/litlanes
void Game::showGui() {
  static int algorithm = Defaults::Perlin;

  if (guiClosed_) {
    return;
  }

  ImGui_ImplGlfwGL3_NewFrame();
  ImGui::BeginPopup(&guiClosed_);

  // Style. No rounded corners
  ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);

  // Position. TopLeft
  ImGui::SetWindowPos(ImVec2(0, 0), ImGuiSetCond_FirstUseEver);

  // Show FPS
  ImGui::Text("Avg %.3f ms/frame (%.1f FPS)",
              1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);

  // Show current tile
  int xTile = std::floor(currentPos_.x / Defaults::TileWidth);
  int zTile = std::floor(currentPos_.z / Defaults::TileWidth);
  ImGui::Text("Current tile: %i,%i", xTile, zTile);

  // Keys
  if (ImGui::CollapsingHeader("Keys")) {
    ImGui::BulletText("Hold left mouse button to look around");
    ImGui::BulletText("Move with <A>, <S>, <D>, <W>, <E> and <Q>");
    ImGui::BulletText("Toggle wireframe with <X>");
    ImGui::BulletText("Toggle this menu with <TAB>");
  }

  if (ImGui::CollapsingHeader("Map Options")) {
    bool showSea = tileManager_->getShowSea();
    float seaLevel = tileManager_->getSeaLevel();

    if (ImGui::Checkbox("Show sea", &showSea)) {
      tileManager_->setShowSea(showSea);
    }

    if (showSea) {
      if (ImGui::SliderFloat("Sea level", &seaLevel, 0,
                             Defaults::MaxMeshHeight)) {
        tileManager_->setSeaLevel(seaLevel);
      }
    }
  }

  // Algorithm
  if (ImGui::CollapsingHeader("Algorithms")) {

    // This code to test if an option is set is not very readable, but i like
    // it. | is the bitwise OR-operator. It returns true if at least one of the
    // two compared bits is true. ImGui::RadioButton returns true if pressed.
    // If this happens just once, btnPressed stays true, no matter the
    // following results.

    bool btnPressed = false;
    btnPressed |= (ImGui::RadioButton("Perlin Noise / fBm", &algorithm,
                                      Defaults::Perlin));
    btnPressed |= (ImGui::RadioButton("Ridged-Multifractal Noise", &algorithm,
                                      Defaults::RidgedMulti));
    btnPressed |=
        (ImGui::RadioButton("Billow Noise", &algorithm, Defaults::Billow));
    btnPressed |=
        (ImGui::RadioButton("Random Noise", &algorithm, Defaults::Random));

    if (btnPressed) {
      tileManager_->setTileAlgorithm(algorithm);
      options_ = tileManager_->getOptions();
    }

    // Algorithm Options
    bool optsChanged = false;

    // TODO: better handling of available options for different algorithms
    if (algorithm != Defaults::Random) {
      optsChanged |= (ImGui::InputInt("Seed", &options_.seed, 1));
      optsChanged |=
          (ImGui::SliderFloat("Frequency", &options_.frequency, 1, 6));
      optsChanged |=
          (ImGui::SliderFloat("Lacunarity", &options_.lacunarity, 0, 4));
      optsChanged |= (ImGui::SliderInt("Octaves", &options_.octaveCount, 1, 6));

      if (algorithm != Defaults::RidgedMulti) {
        optsChanged |=
            (ImGui::SliderFloat("Persistence", &options_.persistence, 0, 1));
      }
    }

    if (optsChanged) {
      tileManager_->setTileAlgorithmOptions(options_);
    }
  }

  ImGui::EndPopup();
}
示例#18
0
文件: Gui.cpp 项目: cyrilcode/cyfw
 void Gui::clear() {
     ImGui_ImplGlfwGL3_NewFrame();
 }
示例#19
0
void GUI::NewFrame(){
    ImGui_ImplGlfwGL3_NewFrame();
}
示例#20
0
文件: main.cpp 项目: kevyuu/falton
int main(int, char**){

    const double FRAME_INTERVAL = 1.0 / 60.0;

    // Setup window
    glfwSetErrorCallback(error_callback);
    if (!glfwInit())
        return 1;
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#if __APPLE__
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
    GLFWwindow* window = glfwCreateWindow(1280, 720, "Falton Debug Visualizer", NULL, NULL);
    glfwMakeContextCurrent(window);
    gl3wInit();

    // Setup ImGui binding
    ImGui_ImplGlfwGL3_Init(window, true);

    ImVec4 clear_color = ImColor(0, 0, 0);

    Phyvis::Context ctx;
    Phyvis::Init(&ctx);

    double prevTime = glfwGetTime();
    double lag = 0.0f;

    // Main loop
    while (!glfwWindowShouldClose(window))
    {
        double time0 = glfwGetTime();
        double delta = time0- prevTime;
        lag += delta;
        prevTime = time0;

        while (lag >= FRAME_INTERVAL) {
            glfwPollEvents();
            ImGui_ImplGlfwGL3_NewFrame();
            
            // Rendering
            int display_w, display_h;
            glfwGetFramebufferSize(window, &display_w, &display_h);
            glViewport(0, 0, display_w, display_h);
            glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

            Phyvis::Tick(&ctx, display_w, display_h);
            ImGui::Render();
            
            glfwSwapBuffers(window);
            lag -= FRAME_INTERVAL;
        }
    }

    Phyvis::Cleanup(&ctx);

    // Cleanup
    ImGui_ImplGlfwGL3_Shutdown();
    glfwTerminate();

    return 0;
}
示例#21
0
//Main Thread
int main(int argc, char** argv)
{
	InitalizeEngine();
	InitalizeNetwork();
	window = new FireCore::Graphics::Window("Graphics Context -FireCore <Opengl 4.5>", 800, 800);

	memoryManager = new FireCore::Managers::MemoryManager();
	fileManager = new FireCore::Managers::FileManager(memoryManager);
	renderer = new FireCore::Managers::Renderer(window);
	sceneManager = new FireCore::Managers::SceneManager(fileManager, renderer,window);

	/// Load Scenes
	sceneManager->AddScene(new FireCore::World::Debug());
	sceneManager->AddScene(new FireCore::World::LoginScreen());
	sceneManager->AddScene(new FireCore::World::Game());
	sceneManager->AddScene(new FireCore::World::Graph());
	sceneManager->Initialise();

	//Threads and loops
#if defined DEBUG
	CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)AdminScene, NULL, NULL, NULL);
#endif
	CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)MessageThread, NULL, NULL, NULL);

	double lastTime = 0;
	ImGui_ImplGlfwGL3_Init(window->getWindow(), true);
	while (true)
	{ 
		double currentTime = glfwGetTime();
		double deltaTime = float(currentTime - lastTime);
		window->Clear();
		sceneManager->Update(deltaTime);
		ImGui_ImplGlfwGL3_NewFrame();
		if (ImGui::BeginMainMenuBar())
		{
			if (ImGui::BeginMenu("Levels"))
			{
				if (ImGui::MenuItem("Forest", "Index : 0 ")) { sceneManager->ChangeLevel(0); }
				ImGui::Separator();
				if (ImGui::MenuItem("Login Screen", "Index : 1 ")) { sceneManager->ChangeLevel(1); }
				ImGui::Separator();
				if (ImGui::MenuItem("Quarry", "Index : 2 ")) { sceneManager->ChangeLevel(2); }
				ImGui::Separator();
				if (ImGui::MenuItem("Graph Example", "Index : 3 ")) { sceneManager->ChangeLevel(3); }
				ImGui::Separator();
				if (ImGui::MenuItem("Exit", "")) { exit(1); }
				ImGui::EndMenu();
			}
			if (ImGui::BeginMenu("Edit"))
			{
				if (ImGui::MenuItem("Edit Object..", NULL, &Edit_Mode))
				{
					if (Edit_Mode){
						EditorWindow(&Edit_Mode, renderer->GetSelectedObject());
					}
				}
				ImGui::Separator();
				if (ImGui::MenuItem("Save..."))
				{
					std::cout << "Saving file not yet implimented noob..." << std::endl;
				}
				ImGui::EndMenu();
			}
			if (ImGui::BeginMenu("Chat"))
			{
				if (ImGui::MenuItem("Chat Console", NULL, &Chat_Enabled))
				{ 
					if (Chat_Enabled){
						NetworkChat(&Chat_Enabled);
					}
				}
				ImGui::EndMenu();
			}
			if (ImGui::BeginMenu("Debug"))
			{
				if (ImGui::MenuItem("Colliders", NULL, &Collider_Debug)){
					renderer->SetDebug(Collider_Debug);
				}
				ImGui::Separator();
				if (ImGui::MenuItem("Camera -> Tracked", NULL, &Camera_TRACKED)){
					Camera_FPS = false;
					Camera_FIXED = false;
					renderer->GetCamera()->SetType(FireCore::Graphics::CameraType::Tracked);
				}
				if (ImGui::MenuItem("Camera -> FPS", NULL, &Camera_FPS)){
					Camera_TRACKED = false;
					Camera_FIXED = false;
					renderer->GetCamera()->SetType(FireCore::Graphics::CameraType::FPS);
				}
				if (ImGui::MenuItem("Camera -> Fixed", NULL, &Camera_FIXED)){
					Camera_FPS = false;
					Camera_TRACKED = false;
					renderer->GetCamera()->SetType(FireCore::Graphics::CameraType::Fixed);
				}
				ImGui::EndMenu();
			}
			ImGui::EndMainMenuBar();
		}
		if (Chat_Enabled){
			NetworkChat(&Chat_Enabled);
		}
		if (Edit_Mode){
			EditorWindow(&Edit_Mode,renderer->GetSelectedObject());
		}		
		ImGui::Render();
		window->Update();
		lastTime = currentTime;
	}
	return 0;
}
示例#22
0
void GUI::BeginRender()
{
	ImGui_ImplGlfwGL3_NewFrame();
}