建站之星做的网站如何导出,app网站如何做推广,营销推广费用预算表,做商业网站是否要备案Visual Studio的下载
Visual Studio 2022 C 编程环境 GLFW库安装
GLFW官网地址
GLFW官网地址#xff1a;https://www.glfw.org下载相应版本#xff0c;如下图#xff1a; CMake软件进行编译安装
下载CMake
下载的如果是源码包#xff0c;需要下载CMake软件进行编译安装…
Visual Studio的下载
Visual Studio 2022 C 编程环境 GLFW库安装
GLFW官网地址
GLFW官网地址https://www.glfw.org下载相应版本如下图 CMake软件进行编译安装
下载CMake
下载的如果是源码包需要下载CMake软件进行编译安装。
CMake官网地址CMake - Upgrade Your Software Build System
进行安装界面如下: 可以修改安装路径到D盘 编译glfw3.4
在下载的GLFW的文件夹glfw-3.4下面创建文件夹buildbuild文件夹下面创建install文件夹用来存放编译后生成的文件。
运行CMake点击Borwsse Source按钮选择要编译的源代码文件夹即glfw-3.4下面的build文件夹点击Borwse Build按钮选择编译文件存放的位置如下图 点击Configure按钮选择编译器等相关信息,这个要选x64 点击Finish按钮进行配置如下所示
修改安装路径把路径改成刚才创建的install文件夹里 用Visual Studio 2022 打开工程文件GLFW.sln 点击ALL BUILD右键--生成 编译成功 选择Install鼠标右键生成将在install文件夹下面生成GLFW的头文件和库文件如下 GLAD库安装
打开glad官网地址https://glad.dav1d.de
选择C/C语言OpenGL库版本选择最新版本4.6这个一定要记住后面编程会用到 选择核心模式。选择后点击GENERATE按钮。会在线生成GLAD的相关文件如下所示 选择.ZIP压缩包下载
解压缩后如下 整理文件选作
创建dependence文件
最后整理完是这样的 在Visual Studio配置
创建一个c的空项目
右键--属性 把包含目录和库目录配置了
包含目录配置include
库目录配置lib
配置的文件都是CMake编译出来的在install里面 配置链接器里的输入 测试代码
一
#includeglad/glad.h
#includeGLFW/glfw3.h#includeiostream// settings
const unsigned int SCR_WIDTH 800;
const unsigned int SCR_HEIGHT 600;const unsigned int VIEW_WIDTH 800;
const unsigned int VIEW_HEIGHT 600;void framebuffer_size_callback(GLFWwindow* window, int width, int height);int main()
{int glfwSate glfwInit();if (glfwSate GLFW_FALSE){std::cout GLFW initialize failed! std::endl;exit(EXIT_FAILURE);}glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);GLFWwindow* window glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, Hello OpenGL, NULL, NULL);if (window NULL){std::cout Failed to create GLFW window std::endl;glfwTerminate();return -1;}glfwMakeContextCurrent(window);// glad: load all OpenGL function pointersif (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)){std::cout Failed to initialize GLAD std::endl;return -1;}glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);//glfwSetKeyCallbackglClearColor(0.2f, 0.3f, 0.3f, 1.0f);while (!glfwWindowShouldClose(window)){glClear(GL_COLOR_BUFFER_BIT);glfwSwapBuffers(window);glfwPollEvents();}glfwTerminate();return 0;
}void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{std::cout Call frame buffer callback function! std::endl;glViewport(0, 0, width, height);
} 二
#include glad/glad.h
#include GLFW/glfw3.h
#include iostream// 视口调整回调函数
void framebuffer_size_callback(GLFWwindow* window, int width, int height) {glViewport(0, 0, width, height);
}// 键盘输入回调函数
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {if (key GLFW_KEY_ESCAPE action GLFW_PRESS) {glfwSetWindowShouldClose(window, true);}
}int main() {// 初始化GLFWglfwInit();glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);// 创建窗口GLFWwindow* window glfwCreateWindow(800, 600, OpenGL Window, NULL, NULL);if (window NULL) {std::cout Failed to create GLFW window std::endl;glfwTerminate();return -1;}glfwMakeContextCurrent(window);// 初始化GLADif (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {std::cout Failed to initialize GLAD std::endl;return -1;}// 设置视口和回调glViewport(0, 0, 800, 600);glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);glfwSetKeyCallback(window, key_callback);// 渲染循环while (!glfwWindowShouldClose(window)) {// 清屏glClearColor(0.2f, 0.3f, 0.3f, 1.0f);glClear(GL_COLOR_BUFFER_BIT);// 交换缓冲并处理事件glfwSwapBuffers(window);glfwPollEvents();}// 清理资源glfwTerminate();return 0;
}