• 【10】使用Test类测试&ImGUI


    看看效果
    在这里插入图片描述
    点击测试按钮
    在这里插入图片描述
    另一个是测试颜色的。

    看看主要代码:

    #include 
    #include  
    
    #include  
    #include 
    #include 
    #include 
    
    #include "Renderer.h"
    
    #include "VertexBuffer.h"
    #include "VertexBufferLayout.h"
    #include "IndexBuffer.h"
    #include "VertexArray.h"
    #include "Shader.h"
    #include "Texture.h"
     
    #include "glm/glm.hpp"
    #include "glm/gtc/matrix_transform.hpp"
    
    #include "imgui/imgui.h"
    #include "imgui/imgui_impl_glfw.h"
    #include 
    
    #include "test/TestClearColor.h"
    #include "test/TestTexture2D.h"
    int main(void)
    {
        GLFWwindow* window;
    
        /* Initialize the library */
        if (!glfwInit())
            return -1; 
    
        /* Create a windowed mode window and its OpenGL context */
        window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
        if (!window)
        {
            glfwTerminate();
            return -1;
        }
    
        /* Make the window's context current */
        glfwMakeContextCurrent(window);
    
        glfwSwapInterval(5); // 屏幕刷新率?
    
        if (glewInit() != GLEW_OK)/*这里就不会报错了*/
            std::cout << "ERROR!-2" << std::endl;
    
        std::cout << glGetString(GL_VERSION) << std::endl;
         
        /*什么作用来着?*/
        GLCall(GL_BLEND);
        GLCall(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
        
        Renderer renderer;
         
        ImGui::CreateContext();
    
        ImGuiIO& io = ImGui::GetIO(); (void)io;
        io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;     // Enable Keyboard Controls
        io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;      // Enable Gamepad Controls
        const char* glsl_version = "#version 130";
    
        ImGui_ImplGlfw_InitForOpenGL(window, true); 
        ImGui_ImplOpenGL3_Init(glsl_version);
        ImGui::StyleColorsDark();
    
        test::Test* currentTest = nullptr;
        test::TestMenu* testMenu = new test::TestMenu(currentTest);
        currentTest = testMenu;
    
        testMenu->RegisterTest<test::TestClearColor>("Clear Color");
        testMenu->RegisterTest<test::TestTexture2D>("TexTexture 2D");
       
        while (!glfwWindowShouldClose(window))
        { 
            GLCall(glClearColor(0.0f, 0.0f, 0.0f, 1.0f));
            renderer.Clear();
             
    
            ImGui_ImplOpenGL3_NewFrame();
            ImGui_ImplGlfw_NewFrame();  
            ImGui::NewFrame();
            if (currentTest)
            {
                currentTest->OnUpdate(0.0f);
                currentTest->OnRender();
                ImGui::Begin("Test");
                /*如果currenTest!=testMenu那么就会初始化burron,如果是,不会判断&&后面*/
                if (currentTest != testMenu && ImGui::Button("-<"))
                {
                    delete currentTest;
                    currentTest = testMenu;
                }
                currentTest->OnImGuiRender();
                ImGui::End();
            }
            
            ImGui::Render(); 
            ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
    
            /* Swap front and back buffers */
            glfwSwapBuffers(window);
    
            /* Poll for and process events */
            glfwPollEvents();
        } 
        delete currentTest;
        if (currentTest != testMenu)
            delete testMenu;
    
        ImGui_ImplGlfw_Shutdown();
        ImGui::DestroyContext();
        glfwTerminate();
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118

    主要是将前面的纹理代码抽象为Test类,源码见:github-TextureTest&ImGUI_openGL

  • 相关阅读:
    CSS通用样式3——表格
    微服务架构的现状与未来:服务网格与云原生趋势解析
    Arduino基础知识
    选择最适合您的Bug管理软件:市场比较与推荐
    基于Java+SpringBoot+Vue的大学生线上心理咨询系统(可随意更改项目主题如医院预约、店铺预约、专家挂号、在线咨询等)
    记录安装Cytoscape的过程
    ClickHouse与Elasticsearch压测实践
    来聊一聊std::function和lambda性能效率问题
    基于51单片机智能IC卡燃气表控制(仿真+源程序+全套资料)
    mapreduce 的工作原理以及 hdfs 上传文件的流程
  • 原文地址:https://blog.csdn.net/m0_46499080/article/details/133149920