Search code examples
opengl-esglfwegl

GLFW fails to load all GL ES 2.0 functions


I am trying to set up GLFW to create window and OpenGL ES 2.0 context,as I need something out of the box to manage input callbacks etc. The problem is this,if I use the following setup:

    glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
    glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_NATIVE_CONTEXT_API);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);

    glfwindow  = glfwCreateWindow(width, height, "Window Title", NULL, NULL);
    if (!glfwindow)
    {
        glfwTerminate();
        exit(1);
    }

    glfwMakeContextCurrent(glfwindow);

Using GLFW_NATIVE_CONTEXT_API for GLFW_CONTEXT_CREATION_API hint gives me the following info on the vendor:

GL version:OpenGL ES 3.2 NVIDIA 368.69 GL vendor:NVIDIA Corporation GL renderer:GeForce GTX 960M/PCIe/SSE2 GLSL version:OpenGL ES GLSL ES 3.20

Then it fails even to create a shader (glCreateShader()) returns 0.

But if instead that hint flag I use GLFW_EGL_CONTEXT_API , I manage to get through of most of the GL routines like shaders loading,program compile and link,GL VBO setup etc.But then I fails on glDrawElements().

And if I print the vendor info with this setup I can see this:

GL version:4.5.0 NVIDIA 368.69 GL vendor:NVIDIA Corporation GL renderer:GeForce GTX 960M/PCIe/SSE2 GLSL version:4.50 NVIDIA

So,it is quite weird to me that when EGL should suppossedly be the underlying API for context creation,I get desktop OpenGL set.

Also if I try to retrieve function pointer for glDrawElements manually,it returns null.

PFNGLDRAWELEMENTSPROC func = reinterpret_cast<PFNGLDRAWELEMENTSPROC>
(eglGetProcAddress("glDrawElements"));

I would like to understand what can be the problem and how to use GLFW for GL ES context creation the right way.


Solution

  • As no one answered my own question,and because I had figured out the root of the problem a long time ago,here is the explanation:

    GLFW works just fine for GLES context initialization.The problem is with the libraries linked.One must not link with opengl32.lib when emulating GLES on Windows.In my case I use PowerVR SDK and its ES2 and ES3 libs.Therefore,the following libs are mandatory:

    glfw3.lib

    libEGL.lib

    libGLESv2.lib

    In my linker,because by default I was using desktop OpenGL,I was also linking with opengl32.lib ,which had probably a precedence before the other GL libs.Make sure you exclude it when running GLES on the desktop platform.