1.首先需要保证Ubuntu安装配置了OpenGL+glad+glfw
可以参考这两篇博客
(1)第一步配置OpenGL
如何在Ubuntu 14.04下安装OpenGL开发环境_不积跬步,无以至千里!-优快云博客
(2)第二步配置glad+glfw
Ubuntu下搭建OpenGL开发环境(GLFW_3.3.1 + GLM_0.9.9 + GLAD)_Hi, Robotics-优快云博客
2.vscode配置
打开一个文件夹,创建main.cpp,我这用的是learnOpenGL上创建三角形的代码。
然后一定要把glad.c放到文件夹下
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void processInput(GLFWwindow *window);
// settings
const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;
const char *vertexShaderSource = "#version 330 core\n"
"layout (location = 0) in vec3 aPos;\n"
"void main()\n"
"{\n"
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
"}\0";
const char *fragmentShaderSource = "#version 330 core\n"
"out vec4 FragColor;\n"
"void main()\n"
"{\n"
" FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
"}\n\0";
int main()
{
// glfw: initialize and configure
// ------------------------------
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPE