Visual Studio 2019 + GLFW + GLAD
?。。∪绻募R耄廊桓鞣N報錯找不到C++源文件,可能是版本問題
即現在是x64,調成x32,以及glfw建議下載32版本
參考文章:https://blog.csdn.net/zjz520yy/article/details/82989067
https://www.bilibili.com/read/cv183332/
https://blog.csdn.net/sigmarising/article/details/80470054
vs2019下載地址https://visualstudio.microsoft.com/zh-hans/vs/
//下載社區版就夠用啦,具體過程在此略過
1.下載GLFW庫
https://www.glfw.org/download.html
根據旁邊的提示,vs10及以上的下載64位,其他下載32位滴,下載完解壓
2.下載GLAD庫
https://glad.dav1d.de/
語言為C/C++,選擇OpenGL,版本選擇最新,API選擇使用的對應OpenGL版本,Profile選擇Core,勾上Generate a loader,點擊GENERATE。下載完解壓
做好準備工作,開始~
配置vs工程
新建opengl(名字不固定啦)文件夾,有子文件夾include,lib,src
把GLFW的子文件夾include下的內容,GLAD中的子文件夾們的內容放在include中
把GLFW子文件夾中的對應版本放到lib中
把GLAD子文件夾中的src復制
最后結構如下:
新建個空項目
把opengl文件夾放到新建項目中
右鍵項目,選擇屬性,在包含目錄中引入include的路徑,在庫目錄中引入lib的路徑
在Linker(鏈接器)選項卡里的Input(輸入)選項卡里添加
opengl32.lib
glfw3.lib
//直接ctrl+c,ctrl+v就好~
在源文件中引入glad.c
新建.cpp的文件,擼代碼測試下
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
using namespace std;
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
int main() {
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow *window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
if (window == NULL) {
cout << "Failed to create GLFW window" << endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}
glViewport(0, 0, 800, 600);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
while (!glfwWindowShouldClose(window)) {
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
void framebuffer_size_callback(GLFWwindow* window, int width, int height) {
glViewport(0, 0, width, height);
}
- 編譯運行,結果如下:
搞定啦(~ ̄▽ ̄)~
總結
以上是生活随笔為你收集整理的Visual Studio 2019 + GLFW + GLAD的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基于Gazebo/ROS2的智能仓储机器
- 下一篇: codeup之有序插入