mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 20:18:47 +02: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:
@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user