GLFW 环境如何配置?

1.使用 https://glad.dav1d.de/ 生成 glad.h 头文件(用来动态加载Opengl函数指针)
2.下载 https://www.glfw.org/ glfw 二进制库(GUI库)

#define GLFW_INCLUDE_NONE
#include "glad.h"
#include <GLFW/glfw3.h>

int main(void)
{
	GLFWwindow* window;

	/* Initialize the library */
	if (!glfwInit())
		return -1;

	/* Create a windowed mode window and its OpenGL context */
	window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
	if (!window)
	{
		glfwTerminate();
		return -1;
	}

	/* Make the window's context current */
	glfwMakeContextCurrent(window);

	// 使用 glad 加载 OPenGL 函数指针
	if (!gladLoadGL()) {
		return -1;
	}

	/* Loop until the user closes the window */
	while (!glfwWindowShouldClose(window))
	{
		/* Render here */
		glClear(GL_COLOR_BUFFER_BIT);
		/* Swap front and back buffers */
		glfwSwapBuffers(window);

		/* Poll for and process events */
		glfwPollEvents();
	}

	glfwTerminate();
	return 0;
}
posted @ 2021-03-04 17:30  學海無涯  阅读(362)  评论(0编辑  收藏  举报