OpenGL中最简单的窗体创建和渲染(初始化GLFW、GLAD、定义视口大小和resize回调、双层缓冲、输入事件处理)

窗口的创建

初始化GLFW并进行配置

GLFW的配置说明

#include <glad/glad.h>
#include <glfw3.h>

//must include GLAD before GLFW. The include file for GLAD includes the required OpenGL headers(GL/gl.h ... )

int main() {
   
	glfwInit(); //initialize GLFW
	//configure the options prefixed with GLFW_
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	return 0;
}

步骤:

  1. 初始化glfw
  2. 声明我们使用的OpenGL的最大和最小版本都为3
  3. 指明使用core-profile(只使用OpenGL特性的子集,没有向后兼容的功能)

要保证OpenGL是3.3版本以上的,查看OpenGL版本的软件

创建窗口对象

创建的窗口对象容纳了所有的窗口数据(初始化之后的代码段)。

	GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL_0_Start", NULL, NULL);//window witdth,height,name
	if (window == NULL) {
   
		cout << "create window failed" << endl;
		glfwTerminate();
		return -1;
	}
	//tell GLFW to make the context of our window the main context on the current threaed
	glfwMakeContextCurrent(window);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值