• 【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

  • 相关阅读:
    html在线商城购物网站制作——基于HTML+CSS+JavaScript(oppo手机商城 6页)
    一软一硬:记录我的工作电脑两次出现性能问题的分析思路和解决过程
    国庆放假作业5
    实现旅行售货员问题的回溯算法
    MogaFX外汇市场保持相对稳定
    Unity——LitJSON的安装
    C语言文件操作总结归纳
    leetcode_98复原IP地址
    五金机电行业智能渠道商管理平台搭建,构建数字化渠道管理新模式
    K8s高可用集群二进制部署-V1.20
  • 原文地址:https://blog.csdn.net/m0_46499080/article/details/133149920