看看效果

点击测试按钮

另一个是测试颜色的。
看看主要代码:
#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;
}
主要是将前面的纹理代码抽象为Test类,源码见:github-TextureTest&ImGUI_openGL