diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 6a1b432e6..b92407cdb 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -104,6 +104,7 @@ Other Changes: - Examples: OpenGL3: Tweaked the imgui_impl_opengl3.cpp to work as-is with Emscripten + WebGL 2.0. (#1941). [@o-micron] - Examples: OpenGL3: Made the example app default to GL 3.0 + GLSL 130 (instead of GL 3.2 + GLSL 150) unless on Mac. - Examples: OpenGL3: Added error output when shaders fail to compile/link. + - Examples: OpenGL3: Added support for glew and glad OpenGL loaders out of the box. (#2001, #2002) [@jdumas] - Examples: OpenGL2: Disabling/restoring GL_LIGHTING and GL_COLOR_MATERIAL to increase compatibility with legacy OpenGL applications. (#1996) - Examples: DirectX10, DirectX11: Fixed unreleased resources in Init and Shutdown functions. (#1944) - Examples: DirectX11: Querying for IDXGIFactory instead of IDXGIFactory1 to increase compatibility. (#1989) [@matt77hias] diff --git a/examples/example_glfw_opengl3/Makefile b/examples/example_glfw_opengl3/Makefile index 3f5a37212..d36b78d80 100644 --- a/examples/example_glfw_opengl3/Makefile +++ b/examples/example_glfw_opengl3/Makefile @@ -19,21 +19,28 @@ SOURCES = main.cpp SOURCES += ../imgui_impl_glfw.cpp ../imgui_impl_opengl3.cpp SOURCES += ../../imgui.cpp ../../imgui_demo.cpp ../../imgui_draw.cpp OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) - UNAME_S := $(shell uname -s) -# Default OpenGL loader: gl3w +##--------------------------------------------------------------------- +## OPENGL LOADER +##--------------------------------------------------------------------- + +## Using OpenGL loader: gl3w [default] SOURCES += ../libs/gl3w/GL/gl3w.c CXXFLAGS = -I../libs/gl3w -# You can switch to glad by changing the following compilation options, -# and changing the rule L73 of this Makefile +## Using OpenGL loader: glew +## (This assumes a system-wide installation) +# CXXFLAGS = -lGLEW -DIMGUI_IMPL_OPENGL_LOADER_GLEW + +## Using OpenGL loader: glad +## (You'll also need to change the rule at line ~77 of this Makefile to compile/link glad.c/.o) # SOURCES += ../libs/glad/src/glad.c # CXXFLAGS = -I../libs/glad/include -DIMGUI_IMPL_OPENGL_LOADER_GLAD -# You can also use glew are you OpenGL loader -# This assumes a system-wide installation -# CXXFLAGS = -lGLEW -DIMGUI_IMPL_OPENGL_LOADER_GLEW +##--------------------------------------------------------------------- +## BUILD FLAGS PER PLATFORM +##--------------------------------------------------------------------- ifeq ($(UNAME_S), Linux) #LINUX ECHO_MESSAGE = "Linux" @@ -64,6 +71,9 @@ ifeq ($(findstring MINGW,$(UNAME_S)),MINGW) CFLAGS = $(CXXFLAGS) endif +##--------------------------------------------------------------------- +## BUILD RULES +##--------------------------------------------------------------------- %.o:%.cpp $(CXX) $(CXXFLAGS) -c -o $@ $< diff --git a/examples/example_glfw_opengl3/main.cpp b/examples/example_glfw_opengl3/main.cpp index d99ec3b09..2795ff49d 100644 --- a/examples/example_glfw_opengl3/main.cpp +++ b/examples/example_glfw_opengl3/main.cpp @@ -1,22 +1,23 @@ // 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. // (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_impl_glfw.h" #include "imgui_impl_opengl3.h" #include -// 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) -#include +#include // Initialize with gl3wInit() #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) -#include +#include // Initialize with glewInit() #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) -#include +#include // Initialize with gladLoadGL() #else -#pragma error("Cannot use custom loader for example application.") +#include IMGUI_IMPL_OPENGL_LOADER_CUSTOM #endif #include // Include glfw3.h after our OpenGL definitions @@ -56,17 +57,18 @@ int main(int, char**) return 1; glfwMakeContextCurrent(window); glfwSwapInterval(1); // Enable vsync + + // Initialize OpenGL loader #if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) - GLenum err = gl3wInit(); - if (!err) { + bool err = gl3wInit() != 0; #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) - GLenum err = glewInit(); - if (GLEW_OK != err) { + bool err = glewInit() != GLEW_OK; #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) - GLenum err = gladLoadGL(); - if (!err) { + bool err = gladLoadGL() != 0; #endif - fprintf(stderr, "Failed to initialize OpenGL\n"); + if (err) + { + fprintf(stderr, "Failed to initialize OpenGL loader!\n"); return 1; } diff --git a/examples/example_sdl_opengl3/Makefile b/examples/example_sdl_opengl3/Makefile index fb826cbca..765c44606 100644 --- a/examples/example_sdl_opengl3/Makefile +++ b/examples/example_sdl_opengl3/Makefile @@ -18,11 +18,29 @@ EXE = example_sdl_opengl3 SOURCES = main.cpp SOURCES += ../imgui_impl_sdl.cpp ../imgui_impl_opengl3.cpp SOURCES += ../../imgui.cpp ../../imgui_demo.cpp ../../imgui_draw.cpp -SOURCES += ../libs/gl3w/GL/gl3w.c OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) - UNAME_S := $(shell uname -s) +##--------------------------------------------------------------------- +## OPENGL LOADER +##--------------------------------------------------------------------- + +## Using OpenGL loader: gl3w [default] +SOURCES += ../libs/gl3w/GL/gl3w.c +CXXFLAGS = -I../libs/gl3w + +## Using OpenGL loader: glew +## (This assumes a system-wide installation) +# CXXFLAGS = -lGLEW -DIMGUI_IMPL_OPENGL_LOADER_GLEW + +## Using OpenGL loader: glad +## (You'll also need to change the rule at line ~77 of this Makefile to compile/link glad.c/.o) +# SOURCES += ../libs/glad/src/glad.c +# CXXFLAGS = -I../libs/glad/include -DIMGUI_IMPL_OPENGL_LOADER_GLAD + +##--------------------------------------------------------------------- +## BUILD FLAGS PER PLATFORM +##--------------------------------------------------------------------- ifeq ($(UNAME_S), Linux) #LINUX ECHO_MESSAGE = "Linux" @@ -51,6 +69,9 @@ ifeq ($(findstring MINGW,$(UNAME_S)),MINGW) CFLAGS = $(CXXFLAGS) endif +##--------------------------------------------------------------------- +## BUILD RULES +##--------------------------------------------------------------------- %.o:%.cpp $(CXX) $(CXXFLAGS) -c -o $@ $< diff --git a/examples/example_sdl_opengl3/main.cpp b/examples/example_sdl_opengl3/main.cpp index 24b25cc87..bdd8a9a8b 100644 --- a/examples/example_sdl_opengl3/main.cpp +++ b/examples/example_sdl_opengl3/main.cpp @@ -9,10 +9,18 @@ #include #include -#include // This example is using gl3w to access OpenGL functions. You may use another OpenGL loader/header such as: glew, glext, glad, glLoadGen, etc. -//#include -//#include -//#include +// 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) +#include // Initialize with gl3wInit() +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) +#include // Initialize with glewInit() +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) +#include // Initialize with gladLoadGL() +#else +#include IMGUI_IMPL_OPENGL_LOADER_CUSTOM +#endif int main(int, char**) { @@ -49,7 +57,20 @@ int main(int, char**) SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+OpenGL3 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE); SDL_GLContext gl_context = SDL_GL_CreateContext(window); SDL_GL_SetSwapInterval(1); // Enable vsync - gl3wInit(); + + // Initialize OpenGL loader +#if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) + bool err = gl3wInit() != 0; +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) + bool err = glewInit() != GLEW_OK; +#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) + bool err = gladLoadGL() != 0; +#endif + if (err) + { + fprintf(stderr, "Failed to initialize OpenGL loader!\n"); + return 1; + } // Setup Dear ImGui binding IMGUI_CHECKVERSION(); diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index 16a9eb4e8..73fa3da5d 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -11,6 +11,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2018-08-29: OpenGL: Added support for more OpenGL loaders: glew and glad, with comments indicative that any loader can be used. // 2018-08-09: OpenGL: Default to OpenGL ES 3 on iOS and Android. GLSL version default to "#version 300 ES". // 2018-07-30: OpenGL: Support for GLSL 300 ES and 410 core. Fixes for Emscripten compilation. // 2018-07-10: OpenGL: Support for more GLSL versions (based on the GLSL version string). Added error output when shaders fail to compile/link. @@ -72,18 +73,16 @@ // OpenGL ES 3 #include // Use GL ES 3 #else -// OpenGL Regular -// (About OpenGL function loaders: modern OpenGL doesn't have a standard header file and requires individual functions to be loaded manually. -// Helper libraries are often used for this purpose! Here we are using gl3w.h, which requires a call to gl3wInit(). -// You may use another any other loader/header of your choice, such as glew, glext, glad, glLoadGen, etc.) +// Regular OpenGL +// 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) #include #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) #include #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) #include -#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEXT) -#include #else #include IMGUI_IMPL_OPENGL_LOADER_CUSTOM #endif diff --git a/examples/imgui_impl_opengl3.h b/examples/imgui_impl_opengl3.h index b5e93b0d0..2812dac5e 100644 --- a/examples/imgui_impl_opengl3.h +++ b/examples/imgui_impl_opengl3.h @@ -9,10 +9,10 @@ // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. // https://github.com/ocornut/imgui -// About OpenGL function loaders: -// Modern OpenGL requires individual functions to be loaded manually. Helper libraries are often used for this purpose. -// Here we are using gl3w.h, which requires a call to gl3wInit(). -// You may use another any other loader/header of your choice, such as glew, glext, glad, glLoadGen, etc. +// About OpenGL function loaders: +// 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. // About GLSL version: // The 'glsl_version' initialization parameter should be NULL (default) or a "#version XXX" string. @@ -20,10 +20,10 @@ // Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp. // Set default OpenGL 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) +#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_GL3W #endif