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:
omar
2018-08-28 15:56:03 +02:00
parent e476b7e727
commit b127027cbd
7 changed files with 95 additions and 41 deletions

View File

@ -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;
}