From 23d66e9b6f4ae26cded37878da37aabcb29e48ad Mon Sep 17 00:00:00 2001 From: raysan5 Date: Thu, 21 Jan 2016 12:24:35 +0100 Subject: Move extensions loading to core module --- src/core.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index f55dba50..6e59e57b 100644 --- a/src/core.c +++ b/src/core.c @@ -54,8 +54,13 @@ #include // Macros for reporting and retrieving error conditions through error codes #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) + #define GLEW_STATIC + #include // GLEW extensions loading lib + //#include "glad.h" // GLAD library: Manage OpenGL headers and extensions + //#define GLFW_INCLUDE_NONE // Disable the standard OpenGL header inclusion on GLFW3 #include // GLFW3 library: Windows, OpenGL context and Input management + #ifdef __linux #define GLFW_EXPOSE_NATIVE_X11 // Linux specific definitions for getting #define GLFW_EXPOSE_NATIVE_GLX // native functions like glfwGetX11Window @@ -1378,6 +1383,40 @@ static void InitDisplay(int width, int height) glfwMakeContextCurrent(window); + // Extensions initialization for OpenGL 3.3 + if (rlGetVersion() == OPENGL_33) + { + #define GLEW_EXTENSIONS_LOADER + #if defined(GLEW_EXTENSIONS_LOADER) + // Initialize extensions using GLEW + glewExperimental = 1; // Needed for core profile + GLenum error = glewInit(); + + if (error != GLEW_OK) TraceLog(ERROR, "Failed to initialize GLEW - Error Code: %s\n", glewGetErrorString(error)); + + if (glewIsSupported("GL_VERSION_3_3")) TraceLog(INFO, "OpenGL 3.3 Core profile supported"); + else TraceLog(ERROR, "OpenGL 3.3 Core profile not supported"); + + // With GLEW, we can check if an extension has been loaded in two ways: + //if (GLEW_ARB_vertex_array_object) { } + //if (glewIsSupported("GL_ARB_vertex_array_object")) { } + + // NOTE: GLEW is a big library that loads ALL extensions, we can use some alternative to load only required ones + // Alternatives: glLoadGen, glad, libepoxy + + #elif defined(GLAD_EXTENSIONS_LOADER) + // NOTE: glad is generated and contains only required OpenGL version and Core extensions + //if (!gladLoadGL()) TraceLog(ERROR, "Failed to initialize glad\n"); + if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) TraceLog(ERROR, "Failed to initialize glad\n"); // No GLFW3 in this module... + + if (GLAD_GL_VERSION_3_3) TraceLog(INFO, "OpenGL 3.3 Core profile supported"); + else TraceLog(ERROR, "OpenGL 3.3 Core profile not supported"); + + // With GLAD, we can check if an extension is supported using the GLAD_GL_xxx booleans + //if (GLAD_GL_ARB_vertex_array_object) // Use GL_ARB_vertex_array_object + #endif + } + // Enables GPU v-sync, so frames are not limited to screen refresh rate (60Hz -> 60 FPS) // If not set, swap interval uses GPU v-sync configuration // Framerate can be setup using SetTargetFPS() -- cgit v1.2.3 From 455be7f6f6dfd80d36ffe42cf09618aef4c1f43e Mon Sep 17 00:00:00 2001 From: raysan5 Date: Thu, 21 Jan 2016 13:52:09 +0100 Subject: Try to implement GLAD support --- src/core.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index 6e59e57b..d0c98cca 100644 --- a/src/core.c +++ b/src/core.c @@ -54,10 +54,15 @@ #include // Macros for reporting and retrieving error conditions through error codes #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) - #define GLEW_STATIC - #include // GLEW extensions loading lib - //#include "glad.h" // GLAD library: Manage OpenGL headers and extensions - + + #define GLEW_EXTENSIONS_LOADER + #if defined(GLEW_EXTENSIONS_LOADER) + #define GLEW_STATIC + #include // GLEW extensions loading lib + #elif defined(GLAD_EXTENSIONS_LOADER) + #include "glad.h" // GLAD library: Manage OpenGL headers and extensions + #endif + //#define GLFW_INCLUDE_NONE // Disable the standard OpenGL header inclusion on GLFW3 #include // GLFW3 library: Windows, OpenGL context and Input management @@ -1386,7 +1391,6 @@ static void InitDisplay(int width, int height) // Extensions initialization for OpenGL 3.3 if (rlGetVersion() == OPENGL_33) { - #define GLEW_EXTENSIONS_LOADER #if defined(GLEW_EXTENSIONS_LOADER) // Initialize extensions using GLEW glewExperimental = 1; // Needed for core profile @@ -1403,7 +1407,6 @@ static void InitDisplay(int width, int height) // NOTE: GLEW is a big library that loads ALL extensions, we can use some alternative to load only required ones // Alternatives: glLoadGen, glad, libepoxy - #elif defined(GLAD_EXTENSIONS_LOADER) // NOTE: glad is generated and contains only required OpenGL version and Core extensions //if (!gladLoadGL()) TraceLog(ERROR, "Failed to initialize glad\n"); -- cgit v1.2.3 From 4e57bd1f18996990546920f2242a58894c6cec81 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Fri, 22 Jan 2016 01:22:45 +0100 Subject: Replaced GLEW by GLAD Removed GLEW external dependency, now it works with GLAD Kept GLEW path, just in case... detected weird behaviour when testing with gDEBugger --- src/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index d0c98cca..9b068300 100644 --- a/src/core.c +++ b/src/core.c @@ -55,7 +55,7 @@ #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) - #define GLEW_EXTENSIONS_LOADER + #define GLAD_EXTENSIONS_LOADER #if defined(GLEW_EXTENSIONS_LOADER) #define GLEW_STATIC #include // GLEW extensions loading lib -- cgit v1.2.3