Windows 操作系统搭建 VS Code/Visual Studio + OpenGL 环境
OpenGL (Open Graphics Library)
A cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics. The API is typically used to interact with a graphics processing unit (GPU), to achieve hardware-accelerated rendering.
“However, OpenGL by itself is not an API, but merely a specification, developed and maintained by the Khronos Group.” – from learnopengl.com
学习 OpenGL 最好的教程:
LearnOpenGL
LearnOpenGL-CN
参考配置
- 操作系统:Windows 10 64-bit
- 系统架构:x64-based PC
- 编译工具:CMake
- OpenGL 应用框架:GLFW
- 访问 OpenGL 规范接口的第三方库:GLAD
- [Option 1]
- 编译器:MinGW-W64
- 编辑器:Visual Studio Code
- [Option 2]
- 编译器:MSVC
- 集成开发环境:Visual Studio 2022
💡 NOTE:
需要提前安装好 CMake,另外:
- 选择 [Option 1] 需要提前安装好 MinGW-W64 和 VS Code
- 选择 [Option 2] 需要提前安装好 Visual Studio
安装 MinGW-w64 与 CMake 可以参考我的上一篇博客 Windows 下 MinGW-W64 与 CMake 的安装
构建 GLFW
GLFW 提供创建 OpenGL Context 和用于显示的窗口、鼠标键盘等操作等接口,否则你需要自己写大量操作系统相关的代码来完成这些工作,因为在不同操作系统上这些操作不同,OpenGL 将它们抽象出去。
访问 GLFW GitHub Releases 页面,选择最新版本 源代码 压缩包 Source code (zip)
下载,或者 GLFW 官方下载页面 点击 Source package
直接下载最新版本 源代码 压缩包 glfw-<latest-version>.zip
。
💡 NOTE: 从源代码编译库可以保证生成的库是兼容你的操作系统和 CPU 的,而预编译的二进制文件可能会出现兼容问题(甚至有时候没提供支持你系统的文件)。
下载源码包之后,将其解压并打开。我们只需要里面的这些内容:
- 编译生成的库
- include 文件夹
- 创建一个单独的文件夹,里面包含 Libs 和 Inclu