-
windows 需安装 MinGW, install gcc、g++、gdb 和 mingw32-make 并 进入到
MinGW\bin
文件夹下 把 mingw32-make.exe 修改成 make.exeMinGW 不要下载 MinGW-w64因为后面可能会出现问题 MinGW,即 Minimalist GNU For Windows。它是一些头文件和端口库的集合,该集合允许人们在没有第三方动态链接库的情况下使用 GCC 产生 Win32 程序。
-
vscode 插件
C/C++
、C/C++ Project Generator
-
glfw 下载
Windows pre-compiled binaries
选择Windows pre-compiled binaries,因为我们使用的 MinGW 所以选择 32-bit Windows binaries 对于 Ubuntu,通过
sudo apt install libglfw3-dev libglfw3
安装 glfw -
glad 在线服务 生成静态库
> gcc ./src/glad.c -c -I ./include/ // 生成 .o文件 > ar -rc libglad.a glad.o // 生成我们所需要的 .a文件
将生成的 libglad.a 复制到 lib 文件下
-
glm 复制到 include 目录下
-
imgui 复制到 include 目下,Makefile 中添加以下命令
# define the C source files SOURCES := $(wildcard $(patsubst %,%/*.cpp, $(SOURCEDIRS))) SOURCES += include/imgui/imgui_impl_glfw.cpp include/imgui/imgui_impl_opengl3.cpp SOURCES += include/imgui/imgui.cpp include/imgui/imgui_demo.cpp include/imgui/imgui_draw.cpp include/imgui/imgui_widgets.cpp
-
assimp 下载已编译好的文件 Assimp3-1-1_MinGW4-8-1_Win32.zip
对于 Ubuntu,通过
sudo apt install libassimp-dev
安装 assimp
测试代码
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
void framebuffer_size_callback(GLFWwindow *window, int width, int height);
void processInput(GLFWwindow *window);
const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;
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(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
if (window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}
while (!glfwWindowShouldClose(window))
{
processInput(window);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
void processInput(GLFWwindow *window)
{
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
}
void framebuffer_size_callback(GLFWwindow *window, int width, int height)
{
glViewport(0, 0, width, height);
}
执行命令 run 编译和运行.exe 程序
make run dir=01_test_glfw
执行命令 clean 删除 .exe 和对应文件夹下的.o 文件
make clean dir=01_test_glfw
需要设置调试一个文件 修改 tasks.json
下面的条目
"label": "build",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"windows": {
"command": "powershell",
"args": [
"-c",
"make dir=01_test_glfw", // 调式 01_test_glfw/main.cpp
]
},