zoukankan      html  css  js  c++  java
  • GL_UI

    #include <imgui.h>
    #include <imgui_impl_glfw_gl3.h>
    #include <glad/glad.h>
    #include <GLFW/glfw3.h>
    #include <cstdio>
    
    void ShowFPS()
    {
        ImGui::SetNextWindowSize(ImVec2(300, 30), ImGuiCond_Appearing);
        ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Appearing);
        ImGui::Begin("", 0,
            ImGuiWindowFlags_NoTitleBar |
            ImGuiWindowFlags_NoResize |
            ImGuiWindowFlags_NoMove);
        ImGui::Text("%.2f ms since last frame (%.1f FPS)",
            ImGui::GetIO().DeltaTime * 1000,
            ImGui::GetIO().Framerate);
        ImGui::End();
    }
    
    void IMGUI_InitialUI(GLFWwindow* window)
    {
        ImGui_ImplGlfwGL3_Init(window, true);
    
        ImGuiIO& io = ImGui::GetIO();
        io.Fonts->AddFontFromFileTTF("../res/font/arialunicodems.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesChinese());
    }
    
    void IMGUI_SetUI()
    {
        ImGui_ImplGlfwGL3_NewFrame();
        ShowFPS();
        ImGui::Button("This is a button.");
    }
    
    void IMGUI_RenderUI()
    {
        ImGui::Render();
    }
    
    void IMGUI_CleanUpUI()
    {
        ImGui_ImplGlfwGL3_Shutdown();
    }
    
    void error_callback(int error, const char* description);
    void framebuffer_size_callback(GLFWwindow* window, int width, int height);
    
    unsigned int WindowWidth = 800;
    unsigned int WindowHeight = 600;
    
    float deltaTime = 0.0f;    
    float lastFrame = 0.0f;
    
    int main()
    {
        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);
    
        GLFWwindow* window = glfwCreateWindow(1280, 720, "UI", NULL, NULL);
    
        glfwMakeContextCurrent(window);
    
        glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
    
        if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
            return -1;
    
        IMGUI_InitialUI(window);
    
        while (!glfwWindowShouldClose(window))
        {
            float currentFrame = glfwGetTime();
            deltaTime = currentFrame - lastFrame;
            lastFrame = currentFrame;
    
            glfwPollEvents();
    
            IMGUI_SetUI();
    
            glClearColor(0.09f, 0.07f, 0.04f, 1.0f);
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    
            IMGUI_RenderUI();
    
            glfwSwapBuffers(window);
        }
    
        IMGUI_CleanUpUI();
        glfwTerminate();
        return 0;
    }
    
    void error_callback(int error, const char* description)
    {
        fprintf(stderr, "Error %d: %s
    ", error, description);
    }
    
    void framebuffer_size_callback(GLFWwindow* window, int width, int height)
    {
        glViewport(0, 0, width, height);
        WindowWidth = width;
        WindowHeight = height;
    }
  • 相关阅读:
    会话状态服务器解决方法
    让笔记本在插上外置鼠标时触摸板自动关闭
    “检测到有潜在危险的 Request.Form(QueryString) 值”的解决方法
    SQL Server2008不能登录解决方法
    SqlHelper
    修改IE查看源代码编辑器
    由于启动用户实例的进程时出错,导致无法生成 SQL Server 的用户实例解决办法
    性能测试用户模型(二):用户模型图
    索引帖:性能测试新手误区系列
    性能测试用户模型(三):基础数据分析、场景数据
  • 原文地址:https://www.cnblogs.com/Searchor/p/8051935.html
Copyright © 2011-2022 走看看