From an x64 dev command prompt. I'm using VS 2019, but earlier and later versions should work the same. GLFW depends on git and cmake being available in PATH. No other dependencies.
git clone https://github.com/glfw/glfw
cd glfw
mkdir build
cd build
cmake -G "NMake Makefiles" .. -DGLFW_BUILD_EXAMPLES=OFF -DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_DOCS=OFF -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_BUILD_TYPE=RELEASE
cd ..
cmake --build build --config Release
copy glfw\build\src\glfw3.lib
to your lib folder
copy glfw\include\GLFW
to your include folder
Go to https://glad.dav1d.de/, select your options.
E.g. https://glad.dav1d.de/#language=c&specification=gl&api=gl%3D4.6&api=gles1%3Dnone&api=gles2%3Dnone&api=glsc2%3Dnone&profile=core&loader=on&localfiles=on for OpenGL 4.6 core with an explicit loader included and no extensions.
Copy the two .h files and the one .c file into your include/glad
folder (for simplicity for what comes later, you can put the glad.c file in your src
directory or whatever)
E.g. like the following simplified from the GLFW docs:
#include <glad/glad.h>
#include <glad/glad.c> // Alternatively, add glad.c to your src directly and add to the command line prompt when compiling
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#include <stdlib.h>
#include <stdio.h>
static void error_callback(int error, const char* description)
{
fprintf(stderr, "Error: %s\n", description);
}
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GLFW_TRUE);
}
int main(void)
{
GLFWwindow* window;
glfwSetErrorCallback(error_callback);
if (!glfwInit())
exit(EXIT_FAILURE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL);
if (!window)
{
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwSetKeyCallback(window, key_callback);
glfwMakeContextCurrent(window);
gladLoadGL(); // gladLoadGL(glfwGetProcAddress) if glad generated without a loader
glfwSwapInterval(1);
glClearColor(1.0, 0.0, 0.0, 1.0);
while (!glfwWindowShouldClose(window))
{
glfwPollEvents();
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
}
glfwDestroyWindow(window);
glfwTerminate();
exit(EXIT_SUCCESS);
}
cl /nologo test_glfw.c /Iinclude lib/glfw3.lib user32.lib gdi32.lib shell32.lib