test.cpp文件
/*
环境:glfw+glad
opengl第三个程序,创建一个窗口,并渲染为墨绿色,按esc键退出。
绘制一个三角形,三个顶点颜色不同。
使用文件读取着色器
*/
#include <glad/glad.h>
#include <GLFW/glfw3.h>//顺序不能换
#include <shader_s.h>
#include <iostream>
using namespace std;
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void processInput(GLFWwindow *window);
int main() {
glfwInit();//初始化glfw
//限制了OpenGL为3.3版本导致一些新特性无法使用
//配置glfw,第一个参数代表选项名称,第二个参数设置这个选项的值。
//glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);//主版本号(Major)和次版本号(Minor)都设为3
//glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);// 核心模式(Core - profile)
//创建一个窗口对象
GLFWwindow* window = glfwCreateWindow(800, 600, "我的第一个 OpenGL", NULL, NULL);
if (window == NULL) {
cout << "创建窗口失败" << endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);//设置当前的窗口上下文
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);//设置回调函数,改变窗口大小
//glad
//GLAD是用来管理OpenGL的函数指针的,所以在调用任何OpenGL的函数之前我们需要初始化GLAD
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
cout << "初始化glad失败" << endl;
return -1;
}
//构建并编译我们的着色程序
Shader ourShader("4.3.shader.vs", "4.3.shader.fs");
//三角形三个顶点
float vertices[] = {
// positions // colors
0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, /