zoukankan      html  css  js  c++  java
  • Base Env

    #include <imgui.h>
    #include <imgui_impl_glfw_gl3.h>
    #include <cstdio>
    #include <cmath>
    #include <glad/glad.h>
    #include <GLFW/glfw3.h>
    
    static 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);
    }
    
    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)
    {
        // Setup ImGui binding
        ImGui_ImplGlfwGL3_Init(window, true);
    
        // Load Fonts
        ImGuiIO& io = ImGui::GetIO();
        io.Fonts->AddFontFromFileTTF("../res/font/arialunicodems.ttf", 18.0f,NULL,io.Fonts->GetGlyphRangesChinese());
    }
    
    void IMGUI_SetUI()
    {
        ImGui_ImplGlfwGL3_NewFrame();
        ShowFPS();
    }
    
    void IMGUI_RenderUI()
    {
        ImGui::Render();
    }
    
    void IMGUI_CleanUpUI()
    {
        ImGui_ImplGlfwGL3_Shutdown();
    }
    
    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, "GL March", NULL, NULL);
    
        glfwMakeContextCurrent(window);
        glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
    
        //glfwSwapInterval(1); // Enable vsync
    
        if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
            return -1;
    
        IMGUI_InitialUI(window);
    
        double PreviousTime = 0.0;
        double CurrentTime = 0.0;
        double DeltaTime = 0.0;
    
        while (!glfwWindowShouldClose(window))
        {
            glfwPollEvents();
            IMGUI_SetUI();
            PreviousTime = CurrentTime;
            CurrentTime = glfwGetTime();
            DeltaTime = CurrentTime - PreviousTime;
            
            glClearColor(sin(CurrentTime),cos(tan(PreviousTime)), sin(tan(CurrentTime)), 1);
    
            glClear(GL_COLOR_BUFFER_BIT);
    
            IMGUI_RenderUI();
            glfwSwapBuffers(window);
        }
    
        IMGUI_CleanUpUI();
        glfwTerminate();
        return 0;
    }

  • 相关阅读:
    Mongoexport导出数据,Mongoimport导入数据,mongodump备份数据,mongorestore恢复恢复
    php7中使用mongodb的驱动
    windows(X64)+apche2.4+php7.2下安装mongodb
    windows(X64)下安装apche2.4+php7.2+mysql5.7
    Django2.0 path与Django1.x版本url正则匹配问题
    Django: ImportError: No module named 'corsheaders'
    linux开启端口
    MySQL 存储过程传参数实现where id in(1,2,3,...)示例
    ubuntu安装pip3
    在Ubuntu 16.04 安装python3.6 环境并设置为默认
  • 原文地址:https://www.cnblogs.com/Searchor/p/7766073.html
Copyright © 2011-2022 走看看