I'm trying to set up a basic OpenGL ES 2.0 application on Windows using ANGLE. I've installed GLFW via vcpkg, together with ANGLE (either by patching vcpkg with #7923 and #8785, or building locally) and can build the application. I've also got d3dcompiler_47.dll in the output directory. Unfortunately at runtime it looks like none of the OpenGL ES calls are succeeding.
I'm initialising GLFW as follows:
#include <iostream>
#define GLFW_INCLUDE_ES2
#include <GLFW/glfw3.h>
int main()
{
if (!glfwInit())
{
std::cerr << "Could not init GLFW\n";
return 1;
}
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
auto window = glfwCreateWindow(640, 480, "Test GLES", nullptr, nullptr);
if (!window)
{
std::cerr << "Could not create window\n";
glfwTerminate();
return 1;
}
glfwMakeContextCurrent(window);
// rest of code goes here
After the call to glfwMakeContextCurrent
I expect the OpenGL ES context to be available. However:
glGetString(GL_VERSION)
, glGetString(GL_RENDERER)
and glGetString(GL_VENDOR)
all return a null pointer.glCreateShader(GL_VERTEX_SHADER)
returns 0 (i.e. failure), but glGetError()
gives GL_NO_ERROR
.The same code is working correctly on Linux on the same machine, so I assume I need to do something else to get things to work on Windows.
My searches have come up with little useful information for doing this (but it did suggest to do the glGetString
checks). I assume that what I'm missing is sufficiently obvious that no-one's bothered to put it in the explanations, so I'm going to feel quite silly when I know what's going wrong.
Any suggestions for what I'm missing here?
As it is specified, you should ask for an OpenGL ES context:
glfwWindowHint (GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API) ;
https://www.glfw.org/docs/latest/window_guide.html#GLFW_CONTEXT_CREATION_API_hint