Examples: OpenGL: Added support for glew and glad OpenGL loaders out of the box. (#2001, #2002). Changelog, tweaks, applied changes to SDL+OpenGL3 example.
// ImGui - standalone example application for GLFW + OpenGL 3, using programmable pipeline
// ImGui - standalone example application for GLFW + OpenGL 3, using programmable pipeline
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
// (GL3W is a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc.)
#include"imgui.h"
#include"imgui.h"
#include"imgui_impl_glfw.h"
#include"imgui_impl_glfw.h"
#include"imgui_impl_opengl3.h"
#include"imgui_impl_opengl3.h"
#include<stdio.h>
#include<stdio.h>
// This example is using gl3w to access OpenGL functions. You may use another OpenGL loader/header such as: glew, glext, glad, glLoadGen, etc.
// About OpenGL function loaders: modern OpenGL doesn't have a standard header file and requires individual function pointers to be loaded manually.
// Helper libraries are often used for this purpose! Here we are supporting a few common ones: gl3w, glew, glad.
// You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own.
#if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
#if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
#include<GL/gl3w.h>
#include<GL/gl3w.h> // Initialize with gl3wInit()
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
#include<GL/glew.h>
#include<GL/glew.h> // Initialize with glewInit()
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
#include<glad/glad.h>
#include<glad/glad.h> // Initialize with gladLoadGL()
#else
#else
#pragma error("Cannot use custom loader for example application.")
#include IMGUI_IMPL_OPENGL_LOADER_CUSTOM
#endif
#endif
#include<GLFW/glfw3.h> // Include glfw3.h after our OpenGL definitions
#include<GLFW/glfw3.h> // Include glfw3.h after our OpenGL definitions
@ -56,17 +57,18 @@ int main(int, char**)
return1;
return1;
glfwMakeContextCurrent(window);
glfwMakeContextCurrent(window);
glfwSwapInterval(1);// Enable vsync
glfwSwapInterval(1);// Enable vsync
// Initialize OpenGL loader
#if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
#if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
GLenumerr=gl3wInit();
boolerr=gl3wInit()!=0;
if(!err){
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
GLenumerr=glewInit();
boolerr=glewInit()!=GLEW_OK;
if(GLEW_OK!=err){
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
GLenumerr=gladLoadGL();
boolerr=gladLoadGL()!=0;
if(!err){
#endif
#endif
fprintf(stderr,"Failed to initialize OpenGL\n");
if(err)
{
fprintf(stderr,"Failed to initialize OpenGL loader!\n");
#include<GL/gl3w.h> // This example is using gl3w to access OpenGL functions. You may use another OpenGL loader/header such as: glew, glext, glad, glLoadGen, etc.
// About OpenGL function loaders: modern OpenGL doesn't have a standard header file and requires individual function pointers to be loaded manually.
//#include <glew.h>
// Helper libraries are often used for this purpose! Here we are supporting a few common ones: gl3w, glew, glad.
//#include <glext.h>
// You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own.
//#include <glad/glad.h>
#if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
#include<GL/gl3w.h> // Initialize with gl3wInit()
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
#include<GL/glew.h> // Initialize with glewInit()
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
#include<glad/glad.h> // Initialize with gladLoadGL()