mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-24 07:40:22 +01:00
Examples: OpenGL: Added support for glew and glad OpenGL loaders out of the box. (#2001, #2002). Changelog, tweaks, applied changes to SDL+OpenGL3 example.
This commit is contained in:
parent
e476b7e727
commit
b127027cbd
@ -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]
|
||||
|
@ -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 $@ $<
|
||||
|
@ -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 <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)
|
||||
#include <GL/gl3w.h>
|
||||
#include <GL/gl3w.h> // Initialize with gl3wInit()
|
||||
#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)
|
||||
#include <glad/glad.h>
|
||||
#include <glad/glad.h> // Initialize with gladLoadGL()
|
||||
#else
|
||||
#pragma error("Cannot use custom loader for example application.")
|
||||
#include IMGUI_IMPL_OPENGL_LOADER_CUSTOM
|
||||
#endif
|
||||
|
||||
#include <GLFW/glfw3.h> // 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;
|
||||
}
|
||||
|
||||
|
@ -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 $@ $<
|
||||
|
@ -9,10 +9,18 @@
|
||||
#include <stdio.h>
|
||||
#include <SDL.h>
|
||||
|
||||
#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.
|
||||
//#include <glew.h>
|
||||
//#include <glext.h>
|
||||
//#include <glad/glad.h>
|
||||
// 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 <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()
|
||||
#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();
|
||||
|
@ -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 <GLES3/gl3.h> // 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 <GL/gl3w.h>
|
||||
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
|
||||
#include <GL/glew.h>
|
||||
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
|
||||
#include <glad/glad.h>
|
||||
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEXT)
|
||||
#include <glext.h>
|
||||
#else
|
||||
#include IMGUI_IMPL_OPENGL_LOADER_CUSTOM
|
||||
#endif
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user