创建一个GLFWwindow实例并为其设置背景色
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <iostream>
using namespace std;
void init(GLFWwindow* window) { }
void display(GLFWwindow* window, double currentTime) {
//指定清楚背景的颜色值
glClearColor(1.0, 0.0, 0.0, 1.0);
//填充颜色缓冲区,GL_COLOR_BUFFER_BIT引用了包含渲染后像素的颜色缓冲区
glClear(GL_COLOR_BUFFER_BIT);
}
int main(void) {
if (!glfwInit()) { exit(EXIT_FAILURE); }//初始化glfwInit()
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);//指定版本
//指定了窗口的宽、高(以像素为单位)以及窗口顶部的标题,后面两个参数为“全屏显示”“资源共享”
GLFWwindow* window = glfwCreateWindow(600, 600, "窗口设置", NULL, NULL);
//将窗口与当前OpenGL上下文关联起来
glfwMakeContextCurrent(window);
if (glewInit() != GLEW_OK) { exit(EXIT_FAILURE); }//初始化glewInit()
glfwSwapInterval(1);
init(window);
while (!glfwWindowShouldClose(window)) {
display(window, glfwGetTime());//glfwGetTime()返回GLFW初始化之后经过的时间
glfwSwapBuffers(window);//绘制屏幕
glfwPollEvents();//处理窗口相关事件
}
glfwDestroyWindow(window);//销毁窗口
glfwTerminate();//终止运行
exit(EXIT_SUCCESS);
}