步骤1:修改examples/imgui_impl_opengl3.h中的默认OpenGL3 loader

此处我使用的是GLAD库,使用GLEW库的话可以改成IMGUI_IMPL_OPENGL_LOADER_GLEW

// Set default OpenGL3 loader to be gl3w
#if !defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)     \&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)     \&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)     \&& !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
#define IMGUI_IMPL_OPENGL_LOADER_GLAD//IMGUI_IMPL_OPENGL_LOADER_GL3W //****修改这里****
#endif

步骤2:

将examples/中的imgui_impl_glfw.h、imgui_impl_glfw.cpp、imgui_impl_opengl3.h(修改后)、imgui_impl_opengl3.cpp添加到项目中
步骤3:调用顺序

这里是examples/example_glfw_opengl3中的main.cpp中的内容的简化版

 // Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;// Setup Dear ImGui style
ImGui::StyleColorsDark();
//ImGui::StyleColorsClassic();// Setup Platform/Renderer bindings
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init(glsl_version); //glsl_version可以使用字符串"#version 150"替代bool show_demo_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);// Main loop
while (!glfwWindowShouldClose(window))
{glfwPollEvents();// Start the Dear ImGui frameImGui_ImplOpenGL3_NewFrame();ImGui_ImplGlfw_NewFrame();ImGui::NewFrame();// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).if (show_demo_window)ImGui::ShowDemoWindow(&show_demo_window);// 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window.{static float f = 0.0f;static int counter = 0;ImGui::Begin("Hello, world!");                          // Create a window called "Hello, world!" and append into it.ImGui::Text("This is some useful text.");               // Display some text (you can use a format strings too)ImGui::Checkbox("Demo Window", &show_demo_window);      // Edit bools storing our window open/close stateImGui::Checkbox("Another Window", &show_another_window);ImGui::SliderFloat("float", &f, 0.0f, 1.0f);            // Edit 1 float using a slider from 0.0f to 1.0fImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a colorif (ImGui::Button("Button"))                            // Buttons return true when clicked (most widgets return true when edited/activated)counter++;ImGui::SameLine();ImGui::Text("counter = %d", counter);ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);ImGui::End();}// 3. Show another simple window.if (show_another_window){ImGui::Begin("Another Window", &show_another_window);   // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)ImGui::Text("Hello from another window!");if (ImGui::Button("Close Me"))show_another_window = false;ImGui::End();}// RenderingImGui::Render();int display_w, display_h;glfwMakeContextCurrent(window);glfwGetFramebufferSize(window, &display_w, &display_h);glViewport(0, 0, display_w, display_h);glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);glClear(GL_COLOR_BUFFER_BIT);ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());glfwMakeContextCurrent(window);glfwSwapBuffers(window);
}// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();

OpenGL:ImGUI在GLFW库和GLAD/GLEW库的环境下使用相关推荐

  1. glew java_使用GLEW在win环境下创建支持高版本OpenGL 上下文

    BOOL Cgl::CreateMultiSample(HWND hwnd, BOOL bCreateZBuffer)/*by ZhouZhuo 2014.06.23 凹凸纹理 启动多采样抗锯齿 */ ...

  2. Linux安装库时安装源错误,linux环境下golang安装第三方库的时候出错的决办法

    1.错误描述 使用如下方式安装beego的时候出错 go get github.com/astaxie/beego 错误信息: go install unicode/utf8: open /opt/g ...

  3. .h头文件 .lib库文件 .dll动态库文件之间的关系

     .h头文件是编译时必须的,lib是链接时需要的,dll是运行时需要的. 附加依赖项的是.lib不是.dll,若生成了DLL,则肯定也生成 LIB文件.如果要完成源代码的编译和链接,有头文件和li ...

  4. openGL使用GLFW、GLEW库绘制点

    前言 openGL使用GLFW.GLEW库绘制点,下面这段代码:绘制蓝色背景,中心点是一个黄色的点,由于代码比较简单,所以我把顶点着色器和片元着色器硬编码到c++程序中.问题就在这!!!由于着色器都写 ...

  5. OpenGL,glx,glaux,glut,freeglut,glew,glfw,mesa

    转自:http://www.lai18.com/content/1297257.html 一.OpenGL OpenGL函数库相关的API有核心库(gl),实用库(glu),辅助库(aux).实用工具 ...

  6. 从零开始的OpenGL之路(1)——配置GLEW

    虽然我们在上一节已经配置好了glfw库,但是还需要一些操作才能使用现代OpenGL.按照惯例,先说说为什么要配置glew库.我们已经知道OpenGL只是一个规范,其本身并没有实现这些方法,具体的实现是 ...

  7. OpenGL创建一个GLFW背景红色窗口的实例

    OpenGL创建一个GLFW背景红色窗口 先上图,再解答. 完整主要的源代码 源代码剖析 先上图,再解答. 完整主要的源代码 #include <glad/glad.h> #include ...

  8. OpenGL创建一个GLFW窗口的实例

    OpenGL创建一个GLFW窗口 先上图,再解答. 完整主要的源代码 源代码剖析 先上图,再解答. 完整主要的源代码 #include <glad/glad.h> #include < ...

  9. OpenGL初探-Win10+VS2017+freeglut+glew+gltools开发环境搭建

    最近在研究OpenGL,主要看的书是<OpenGL超级宝典(第5版)>,学习编程自然少不了从环境搭建开始,然后写一个Demo,运行成功即告开篇成功,本篇文章将使用书本中的2.5章节< ...

最新文章

  1. Maven 模块继承、聚合
  2. git-diff忽略^ M.
  3. 互联网协议 — 使用 Wireshark 调试 HTTPS 及 HTTP/2 流量
  4. 【直播回放】100分钟全面剖析图像分割任务,学习CV必知
  5. python创建软连接_centos7 上 创建软连接 ln -s
  6. 53pagecontext对象
  7. php接受post接受不到数据,PHP $_POST接受不到数据,但$_GET可以接受数据
  8. php 判断函数禁用,php禁用函数设置及查看方法的介绍(附示例)
  9. cisco交换机MAC/CAW***防范
  10. UVA11173 Grey Codes【位操作】
  11. Web XR 混合现实浏览器
  12. 充电速度公式_关于电池充电时间计算公式
  13. 保姆级win10纯净系统安装 数字权利激活工具 / KMS激活 + U盘启动盘制作
  14. 什么是Microsoft Visual FoxPro?
  15. java 微信高级群发_java微信平台,高级群发接口开发
  16. 易点易动【设备管理】产品全新上线
  17. oracle编程语言是什么意思,OraclePL编程语言的优点介绍
  18. 两个主要问题将决定微信支付成败
  19. 华为南京研究所各部门
  20. 金立金刚GN5001刷机救黑砖

热门文章

  1. 怎么关闭微信微众银行账户服务器,微信微众银行要怎么关闭,微信微众银行注销方法...
  2. 拼写检查工具是android,Android的文本和输入---拼写检查器(一)-Go语言中文社区...
  3. java enum 定义属性_java enum(枚举)使用详解 + 总结
  4. Precision和Recall
  5. spring事物配置,声明式事务管理和基于@Transactional注解的使用
  6. 最简便的备份MySql数据库方法
  7. Vim 实用技术,第 2 部分: 常用插件
  8. 20321关系数据库理论基础
  9. Flask出现Error code 400, message Bad request syntax异常
  10. 使用Ant Design 和Vue,React中后台开发套餐