# 01_hello_window **Repository Path**: open-gl_3/01_hello_window ## Basic Information - **Project Name**: 01_hello_window - **Description**: 第一个OpenGL练习代码:OpenGL窗口,填充 OpenGL 背景。 - **Primary Language**: C++ - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2024-05-03 - **Last Updated**: 2024-06-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # README 官方教程:[Getting started](https://www.glfw.org/docs/latest/quick.html) ## 哔哩哔哩视频教程 - [大名鼎鼎的Learn OpenGL的视频教程](https://www.bilibili.com/video/BV1Sv411g7pp/) ## 说明 第一个`OpenGL`练习项目代码,熟悉使用`CMake`进行`OpenGL`的项目配置。练习教程章节链接[你好,窗口](https://learnopengl-cn.github.io/01%20Getting%20started/03%20Hello%20Window/)。 前期准备: ### 1. 编译安装`GLFW3` 从[GLFW3 repo]( https://github.com/glfw/glfw.git)下载并编译安装`GLFW3`。使用默认`CMake`配置即可。 ### 2. 下载`glad`源码 使用`glad`在线服务,选择`OpenGL`版本为`3.3`,选择`Profile`为`Core`,编程语言`C/C++`,即可下载`glad`源码,并放在项目目录下(或单独编译为库文件)。参考教程:[LearnOpenGL-CN -- 创建窗口 -- GLAD](https://learnopengl-cn.github.io/01%20Getting%20started/02%20Creating%20a%20window/)。 ### 3. 查看`OpenGL`版本 由于教程需要使用`OpenGL 3.3`或以上版本,否则此应用有可能会崩溃或者出现不可预知的错误。 在windows上,可以用`OpenGL Extensions Viewer`查看`OpenGL`版本:[显卡GL版本查看及测试 OpenGL Extensions Viewer 汉化版](https://www.ksite.cn/contents/glview.html)。 在linux上,可以用`glxinfo`命令查看`OpenGL`版本。 ## GLFW3编译说明 `GLFW3`使用`CMake`编译安装之后,需要编辑安装目录下的`glfw3Targets.cmake`文件,设置`GLFW3_INCLUDE_DIRS`,`GLFW3_LIBRARY_DIRS`两个变量: ```bash set_target_properties(glfw PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include" INTERFACE_LINK_LIBRARIES "\$" ) # 添加导出变量 set(GLFW3_INCLUDE_DIRS ${_IMPORT_PREFIX}/include) set(GLFW3_LIBRARY_DIRS ${_IMPORT_PREFIX}/lib) ``` ## 代码说明 使用`glad`生成导出函数。在添加头文件时,要确保先包含`glad.h`,再包含`glfw.h`: ```C++ #include // make sure to include this before glfw.h #include ``` ## 参考 - [LearnOpenGL-CN -- 你好,窗口](https://learnopengl-cn.github.io/01%20Getting%20started/03%20Hello%20Window/) - [Glitter -- CMakeLists.txt](https://github.com/Polytonic/Glitter/blob/master/CMakeLists.txt) - [GLFW官方文档 -- Building applications](https://www.glfw.org/docs/3.3/build_guide.html) - [新手如何学习 OpenGL?可以选哪些资料入门学习?](https://www.zhihu.com/question/20194540)