【深圳大学计算机图形学】期末大作业 虚拟场景建模
在本次实验中,综合了这学期学过的众多知识,包括层级建模,图形绘制,物体绘制,阴影绘制添加纹理,键盘控制,场景交互,相机转动等,所含知识点和实验操作非常多。通过本次实验,更加熟悉了此前不太掌握的纹理绘制和层级建模原理,此外最大的收益在于更深入了解了计算机图形学的原理,熟悉了OpenGL下的基本框架,学会该如何利用计算机进行包含众多物体的场景绘制以及交互控制物体。层级建模的最深层次需要达到至少四层。参
目录
实验内容
在屏幕上显示一个包含多个虚拟物体的虚拟场景,并且响应一定的用户交互操作。如以下例图:
实验要求
1. 场景设计和显示
学生可以通过层级建模( 实验补充1和2)的方式建立多个虚拟物体,由多个虚拟物体组成一个虚拟场景,要求在程序中显示该虚拟场景,场景可以是室内或者室外场景;场景应包含地面。层级建模的最深层次需要达到至少四层。
2. 添加纹理
参考实验4.1,为场景中至少两个主要物体添加纹理贴图 。
3. 添加光照、材质、阴影效果
参考实验3.2,实验3.3和实验3.4,实现光照效果、材质、阴影等。
4. 用户交互实现视角切换完成对场景的任意角度浏览
参考实验3.1,完成相机变换。
5. 通过交互控制物体
参考实验2.3,实现物体的变换,允许用户通过键盘或者鼠标实现场景中至少两个物体的控制(移动,旋转,缩放等等)。
实验过程
1. 层级建模实现一个机器人,躯干->左上臂->左下臂->剑,达到了四层的层次,如下图所示。
2. 在层次建模中,利用层级树的方法进行遍历绘制多个长方体,最终拼成一个机器人。
按深度优先顺序,即 “躯干 -> 头 -> 左上臂 -> 左小臂 -> 剑 -> 右上臂 -> 右下臂 -> 左上腿 -> 左下腿 -> 右上腿 -> 右下腿”的顺序完成层级树的遍历,完成display()函数。
先分别实现物体各部位的绘制函数,如head(glm::mat4 modelMatrix)等,再根据上图树的思想,利用堆栈进行绘制。
3.先建立Robot结构体,存储相关参数。
4.新建变量,为后面绘制做好准备。
5.实现一系列函数,完成对身体各个部分的绘制。
6.在init函数中设置物体的大小(初始的旋转和位移都为0),并将物体的顶点数据传递。
7.在display函数中进行机器人的绘制。
8.设置操控机器人的按键。
[机器人控制选择]
1: 躯干
2: 头部
3: 左大臂
4: 左小臂
5: 右大臂
6: 右小臂
7: 左大腿
8: 左小腿
9: 右大腿
0: 右小腿
[机器人操作]
a/A: 增加旋转角度
s/S: 减小旋转角度
10.运行代码,操控机器人如图所示。
11.读取桌子模型并给其附加上红木纹理。
12.读取girl模型并给其附加上纹理。
13.读取lamp模型并附加上纹理。
14.运行代码,table、girl、lamp如下图所示。
15.创建长方形平面,并附加上木质纹理,作为木质地板。
16.运行代码,木质地板如下图所示。
17.将背景变为天蓝色,作为天空背景。
18.运行代码,如下图所示。
19.读取皮卡丘off模型。
20.设置根据按键切换不同的off模型。
[模型切换]
v/V: 切换为球体
b/B: 切换为牛
n/N: 切换为松鼠
m/M: 切换为皮卡丘
21.运行代码,如下图所示,按键可以切换不同的模型。
22.设置光源和阴影。
23.设置物体材质。
24.调用draw_obj函数绘制图像,将isShadow设置为0表示根据光照绘制,并传递光照和材质数据。
25. 调用draw_sha函数绘制阴影,确定投影矩阵,将isShadow设置为3表示黑色。
26.在display函数中绘制光照模型及阴影。
27.实现相机以及对视图的切换。
28.设置键盘快捷键进行操控。
[相机控制]
j/J: 顺时针旋转/逆时针旋转
k/K: 上移视角/下移视角
SPACE: 重置相机
29.运行代码,切换不同的视角进行观看。
30.添加操控功能,可以对不同的物体进行放大、缩小、前移、后移、左移、右移、顺时针旋转、逆时针旋转操作。
[物体控制选择]
u/U: 控制桌子
i/i: 控制女孩
o/O: 控制灯笼
p/P: 控制模型
[物体操作]
left: 左移
right: 右移
up: 前移
down: 后移
+/=: 变大
-/_: 变小
r/R: 顺时针旋转/逆时针旋转
31.运行代码,进行操控如下图所示。
32.添加光源控制功能,能够控制光源左移、右移、上移、下移、前移、后移。
[光源控制]
x/X: 光源左移/光源右移
y/Y: 光源下移/光源上移
z/Z: 光源前移/光源后移
33.运行代码,如下图所示。
34.添加用户交互界面说明,完善交互性,使得交互更易懂。
35.运行代码,如下图所示。
Bug解决
(1)中文输出失败,有中文时编译错误。
解决方法:更改文件格式为gbk。
(2)地板附加了木质纹理,在输出的时候,同样会有阴影产生。导致出现平面下半面有纹理,而上半面全黑色,即被阴影覆盖了,如下图所示。
解决方案:在绘制时添加一个信号变量,来决定是否要绘制阴影,以此使得地板不被绘制阴影。
实验结论
在本次实验中,综合了这学期学过的众多知识,包括层级建模,图形绘制,物体绘制,阴影绘制添加纹理,键盘控制,场景交互,相机转动等,所含知识点和实验操作非常多。要想顺利完成整个实验,需要扎实的基础知识,熟悉并实操此前所完成的各种实验并掌握原理,这样才能在自己的场景中灵活运用实现想要的效果。
通过本次实验,更加熟悉了此前不太掌握的纹理绘制和层级建模原理,此外最大的收益在于更深入了解了计算机图形学的原理,熟悉了OpenGL下的基本框架,学会该如何利用计算机进行包含众多物体的场景绘制以及交互控制物体。
实验代码
main.cpp
#include "Angel.h"
#include "TriMesh.h"
#include "Camera.h"
#include "MeshPainter.h"
#include <vector>
#include <string>
#include <algorithm>
#include <assert.h>
int WIDTH = 600;
int HEIGHT = 600;
int mainWindow;
class MatrixStack {
int _index;
int _size;
glm::mat4* _matrices;
public:
MatrixStack(int numMatrices = 100) :_index(0), _size(numMatrices)
{
_matrices = new glm::mat4[numMatrices];
}
~MatrixStack()
{
delete[]_matrices;
}
void push(const glm::mat4& m) {
assert(_index + 1 < _size);
_matrices[_index++] = m;
}
glm::mat4& pop() {
assert(_index - 1 >= 0);
_index--;
return _matrices[_index];
}
};
#define White glm::vec3(1.0, 1.0, 1.0)
#define Yellow glm::vec3(1.0, 1.0, 0.0)
#define Green glm::vec3(0.0, 1.0, 0.0)
#define Cyan glm::vec3(0.0, 1.0, 1.0)
#define Magenta glm::vec3(1.0, 0.0, 1.0)
#define Red glm::vec3(1.0, 0.0, 0.0)
#define Black glm::vec3(0.0, 0.0, 0.0)
#define Blue glm::vec3(0.0, 0.0, 1.0)
#define Brown glm::vec3(0.5, 0.5, 0.5)
#define Purple glm::vec3(0.5, 0.0, 0.5)
#define sky glm::vec3(0.4, 0.77, 1.0)
struct Robot
{
// 关节大小
float TORSO_HEIGHT = 4.0 * 0.1;
float TORSO_WIDTH = 2.5 * 0.1;
float UPPER_ARM_HEIGHT = 2.5 * 0.1;
float LOWER_ARM_HEIGHT = 1.8 * 0.1;
float UPPER_ARM_WIDTH = 0.8 * 0.1;
float LOWER_ARM_WIDTH = 0.5 * 0.1;
float UPPER_LEG_HEIGHT = 2.8 * 0.1;
float LOWER_LEG_HEIGHT = 2.2 * 0.1;
float UPPER_LEG_WIDTH = 1.0 * 0.1;
float LOWER_LEG_WIDTH = 0.5 * 0.1;
float HEAD_HEIGHT = 1.8 * 0.1;
float HEAD_WIDTH = 1.5 * 0.1;
// 关节角和菜单选项值
enum {
Torso, // 躯干
Head, // 头部
RightUpperArm, // 右大臂
RightLowerArm, // 右小臂
LeftUpperArm, // 左大臂
LeftLowerArm, // 左小臂
RightUpperLeg, // 右大腿
RightLowerLeg, // 右小腿
LeftUpperLeg, // 左大腿
LeftLowerLeg, // 左小腿
left_sword,
};
// 关节角大小
GLfloat theta[10] = {
0.0, // Torso
0.0, // Head
0.0, // RightUpperArm
0.0, // RightLowerArm
0.0, // LeftUpperArm
0.0, // LeftLowerArm
0.0, // RightUpperLeg
0.0, // RightLowerLeg
0.0, // LeftUpperLeg
0.0 // LeftLowerLeg
};
};
Robot robot;
// 被选中的物体
int Selected_mesh = robot.Torso;
TriMesh* Torso = new TriMesh();
TriMesh* Head = new TriMesh();
TriMesh* RightUpperArm = new TriMesh();
TriMesh* RightLowerArm = new TriMesh();
TriMesh* LeftUpperArm = new TriMesh();
TriMesh* LeftLowerArm = new TriMesh();
TriMesh* RightUpperLeg = new TriMesh();
TriMesh* RightLowerLeg = new TriMesh();
TriMesh* LeftUpperLeg = new TriMesh();
TriMesh* LeftLowerLeg = new TriMesh();
TriMesh* left_sword = new TriMesh();
openGLObject TorsoObject;
openGLObject HeadObject;
openGLObject RightUpperArmObject;
openGLObject RightLowerArmObject;
openGLObject LeftUpperArmObject;
openGLObject LeftLowerArmObject;
openGLObject RightUpperLegObject;
openGLObject RightLowerLegObject;
openGLObject LeftUpperLegObject;
openGLObject LeftLowerLegObject;
openGLObject left_sword_Object;
openGLObject mesh_object;
openGLObject plane_object;
TriMesh* table = new TriMesh();
TriMesh* girl = new TriMesh();
TriMesh* lamp = new TriMesh();
TriMesh* plane = new TriMesh();
TriMesh* mesh = new TriMesh();
Camera* camera = new Camera();
Light* light = new Light();
MeshPainter* painter = new MeshPainter();
MeshPainter* plane_painter = new MeshPainter();
glm::vec3 light_position;
float move_step_size = 0.2;
// 获取生成的所有模型,用于结束程序时释放内存
std::vector<TriMesh*> meshList;
void draw_sha(TriMesh* m, openGLObject& mesh_object, int sha);
void bindLightAndMaterial(TriMesh* mesh, openGLObject& object, Light* light, Camera* camera);
void drawMesh(glm::mat4 modelMatrix, TriMesh* mesh, openGLObject object) {
glBindVertexArray(object.vao);
glUseProgram(object.program);
// 父节点矩阵 * 本节点局部变换矩阵
glUniformMatrix4fv(object.modelLocation, 1, GL_FALSE, &modelMatrix[0][0]);
glUniformMatrix4fv(object.viewLocation, 1, GL_TRUE, &camera->viewMatrix[0][0]);
glUniformMatrix4fv(object.projectionLocation, 1, GL_TRUE, &camera->projMatrix[0][0]);
glUniform1i(object.shadowLocation, 0);
bindLightAndMaterial(mesh, object, light, camera);
// 绘制
glDrawArrays(GL_TRIANGLES, 0, mesh->getPoints().size());
// 根据光源位置,计算阴影投影矩阵
light_position = light->getTranslation();
float lx = light_position[0];
float ly = light_position[1];
float lz = light_position[2];
glm::mat4 shadowProjMatrix(
-ly, 0.0, 0.0, 0.0,
lx, 0.0, lz, 1.0,
0.0, 0.0, -ly, 0.0,
0.0, 0.0, 0.0, -ly);
// 计算阴影的模型变换矩阵。
modelMatrix = shadowProjMatrix * modelMatrix;
// 传递 isShadow 变量,1表示黑色。
glUniform1i(object.shadowLocation, 1);
// 传递 unifrom 关键字的矩阵数据。
glUniformMatrix4fv(object.modelLocation, 1, GL_FALSE, &modelMatrix[0][0]);
// 绘制
glDrawArrays(GL_TRIANGLES, 0, mesh->getPoints().size());
}
// 躯体
void torso(glm::mat4 modelMatrix)
{
// 本节点局部变换矩阵
glm::mat4 instance = glm::mat4(1.0);
instance = glm::translate(instance, glm::vec3(0.0, 0.5 * robot.TORSO_HEIGHT, 0.0));
instance = glm::scale(instance, glm::vec3(robot.TORSO_WIDTH, robot.TORSO_HEIGHT, robot.TORSO_WIDTH));
// 乘以来自父物体的模型变换矩阵,绘制当前物体
drawMesh(modelMatrix * instance, Torso, TorsoObject);
}
// 头部
void head(glm::mat4 modelMatrix)
{
// 本节点局部变换矩阵
glm::mat4 instance = glm::mat4(1.0);
instance = glm::translate(instance, glm::vec3(0.0, 0.5 * robot.HEAD_HEIGHT, 0.0));
instance = glm::scale(instance, glm::vec3(robot.HEAD_WIDTH, robot.HEAD_HEIGHT, robot.HEAD_WIDTH));
// 乘以来自父物体的模型变换矩阵,绘制当前物体
drawMesh(modelMatrix * instance, Head, HeadObject);
}
// 左大臂
void left_upper_arm(glm::mat4 modelMatrix)
{
// 本节点局部变换矩阵
glm::mat4 instance = glm::mat4(1.0);
instance = glm::translate(instance, glm::vec3(0.0, -0.5 * robot.UPPER_ARM_HEIGHT, 0.0));
instance = glm::scale(instance, glm::vec3(robot.UPPER_ARM_WIDTH, robot.UPPER_ARM_HEIGHT, robot.UPPER_ARM_WIDTH));
// 乘以来自父物体的模型变换矩阵,绘制当前物体
drawMesh(modelMatrix * instance, LeftUpperArm, LeftUpperArmObject);
}
// @TODO: 左小臂
void left_lower_arm(glm::mat4 modelMatrix)
{
// 本节点局部变换矩阵
glm::mat4 instance = glm::mat4(1.0);
instance = glm::translate(instance, glm::vec3(0.0, -0.5 * robot.LOWER_ARM_HEIGHT, 0.0));
instance = glm::scale(instance, glm::vec3(robot.LOWER_ARM_WIDTH, robot.LOWER_ARM_HEIGHT, robot.LOWER_ARM_WIDTH));
// 乘以来自父物体的模型变换矩阵,绘制当前物体
drawMesh(modelMatrix * instance, LeftLowerArm, LeftLowerArmObject);
}
// 圆柱体
void draw_left_sword(glm::mat4 modelMatrix)
{
// 本节点局部变换矩阵
glm::mat4 instance = glm::mat4(1.0);
instance = glm::translate(instance, glm::vec3(0.0, 0.1, 0.15));
instance = glm::scale(instance, glm::vec3(0.03, 0.03, 0.4));
// 乘以来自父物体的模型变换矩阵,绘制当前物体
drawMesh(modelMatrix * instance, left_sword, left_sword_Object);
}
// @TODO: 右大臂
void right_upper_arm(glm::mat4 modelMatrix)
{
// 本节点局部变换矩阵
glm::mat4 instance = glm::mat4(1.0);
instance = glm::translate(instance, glm::vec3(0.0, -0.5 * robot.UPPER_ARM_HEIGHT, 0.0));
instance = glm::scale(instance, glm::vec3(robot.UPPER_ARM_WIDTH, robot.UPPER_ARM_HEIGHT, robot.UPPER_ARM_WIDTH));
// 乘以来自父物体的模型变换矩阵,绘制当前物体
drawMesh(modelMatrix * instance, RightUpperArm, RightUpperArmObject);
}
// @TODO: 右小臂
void right_lower_arm(glm::mat4 modelMatrix)
{
// 本节点局部变换矩阵
glm::mat4 instance = glm::mat4(1.0);
instance = glm::translate(instance, glm::vec3(0.0, -0.5 * robot.LOWER_ARM_HEIGHT, 0.0));
instance = glm::scale(instance, glm::vec3(robot.LOWER_ARM_WIDTH, robot.LOWER_ARM_HEIGHT, robot.LOWER_ARM_WIDTH));
// 乘以来自父物体的模型变换矩阵,绘制当前物体
drawMesh(modelMatrix * instance, RightLowerArm, RightLowerArmObject);
}
// @TODO: 左大腿
void left_upper_leg(glm::mat4 modelMatrix)
{
// 本节点局部变换矩阵
glm::mat4 instance = glm::mat4(1.0);
instance = glm::translate(instance, glm::vec3(0.0, -0.5 * robot.UPPER_LEG_HEIGHT, 0.0));
instance = glm::scale(instance, glm::vec3(robot.UPPER_LEG_WIDTH, robot.UPPER_LEG_HEIGHT, robot.UPPER_LEG_WIDTH));
// 乘以来自父物体的模型变换矩阵,绘制当前物体
drawMesh(modelMatrix * instance, LeftUpperLeg, LeftUpperLegObject);
}
// @TODO: 左小腿
void left_lower_leg(glm::mat4 modelMatrix)
{
// 本节点局部变换矩阵
glm::mat4 instance = glm::mat4(1.0);
instance = glm::translate(instance, glm::vec3(0.0, -0.5 * robot.LOWER_LEG_HEIGHT, 0.0));
instance = glm::scale(instance, glm::vec3(robot.LOWER_LEG_WIDTH, robot.LOWER_LEG_HEIGHT, robot.LOWER_LEG_WIDTH));
// 乘以来自父物体的模型变换矩阵,绘制当前物体
drawMesh(modelMatrix * instance, LeftLowerLeg, LeftLowerLegObject);
}
// @TODO: 右大腿
void right_upper_leg(glm::mat4 modelMatrix)
{
// 本节点局部变换矩阵
glm::mat4 instance = glm::mat4(1.0);
instance = glm::translate(instance, glm::vec3(0.0, -0.5 * robot.UPPER_LEG_HEIGHT, 0.0));
instance = glm::scale(instance, glm::vec3(robot.UPPER_LEG_WIDTH, robot.UPPER_LEG_HEIGHT, robot.UPPER_LEG_WIDTH));
// 乘以来自父物体的模型变换矩阵,绘制当前物体
drawMesh(modelMatrix * instance, RightUpperLeg, RightUpperLegObject);
}
// @TODO: 右小腿
void right_lower_leg(glm::mat4 modelMatrix)
{
// 本节点局部变换矩阵
glm::mat4 instance = glm::mat4(1.0);
instance = glm::translate(instance, glm::vec3(0.0, -0.5 * robot.LOWER_LEG_HEIGHT, 0.0));
instance = glm::scale(instance, glm::vec3(robot.LOWER_LEG_WIDTH, robot.LOWER_LEG_HEIGHT, robot.LOWER_LEG_WIDTH));
// 乘以来自父物体的模型变换矩阵,绘制当前物体
drawMesh(modelMatrix * instance, RightLowerLeg, RightLowerLegObject);
}
void bindObjectAndData(TriMesh* mesh, openGLObject& object, const std::string& vshader, const std::string& fshader) {
// 创建顶点数组对象
glGenVertexArrays(1, &object.vao); // 分配1个顶点数组对象
glBindVertexArray(object.vao); // 绑定顶点数组对象
// 创建并初始化顶点缓存对象
glGenBuffers(1, &object.vbo);
glBindBuffer(GL_ARRAY_BUFFER, object.vbo);
glBufferData(GL_ARRAY_BUFFER,
(mesh->getPoints().size() + mesh->getColors().size() + mesh->getNormals().size()) * sizeof(glm::vec3),
NULL,
GL_STATIC_DRAW);
// 修改完TriMesh.cpp的代码成后再打开下面注释,否则程序会报错
glBufferSubData(GL_ARRAY_BUFFER, 0, mesh->getPoints().size() * sizeof(glm::vec3), &mesh->getPoints()[0]);
glBufferSubData(GL_ARRAY_BUFFER, mesh->getPoints().size() * sizeof(glm::vec3), mesh->getColors().size() * sizeof(glm::vec3), &mesh->getColors()[0]);
glBufferSubData(GL_ARRAY_BUFFER, (mesh->getPoints().size() + mesh->getColors().size()) * sizeof(glm::vec3), mesh->getNormals().size() * sizeof(glm::vec3), &mesh->getNormals()[0]);
object.vshader = vshader;
object.fshader = fshader;
object.program = InitShader(object.vshader.c_str(), object.fshader.c_str());
// 从顶点着色器中初始化顶点的坐标
object.pLocation = glGetAttribLocation(object.program, "vPosition");
glEnableVertexAttribArray(object.pLocation);
glVertexAttribPointer(object.pLocation, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
// 从顶点着色器中初始化顶点的颜色
object.cLocation = glGetAttribLocation(object.program, "vColor");
glEnableVertexAttribArray(object.cLocation);
glVertexAttribPointer(object.cLocation, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(mesh->getPoints().size() * sizeof(glm::vec3)));
// 从顶点着色器中初始化顶点的法向量
object.nLocation = glGetAttribLocation(object.program, "vNormal");
glEnableVertexAttribArray(object.nLocation);
glVertexAttribPointer(object.nLocation, 3,
GL_FLOAT, GL_FALSE, 0,
BUFFER_OFFSET((mesh->getPoints().size() + mesh->getColors().size()) * sizeof(glm::vec3)));
// 获得矩阵位置
object.modelLocation = glGetUniformLocation(object.program, "model");
object.viewLocation = glGetUniformLocation(object.program, "view");
object.projectionLocation = glGetUniformLocation(object.program, "projection");
object.shadowLocation = glGetUniformLocation(object.program, "isShadow");
}
void bindLightAndMaterial(TriMesh* mesh, openGLObject& object, Light* light, Camera* camera) {
// 传递相机的位置
glUniform3fv(glGetUniformLocation(object.program, "eye_position"), 1, &camera->eye[0]);
// 传递物体的材质
glm::vec4 meshAmbient = mesh->getAmbient();
glm::vec4 meshDiffuse = mesh->getDiffuse();
glm::vec4 meshSpecular = mesh->getSpecular();
float meshShininess = mesh->getShininess();
glUniform4fv(glGetUniformLocation(object.program, "material.ambient"), 1, &meshAmbient[0]);
glUniform4fv(glGetUniformLocation(object.program, "material.diffuse"), 1, &meshDiffuse[0]);
glUniform4fv(glGetUniformLocation(object.program, "material.specular"), 1, &meshSpecular[0]);
glUniform1f(glGetUniformLocation(object.program, "material.shininess"), meshShininess);
// 传递光源信息
glm::vec4 lightAmbient = light->getAmbient();
glm::vec4 lightDiffuse = light->getDiffuse();
glm::vec4 lightSpecular = light->getSpecular();
glm::vec3 lightPosition = light->getTranslation();
glUniform4fv(glGetUniformLocation(object.program, "light.ambient"), 1, &lightAmbient[0]);
glUniform4fv(glGetUniformLocation(object.program, "light.diffuse"), 1, &lightDiffuse[0]);
glUniform4fv(glGetUniformLocation(object.program, "light.specular"), 1, &lightSpecular[0]);
glUniform3fv(glGetUniformLocation(object.program, "light.position"), 1, &lightPosition[0]);
}
void mesh_init() {
std::string vshader, fshader;
// 读取着色器并使用
vshader = "shaders/vshader.glsl";
fshader = "shaders/fshader.glsl";
// 设置物体的旋转位移
mesh->setTranslation(glm::vec3(0.9, 0.34, 0.0));
mesh->setRotation(glm::vec3(0.0, -90.0, 0.0));
mesh->setScale(glm::vec3(1.0, 1.0, 1.0));
// 设置材质
mesh->setAmbient(glm::vec4(0.2, 0.2, 0.2, 1.0)); // 环境光
mesh->setDiffuse(glm::vec4(0.7, 0.7, 0.7, 1.0)); // 漫反射
mesh->setSpecular(glm::vec4(0.2, 0.2, 0.2, 1.0)); // 镜面反射
mesh->setShininess(1.0); //高光系数
// 将物体的顶点数据传递
bindObjectAndData(mesh, mesh_object, vshader, fshader);
}
void init()
{
std::string vshader, fshader;
// 读取着色器并使用
vshader = "shaders/vshader.glsl";
fshader = "shaders/fshader.glsl";
// 设置光源位置
light->setTranslation(glm::vec3(-5.0, 15.0, 10.0));
light->setAmbient(glm::vec4(1.0, 1.0, 1.0, 1.0)); // 环境光
light->setDiffuse(glm::vec4(1.0, 1.0, 1.0, 1.0)); // 漫反射
light->setSpecular(glm::vec4(1.0, 1.0, 1.0, 1.0)); // 镜面反射
light->setAttenuation(1.0, 0.045, 0.0075); // 衰减系数
// 设置物体纹理
// @TODO: Task2 读取桌子模型
table->setNormalize(true);
table->readObj("./assets/table.obj");
// 设置物体的旋转位移
table->setTranslation(glm::vec3(0.0, 0.23, 0.0));
table->setRotation(glm::vec3(-90.0, 0.0, 0.0));
table->setScale(glm::vec3(1.0, 1.0, 1.0));
// 加到painter中
//painter->addMesh(table, "mesh_a", "./assets/table.png", vshader, fshader); // 指定纹理与着色器
painter->addMesh(table, "mesh_a", "./assets/cat/table.png", vshader, fshader); // 指定纹理与着色器
// 我们创建的这个加入一个容器内,为了程序结束时将这些数据释放
meshList.push_back(table);
// 读取girl模型
girl->setNormalize(true);
//sword->readObj("./assets/chr_sword/chr_sword.obj");
//sword->readObj("./assets/cat/cat.obj");
girl->readObj("./assets/cat/cat2.obj");
// 设置物体的旋转位移
girl->setTranslation(glm::vec3(0.0, 0.45, -0.85));
girl->setRotation(glm::vec3(0.0, 0.0, 0.0));
girl->setScale(glm::vec3(1.0, 1.0, 1.0));
// 设置材质
girl->setAmbient(glm::vec4(0.60f, 0.60f, 0.60f, 1.0f)); // 环境光
girl->setDiffuse(glm::vec4(1.700f, 1.700f, 1.700f, 1.0f)); // 漫反射
girl->setSpecular(glm::vec4(0.000f, 0.000f, 0.000f, 1.0f)); // 镜面反射
girl->setShininess(1.0f); //高光系数
// 使用默认颜色填充模型
//glm::vec3 defaultColor = glm::vec3(0.7, 0.7, 0.7); // 设置默认颜色
//sword->generateCube(defaultColor);
// 加到painter中
//painter->addMesh(sword, "mesh_b", "./assets/chr_sword/chr_sword.png", vshader, fshader);
/*painter->addMesh(sword, "mesh_b1", "./assets/cat/1.png", vshader, fshader);
painter->addMesh(sword, "mesh_b2", "./assets/cat/2.png", vshader, fshader);
painter->addMesh(sword, "mesh_b3", "./assets/cat/3.png", vshader, fshader);
painter->addMesh(sword, "mesh_b4", "./assets/cat/4.png", vshader, fshader);
painter->addMesh(sword, "mesh_b5", "./assets/cat/5.png", vshader, fshader);
painter->addMesh(sword, "mesh_b6", "./assets/cat/6.png", vshader, fshader);*/
painter->addMesh(girl, "mesh_b7", "./assets/cat/cat2.png", vshader, fshader);
//painter->addMesh(sword, "mesh_b7", "./assets/disk.jpg", vshader, fshader);
// 我们创建的这个加入一个容器内,为了程序结束时将这些数据释放
meshList.push_back(girl);
// 读取lamp模型
lamp->setNormalize(true);
//wawa->readObj("./assets/wawa.obj");
lamp->readObj("./assets/cat/lamp.obj");
// 设置物体的旋转位移
lamp->setTranslation(glm::vec3(-0.85, 0.42, 0.0));
lamp->setRotation(glm::vec3(180.0, 0.0, 0.0));
lamp->setScale(glm::vec3(1.0, 1.0, 1.0));
// 设置材质
lamp->setAmbient(glm::vec4(0.2, 0.2, 0.2, 1.0)); // 环境光
lamp->setDiffuse(glm::vec4(0.7, 0.7, 0.7, 1.0)); // 漫反射
lamp->setSpecular(glm::vec4(0.2, 0.2, 0.2, 1.0)); // 镜面反射
lamp->setShininess(100.0); //高光系数
// 加到painter中
//painter->addMesh(wawa, "mesh_c", "./assets/wawa.png", vshader, fshader);
painter->addMesh(lamp, "mesh_c", "./assets/cat/lamp.png", vshader, fshader);
// 我们创建的这个加入一个容器内,为了程序结束时将这些数据释放
meshList.push_back(lamp);
mesh_init();
// 创建长方形平面,给它一个其他颜色
//plane->generateSquare(glm::vec3(0.6, 0.8, 0.0));
plane->generateSquare(Purple);
// 设置正方形的位置和旋转,注意这里我们将正方形平面下移了一点点距离,
// 这是为了防止和阴影三角形重叠在同个平面上导致颜色交叉
plane->setRotation(glm::vec3(90, 0, 0));
plane->setTranslation(glm::vec3(0, -0.01, 0));
plane->setScale(glm::vec3(4, 4, 4));
//plane->setScale(glm::vec3(1,1,1));
// 设置材质
//plane->setAmbient(glm::vec4(0.329412f, 0.223529f, 0.027451f, 1.0f)); // 环境光
//plane->setDiffuse(glm::vec4(0.780392f, 0.568627f, 0.113725f, 1.0f)); // 漫反射
//plane->setSpecular(glm::vec4(0.992157f, 0.941176f, 0.807843f, 1.0f)); // 镜面反射
//plane->setShininess(27.8974f); //高光系数
// 加到plane_painter中
plane_painter->addMesh(plane, "mesh_plane", "./assets/cat/egg.png", vshader, fshader);
//bindObjectAndData(plane, plane_object, vshader, fshader);
fshader = "shaders/fshader_1.glsl";
// 设置物体的大小(初始的旋转和位移都为0)
Torso->setNormalize(true);
Head->setNormalize(true);
RightUpperArm->setNormalize(true);
LeftUpperArm->setNormalize(true);
RightUpperLeg->setNormalize(true);
LeftUpperLeg->setNormalize(true);
RightLowerArm->setNormalize(true);
LeftLowerArm->setNormalize(true);
RightLowerLeg->setNormalize(true);
LeftLowerLeg->setNormalize(true);
left_sword->setNormalize(true);
Torso->generateCube(Blue);
Head->generateCube(Green);
RightUpperArm->generateCube(Yellow);
LeftUpperArm->generateCube(Yellow);
RightUpperLeg->generateCube(Brown);
LeftUpperLeg->generateCube(Brown);
RightLowerArm->generateCube(Red);
LeftLowerArm->generateCube(Red);
RightLowerLeg->generateCube(Cyan);
LeftLowerLeg->generateCube(Cyan);
left_sword->generateCube(Purple);
// 将物体的顶点数据传递
bindObjectAndData(Torso, TorsoObject, vshader, fshader);
bindObjectAndData(Head, HeadObject, vshader, fshader);
bindObjectAndData(RightUpperArm, RightUpperArmObject, vshader, fshader);
bindObjectAndData(LeftUpperArm, LeftUpperArmObject, vshader, fshader);
bindObjectAndData(RightUpperLeg, RightUpperLegObject, vshader, fshader);
bindObjectAndData(LeftUpperLeg, LeftUpperLegObject, vshader, fshader);
bindObjectAndData(RightLowerArm, RightLowerArmObject, vshader, fshader);
bindObjectAndData(LeftLowerArm, LeftLowerArmObject, vshader, fshader);
bindObjectAndData(RightLowerLeg, RightLowerLegObject, vshader, fshader);
bindObjectAndData(LeftLowerLeg, LeftLowerLegObject, vshader, fshader);
bindObjectAndData(left_sword, left_sword_Object, vshader, fshader);
//glClearColor(135.0f / 255.0f, 206.0f / 255.0f, 250.0f / 255.0f, 1.0);
glClearColor(0.4,0.77,1.0, 1.0);
}
void draw_obj(TriMesh* mesh, openGLObject& mesh_object, int a) {
glm::mat4 modelMatrix;
// 绘制光照物体
glBindVertexArray(mesh_object.vao);
glUseProgram(mesh_object.program);
modelMatrix = mesh->getModelMatrix();
glUniformMatrix4fv(mesh_object.modelLocation, 1, GL_FALSE, &modelMatrix[0][0]);
glUniformMatrix4fv(mesh_object.viewLocation, 1, GL_TRUE, &camera->viewMatrix[0][0]);
glUniformMatrix4fv(mesh_object.projectionLocation, 1, GL_TRUE, &camera->projMatrix[0][0]);
// 将isShadow设置为a,根据传入的参数绘制
glUniform1i(mesh_object.shadowLocation, a);
bindLightAndMaterial(mesh, mesh_object, light, camera);
glDrawArrays(GL_TRIANGLES, 0, mesh->getPoints().size());
}
void draw_sha(TriMesh* m, openGLObject& mesh_object, int sha) {
// 根据光源位置,计算阴影投影矩阵
light_position = light->getTranslation();
float lx = light_position[0];
float ly = light_position[1];
float lz = light_position[2];
glm::mat4 shadowProjMatrix(
-ly, 0.0, 0.0, 0.0,
lx, 0.0, lz, 1.0,
0.0, 0.0, -ly, 0.0,
0.0, 0.0, 0.0, -ly);
// 计算阴影的模型变换矩阵。
glm::mat4 modelMatrix = m->getModelMatrix();
modelMatrix = shadowProjMatrix * modelMatrix;
// 传递 isShadow 变量,3表示黑色。
glUniform1i(mesh_object.shadowLocation, sha);
// 传递 unifrom 关键字的矩阵数据。
glUniformMatrix4fv(mesh_object.modelLocation, 1, GL_FALSE, &modelMatrix[0][0]);
// 绘制
glDrawArrays(GL_TRIANGLES, 0, m->getPoints().size());
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// 相机矩阵计算
camera->updateCamera();
camera->viewMatrix = camera->getViewMatrix();
camera->projMatrix = camera->getProjectionMatrix(true);
// 绘制一系列带纹理物体
painter->drawMeshes(light, camera,1);
plane_painter->drawMeshes(light, camera,-1);
// 绘制平面
//draw_obj(plane, plane_object, 1);
// 绘制光照模型及阴影
draw_obj(mesh, mesh_object, 0);
draw_sha(mesh, mesh_object, 3);
// 物体的变换矩阵
glm::mat4 modelMatrix;
modelMatrix = glm::mat4(1.0);
// 保持变换矩阵的栈
MatrixStack mstack;
// 躯干(这里我们希望机器人的躯干只绕Y轴旋转,所以只计算了RotateY)
modelMatrix = glm::translate(modelMatrix, glm::vec3(0.0, 0.5, 0.7));
modelMatrix = glm::rotate(modelMatrix, glm::radians(robot.theta[robot.Torso]), glm::vec3(0.0, 1.0, 0.0));
torso(modelMatrix);
mstack.push(modelMatrix); // 保存躯干变换矩阵
// 头部(这里我们希望机器人的头部只绕Y轴旋转,所以只计算了RotateY)
modelMatrix = glm::translate(modelMatrix, glm::vec3(0.0, robot.TORSO_HEIGHT, 0.0));
modelMatrix = glm::rotate(modelMatrix, glm::radians(robot.theta[robot.Head]), glm::vec3(0.0, 1.0, 0.0));
head(modelMatrix);
modelMatrix = mstack.pop(); // 恢复躯干变换矩阵
// =========== 左臂 ===========
mstack.push(modelMatrix); // 保存躯干变换矩阵
// 左大臂(这里我们希望机器人的左大臂只绕X轴旋转,所以只计算了RotateX,后面同理)
modelMatrix = glm::translate(modelMatrix, glm::vec3(-0.5 * robot.TORSO_WIDTH - 0.5 * robot.UPPER_ARM_WIDTH, robot.TORSO_HEIGHT, 0.0));
modelMatrix = glm::rotate(modelMatrix, glm::radians(robot.theta[robot.LeftUpperArm]), glm::vec3(1.0, 0.0, 0.0));
left_upper_arm(modelMatrix);
// @TODO: 左小臂
modelMatrix = glm::translate(modelMatrix, glm::vec3(0.0, -robot.UPPER_ARM_HEIGHT, 0.0));
modelMatrix = glm::rotate(modelMatrix, glm::radians(robot.theta[robot.LeftLowerArm]), glm::vec3(1.0, 0.0, 0.0));
left_lower_arm(modelMatrix);
// 长方体
modelMatrix = glm::translate(modelMatrix, glm::vec3(0.0, -robot.UPPER_ARM_HEIGHT, 0.0));
modelMatrix = glm::rotate(modelMatrix, glm::radians(robot.theta[robot.left_sword]), glm::vec3(0.0, 1.0, 0.0));
draw_left_sword(modelMatrix);
modelMatrix = mstack.pop(); // 恢复躯干变换矩阵
// =========== 右臂 ===========
mstack.push(modelMatrix); // 保存躯干变换矩阵
// @TODO: 右大臂
modelMatrix = glm::translate(modelMatrix, glm::vec3(0.5 * robot.TORSO_WIDTH + 0.5 * robot.UPPER_ARM_WIDTH, robot.TORSO_HEIGHT, 0.0));
modelMatrix = glm::rotate(modelMatrix, glm::radians(robot.theta[robot.RightUpperArm]), glm::vec3(1.0, .0, 0.0));
right_upper_arm(modelMatrix);
// @TODO: 右小臂
modelMatrix = glm::translate(modelMatrix, glm::vec3(0.0, -robot.UPPER_ARM_HEIGHT, 0.0));
modelMatrix = glm::rotate(modelMatrix, glm::radians(robot.theta[robot.RightLowerArm]), glm::vec3(1.0, 0.0, 0.0));
right_lower_arm(modelMatrix);
modelMatrix = mstack.pop(); // 恢复躯干变换矩阵
// =========== 左腿 ===========
mstack.push(modelMatrix); // 保存躯干变换矩阵
// @TODO: 左大腿
modelMatrix = glm::translate(modelMatrix, glm::vec3(-0.35 * robot.TORSO_WIDTH, 0.0, 0.0));
modelMatrix = glm::rotate(modelMatrix, glm::radians(robot.theta[robot.LeftUpperLeg]), glm::vec3(1.0, 0.0, 0.0));
left_upper_leg(modelMatrix);
// @TODO: 左小腿
modelMatrix = glm::translate(modelMatrix, glm::vec3(0.0, -robot.UPPER_LEG_HEIGHT, 0.0));
modelMatrix = glm::rotate(modelMatrix, glm::radians(robot.theta[robot.LeftLowerLeg]), glm::vec3(1.0, 0.0, 0.0));
left_lower_leg(modelMatrix);
modelMatrix = mstack.pop(); // 恢复躯干变换矩阵
// =========== 右腿 ===========
mstack.push(modelMatrix); // 保存躯干变换矩阵
// @TODO: 右大腿
modelMatrix = glm::translate(modelMatrix, glm::vec3(0.35 * robot.TORSO_WIDTH, 0.0, 0.0));
modelMatrix = glm::rotate(modelMatrix, glm::radians(robot.theta[robot.RightUpperLeg]), glm::vec3(1.0, 0.0, 0.0));
right_upper_leg(modelMatrix);
// @TODO: 右小腿
modelMatrix = glm::translate(modelMatrix, glm::vec3(0.0, -robot.UPPER_LEG_HEIGHT, 0.0));
modelMatrix = glm::rotate(modelMatrix, glm::radians(robot.theta[robot.RightLowerLeg]), glm::vec3(1.0, 0.0, 0.0));
right_lower_leg(modelMatrix);
modelMatrix = mstack.pop(); // 恢复躯干变换矩阵
}
void printHelp()
{
std::cout << "=========================按键介绍==============================" << std::endl << std::endl;
//std::cout << "按键介绍" << std::endl;
std::cout <<
" [窗口控制]" << std::endl <<
" ESC: 退出" << std::endl <<
std::endl <<
//" [机器人控制]" << std::endl <<
" [机器人控制选择]" << std::endl <<
" 1: 躯干" << std::endl <<
" 2: 头部" << std::endl <<
" 3: 左大臂" << std::endl <<
" 4: 左小臂" << std::endl <<
" 5: 右大臂" << std::endl <<
" 6: 右小臂" << std::endl <<
" 7: 左大腿" << std::endl <<
" 8: 左小腿" << std::endl <<
" 9: 右大腿" << std::endl <<
" 0: 右小腿" << std::endl <<std::endl<<
" [机器人操作]" << std::endl <<
" a/A: 增加旋转角度" << std::endl <<
" s/S: 减小旋转角度" << std::endl <<
std::endl <<
" [模型切换]" << std::endl <<
" v/V: 切换为球体" << std::endl <<
" b/B: 切换为牛" << std::endl <<
" n/N: 切换为松鼠" << std::endl <<
" m/M: 切换为皮卡丘" << std::endl <<
std::endl <<
" [物体控制选择]" << std::endl <<
" u/U: 控制桌子" << std::endl <<
" i/i: 控制女孩" << std::endl <<
" o/O: 控制灯笼" << std::endl <<
" p/P: 控制模型" << std::endl << std::endl <<
" [物体操作]" << std::endl <<
" left: 左移" << std::endl <<
" right: 右移" << std::endl <<
" up: 前移" << std::endl <<
" down: 后移" << std::endl <<
" +/=: 变大" << std::endl <<
" -/_: 变小" << std::endl <<
" r/R: 顺时针旋转/逆时针旋转" << std::endl <<
std::endl <<
" [相机控制]" << std::endl <<
" j/J: 顺时针旋转/逆时针旋转" << std::endl <<
" k/K: 上移视角/下移视角" << std::endl <<
" SPACE: 重置相机" << std::endl <<
std::endl <<
" [光源控制]" << std::endl <<
" x/X: 光源左移/光源右移" << std::endl <<
" y/Y: 光源下移/光源上移" << std::endl <<
" z/Z: 光源前移/光源后移" << std::endl <<
std::endl;
}
TriMesh* obj = new TriMesh();
// 键盘响应函数
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode)
{
float tmp;
glm::vec3 temp;
glm::vec4 ambient;
if (action == GLFW_PRESS || action == GLFW_REPEAT) {
switch (key)
{
case GLFW_KEY_ESCAPE: exit(EXIT_SUCCESS); break;
case GLFW_KEY_Q: exit(EXIT_SUCCESS); break;
case GLFW_KEY_GRAVE_ACCENT: Selected_mesh = robot.left_sword; break;
case GLFW_KEY_1: Selected_mesh = robot.Torso; break;
case GLFW_KEY_2: Selected_mesh = robot.Head; break;
case GLFW_KEY_3: Selected_mesh = robot.RightUpperArm; break;
case GLFW_KEY_4: Selected_mesh = robot.RightLowerArm; break;
case GLFW_KEY_5: Selected_mesh = robot.LeftUpperArm; break;
case GLFW_KEY_6: Selected_mesh = robot.LeftLowerArm; break;
case GLFW_KEY_7: Selected_mesh = robot.RightUpperLeg; break;
case GLFW_KEY_8: Selected_mesh = robot.RightLowerLeg; break;
case GLFW_KEY_9: Selected_mesh = robot.LeftUpperLeg; break;
case GLFW_KEY_0: Selected_mesh = robot.LeftLowerLeg; break;
// 通过按键旋转机器人
case GLFW_KEY_A:
robot.theta[Selected_mesh] += 5.0;
if (robot.theta[Selected_mesh] > 360.0)
robot.theta[Selected_mesh] -= 360.0;
break;
case GLFW_KEY_S:
robot.theta[Selected_mesh] -= 5.0;
if (robot.theta[Selected_mesh] < 0.0)
robot.theta[Selected_mesh] += 360.0;
break;
// 选择展示光照效果的物体
case GLFW_KEY_V:
mesh = new TriMesh();
mesh->readOff("./assets/sphere.off");
mesh_init();
break;
case GLFW_KEY_B:
mesh = new TriMesh();
mesh->readOff("./assets/cow.off");
mesh_init();
break;
case GLFW_KEY_N:
mesh = new TriMesh();
mesh->readOff("./assets/Squirtle.off");
mesh_init();
break;
case GLFW_KEY_M:
mesh = new TriMesh();
mesh->readOff("./assets/Pikachu.off");
mesh_init();
break;
// 选择需要控制的物体
case GLFW_KEY_U:
obj = table;
break;
case GLFW_KEY_I:
obj = girl;
break;
case GLFW_KEY_O:
obj = lamp;
break;
case GLFW_KEY_P:
obj = mesh;
break;
case GLFW_KEY_MINUS:
temp = obj->getScale();
temp.x -= 0.2;
temp.y -= 0.2;
temp.z -= 0.2;
obj->setScale(temp);
break;
case GLFW_KEY_EQUAL:
temp = obj->getScale();
temp.x += 0.2;
temp.y += 0.2;
temp.z += 0.2;
obj->setScale(temp);
break;
case GLFW_KEY_R:
temp = obj->getRotation();
if (mode == GLFW_MOD_SHIFT)
temp.y += 90.0;
else
temp.y -= 90.0;
obj->setRotation(temp);
break;
case GLFW_KEY_LEFT:
temp = obj->getTranslation();
temp.x -= 0.2;
obj->setTranslation(temp);
break;
case GLFW_KEY_RIGHT:
temp = obj->getTranslation();
temp.x += 0.2;
obj->setTranslation(temp);
break;
case GLFW_KEY_UP:
temp = obj->getTranslation();
temp.z -= 0.2;
obj->setTranslation(temp);
break;
case GLFW_KEY_DOWN:
temp = obj->getTranslation();
temp.z += 0.2;
obj->setTranslation(temp);
break;
case GLFW_KEY_X:
light_position = light->getTranslation();
if (mode == GLFW_MOD_SHIFT)
light_position[0] += move_step_size;
else
light_position[0] -= move_step_size;
light->setTranslation(light_position);
break;
case GLFW_KEY_Y:
light_position = light->getTranslation();
if (mode == GLFW_MOD_SHIFT)
light_position[1] += move_step_size;
else {
light_position[1] -= move_step_size;
if (light_position[1] <= 1.0) {
light_position[1] += move_step_size;
}
}
light->setTranslation(light_position);
break;
case GLFW_KEY_Z:
light_position = light->getTranslation();
if (mode == GLFW_MOD_SHIFT)
light_position[2] += move_step_size;
else
light_position[2] -= move_step_size;
light->setTranslation(light_position);
break;
default:
camera->keyboard(key, action, mode);
break;
}
}
}
void cleanData() {
// 释放内存
delete camera;
camera = NULL;
delete light;
light = NULL;
painter->cleanMeshes();
delete painter;
painter = NULL;
for (int i = 0; i < meshList.size(); i++) {
meshList[i]->cleanData();
delete meshList[i];
}
meshList.clear();
}
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
int main(int argc, char** argv)
{
// 初始化GLFW库,必须是应用程序调用的第一个GLFW函数
glfwInit();
// 配置GLFW
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
//设置字符格式
#pragma execution_character_set("utf-8");
// 配置窗口属性
GLFWwindow* window = glfwCreateWindow(600, 600, "xxx_xxx_期末大作业", NULL, NULL);
if (window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glfwSetKeyCallback(window, key_callback);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
// 调用任何OpenGL的函数之前初始化GLAD
// ---------------------------------------
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}
mesh->setNormalize(true);
mesh->readOff("./assets/Pikachu.off");
// Init mesh, shaders, buffer
init();
// 输出帮助信息
printHelp();
// 启用深度测试
glEnable(GL_DEPTH_TEST);
while (!glfwWindowShouldClose(window))
{
display();
// 交换颜色缓冲 以及 检查有没有触发什么事件(比如键盘输入、鼠标移动等)
// -------------------------------------------------------------------------------
glfwSwapBuffers(window);
glfwPollEvents();
}
cleanData();
return 0;
}
// 每当窗口改变大小,GLFW会调用这个函数并填充相应的参数供你处理。
// ---------------------------------------------------------------------------------------------
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
// make sure the viewport matches the new window dimensions; note that width and
// height will be significantly larger than specified on retina displays.
glViewport(0, 0, width, height);
}
Camera.cpp
#include "Camera.h"
Camera::Camera() {
initCamera();
updateCamera();
};
Camera::~Camera() {}
glm::mat4 Camera::getViewMatrix()
{
return this->lookAt(eye, at, up);
}
glm::mat4 Camera::getProjectionMatrix(bool isOrtho)
{
if (isOrtho) {
return this->ortho(-scale, scale, -scale, scale, this->zNear, this->zFar);
}
else {
return this->perspective(this->fovy, this->aspect, this->zNear, this->zFar);
}
}
glm::mat4 Camera::lookAt(const glm::vec4& eye, const glm::vec4& at, const glm::vec4& up)
{
// @TODO: Task1:请按照实验课内容补全相机观察矩阵的计算
// 获得相机方向。
glm::vec4 n = glm::normalize(eye - at);
// 获得右(x)轴方向。
glm::vec3 up_3 = up;
glm::vec3 n_3 = n;
glm::vec4 u = glm::normalize(glm::vec4(glm::cross(up_3, n_3), 0.0));
// 获得上(y)轴方向。
glm::vec3 u_3 = u;
glm::vec4 v = glm::normalize(glm::vec4(glm::cross(n_3, u_3), 0.0));
glm::vec4 t = glm::vec4(0.0, 0.0, 0.0, 1.0);
glm::mat4 c = glm::mat4(u, v, n, t);
// 处理相机位置向量。
glm::mat4 p = glm::mat4(1.0f);
p[0].w = -(eye.x);
p[1].w = -(eye.y);
p[2].w = -(eye.z);
glm::mat4 view = p * c;
return view; // 计算最后需要沿-eye方向平移
}
glm::mat4 Camera::ortho(const GLfloat left, const GLfloat right,
const GLfloat bottom, const GLfloat top,
const GLfloat zNear, const GLfloat zFar)
{
// @TODO: Task2:请按照实验课内容补全正交投影矩阵的计算
glm::mat4 c = glm::mat4(1.0f);
c[0][0] = 2.0 / (right - left);
c[1][1] = 2.0 / (top - bottom);
c[2][2] = -2.0 / (zFar - zNear);
c[3][3] = 1.0;
c[0][3] = -(right + left) / (right - left);
c[1][3] = -(top + bottom) / (top - bottom);
c[2][3] = -(zFar + zNear) / (zFar - zNear);
return c;
}
glm::mat4 Camera::perspective(const GLfloat fovy, const GLfloat aspect,
const GLfloat zNear, const GLfloat zFar)
{
// @TODO: Task2:请按照实验课内容补全透视投影矩阵的计算
GLfloat top = tan(fovy * M_PI / 180 / 2) * zNear;
GLfloat right = top * aspect;
glm::mat4 c = glm::mat4(1.0f);
c[0][0] = zNear / right;
c[1][1] = zNear / top;
c[2][2] = -(zFar + zNear) / (zFar - zNear);
c[2][3] = -(2.0 * zFar * zNear) / (zFar - zNear);
c[3][2] = -1.0;
c[3][3] = 0.0;
return c;
}
glm::mat4 Camera::frustum(const GLfloat left, const GLfloat right,
const GLfloat bottom, const GLfloat top,
const GLfloat zNear, const GLfloat zFar)
{
// 任意视锥体矩阵
glm::mat4 c = glm::mat4(1.0f);
c[0][0] = 2.0 * zNear / (right - left);
c[0][2] = (right + left) / (right - left);
c[1][1] = 2.0 * zNear / (top - bottom);
c[1][2] = (top + bottom) / (top - bottom);
c[2][2] = -(zFar + zNear) / (zFar - zNear);
c[2][3] = -2.0 * zFar * zNear / (zFar - zNear);
c[3][2] = -1.0;
c[3][3] = 0.0;
return c;
}
void Camera::updateCamera()
{
// 使用相对于at的角度控制相机的时候,注意在upAngle大于90的时候,相机坐标系的u向量会变成相反的方向,
// 要将up的y轴改为负方向才不会发生这种问题
// 也可以考虑直接控制相机自身的俯仰角,
// 保存up,eye-at 这些向量,并修改这些向量方向来控制
// 看到这里的有缘人可以试一试
up = glm::vec4(0.0, 1.0, 0.0, 0.0);
if (upAngle > 90) {
up.y = -1;
}
else if (upAngle < -90) {
up.y = -1;
}
float eyex = radius * cos(upAngle * M_PI / 180.0) * sin(rotateAngle * M_PI / 180.0);
float eyey = radius * sin(upAngle * M_PI / 180.0);
float eyez = radius * cos(upAngle * M_PI / 180.0) * cos(rotateAngle * M_PI / 180.0);
eye = glm::vec4(eyex, eyey, eyez, 1.0);
}
void Camera::initCamera() {
at = glm::vec4(0.0, 0.0, 0.0, 1.0);
radius = 4.0; //前后远近变动视角角度
rotateAngle = 20.0; //环绕中心左右转动视角角度
upAngle = 20.0; //环绕中心上下转动视角角度
fovy = 45.0;
aspect = 1.0;
scale = 1.5;
zNear = 0.01;
zFar = 100.0;
}
void Camera::keyboard(int key, int action, int mode)
{
// 键盘事件处理
// 通过按键改变相机和投影的参数
if (key == GLFW_KEY_J && mode == 0x0000) {
rotateAngle += 5.0;
if (rotateAngle > 180)
rotateAngle = rotateAngle - 360;
}
else if (key == GLFW_KEY_J && mode == GLFW_MOD_SHIFT) {
rotateAngle -= 5.0;
if (rotateAngle < -180)
rotateAngle = rotateAngle + 360;
}
else if (key == GLFW_KEY_K && mode == 0x0000) {
upAngle += 5.0;
if (upAngle >= 180)
upAngle = upAngle - 360;
}
else if (key == GLFW_KEY_K && mode == GLFW_MOD_SHIFT) {
upAngle -= 5.0;
if (upAngle <= -180)
upAngle = upAngle + 360;
}
else if (key == GLFW_KEY_L && mode == 0x0000) {
radius += 0.1;
}
else if (key == GLFW_KEY_L && mode == GLFW_MOD_SHIFT) {
radius -= 0.1;
}
// 空格键初始化所有参数
else if (key == GLFW_KEY_SPACE && mode == 0x0000) {
initCamera();
}
}
MeshPainter.cpp
#include "MeshPainter.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
MeshPainter::MeshPainter() {};
MeshPainter::~MeshPainter() {};
std::vector<std::string> MeshPainter::getMeshNames() { return mesh_names; };
std::vector<TriMesh*> MeshPainter::getMeshes() { return meshes; };
std::vector<openGLObject> MeshPainter::getOpenGLObj() { return opengl_objects; };
void MeshPainter::bindObjectAndData(TriMesh* mesh, openGLObject& object, const std::string& texture_image, const std::string& vshader, const std::string& fshader) {
// 初始化各种对象
std::vector<glm::vec3> points = mesh->getPoints();
std::vector<glm::vec3> normals = mesh->getNormals();
std::vector<glm::vec3> colors = mesh->getColors();
std::vector<glm::vec2> textures = mesh->getTextures();
// 创建顶点数组对象
#ifdef __APPLE__ // for MacOS
glGenVertexArraysAPPLE(1, &object.vao); // 分配1个顶点数组对象
glBindVertexArrayAPPLE(object.vao); // 绑定顶点数组对象
#else // for Windows
glGenVertexArrays(1, &object.vao); // 分配1个顶点数组对象
glBindVertexArray(object.vao); // 绑定顶点数组对象
#endif
// 创建并初始化顶点缓存对象
glGenBuffers(1, &object.vbo);
glBindBuffer(GL_ARRAY_BUFFER, object.vbo);
glBufferData(GL_ARRAY_BUFFER,
points.size() * sizeof(glm::vec3) +
normals.size() * sizeof(glm::vec3) +
colors.size() * sizeof(glm::vec3) +
textures.size() * sizeof(glm::vec2),
NULL, GL_STATIC_DRAW);
// 绑定顶点数据
glBufferSubData(GL_ARRAY_BUFFER, 0, points.size() * sizeof(glm::vec3), points.data());
// 绑定颜色数据
glBufferSubData(GL_ARRAY_BUFFER, points.size() * sizeof(glm::vec3), colors.size() * sizeof(glm::vec3), colors.data());
// 绑定法向量数据
glBufferSubData(GL_ARRAY_BUFFER, (points.size() + colors.size()) * sizeof(glm::vec3), normals.size() * sizeof(glm::vec3), normals.data());
// 绑定纹理数据
glBufferSubData(GL_ARRAY_BUFFER, (points.size() + normals.size() + colors.size()) * sizeof(glm::vec3), textures.size() * sizeof(glm::vec2), textures.data());
object.vshader = vshader;
object.fshader = fshader;
object.program = InitShader(object.vshader.c_str(), object.fshader.c_str());
// 将顶点传入着色器
object.pLocation = glGetAttribLocation(object.program, "vPosition");
glEnableVertexAttribArray(object.pLocation);
glVertexAttribPointer(object.pLocation, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
// 将颜色传入着色器
object.cLocation = glGetAttribLocation(object.program, "vColor");
glEnableVertexAttribArray(object.cLocation);
glVertexAttribPointer(object.cLocation, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(points.size() * sizeof(glm::vec3)));
// 将法向量传入着色器
object.nLocation = glGetAttribLocation(object.program, "vNormal");
glEnableVertexAttribArray(object.nLocation);
glVertexAttribPointer(object.nLocation, 3,
GL_FLOAT, GL_FALSE, 0,
BUFFER_OFFSET((points.size() + colors.size()) * sizeof(glm::vec3)));
object.tLocation = glGetAttribLocation(object.program, "vTexture");
glEnableVertexAttribArray(object.tLocation);
glVertexAttribPointer(object.tLocation, 2,
GL_FLOAT, GL_FALSE, 0,
BUFFER_OFFSET((points.size() + colors.size() + normals.size()) * sizeof(glm::vec3)));
// 获得矩阵位置
object.modelLocation = glGetUniformLocation(object.program, "model");
object.viewLocation = glGetUniformLocation(object.program, "view");
object.projectionLocation = glGetUniformLocation(object.program, "projection");
object.shadowLocation = glGetUniformLocation(object.program, "isShadow");
// 读取纹理图片数
object.texture_image = texture_image;
// 创建纹理的缓存对象
glGenTextures(1, &object.texture);
// 调用stb_image生成纹理
load_texture_STBImage(object.texture_image, object.texture);
// Clean up
glUseProgram(0);
#ifdef __APPLE__
glBindVertexArrayAPPLE(0);
#else
glBindVertexArray(0);
#endif
};
void MeshPainter::bindLightAndMaterial(TriMesh* mesh, openGLObject& object, Light* light, Camera* camera) {
// 传递材质、光源等数据给着色器
// 传递相机的位置
glUniform3fv(glGetUniformLocation(object.program, "eye_position"), 1, &camera->eye[0]);
// 传递物体的材质
glm::vec4 meshAmbient = mesh->getAmbient();
glm::vec4 meshDiffuse = mesh->getDiffuse();
glm::vec4 meshSpecular = mesh->getSpecular();
float meshShininess = mesh->getShininess();
glUniform4fv(glGetUniformLocation(object.program, "material.ambient"), 1, &meshAmbient[0]);
glUniform4fv(glGetUniformLocation(object.program, "material.diffuse"), 1, &meshDiffuse[0]);
glUniform4fv(glGetUniformLocation(object.program, "material.specular"), 1, &meshSpecular[0]);
glUniform1f(glGetUniformLocation(object.program, "material.shininess"), meshShininess);
// 传递光源信息
glm::vec4 lightAmbient = light->getAmbient();
glm::vec4 lightDiffuse = light->getDiffuse();
glm::vec4 lightSpecular = light->getSpecular();
glm::vec3 lightPosition = light->getTranslation();
glUniform4fv(glGetUniformLocation(object.program, "light.ambient"), 1, &lightAmbient[0]);
glUniform4fv(glGetUniformLocation(object.program, "light.diffuse"), 1, &lightDiffuse[0]);
glUniform4fv(glGetUniformLocation(object.program, "light.specular"), 1, &lightSpecular[0]);
glUniform3fv(glGetUniformLocation(object.program, "light.position"), 1, &lightPosition[0]);
glUniform1f(glGetUniformLocation(object.program, "light.constant"), light->getConstant());
glUniform1f(glGetUniformLocation(object.program, "light.linear"), light->getLinear());
glUniform1f(glGetUniformLocation(object.program, "light.quadratic"), light->getQuadratic());
}
void MeshPainter::addMesh(TriMesh* mesh, const std::string& name, const std::string& texture_image, const std::string& vshader, const std::string& fshader) {
mesh_names.push_back(name);
meshes.push_back(mesh);
openGLObject object;
// 绑定openGL对象,并传递顶点属性的数据
bindObjectAndData(mesh, object, texture_image, vshader, fshader);
opengl_objects.push_back(object);
};
void MeshPainter::drawMesh(TriMesh* mesh, openGLObject& object, Light* light, Camera* camera,int flag) {
// 相机矩阵计算
camera->updateCamera();
camera->viewMatrix = camera->getViewMatrix();
camera->projMatrix = camera->getProjectionMatrix(true);
#ifdef __APPLE__ // for MacOS
glBindVertexArrayAPPLE(object.vao);
#else
glBindVertexArray(object.vao);
#endif
glUseProgram(object.program);
// 物体的变换矩阵
glm::mat4 modelMatrix = mesh->getModelMatrix();
// 传递矩阵
glUniformMatrix4fv(object.modelLocation, 1, GL_FALSE, &modelMatrix[0][0]);
glUniformMatrix4fv(object.viewLocation, 1, GL_TRUE, &camera->viewMatrix[0][0]);
glUniformMatrix4fv(object.projectionLocation, 1, GL_TRUE, &camera->projMatrix[0][0]);
// 将着色器 isShadow 设置为2,表示根据纹理绘制
glUniform1i(object.shadowLocation, 2);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, object.texture);// 该语句必须,否则将只使用同一个纹理进行绘制
// 传递纹理数据 将生成的纹理传给shader
glUniform1i(glGetUniformLocation(object.program, "texture"), 0);
// 将材质和光源数据传递给着色器
bindLightAndMaterial(mesh, object, light, camera);
// 绘制
glDrawArrays(GL_TRIANGLES, 0, mesh->getPoints().size());
// @TODO: 根据光源位置,计算阴影投影矩阵
glm::vec3 light_position = light->getTranslation();
float lx = light_position[0];
float ly = light_position[1];
float lz = light_position[2];
glm::mat4 shadowProjMatrix(
-ly, 0.0, 0.0, 0.0,
lx, 0.0, lz, 1.0,
0.0, 0.0, -ly, 0.0,
0.0, 0.0, 0.0, -ly);
// 计算阴影的模型变换矩阵。
modelMatrix = shadowProjMatrix * modelMatrix;
if (flag != -1)//若flag为-1则不绘制阴影
{
// 传递 isShadow 变量,3表示黑色。
glUniform1i(object.shadowLocation, 3);
// 传递 unifrom 关键字的矩阵数据。
glUniformMatrix4fv(object.modelLocation, 1, GL_FALSE, &modelMatrix[0][0]);
// 绘制
glDrawArrays(GL_TRIANGLES, 0, mesh->getPoints().size());
}
#ifdef __APPLE__ // for MacOS
glBindVertexArrayAPPLE(0);
#else
glBindVertexArray(0);
#endif
glUseProgram(0);
};
void MeshPainter::drawMeshes(Light* light, Camera* camera,int flag) {
for (int i = 0; i < meshes.size(); i++)
{
drawMesh(meshes[i], opengl_objects[i], light, camera,flag);
}
};
void MeshPainter::cleanMeshes() {
// 将数据都清空释放
mesh_names.clear();
for (int i = 0; i < meshes.size(); i++)
{
meshes[i]->cleanData();
delete meshes[i];
meshes[i] = NULL;
#ifdef __APPLE__
glDeleteVertexArraysAPPLE(1, &opengl_objects[i].vao);
#else
glDeleteVertexArrays(1, &opengl_objects[i].vao);
#endif
glDeleteBuffers(1, &opengl_objects[i].vbo);
glDeleteProgram(opengl_objects[i].program);
}
meshes.clear();
opengl_objects.clear();
};
void MeshPainter::load_texture_STBImage(const std::string& file_name, GLuint& texture) {
// 读取纹理图片,并将其传递给着色器
int width, height, channels = 0;
unsigned char* pixels = NULL;
// 读取图片的时候先翻转一下图片,如果不设置的话显示出来是反过来的图片
stbi_set_flip_vertically_on_load(true);
// 读取图片数据
pixels = stbi_load(file_name.c_str(), &width, &height, &channels, 0);
// 调整行对齐格式
if (width * channels % 4 != 0)
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
GLenum format = GL_RGB;
// 设置通道格式
switch (channels)
{
case 1:
format = GL_RED;
break;
case 3:
format = GL_RGB;
break;
case 4:
format = GL_RGBA;
break;
default:
format = GL_RGB;
break;
}
// 绑定纹理对象
glBindTexture(GL_TEXTURE_2D, texture);
// 指定纹理的放大,缩小滤波,使用线性方式,即当图片放大的时候插值方式
// 将图片的rgb数据上传给opengl
glTexImage2D(
GL_TEXTURE_2D, // 指定目标纹理,这个值必须是GL_TEXTURE_2D
0, // 执行细节级别,0是最基本的图像级别,n表示第N级贴图细化级别
format, // 纹理数据的颜色格式(GPU显存)
width, // 宽度。早期的显卡不支持不规则的纹理,则宽度和高度必须是2^n
height, // 高度。早期的显卡不支持不规则的纹理,则宽度和高度必须是2^n
0, // 指定边框的宽度。必须为0
format, // 像素数据的颜色格式(CPU内存)
GL_UNSIGNED_BYTE, // 指定像素数据的数据类型
pixels // 指定内存中指向图像数据的指针
);
// 生成多级渐远纹理,多消耗1/3的显存,较小分辨率时获得更好的效果
// glGenerateMipmap(GL_TEXTURE_2D);
// 指定插值方法
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
// 恢复初始对齐格式
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
// 释放图形内存
stbi_image_free(pixels);
};
TriMesh.cpp
#include "TriMesh.h"
// 一些基础颜色
const glm::vec3 basic_colors[8] = {
glm::vec3(1.0, 1.0, 1.0), // White
glm::vec3(1.0, 1.0, 0.0), // Yellow
glm::vec3(0.0, 1.0, 0.0), // Green
glm::vec3(0.0, 1.0, 1.0), // Cyan
glm::vec3(1.0, 0.0, 1.0), // Magenta
glm::vec3(1.0, 0.0, 0.0), // Red
glm::vec3(0.0, 0.0, 0.0), // Black
glm::vec3(0.0, 0.0, 1.0) // Blue
};
// 立方体的各个点
const glm::vec3 cube_vertices[8] = {
glm::vec3(-0.5, -0.5, -0.5),
glm::vec3(0.5, -0.5, -0.5),
glm::vec3(-0.5, 0.5, -0.5),
glm::vec3(0.5, 0.5, -0.5),
glm::vec3(-0.5, -0.5, 0.5),
glm::vec3(0.5, -0.5, 0.5),
glm::vec3(-0.5, 0.5, 0.5),
glm::vec3(0.5, 0.5, 0.5)
};
// 三角形的点
const glm::vec3 triangle_vertices[3] = {
glm::vec3(-0.5, -0.5, 0.0),
glm::vec3(0.5, -0.5, 0.0),
glm::vec3(0.0, 0.5, 0.0)
};
// 正方形平面
const glm::vec3 square_vertices[4] = {
glm::vec3(-0.5, -0.5, 0.0),
glm::vec3(0.5, -0.5, 0.0),
glm::vec3(0.5, 0.5, 0.0),
glm::vec3(-0.5, 0.5, 0.0),
};
TriMesh::TriMesh()
{
}
TriMesh::~TriMesh()
{
}
std::vector<glm::vec3> TriMesh::getVertexPositions()
{
return vertex_positions;
}
std::vector<glm::vec3> TriMesh::getVertexColors()
{
return vertex_colors;
}
std::vector<glm::vec3> TriMesh::getVertexNormals()
{
return vertex_normals;
}
std::vector<vec3i> TriMesh::getFaces()
{
return faces;
}
std::vector<glm::vec3> TriMesh::getPoints()
{
return points;
}
std::vector<glm::vec3> TriMesh::getColors()
{
return colors;
}
std::vector<glm::vec3> TriMesh::getNormals()
{
return normals;
}
std::vector<glm::vec2> TriMesh::getTextures()
{
return textures;
}
void TriMesh::computeTriangleNormals()
{
face_normals.resize(faces.size());
for (size_t i = 0; i < faces.size(); i++) {
auto& face = faces[i];
// @TODO: Task2 计算每个面片的法向量并归一化
glm::vec3 v01 = vertex_positions[face.y] - vertex_positions[face.x];
glm::vec3 v02 = vertex_positions[face.z] - vertex_positions[face.x];
face_normals[i] = normalize(cross(v01, v02));
}
}
void TriMesh::computeVertexNormals()
{
// 计算面片的法向量
if (face_normals.size() == 0 && faces.size() > 0) {
computeTriangleNormals();
}
// 初始化法向量为0
vertex_normals.resize(vertex_positions.size(), glm::vec3(0, 0, 0));
// @TODO: Task2 求法向量均值
for (size_t i = 0; i < faces.size(); i++) {
auto& face = faces[i];
// @TODO: 先累加面的法向量
vertex_normals[face.x] += face_normals[i];
vertex_normals[face.y] += face_normals[i];
vertex_normals[face.z] += face_normals[i];
}
@TODO 对累加的法向量并归一化
for (size_t i = 0; i < vertex_normals.size(); i++) {
vertex_normals[i] = normalize(vertex_normals[i]);
}
// 球心在原点的球法向量为坐标
// for (int i = 0; i < vertex_positions.size(); i++)
// vertex_normals.push_back(vertex_positions[i] - vec3(0.0, 0.0, 0.0));
}
void TriMesh::setNormalize(bool do_norm) { do_normalize_size = do_norm; }
bool TriMesh::getNormalize() { return do_normalize_size; }
float TriMesh::getDiagonalLength() { return diagonal_length; }
glm::vec3 TriMesh::getTranslation()
{
return translation;
}
glm::vec3 TriMesh::getRotation()
{
return rotation;
}
glm::vec3 TriMesh::getScale()
{
return scale;
}
glm::mat4 TriMesh::getModelMatrix()
{
glm::mat4 model = glm::mat4(1.0f);
glm::vec3 trans = getTranslation();
model = glm::translate(model, getTranslation());
model = glm::rotate(model, glm::radians(getRotation()[2]), glm::vec3(0.0, 0.0, 1.0));
model = glm::rotate(model, glm::radians(getRotation()[1]), glm::vec3(0.0, 1.0, 0.0));
model = glm::rotate(model, glm::radians(getRotation()[0]), glm::vec3(1.0, 0.0, 0.0));
model = glm::scale(model, getScale());
return model;
}
void TriMesh::setTranslation(glm::vec3 translation)
{
this->translation = translation;
}
void TriMesh::setRotation(glm::vec3 rotation)
{
this->rotation = rotation;
}
void TriMesh::setScale(glm::vec3 scale)
{
this->scale = scale;
}
glm::vec4 TriMesh::getAmbient() { return ambient; };
glm::vec4 TriMesh::getDiffuse() { return diffuse; };
glm::vec4 TriMesh::getSpecular() { return specular; };
float TriMesh::getShininess() { return shininess; };
void TriMesh::setAmbient(glm::vec4 _ambient) { ambient = _ambient; };
void TriMesh::setDiffuse(glm::vec4 _diffuse) { diffuse = _diffuse; };
void TriMesh::setSpecular(glm::vec4 _specular) { specular = _specular; };
void TriMesh::setShininess(float _shininess) { shininess = _shininess; };
void TriMesh::cleanData() {
vertex_positions.clear();
vertex_colors.clear();
vertex_normals.clear();
vertex_textures.clear();
faces.clear();
normal_index.clear();
color_index.clear();
texture_index.clear();
face_normals.clear();
points.clear();
colors.clear();
normals.clear();
textures.clear();
}
void TriMesh::norm() {
if (do_normalize_size) {
// 记录物体包围盒大小,可以用于大小的归一化
// 先获得包围盒的对角顶点
float max_x = -FLT_MAX;
float max_y = -FLT_MAX;
float max_z = -FLT_MAX;
float min_x = FLT_MAX;
float min_y = FLT_MAX;
float min_z = FLT_MAX;
for (int i = 0; i < vertex_positions.size(); i++) {
auto& position = vertex_positions[i];
if (position.x > max_x) max_x = position.x;
if (position.y > max_y) max_y = position.y;
if (position.z > max_z) max_z = position.z;
if (position.x < min_x) min_x = position.x;
if (position.y < min_y) min_y = position.y;
if (position.z < min_z) min_z = position.z;
}
up_corner = glm::vec3(max_x, max_y, max_z);
down_corner = glm::vec3(min_x, min_y, min_z);
center = glm::vec3((min_x + max_x) / 2.0, (min_y + max_y) / 2.0, (min_z + max_z) / 2.0);
diagonal_length = length(up_corner - down_corner);
for (int i = 0; i < vertex_positions.size(); i++) {
vertex_positions[i] = (vertex_positions[i] - center) / diagonal_length;
}
}
}
void TriMesh::storeFacesPoints() {
norm();
// 计算法向量
if (vertex_normals.size() == 0)
computeVertexNormals();
// 根据每个三角面片的顶点下标存储要传入GPU的数据
for (int i = 0; i < faces.size(); i++)
{
// 坐标
points.push_back(vertex_positions[faces[i].x]);
points.push_back(vertex_positions[faces[i].y]);
points.push_back(vertex_positions[faces[i].z]);
// 颜色
colors.push_back(vertex_colors[color_index[i].x]);
colors.push_back(vertex_colors[color_index[i].y]);
colors.push_back(vertex_colors[color_index[i].z]);
// 法向量
if (vertex_normals.size() != 0)
{
normals.push_back(vertex_normals[normal_index[i].x]);
normals.push_back(vertex_normals[normal_index[i].y]);
normals.push_back(vertex_normals[normal_index[i].z]);
}
// 纹理
if (vertex_textures.size() != 0)
{
textures.push_back(vertex_textures[texture_index[i].x]);
textures.push_back(vertex_textures[texture_index[i].y]);
textures.push_back(vertex_textures[texture_index[i].z]);
}
}
}
void TriMesh::storeFacesPoints_1() {
// 计算法向量
if (vertex_normals.size() == 0)
computeVertexNormals();
// 根据每个三角面片的顶点下标存储要传入GPU的数据
for (int i = 0; i < faces.size(); i++)
{
// 坐标
points.push_back(vertex_positions[faces[i].x]);
points.push_back(vertex_positions[faces[i].y]);
points.push_back(vertex_positions[faces[i].z]);
// 颜色
colors.push_back(vertex_colors[faces[i].x]);
colors.push_back(vertex_colors[faces[i].y]);
colors.push_back(vertex_colors[faces[i].z]);
// 颜色
/*colors.push_back(glm::vec3(0.5, 0.0, 0.5));
colors.push_back(glm::vec3(0.5, 0.0, 0.5));
colors.push_back(glm::vec3(0.5, 0.0, 0.5));*/
// 法向量
if (vertex_normals.size() != 0) {
normals.push_back(vertex_normals[faces[i].x]);
normals.push_back(vertex_normals[faces[i].y]);
normals.push_back(vertex_normals[faces[i].z]);
}
}
}
// 立方体生成12个三角形的顶点索引
void TriMesh::generateCube(glm::vec3 _color)
{
// 创建顶点前要先把那些vector清空
cleanData();
for (int i = 0; i < 8; i++)
{
vertex_positions.push_back(cube_vertices[i]);
if (_color[0] == -1) {
vertex_colors.push_back(basic_colors[i]);
}
else {
vertex_colors.push_back(_color);
}
}
// 每个三角面片的顶点下标
// 每个三角面片的顶点下标
faces.push_back(vec3i(0, 1, 3));
faces.push_back(vec3i(0, 3, 2));
faces.push_back(vec3i(1, 4, 5));
faces.push_back(vec3i(1, 0, 4));
faces.push_back(vec3i(4, 0, 2));
faces.push_back(vec3i(4, 2, 6));
faces.push_back(vec3i(5, 6, 4));
faces.push_back(vec3i(5, 7, 6));
faces.push_back(vec3i(2, 6, 7));
faces.push_back(vec3i(2, 7, 3));
faces.push_back(vec3i(1, 5, 7));
faces.push_back(vec3i(1, 7, 3));
storeFacesPoints_1();
normals.clear();
// 正方形的法向量不能靠之前顶点法向量的方法直接计算,因为每个四边形平面是正交的,不是连续曲面
for (int i = 0; i < faces.size(); i++)
{
normals.push_back(face_normals[i]);
normals.push_back(face_normals[i]);
normals.push_back(face_normals[i]);
}
}
void TriMesh::generateSquare(glm::vec3 color)
{
// 创建顶点前要先把那些vector清空
cleanData();
for (int i = 0; i < 4; i++)
{
vertex_positions.push_back(square_vertices[i]);
vertex_colors.push_back(color);
//vertex_colors.push_back(glm::vec3(0.5, 0.0, 0.5));
}
// 每个三角面片的顶点下标
faces.push_back(vec3i(0, 1, 2));
faces.push_back(vec3i(0, 2, 3));
storeFacesPoints_1();
}
void TriMesh::generateCylinder(int num_division, float radius, float height)
{
cleanData();
int num_samples = num_division;
float step = 2 * M_PI / num_samples; // 每个切片的弧度
// 按cos和sin生成x,y坐标,z为负,即得到下表面顶点坐标
// 顶点, 纹理
float z = -height;
for (int i = 0; i < num_samples; i++)
{
float r_r_r = i * step;
float x = radius * cos(r_r_r);
float y = radius * sin(r_r_r);
// 添加顶点坐标
vertex_positions.push_back(glm::vec3(x, y, z));
vertex_normals.push_back(normalize(glm::vec3(x, y, 0)));
// 这里颜色和法向量一样
vertex_colors.push_back(normalize(glm::vec3(x, y, 0)));
}
// 按cos和sin生成x,y坐标,z为正,即得到上表面顶点坐标
z = height;
for (int i = 0; i < num_samples; i++)
{
float r_r_r = i * step;
float x = radius * cos(r_r_r);
float y = radius * sin(r_r_r);
vertex_positions.push_back(glm::vec3(x, y, z));
vertex_normals.push_back(normalize(glm::vec3(x, y, 0)));
vertex_colors.push_back(normalize(glm::vec3(x, y, 0)));
}
// 面片生成三角面片,每个矩形由两个三角形面片构成
for (int i = 0; i < num_samples; i++)
{
// 面片1
faces.push_back(vec3i(i, (i + 1) % num_samples, (i)+num_samples));
// 面片2
faces.push_back(vec3i((i)+num_samples, (i + 1) % num_samples, (i + num_samples + 1) % (num_samples)+num_samples));
// 面片1对应的顶点的纹理坐标
vertex_textures.push_back(glm::vec2(1.0 * i / num_samples, 0.0));
vertex_textures.push_back(glm::vec2(1.0 * (i + 1) / num_samples, 0.0));
vertex_textures.push_back(glm::vec2(1.0 * i / num_samples, 1.0));
// 对应的三角面片的纹理坐标的下标
texture_index.push_back(vec3i(6 * i, 6 * i + 1, 6 * i + 2));
// 面片2对应的顶点的纹理坐标
vertex_textures.push_back(glm::vec2(1.0 * i / num_samples, 1.0));
vertex_textures.push_back(glm::vec2(1.0 * (i + 1) / num_samples, 0.0));
vertex_textures.push_back(glm::vec2(1.0 * (i + 1) / num_samples, 1.0));
// 对应的三角面片的纹理坐标的下标
texture_index.push_back(vec3i(6 * i + 3, 6 * i + 4, 6 * i + 5));
}
// 三角面片的每个顶点的法向量的下标,这里和顶点坐标的下标 faces是一致的,所以我们用faces就行
normal_index = faces;
// 三角面片的每个顶点的颜色的下标
color_index = faces;
storeFacesPoints();
}
void TriMesh::readOff(const std::string& filename)
{
// fin打开文件读取文件信息
if (filename.empty())
{
return;
}
std::ifstream fin;
fin.open(filename);
// @TODO: Task1:修改此函数读取OFF文件中三维模型的信息
if (!fin)
{
printf("File on error\n");
return;
}
else
{
//printf("File open success\n");
cleanData();
int nVertices, nFaces, nEdges;
// 读取OFF字符串
std::string str;
fin >> str;
// 读取文件中顶点数、面片数、边数
fin >> nVertices >> nFaces >> nEdges;
// @TODO
// 根据顶点数,循环读取每个顶点坐标
for (int i = 0; i < nVertices; i++)
{
glm::vec3 tmp_node;
fin >> tmp_node.x >> tmp_node.y >> tmp_node.z;
vertex_positions.push_back(tmp_node);
vertex_colors.push_back(tmp_node);
}
// 根据面片数,循环读取每个面片信息,并用构建的vec3i结构体保存
for (int i = 0; i < nFaces; i++)
{
int num, a, b, c;
// num记录此面片由几个顶点构成,a、b、c为构成该面片顶点序号
fin >> num >> a >> b >> c;
faces.push_back(vec3i(a, b, c));
}
}
fin.close();
norm();
storeFacesPoints_1();
};
void TriMesh::readObj(const std::string& filename)
{
std::ifstream fin(filename);
std::string line;
if (!fin)
{
std::cout << "ERROR: cannot open the file: " << filename << std::endl;
exit(0); // 退出程序
}
cleanData();
while (std::getline(fin, line))
{
std::istringstream sin(line);
std::string type;
GLfloat _x, _y, _z;
int a0, b0, c0;
int a1, b1, c1;
int a2, b2, c2;
int a3, b3, c3;
char slash;
sin >> type;
// @TODO: Task2 读取obj文件,记录里面的这些数据,可以参考readOff的写法
// vertex_positions
// vertex_normals
// vertex_textures
if (type == "v")
{
sin >> _x >> _y >> _z;
vertex_positions.push_back(glm::vec3(_x, _y, _z));
}
if (type == "vn")
{
sin >> _x >> _y >> _z;
vertex_normals.push_back(glm::vec3(_x, _y, _z));
//vertex_colors.push_back(glm::vec3(_x, _y, _z));
}
if (type == "vt")
{
sin >> _x >> _y >> _z;
vertex_textures.push_back(glm::vec2(_x, _y));
}
// faces
// normal_index
// texture_index
if (type == "f")
{
sin >> a0 >> slash >> b0 >> slash >> c0;
sin >> a1 >> slash >> b1 >> slash >> c1;
sin >> a2 >> slash >> b2 >> slash >> c2;
//sin >> a3 >> slash >> b3 >> slash >> c3;
faces.push_back(vec3i(a0 - 1, a1 - 1, a2 - 1));
texture_index.push_back(vec3i(b0 - 1, b1 - 1, b2 - 1));
normal_index.push_back(vec3i(c0 - 1, c1 - 1, c2 - 1));
}
// 其中vertex_color和color_index可以用法向量的数值赋值
}
vertex_colors = vertex_normals;
color_index = normal_index;
storeFacesPoints();
}
// Light
glm::mat4 Light::getShadowProjectionMatrix() {
// 这里只实现了Y=0平面上的阴影投影矩阵,其他情况自己补充
float lx, ly, lz;
glm::mat4 modelMatrix = this->getModelMatrix();
glm::vec4 light_position = modelMatrix * glm::vec4(this->translation, 1.0);
lx = light_position[0];
ly = light_position[1];
lz = light_position[2];
return glm::mat4(
-ly, 0.0, 0.0, 0.0,
lx, 0.0, lz, 1.0,
0.0, 0.0, -ly, 0.0,
0.0, 0.0, 0.0, -ly
);
}
fshader.glsl
#version 330 core
// 给光源数据一个结构体
struct Light{
vec4 ambient;
vec4 diffuse;
vec4 specular;
vec3 position;
// 光源衰减系数的三个参数
float constant; // 常数项
float linear; // 一次项
float quadratic;// 二次项
};
// 给物体材质数据一个结构体
struct Material{
vec4 ambient;
vec4 diffuse;
vec4 specular;
float shininess;
};
in vec3 position;
in vec3 normal;
in vec2 texCoord;
// 相机坐标
uniform vec3 eye_position;
// 光源
uniform Light light;
// 物体材质
uniform Material material;
uniform int isShadow;
// 纹理数据
uniform sampler2D texture;
in vec3 color;
out vec4 fColor;
void main()
{
if (isShadow == 0) {
// 将顶点坐标、光源坐标和法向量转换到相机坐标系
vec3 norm = (vec4(normal, 0.0)).xyz;
// @TODO: 计算四个归一化的向量 N,V,L,R(或半角向量H)
vec3 N = normalize(norm);
vec3 V = normalize(eye_position - position);
vec3 L = normalize(light.position - position);
vec3 R = reflect(-L, N);
// 环境光分量I_a
vec4 I_a = light.ambient * material.ambient;
// @TODO: Task2 计算系数和漫反射分量I_d
float diffuse_dot = max(dot(L, N), 0);
vec4 I_d = diffuse_dot * light.diffuse * material.diffuse;
// @TODO: Task2 计算系数和镜面反射分量I_s
float specular_dot_pow = pow(max(dot(R, V), 0), material.shininess);
vec4 I_s = specular_dot_pow * light.specular * material.specular;
// @TODO: Task2 计算高光系数beta和镜面反射分量I_s
// 注意如果光源在背面则去除高光
if( dot(L, N) < 0.0 ) {
I_s = vec4(0.0, 0.0, 0.0, 1.0);
}
// 合并三个分量的颜色,修正透明度
fColor = I_a + I_d + I_s;
fColor.a = 1.0;
}
else if (isShadow == 2) {
fColor = texture2D( texture, texCoord );
}
else if (isShadow == 1) {
fColor = vec4(0.0, 0.5, 0.5, 1.0); //黑色
}
else if (isShadow == 3) {
fColor = vec4(0.0, 0.0, 0.0, 1.0); //黑色
}
// else if (isShadow == 1) {
// fColor = vec4(0.0, 1.0, 0.0, 1.0);
// }
}
fshader_1.glsl
// #version 330 core
// in vec3 position;
// in vec3 normal;
// in vec3 color;
// uniform int isShadow;
// out vec4 fColor;
// void main()
// {
// if (isShadow == 1) {
// fColor = vec4(0.0, 0.0, 0.0, 1.0);
// }
// else {
// fColor = vec4(color, 1.0);
// }
// }
#version 330 core
in vec3 color;
// 给光源数据一个结构体
struct Light{
vec4 ambient;
vec4 diffuse;
vec4 specular;
vec3 position;
// 光源衰减系数的三个参数
float constant; // 常数项
float linear; // 一次项
float quadratic;// 二次项
};
// 给物体材质数据一个结构体
struct Material{
vec4 ambient;
vec4 diffuse;
vec4 specular;
float shininess;
};
in vec3 position;
in vec3 normal;
in vec2 texCoord;
// 相机坐标
uniform vec3 eye_position;
// 光源
uniform Light light;
// 物体材质
uniform Material material;
uniform int isShadow;
// 纹理数据
uniform sampler2D texture;
out vec4 fColor;
void main()
{
if (isShadow == 1) {
fColor = vec4(0.0, 0.0, 0.0, 1.0);
}
else {
//fColor = texture2D( texture, texCoord );
fColor = vec4(color, 1.0);
}
}
vshader.glsl
#version 330 core
// 顶点着色器
in vec3 vPosition;
in vec3 vColor;
in vec3 vNormal;
in vec2 vTexture;
// 传给片元着色器的变量
out vec3 position;
out vec3 normal;
out vec3 color;
out vec2 texCoord;
// 模型变换矩阵、相机观察矩阵、投影矩阵
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
vec4 v1 = model * vec4(vPosition, 1.0);
// 由于model矩阵有可能为阴影矩阵,为了得到正确位置,我们需要做一次透视除法
vec4 v2 = vec4(v1.xyz / v1.w, 1.0);
// 考虑相机和投影
vec4 v3 = projection* view * v2;
gl_Position = v3;
position = vec3(v2.xyz);
normal = vec3( model * vec4(vNormal, 0.0) );
color = vColor;
normal = vec3( (model * vec4(vNormal, 0.0)).xyz );
texCoord = vTexture;
}
CMakeLists.txt
# cmake version
cmake_minimum_required(VERSION 3.1)
# c++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# vcpkg
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "")
endif()
if(DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "")
endif()
# project
project(main)
# target
aux_source_directory("./" PROJECT_SOURCES)
add_executable(main ${PROJECT_SOURCES})
target_include_directories(main PRIVATE include)
if(APPLE)
find_package(glfw3 CONFIG REQUIRED)
find_package(glm CONFIG REQUIRED)
# link
target_link_libraries(main PRIVATE glfw)
target_link_libraries(main PRIVATE glm::glm)
else()
# dependency
find_package(glad CONFIG REQUIRED)
find_package(glfw3 CONFIG REQUIRED)
find_package(glm CONFIG REQUIRED)
# link
target_link_libraries(main PRIVATE glad::glad)
target_link_libraries(main PRIVATE glfw)
target_link_libraries(main PRIVATE glm::glm)
endif(APPLE)
InitShader.cpp
#include "Angel.h"
namespace Angel {
// Create a NULL-terminated string by reading the provided file
static char*
readShaderSource(const char* shaderFile)
{
#ifdef __APPLE__ // for MacOS
FILE *fp;
fp = fopen(shaderFile, "r");
#else // for windows
FILE *fp;
fopen_s(&fp, shaderFile, "r");
#endif
if ( fp == NULL ) { return NULL; }
fseek(fp, 0L, SEEK_END);
long size = ftell(fp);
fseek(fp, 0L, SEEK_SET);
char* buf = new char[size + 1];
memset(buf, 0, size + 1);
fread(buf, 1, size, fp);
buf[size] = '\0';
fclose(fp);
return buf;
}
// Create a GLSL program object from vertex and fragment shader files
GLuint
InitShader(const char* vShaderFile, const char* fShaderFile)
{
struct Shader {
const char* filename;
GLenum type;
GLchar* source;
} shaders[2] = {
{ vShaderFile, GL_VERTEX_SHADER, NULL },
{ fShaderFile, GL_FRAGMENT_SHADER, NULL }
};
GLuint program = glCreateProgram();
for ( int i = 0; i < 2; ++i ) {
Shader& s = shaders[i];
s.source = readShaderSource( s.filename );
if ( shaders[i].source == NULL ) {
std::cerr << "Failed to read " << s.filename << std::endl;
exit( EXIT_FAILURE );
}
GLuint shader = glCreateShader( s.type );
glShaderSource( shader, 1, (const GLchar**) &s.source, NULL );
glCompileShader( shader );
GLint compiled;
glGetShaderiv( shader, GL_COMPILE_STATUS, &compiled );
if ( !compiled ) {
std::cerr << s.filename << " failed to compile:" << std::endl;
GLint logSize;
glGetShaderiv( shader, GL_INFO_LOG_LENGTH, &logSize );
char* logMsg = new char[logSize];
glGetShaderInfoLog( shader, logSize, NULL, logMsg );
std::cerr << logMsg << std::endl;
delete [] logMsg;
exit( EXIT_FAILURE );
}
delete [] s.source;
glAttachShader( program, shader );
}
/* link and error check */
glLinkProgram(program);
GLint linked;
glGetProgramiv( program, GL_LINK_STATUS, &linked );
if ( !linked ) {
std::cerr << "Shader program failed to link" << std::endl;
GLint logSize;
glGetProgramiv( program, GL_INFO_LOG_LENGTH, &logSize);
char* logMsg = new char[logSize];
glGetProgramInfoLog( program, logSize, NULL, logMsg );
std::cerr << logMsg << std::endl;
delete [] logMsg;
exit( EXIT_FAILURE );
}
/* use program object */
glUseProgram(program);
return program;
}
} // Close namespace Angel block
glad.c
/*
OpenGL loader generated by glad 0.1.34 on Wed Aug 11 08:05:48 2021.
Language/Generator: C/C++
Specification: gl
APIs: gl=3.3
Profile: core
Extensions:
Loader: True
Local files: False
Omit khrplatform: False
Reproducible: False
Commandline:
--profile="core" --api="gl=3.3" --generator="c" --spec="gl" --extensions=""
Online:
https://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gl%3D3.3
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glad/glad.h>
static void* get_proc(const char *namez);
#if defined(_WIN32) || defined(__CYGWIN__)
#ifndef _WINDOWS_
#undef APIENTRY
#endif
#include <windows.h>
static HMODULE libGL;
typedef void* (APIENTRYP PFNWGLGETPROCADDRESSPROC_PRIVATE)(const char*);
static PFNWGLGETPROCADDRESSPROC_PRIVATE gladGetProcAddressPtr;
#ifdef _MSC_VER
#ifdef __has_include
#if __has_include(<winapifamily.h>)
#define HAVE_WINAPIFAMILY 1
#endif
#elif _MSC_VER >= 1700 && !_USING_V110_SDK71_
#define HAVE_WINAPIFAMILY 1
#endif
#endif
#ifdef HAVE_WINAPIFAMILY
#include <winapifamily.h>
#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
#define IS_UWP 1
#endif
#endif
static
int open_gl(void) {
#ifndef IS_UWP
libGL = LoadLibraryW(L"opengl32.dll");
if(libGL != NULL) {
void (* tmp)(void);
tmp = (void(*)(void)) GetProcAddress(libGL, "wglGetProcAddress");
gladGetProcAddressPtr = (PFNWGLGETPROCADDRESSPROC_PRIVATE) tmp;
return gladGetProcAddressPtr != NULL;
}
#endif
return 0;
}
static
void close_gl(void) {
if(libGL != NULL) {
FreeLibrary((HMODULE) libGL);
libGL = NULL;
}
}
#else
#include <dlfcn.h>
static void* libGL;
#if !defined(__APPLE__) && !defined(__HAIKU__)
typedef void* (APIENTRYP PFNGLXGETPROCADDRESSPROC_PRIVATE)(const char*);
static PFNGLXGETPROCADDRESSPROC_PRIVATE gladGetProcAddressPtr;
#endif
static
int open_gl(void) {
#ifdef __APPLE__
static const char *NAMES[] = {
"../Frameworks/OpenGL.framework/OpenGL",
"/Library/Frameworks/OpenGL.framework/OpenGL",
"/System/Library/Frameworks/OpenGL.framework/OpenGL",
"/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL"
};
#else
static const char *NAMES[] = {"libGL.so.1", "libGL.so"};
#endif
unsigned int index = 0;
for(index = 0; index < (sizeof(NAMES) / sizeof(NAMES[0])); index++) {
libGL = dlopen(NAMES[index], RTLD_NOW | RTLD_GLOBAL);
if(libGL != NULL) {
#if defined(__APPLE__) || defined(__HAIKU__)
return 1;
#else
gladGetProcAddressPtr = (PFNGLXGETPROCADDRESSPROC_PRIVATE)dlsym(libGL,
"glXGetProcAddressARB");
return gladGetProcAddressPtr != NULL;
#endif
}
}
return 0;
}
static
void close_gl(void) {
if(libGL != NULL) {
dlclose(libGL);
libGL = NULL;
}
}
#endif
static
void* get_proc(const char *namez) {
void* result = NULL;
if(libGL == NULL) return NULL;
#if !defined(__APPLE__) && !defined(__HAIKU__)
if(gladGetProcAddressPtr != NULL) {
result = gladGetProcAddressPtr(namez);
}
#endif
if(result == NULL) {
#if defined(_WIN32) || defined(__CYGWIN__)
result = (void*)GetProcAddress((HMODULE) libGL, namez);
#else
result = dlsym(libGL, namez);
#endif
}
return result;
}
int gladLoadGL(void) {
int status = 0;
if(open_gl()) {
status = gladLoadGLLoader(&get_proc);
close_gl();
}
return status;
}
struct gladGLversionStruct GLVersion = { 0, 0 };
#if defined(GL_ES_VERSION_3_0) || defined(GL_VERSION_3_0)
#define _GLAD_IS_SOME_NEW_VERSION 1
#endif
static int max_loaded_major;
static int max_loaded_minor;
static const char *exts = NULL;
static int num_exts_i = 0;
static char **exts_i = NULL;
static int get_exts(void) {
#ifdef _GLAD_IS_SOME_NEW_VERSION
if(max_loaded_major < 3) {
#endif
exts = (const char *)glGetString(GL_EXTENSIONS);
#ifdef _GLAD_IS_SOME_NEW_VERSION
} else {
unsigned int index;
num_exts_i = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &num_exts_i);
if (num_exts_i > 0) {
exts_i = (char **)malloc((size_t)num_exts_i * (sizeof *exts_i));
}
if (exts_i == NULL) {
return 0;
}
for(index = 0; index < (unsigned)num_exts_i; index++) {
const char *gl_str_tmp = (const char*)glGetStringi(GL_EXTENSIONS, index);
size_t len = strlen(gl_str_tmp);
char *local_str = (char*)malloc((len+1) * sizeof(char));
if(local_str != NULL) {
memcpy(local_str, gl_str_tmp, (len+1) * sizeof(char));
}
exts_i[index] = local_str;
}
}
#endif
return 1;
}
static void free_exts(void) {
if (exts_i != NULL) {
int index;
for(index = 0; index < num_exts_i; index++) {
free((char *)exts_i[index]);
}
free((void *)exts_i);
exts_i = NULL;
}
}
static int has_ext(const char *ext) {
#ifdef _GLAD_IS_SOME_NEW_VERSION
if(max_loaded_major < 3) {
#endif
const char *extensions;
const char *loc;
const char *terminator;
extensions = exts;
if(extensions == NULL || ext == NULL) {
return 0;
}
while(1) {
loc = strstr(extensions, ext);
if(loc == NULL) {
return 0;
}
terminator = loc + strlen(ext);
if((loc == extensions || *(loc - 1) == ' ') &&
(*terminator == ' ' || *terminator == '\0')) {
return 1;
}
extensions = terminator;
}
#ifdef _GLAD_IS_SOME_NEW_VERSION
} else {
int index;
if(exts_i == NULL) return 0;
for(index = 0; index < num_exts_i; index++) {
const char *e = exts_i[index];
if(exts_i[index] != NULL && strcmp(e, ext) == 0) {
return 1;
}
}
}
#endif
return 0;
}
int GLAD_GL_VERSION_1_0 = 0;
int GLAD_GL_VERSION_1_1 = 0;
int GLAD_GL_VERSION_1_2 = 0;
int GLAD_GL_VERSION_1_3 = 0;
int GLAD_GL_VERSION_1_4 = 0;
int GLAD_GL_VERSION_1_5 = 0;
int GLAD_GL_VERSION_2_0 = 0;
int GLAD_GL_VERSION_2_1 = 0;
int GLAD_GL_VERSION_3_0 = 0;
int GLAD_GL_VERSION_3_1 = 0;
int GLAD_GL_VERSION_3_2 = 0;
int GLAD_GL_VERSION_3_3 = 0;
PFNGLACTIVETEXTUREPROC glad_glActiveTexture = NULL;
PFNGLATTACHSHADERPROC glad_glAttachShader = NULL;
PFNGLBEGINCONDITIONALRENDERPROC glad_glBeginConditionalRender = NULL;
PFNGLBEGINQUERYPROC glad_glBeginQuery = NULL;
PFNGLBEGINTRANSFORMFEEDBACKPROC glad_glBeginTransformFeedback = NULL;
PFNGLBINDATTRIBLOCATIONPROC glad_glBindAttribLocation = NULL;
PFNGLBINDBUFFERPROC glad_glBindBuffer = NULL;
PFNGLBINDBUFFERBASEPROC glad_glBindBufferBase = NULL;
PFNGLBINDBUFFERRANGEPROC glad_glBindBufferRange = NULL;
PFNGLBINDFRAGDATALOCATIONPROC glad_glBindFragDataLocation = NULL;
PFNGLBINDFRAGDATALOCATIONINDEXEDPROC glad_glBindFragDataLocationIndexed = NULL;
PFNGLBINDFRAMEBUFFERPROC glad_glBindFramebuffer = NULL;
PFNGLBINDRENDERBUFFERPROC glad_glBindRenderbuffer = NULL;
PFNGLBINDSAMPLERPROC glad_glBindSampler = NULL;
PFNGLBINDTEXTUREPROC glad_glBindTexture = NULL;
PFNGLBINDVERTEXARRAYPROC glad_glBindVertexArray = NULL;
PFNGLBLENDCOLORPROC glad_glBlendColor = NULL;
PFNGLBLENDEQUATIONPROC glad_glBlendEquation = NULL;
PFNGLBLENDEQUATIONSEPARATEPROC glad_glBlendEquationSeparate = NULL;
PFNGLBLENDFUNCPROC glad_glBlendFunc = NULL;
PFNGLBLENDFUNCSEPARATEPROC glad_glBlendFuncSeparate = NULL;
PFNGLBLITFRAMEBUFFERPROC glad_glBlitFramebuffer = NULL;
PFNGLBUFFERDATAPROC glad_glBufferData = NULL;
PFNGLBUFFERSUBDATAPROC glad_glBufferSubData = NULL;
PFNGLCHECKFRAMEBUFFERSTATUSPROC glad_glCheckFramebufferStatus = NULL;
PFNGLCLAMPCOLORPROC glad_glClampColor = NULL;
PFNGLCLEARPROC glad_glClear = NULL;
PFNGLCLEARBUFFERFIPROC glad_glClearBufferfi = NULL;
PFNGLCLEARBUFFERFVPROC glad_glClearBufferfv = NULL;
PFNGLCLEARBUFFERIVPROC glad_glClearBufferiv = NULL;
PFNGLCLEARBUFFERUIVPROC glad_glClearBufferuiv = NULL;
PFNGLCLEARCOLORPROC glad_glClearColor = NULL;
PFNGLCLEARDEPTHPROC glad_glClearDepth = NULL;
PFNGLCLEARSTENCILPROC glad_glClearStencil = NULL;
PFNGLCLIENTWAITSYNCPROC glad_glClientWaitSync = NULL;
PFNGLCOLORMASKPROC glad_glColorMask = NULL;
PFNGLCOLORMASKIPROC glad_glColorMaski = NULL;
PFNGLCOLORP3UIPROC glad_glColorP3ui = NULL;
PFNGLCOLORP3UIVPROC glad_glColorP3uiv = NULL;
PFNGLCOLORP4UIPROC glad_glColorP4ui = NULL;
PFNGLCOLORP4UIVPROC glad_glColorP4uiv = NULL;
PFNGLCOMPILESHADERPROC glad_glCompileShader = NULL;
PFNGLCOMPRESSEDTEXIMAGE1DPROC glad_glCompressedTexImage1D = NULL;
PFNGLCOMPRESSEDTEXIMAGE2DPROC glad_glCompressedTexImage2D = NULL;
PFNGLCOMPRESSEDTEXIMAGE3DPROC glad_glCompressedTexImage3D = NULL;
PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC glad_glCompressedTexSubImage1D = NULL;
PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC glad_glCompressedTexSubImage2D = NULL;
PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC glad_glCompressedTexSubImage3D = NULL;
PFNGLCOPYBUFFERSUBDATAPROC glad_glCopyBufferSubData = NULL;
PFNGLCOPYTEXIMAGE1DPROC glad_glCopyTexImage1D = NULL;
PFNGLCOPYTEXIMAGE2DPROC glad_glCopyTexImage2D = NULL;
PFNGLCOPYTEXSUBIMAGE1DPROC glad_glCopyTexSubImage1D = NULL;
PFNGLCOPYTEXSUBIMAGE2DPROC glad_glCopyTexSubImage2D = NULL;
PFNGLCOPYTEXSUBIMAGE3DPROC glad_glCopyTexSubImage3D = NULL;
PFNGLCREATEPROGRAMPROC glad_glCreateProgram = NULL;
PFNGLCREATESHADERPROC glad_glCreateShader = NULL;
PFNGLCULLFACEPROC glad_glCullFace = NULL;
PFNGLDELETEBUFFERSPROC glad_glDeleteBuffers = NULL;
PFNGLDELETEFRAMEBUFFERSPROC glad_glDeleteFramebuffers = NULL;
PFNGLDELETEPROGRAMPROC glad_glDeleteProgram = NULL;
PFNGLDELETEQUERIESPROC glad_glDeleteQueries = NULL;
PFNGLDELETERENDERBUFFERSPROC glad_glDeleteRenderbuffers = NULL;
PFNGLDELETESAMPLERSPROC glad_glDeleteSamplers = NULL;
PFNGLDELETESHADERPROC glad_glDeleteShader = NULL;
PFNGLDELETESYNCPROC glad_glDeleteSync = NULL;
PFNGLDELETETEXTURESPROC glad_glDeleteTextures = NULL;
PFNGLDELETEVERTEXARRAYSPROC glad_glDeleteVertexArrays = NULL;
PFNGLDEPTHFUNCPROC glad_glDepthFunc = NULL;
PFNGLDEPTHMASKPROC glad_glDepthMask = NULL;
PFNGLDEPTHRANGEPROC glad_glDepthRange = NULL;
PFNGLDETACHSHADERPROC glad_glDetachShader = NULL;
PFNGLDISABLEPROC glad_glDisable = NULL;
PFNGLDISABLEVERTEXATTRIBARRAYPROC glad_glDisableVertexAttribArray = NULL;
PFNGLDISABLEIPROC glad_glDisablei = NULL;
PFNGLDRAWARRAYSPROC glad_glDrawArrays = NULL;
PFNGLDRAWARRAYSINSTANCEDPROC glad_glDrawArraysInstanced = NULL;
PFNGLDRAWBUFFERPROC glad_glDrawBuffer = NULL;
PFNGLDRAWBUFFERSPROC glad_glDrawBuffers = NULL;
PFNGLDRAWELEMENTSPROC glad_glDrawElements = NULL;
PFNGLDRAWELEMENTSBASEVERTEXPROC glad_glDrawElementsBaseVertex = NULL;
PFNGLDRAWELEMENTSINSTANCEDPROC glad_glDrawElementsInstanced = NULL;
PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC glad_glDrawElementsInstancedBaseVertex = NULL;
PFNGLDRAWRANGEELEMENTSPROC glad_glDrawRangeElements = NULL;
PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC glad_glDrawRangeElementsBaseVertex = NULL;
PFNGLENABLEPROC glad_glEnable = NULL;
PFNGLENABLEVERTEXATTRIBARRAYPROC glad_glEnableVertexAttribArray = NULL;
PFNGLENABLEIPROC glad_glEnablei = NULL;
PFNGLENDCONDITIONALRENDERPROC glad_glEndConditionalRender = NULL;
PFNGLENDQUERYPROC glad_glEndQuery = NULL;
PFNGLENDTRANSFORMFEEDBACKPROC glad_glEndTransformFeedback = NULL;
PFNGLFENCESYNCPROC glad_glFenceSync = NULL;
PFNGLFINISHPROC glad_glFinish = NULL;
PFNGLFLUSHPROC glad_glFlush = NULL;
PFNGLFLUSHMAPPEDBUFFERRANGEPROC glad_glFlushMappedBufferRange = NULL;
PFNGLFRAMEBUFFERRENDERBUFFERPROC glad_glFramebufferRenderbuffer = NULL;
PFNGLFRAMEBUFFERTEXTUREPROC glad_glFramebufferTexture = NULL;
PFNGLFRAMEBUFFERTEXTURE1DPROC glad_glFramebufferTexture1D = NULL;
PFNGLFRAMEBUFFERTEXTURE2DPROC glad_glFramebufferTexture2D = NULL;
PFNGLFRAMEBUFFERTEXTURE3DPROC glad_glFramebufferTexture3D = NULL;
PFNGLFRAMEBUFFERTEXTURELAYERPROC glad_glFramebufferTextureLayer = NULL;
PFNGLFRONTFACEPROC glad_glFrontFace = NULL;
PFNGLGENBUFFERSPROC glad_glGenBuffers = NULL;
PFNGLGENFRAMEBUFFERSPROC glad_glGenFramebuffers = NULL;
PFNGLGENQUERIESPROC glad_glGenQueries = NULL;
PFNGLGENRENDERBUFFERSPROC glad_glGenRenderbuffers = NULL;
PFNGLGENSAMPLERSPROC glad_glGenSamplers = NULL;
PFNGLGENTEXTURESPROC glad_glGenTextures = NULL;
PFNGLGENVERTEXARRAYSPROC glad_glGenVertexArrays = NULL;
PFNGLGENERATEMIPMAPPROC glad_glGenerateMipmap = NULL;
PFNGLGETACTIVEATTRIBPROC glad_glGetActiveAttrib = NULL;
PFNGLGETACTIVEUNIFORMPROC glad_glGetActiveUniform = NULL;
PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC glad_glGetActiveUniformBlockName = NULL;
PFNGLGETACTIVEUNIFORMBLOCKIVPROC glad_glGetActiveUniformBlockiv = NULL;
PFNGLGETACTIVEUNIFORMNAMEPROC glad_glGetActiveUniformName = NULL;
PFNGLGETACTIVEUNIFORMSIVPROC glad_glGetActiveUniformsiv = NULL;
PFNGLGETATTACHEDSHADERSPROC glad_glGetAttachedShaders = NULL;
PFNGLGETATTRIBLOCATIONPROC glad_glGetAttribLocation = NULL;
PFNGLGETBOOLEANI_VPROC glad_glGetBooleani_v = NULL;
PFNGLGETBOOLEANVPROC glad_glGetBooleanv = NULL;
PFNGLGETBUFFERPARAMETERI64VPROC glad_glGetBufferParameteri64v = NULL;
PFNGLGETBUFFERPARAMETERIVPROC glad_glGetBufferParameteriv = NULL;
PFNGLGETBUFFERPOINTERVPROC glad_glGetBufferPointerv = NULL;
PFNGLGETBUFFERSUBDATAPROC glad_glGetBufferSubData = NULL;
PFNGLGETCOMPRESSEDTEXIMAGEPROC glad_glGetCompressedTexImage = NULL;
PFNGLGETDOUBLEVPROC glad_glGetDoublev = NULL;
PFNGLGETERRORPROC glad_glGetError = NULL;
PFNGLGETFLOATVPROC glad_glGetFloatv = NULL;
PFNGLGETFRAGDATAINDEXPROC glad_glGetFragDataIndex = NULL;
PFNGLGETFRAGDATALOCATIONPROC glad_glGetFragDataLocation = NULL;
PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC glad_glGetFramebufferAttachmentParameteriv = NULL;
PFNGLGETINTEGER64I_VPROC glad_glGetInteger64i_v = NULL;
PFNGLGETINTEGER64VPROC glad_glGetInteger64v = NULL;
PFNGLGETINTEGERI_VPROC glad_glGetIntegeri_v = NULL;
PFNGLGETINTEGERVPROC glad_glGetIntegerv = NULL;
PFNGLGETMULTISAMPLEFVPROC glad_glGetMultisamplefv = NULL;
PFNGLGETPROGRAMINFOLOGPROC glad_glGetProgramInfoLog = NULL;
PFNGLGETPROGRAMIVPROC glad_glGetProgramiv = NULL;
PFNGLGETQUERYOBJECTI64VPROC glad_glGetQueryObjecti64v = NULL;
PFNGLGETQUERYOBJECTIVPROC glad_glGetQueryObjectiv = NULL;
PFNGLGETQUERYOBJECTUI64VPROC glad_glGetQueryObjectui64v = NULL;
PFNGLGETQUERYOBJECTUIVPROC glad_glGetQueryObjectuiv = NULL;
PFNGLGETQUERYIVPROC glad_glGetQueryiv = NULL;
PFNGLGETRENDERBUFFERPARAMETERIVPROC glad_glGetRenderbufferParameteriv = NULL;
PFNGLGETSAMPLERPARAMETERIIVPROC glad_glGetSamplerParameterIiv = NULL;
PFNGLGETSAMPLERPARAMETERIUIVPROC glad_glGetSamplerParameterIuiv = NULL;
PFNGLGETSAMPLERPARAMETERFVPROC glad_glGetSamplerParameterfv = NULL;
PFNGLGETSAMPLERPARAMETERIVPROC glad_glGetSamplerParameteriv = NULL;
PFNGLGETSHADERINFOLOGPROC glad_glGetShaderInfoLog = NULL;
PFNGLGETSHADERSOURCEPROC glad_glGetShaderSource = NULL;
PFNGLGETSHADERIVPROC glad_glGetShaderiv = NULL;
PFNGLGETSTRINGPROC glad_glGetString = NULL;
PFNGLGETSTRINGIPROC glad_glGetStringi = NULL;
PFNGLGETSYNCIVPROC glad_glGetSynciv = NULL;
PFNGLGETTEXIMAGEPROC glad_glGetTexImage = NULL;
PFNGLGETTEXLEVELPARAMETERFVPROC glad_glGetTexLevelParameterfv = NULL;
PFNGLGETTEXLEVELPARAMETERIVPROC glad_glGetTexLevelParameteriv = NULL;
PFNGLGETTEXPARAMETERIIVPROC glad_glGetTexParameterIiv = NULL;
PFNGLGETTEXPARAMETERIUIVPROC glad_glGetTexParameterIuiv = NULL;
PFNGLGETTEXPARAMETERFVPROC glad_glGetTexParameterfv = NULL;
PFNGLGETTEXPARAMETERIVPROC glad_glGetTexParameteriv = NULL;
PFNGLGETTRANSFORMFEEDBACKVARYINGPROC glad_glGetTransformFeedbackVarying = NULL;
PFNGLGETUNIFORMBLOCKINDEXPROC glad_glGetUniformBlockIndex = NULL;
PFNGLGETUNIFORMINDICESPROC glad_glGetUniformIndices = NULL;
PFNGLGETUNIFORMLOCATIONPROC glad_glGetUniformLocation = NULL;
PFNGLGETUNIFORMFVPROC glad_glGetUniformfv = NULL;
PFNGLGETUNIFORMIVPROC glad_glGetUniformiv = NULL;
PFNGLGETUNIFORMUIVPROC glad_glGetUniformuiv = NULL;
PFNGLGETVERTEXATTRIBIIVPROC glad_glGetVertexAttribIiv = NULL;
PFNGLGETVERTEXATTRIBIUIVPROC glad_glGetVertexAttribIuiv = NULL;
PFNGLGETVERTEXATTRIBPOINTERVPROC glad_glGetVertexAttribPointerv = NULL;
PFNGLGETVERTEXATTRIBDVPROC glad_glGetVertexAttribdv = NULL;
PFNGLGETVERTEXATTRIBFVPROC glad_glGetVertexAttribfv = NULL;
PFNGLGETVERTEXATTRIBIVPROC glad_glGetVertexAttribiv = NULL;
PFNGLHINTPROC glad_glHint = NULL;
PFNGLISBUFFERPROC glad_glIsBuffer = NULL;
PFNGLISENABLEDPROC glad_glIsEnabled = NULL;
PFNGLISENABLEDIPROC glad_glIsEnabledi = NULL;
PFNGLISFRAMEBUFFERPROC glad_glIsFramebuffer = NULL;
PFNGLISPROGRAMPROC glad_glIsProgram = NULL;
PFNGLISQUERYPROC glad_glIsQuery = NULL;
PFNGLISRENDERBUFFERPROC glad_glIsRenderbuffer = NULL;
PFNGLISSAMPLERPROC glad_glIsSampler = NULL;
PFNGLISSHADERPROC glad_glIsShader = NULL;
PFNGLISSYNCPROC glad_glIsSync = NULL;
PFNGLISTEXTUREPROC glad_glIsTexture = NULL;
PFNGLISVERTEXARRAYPROC glad_glIsVertexArray = NULL;
PFNGLLINEWIDTHPROC glad_glLineWidth = NULL;
PFNGLLINKPROGRAMPROC glad_glLinkProgram = NULL;
PFNGLLOGICOPPROC glad_glLogicOp = NULL;
PFNGLMAPBUFFERPROC glad_glMapBuffer = NULL;
PFNGLMAPBUFFERRANGEPROC glad_glMapBufferRange = NULL;
PFNGLMULTIDRAWARRAYSPROC glad_glMultiDrawArrays = NULL;
PFNGLMULTIDRAWELEMENTSPROC glad_glMultiDrawElements = NULL;
PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC glad_glMultiDrawElementsBaseVertex = NULL;
PFNGLMULTITEXCOORDP1UIPROC glad_glMultiTexCoordP1ui = NULL;
PFNGLMULTITEXCOORDP1UIVPROC glad_glMultiTexCoordP1uiv = NULL;
PFNGLMULTITEXCOORDP2UIPROC glad_glMultiTexCoordP2ui = NULL;
PFNGLMULTITEXCOORDP2UIVPROC glad_glMultiTexCoordP2uiv = NULL;
PFNGLMULTITEXCOORDP3UIPROC glad_glMultiTexCoordP3ui = NULL;
PFNGLMULTITEXCOORDP3UIVPROC glad_glMultiTexCoordP3uiv = NULL;
PFNGLMULTITEXCOORDP4UIPROC glad_glMultiTexCoordP4ui = NULL;
PFNGLMULTITEXCOORDP4UIVPROC glad_glMultiTexCoordP4uiv = NULL;
PFNGLNORMALP3UIPROC glad_glNormalP3ui = NULL;
PFNGLNORMALP3UIVPROC glad_glNormalP3uiv = NULL;
PFNGLPIXELSTOREFPROC glad_glPixelStoref = NULL;
PFNGLPIXELSTOREIPROC glad_glPixelStorei = NULL;
PFNGLPOINTPARAMETERFPROC glad_glPointParameterf = NULL;
PFNGLPOINTPARAMETERFVPROC glad_glPointParameterfv = NULL;
PFNGLPOINTPARAMETERIPROC glad_glPointParameteri = NULL;
PFNGLPOINTPARAMETERIVPROC glad_glPointParameteriv = NULL;
PFNGLPOINTSIZEPROC glad_glPointSize = NULL;
PFNGLPOLYGONMODEPROC glad_glPolygonMode = NULL;
PFNGLPOLYGONOFFSETPROC glad_glPolygonOffset = NULL;
PFNGLPRIMITIVERESTARTINDEXPROC glad_glPrimitiveRestartIndex = NULL;
PFNGLPROVOKINGVERTEXPROC glad_glProvokingVertex = NULL;
PFNGLQUERYCOUNTERPROC glad_glQueryCounter = NULL;
PFNGLREADBUFFERPROC glad_glReadBuffer = NULL;
PFNGLREADPIXELSPROC glad_glReadPixels = NULL;
PFNGLRENDERBUFFERSTORAGEPROC glad_glRenderbufferStorage = NULL;
PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC glad_glRenderbufferStorageMultisample = NULL;
PFNGLSAMPLECOVERAGEPROC glad_glSampleCoverage = NULL;
PFNGLSAMPLEMASKIPROC glad_glSampleMaski = NULL;
PFNGLSAMPLERPARAMETERIIVPROC glad_glSamplerParameterIiv = NULL;
PFNGLSAMPLERPARAMETERIUIVPROC glad_glSamplerParameterIuiv = NULL;
PFNGLSAMPLERPARAMETERFPROC glad_glSamplerParameterf = NULL;
PFNGLSAMPLERPARAMETERFVPROC glad_glSamplerParameterfv = NULL;
PFNGLSAMPLERPARAMETERIPROC glad_glSamplerParameteri = NULL;
PFNGLSAMPLERPARAMETERIVPROC glad_glSamplerParameteriv = NULL;
PFNGLSCISSORPROC glad_glScissor = NULL;
PFNGLSECONDARYCOLORP3UIPROC glad_glSecondaryColorP3ui = NULL;
PFNGLSECONDARYCOLORP3UIVPROC glad_glSecondaryColorP3uiv = NULL;
PFNGLSHADERSOURCEPROC glad_glShaderSource = NULL;
PFNGLSTENCILFUNCPROC glad_glStencilFunc = NULL;
PFNGLSTENCILFUNCSEPARATEPROC glad_glStencilFuncSeparate = NULL;
PFNGLSTENCILMASKPROC glad_glStencilMask = NULL;
PFNGLSTENCILMASKSEPARATEPROC glad_glStencilMaskSeparate = NULL;
PFNGLSTENCILOPPROC glad_glStencilOp = NULL;
PFNGLSTENCILOPSEPARATEPROC glad_glStencilOpSeparate = NULL;
PFNGLTEXBUFFERPROC glad_glTexBuffer = NULL;
PFNGLTEXCOORDP1UIPROC glad_glTexCoordP1ui = NULL;
PFNGLTEXCOORDP1UIVPROC glad_glTexCoordP1uiv = NULL;
PFNGLTEXCOORDP2UIPROC glad_glTexCoordP2ui = NULL;
PFNGLTEXCOORDP2UIVPROC glad_glTexCoordP2uiv = NULL;
PFNGLTEXCOORDP3UIPROC glad_glTexCoordP3ui = NULL;
PFNGLTEXCOORDP3UIVPROC glad_glTexCoordP3uiv = NULL;
PFNGLTEXCOORDP4UIPROC glad_glTexCoordP4ui = NULL;
PFNGLTEXCOORDP4UIVPROC glad_glTexCoordP4uiv = NULL;
PFNGLTEXIMAGE1DPROC glad_glTexImage1D = NULL;
PFNGLTEXIMAGE2DPROC glad_glTexImage2D = NULL;
PFNGLTEXIMAGE2DMULTISAMPLEPROC glad_glTexImage2DMultisample = NULL;
PFNGLTEXIMAGE3DPROC glad_glTexImage3D = NULL;
PFNGLTEXIMAGE3DMULTISAMPLEPROC glad_glTexImage3DMultisample = NULL;
PFNGLTEXPARAMETERIIVPROC glad_glTexParameterIiv = NULL;
PFNGLTEXPARAMETERIUIVPROC glad_glTexParameterIuiv = NULL;
PFNGLTEXPARAMETERFPROC glad_glTexParameterf = NULL;
PFNGLTEXPARAMETERFVPROC glad_glTexParameterfv = NULL;
PFNGLTEXPARAMETERIPROC glad_glTexParameteri = NULL;
PFNGLTEXPARAMETERIVPROC glad_glTexParameteriv = NULL;
PFNGLTEXSUBIMAGE1DPROC glad_glTexSubImage1D = NULL;
PFNGLTEXSUBIMAGE2DPROC glad_glTexSubImage2D = NULL;
PFNGLTEXSUBIMAGE3DPROC glad_glTexSubImage3D = NULL;
PFNGLTRANSFORMFEEDBACKVARYINGSPROC glad_glTransformFeedbackVaryings = NULL;
PFNGLUNIFORM1FPROC glad_glUniform1f = NULL;
PFNGLUNIFORM1FVPROC glad_glUniform1fv = NULL;
PFNGLUNIFORM1IPROC glad_glUniform1i = NULL;
PFNGLUNIFORM1IVPROC glad_glUniform1iv = NULL;
PFNGLUNIFORM1UIPROC glad_glUniform1ui = NULL;
PFNGLUNIFORM1UIVPROC glad_glUniform1uiv = NULL;
PFNGLUNIFORM2FPROC glad_glUniform2f = NULL;
PFNGLUNIFORM2FVPROC glad_glUniform2fv = NULL;
PFNGLUNIFORM2IPROC glad_glUniform2i = NULL;
PFNGLUNIFORM2IVPROC glad_glUniform2iv = NULL;
PFNGLUNIFORM2UIPROC glad_glUniform2ui = NULL;
PFNGLUNIFORM2UIVPROC glad_glUniform2uiv = NULL;
PFNGLUNIFORM3FPROC glad_glUniform3f = NULL;
PFNGLUNIFORM3FVPROC glad_glUniform3fv = NULL;
PFNGLUNIFORM3IPROC glad_glUniform3i = NULL;
PFNGLUNIFORM3IVPROC glad_glUniform3iv = NULL;
PFNGLUNIFORM3UIPROC glad_glUniform3ui = NULL;
PFNGLUNIFORM3UIVPROC glad_glUniform3uiv = NULL;
PFNGLUNIFORM4FPROC glad_glUniform4f = NULL;
PFNGLUNIFORM4FVPROC glad_glUniform4fv = NULL;
PFNGLUNIFORM4IPROC glad_glUniform4i = NULL;
PFNGLUNIFORM4IVPROC glad_glUniform4iv = NULL;
PFNGLUNIFORM4UIPROC glad_glUniform4ui = NULL;
PFNGLUNIFORM4UIVPROC glad_glUniform4uiv = NULL;
PFNGLUNIFORMBLOCKBINDINGPROC glad_glUniformBlockBinding = NULL;
PFNGLUNIFORMMATRIX2FVPROC glad_glUniformMatrix2fv = NULL;
PFNGLUNIFORMMATRIX2X3FVPROC glad_glUniformMatrix2x3fv = NULL;
PFNGLUNIFORMMATRIX2X4FVPROC glad_glUniformMatrix2x4fv = NULL;
PFNGLUNIFORMMATRIX3FVPROC glad_glUniformMatrix3fv = NULL;
PFNGLUNIFORMMATRIX3X2FVPROC glad_glUniformMatrix3x2fv = NULL;
PFNGLUNIFORMMATRIX3X4FVPROC glad_glUniformMatrix3x4fv = NULL;
PFNGLUNIFORMMATRIX4FVPROC glad_glUniformMatrix4fv = NULL;
PFNGLUNIFORMMATRIX4X2FVPROC glad_glUniformMatrix4x2fv = NULL;
PFNGLUNIFORMMATRIX4X3FVPROC glad_glUniformMatrix4x3fv = NULL;
PFNGLUNMAPBUFFERPROC glad_glUnmapBuffer = NULL;
PFNGLUSEPROGRAMPROC glad_glUseProgram = NULL;
PFNGLVALIDATEPROGRAMPROC glad_glValidateProgram = NULL;
PFNGLVERTEXATTRIB1DPROC glad_glVertexAttrib1d = NULL;
PFNGLVERTEXATTRIB1DVPROC glad_glVertexAttrib1dv = NULL;
PFNGLVERTEXATTRIB1FPROC glad_glVertexAttrib1f = NULL;
PFNGLVERTEXATTRIB1FVPROC glad_glVertexAttrib1fv = NULL;
PFNGLVERTEXATTRIB1SPROC glad_glVertexAttrib1s = NULL;
PFNGLVERTEXATTRIB1SVPROC glad_glVertexAttrib1sv = NULL;
PFNGLVERTEXATTRIB2DPROC glad_glVertexAttrib2d = NULL;
PFNGLVERTEXATTRIB2DVPROC glad_glVertexAttrib2dv = NULL;
PFNGLVERTEXATTRIB2FPROC glad_glVertexAttrib2f = NULL;
PFNGLVERTEXATTRIB2FVPROC glad_glVertexAttrib2fv = NULL;
PFNGLVERTEXATTRIB2SPROC glad_glVertexAttrib2s = NULL;
PFNGLVERTEXATTRIB2SVPROC glad_glVertexAttrib2sv = NULL;
PFNGLVERTEXATTRIB3DPROC glad_glVertexAttrib3d = NULL;
PFNGLVERTEXATTRIB3DVPROC glad_glVertexAttrib3dv = NULL;
PFNGLVERTEXATTRIB3FPROC glad_glVertexAttrib3f = NULL;
PFNGLVERTEXATTRIB3FVPROC glad_glVertexAttrib3fv = NULL;
PFNGLVERTEXATTRIB3SPROC glad_glVertexAttrib3s = NULL;
PFNGLVERTEXATTRIB3SVPROC glad_glVertexAttrib3sv = NULL;
PFNGLVERTEXATTRIB4NBVPROC glad_glVertexAttrib4Nbv = NULL;
PFNGLVERTEXATTRIB4NIVPROC glad_glVertexAttrib4Niv = NULL;
PFNGLVERTEXATTRIB4NSVPROC glad_glVertexAttrib4Nsv = NULL;
PFNGLVERTEXATTRIB4NUBPROC glad_glVertexAttrib4Nub = NULL;
PFNGLVERTEXATTRIB4NUBVPROC glad_glVertexAttrib4Nubv = NULL;
PFNGLVERTEXATTRIB4NUIVPROC glad_glVertexAttrib4Nuiv = NULL;
PFNGLVERTEXATTRIB4NUSVPROC glad_glVertexAttrib4Nusv = NULL;
PFNGLVERTEXATTRIB4BVPROC glad_glVertexAttrib4bv = NULL;
PFNGLVERTEXATTRIB4DPROC glad_glVertexAttrib4d = NULL;
PFNGLVERTEXATTRIB4DVPROC glad_glVertexAttrib4dv = NULL;
PFNGLVERTEXATTRIB4FPROC glad_glVertexAttrib4f = NULL;
PFNGLVERTEXATTRIB4FVPROC glad_glVertexAttrib4fv = NULL;
PFNGLVERTEXATTRIB4IVPROC glad_glVertexAttrib4iv = NULL;
PFNGLVERTEXATTRIB4SPROC glad_glVertexAttrib4s = NULL;
PFNGLVERTEXATTRIB4SVPROC glad_glVertexAttrib4sv = NULL;
PFNGLVERTEXATTRIB4UBVPROC glad_glVertexAttrib4ubv = NULL;
PFNGLVERTEXATTRIB4UIVPROC glad_glVertexAttrib4uiv = NULL;
PFNGLVERTEXATTRIB4USVPROC glad_glVertexAttrib4usv = NULL;
PFNGLVERTEXATTRIBDIVISORPROC glad_glVertexAttribDivisor = NULL;
PFNGLVERTEXATTRIBI1IPROC glad_glVertexAttribI1i = NULL;
PFNGLVERTEXATTRIBI1IVPROC glad_glVertexAttribI1iv = NULL;
PFNGLVERTEXATTRIBI1UIPROC glad_glVertexAttribI1ui = NULL;
PFNGLVERTEXATTRIBI1UIVPROC glad_glVertexAttribI1uiv = NULL;
PFNGLVERTEXATTRIBI2IPROC glad_glVertexAttribI2i = NULL;
PFNGLVERTEXATTRIBI2IVPROC glad_glVertexAttribI2iv = NULL;
PFNGLVERTEXATTRIBI2UIPROC glad_glVertexAttribI2ui = NULL;
PFNGLVERTEXATTRIBI2UIVPROC glad_glVertexAttribI2uiv = NULL;
PFNGLVERTEXATTRIBI3IPROC glad_glVertexAttribI3i = NULL;
PFNGLVERTEXATTRIBI3IVPROC glad_glVertexAttribI3iv = NULL;
PFNGLVERTEXATTRIBI3UIPROC glad_glVertexAttribI3ui = NULL;
PFNGLVERTEXATTRIBI3UIVPROC glad_glVertexAttribI3uiv = NULL;
PFNGLVERTEXATTRIBI4BVPROC glad_glVertexAttribI4bv = NULL;
PFNGLVERTEXATTRIBI4IPROC glad_glVertexAttribI4i = NULL;
PFNGLVERTEXATTRIBI4IVPROC glad_glVertexAttribI4iv = NULL;
PFNGLVERTEXATTRIBI4SVPROC glad_glVertexAttribI4sv = NULL;
PFNGLVERTEXATTRIBI4UBVPROC glad_glVertexAttribI4ubv = NULL;
PFNGLVERTEXATTRIBI4UIPROC glad_glVertexAttribI4ui = NULL;
PFNGLVERTEXATTRIBI4UIVPROC glad_glVertexAttribI4uiv = NULL;
PFNGLVERTEXATTRIBI4USVPROC glad_glVertexAttribI4usv = NULL;
PFNGLVERTEXATTRIBIPOINTERPROC glad_glVertexAttribIPointer = NULL;
PFNGLVERTEXATTRIBP1UIPROC glad_glVertexAttribP1ui = NULL;
PFNGLVERTEXATTRIBP1UIVPROC glad_glVertexAttribP1uiv = NULL;
PFNGLVERTEXATTRIBP2UIPROC glad_glVertexAttribP2ui = NULL;
PFNGLVERTEXATTRIBP2UIVPROC glad_glVertexAttribP2uiv = NULL;
PFNGLVERTEXATTRIBP3UIPROC glad_glVertexAttribP3ui = NULL;
PFNGLVERTEXATTRIBP3UIVPROC glad_glVertexAttribP3uiv = NULL;
PFNGLVERTEXATTRIBP4UIPROC glad_glVertexAttribP4ui = NULL;
PFNGLVERTEXATTRIBP4UIVPROC glad_glVertexAttribP4uiv = NULL;
PFNGLVERTEXATTRIBPOINTERPROC glad_glVertexAttribPointer = NULL;
PFNGLVERTEXP2UIPROC glad_glVertexP2ui = NULL;
PFNGLVERTEXP2UIVPROC glad_glVertexP2uiv = NULL;
PFNGLVERTEXP3UIPROC glad_glVertexP3ui = NULL;
PFNGLVERTEXP3UIVPROC glad_glVertexP3uiv = NULL;
PFNGLVERTEXP4UIPROC glad_glVertexP4ui = NULL;
PFNGLVERTEXP4UIVPROC glad_glVertexP4uiv = NULL;
PFNGLVIEWPORTPROC glad_glViewport = NULL;
PFNGLWAITSYNCPROC glad_glWaitSync = NULL;
static void load_GL_VERSION_1_0(GLADloadproc load) {
if(!GLAD_GL_VERSION_1_0) return;
glad_glCullFace = (PFNGLCULLFACEPROC)load("glCullFace");
glad_glFrontFace = (PFNGLFRONTFACEPROC)load("glFrontFace");
glad_glHint = (PFNGLHINTPROC)load("glHint");
glad_glLineWidth = (PFNGLLINEWIDTHPROC)load("glLineWidth");
glad_glPointSize = (PFNGLPOINTSIZEPROC)load("glPointSize");
glad_glPolygonMode = (PFNGLPOLYGONMODEPROC)load("glPolygonMode");
glad_glScissor = (PFNGLSCISSORPROC)load("glScissor");
glad_glTexParameterf = (PFNGLTEXPARAMETERFPROC)load("glTexParameterf");
glad_glTexParameterfv = (PFNGLTEXPARAMETERFVPROC)load("glTexParameterfv");
glad_glTexParameteri = (PFNGLTEXPARAMETERIPROC)load("glTexParameteri");
glad_glTexParameteriv = (PFNGLTEXPARAMETERIVPROC)load("glTexParameteriv");
glad_glTexImage1D = (PFNGLTEXIMAGE1DPROC)load("glTexImage1D");
glad_glTexImage2D = (PFNGLTEXIMAGE2DPROC)load("glTexImage2D");
glad_glDrawBuffer = (PFNGLDRAWBUFFERPROC)load("glDrawBuffer");
glad_glClear = (PFNGLCLEARPROC)load("glClear");
glad_glClearColor = (PFNGLCLEARCOLORPROC)load("glClearColor");
glad_glClearStencil = (PFNGLCLEARSTENCILPROC)load("glClearStencil");
glad_glClearDepth = (PFNGLCLEARDEPTHPROC)load("glClearDepth");
glad_glStencilMask = (PFNGLSTENCILMASKPROC)load("glStencilMask");
glad_glColorMask = (PFNGLCOLORMASKPROC)load("glColorMask");
glad_glDepthMask = (PFNGLDEPTHMASKPROC)load("glDepthMask");
glad_glDisable = (PFNGLDISABLEPROC)load("glDisable");
glad_glEnable = (PFNGLENABLEPROC)load("glEnable");
glad_glFinish = (PFNGLFINISHPROC)load("glFinish");
glad_glFlush = (PFNGLFLUSHPROC)load("glFlush");
glad_glBlendFunc = (PFNGLBLENDFUNCPROC)load("glBlendFunc");
glad_glLogicOp = (PFNGLLOGICOPPROC)load("glLogicOp");
glad_glStencilFunc = (PFNGLSTENCILFUNCPROC)load("glStencilFunc");
glad_glStencilOp = (PFNGLSTENCILOPPROC)load("glStencilOp");
glad_glDepthFunc = (PFNGLDEPTHFUNCPROC)load("glDepthFunc");
glad_glPixelStoref = (PFNGLPIXELSTOREFPROC)load("glPixelStoref");
glad_glPixelStorei = (PFNGLPIXELSTOREIPROC)load("glPixelStorei");
glad_glReadBuffer = (PFNGLREADBUFFERPROC)load("glReadBuffer");
glad_glReadPixels = (PFNGLREADPIXELSPROC)load("glReadPixels");
glad_glGetBooleanv = (PFNGLGETBOOLEANVPROC)load("glGetBooleanv");
glad_glGetDoublev = (PFNGLGETDOUBLEVPROC)load("glGetDoublev");
glad_glGetError = (PFNGLGETERRORPROC)load("glGetError");
glad_glGetFloatv = (PFNGLGETFLOATVPROC)load("glGetFloatv");
glad_glGetIntegerv = (PFNGLGETINTEGERVPROC)load("glGetIntegerv");
glad_glGetString = (PFNGLGETSTRINGPROC)load("glGetString");
glad_glGetTexImage = (PFNGLGETTEXIMAGEPROC)load("glGetTexImage");
glad_glGetTexParameterfv = (PFNGLGETTEXPARAMETERFVPROC)load("glGetTexParameterfv");
glad_glGetTexParameteriv = (PFNGLGETTEXPARAMETERIVPROC)load("glGetTexParameteriv");
glad_glGetTexLevelParameterfv = (PFNGLGETTEXLEVELPARAMETERFVPROC)load("glGetTexLevelParameterfv");
glad_glGetTexLevelParameteriv = (PFNGLGETTEXLEVELPARAMETERIVPROC)load("glGetTexLevelParameteriv");
glad_glIsEnabled = (PFNGLISENABLEDPROC)load("glIsEnabled");
glad_glDepthRange = (PFNGLDEPTHRANGEPROC)load("glDepthRange");
glad_glViewport = (PFNGLVIEWPORTPROC)load("glViewport");
}
static void load_GL_VERSION_1_1(GLADloadproc load) {
if(!GLAD_GL_VERSION_1_1) return;
glad_glDrawArrays = (PFNGLDRAWARRAYSPROC)load("glDrawArrays");
glad_glDrawElements = (PFNGLDRAWELEMENTSPROC)load("glDrawElements");
glad_glPolygonOffset = (PFNGLPOLYGONOFFSETPROC)load("glPolygonOffset");
glad_glCopyTexImage1D = (PFNGLCOPYTEXIMAGE1DPROC)load("glCopyTexImage1D");
glad_glCopyTexImage2D = (PFNGLCOPYTEXIMAGE2DPROC)load("glCopyTexImage2D");
glad_glCopyTexSubImage1D = (PFNGLCOPYTEXSUBIMAGE1DPROC)load("glCopyTexSubImage1D");
glad_glCopyTexSubImage2D = (PFNGLCOPYTEXSUBIMAGE2DPROC)load("glCopyTexSubImage2D");
glad_glTexSubImage1D = (PFNGLTEXSUBIMAGE1DPROC)load("glTexSubImage1D");
glad_glTexSubImage2D = (PFNGLTEXSUBIMAGE2DPROC)load("glTexSubImage2D");
glad_glBindTexture = (PFNGLBINDTEXTUREPROC)load("glBindTexture");
glad_glDeleteTextures = (PFNGLDELETETEXTURESPROC)load("glDeleteTextures");
glad_glGenTextures = (PFNGLGENTEXTURESPROC)load("glGenTextures");
glad_glIsTexture = (PFNGLISTEXTUREPROC)load("glIsTexture");
}
static void load_GL_VERSION_1_2(GLADloadproc load) {
if(!GLAD_GL_VERSION_1_2) return;
glad_glDrawRangeElements = (PFNGLDRAWRANGEELEMENTSPROC)load("glDrawRangeElements");
glad_glTexImage3D = (PFNGLTEXIMAGE3DPROC)load("glTexImage3D");
glad_glTexSubImage3D = (PFNGLTEXSUBIMAGE3DPROC)load("glTexSubImage3D");
glad_glCopyTexSubImage3D = (PFNGLCOPYTEXSUBIMAGE3DPROC)load("glCopyTexSubImage3D");
}
static void load_GL_VERSION_1_3(GLADloadproc load) {
if(!GLAD_GL_VERSION_1_3) return;
glad_glActiveTexture = (PFNGLACTIVETEXTUREPROC)load("glActiveTexture");
glad_glSampleCoverage = (PFNGLSAMPLECOVERAGEPROC)load("glSampleCoverage");
glad_glCompressedTexImage3D = (PFNGLCOMPRESSEDTEXIMAGE3DPROC)load("glCompressedTexImage3D");
glad_glCompressedTexImage2D = (PFNGLCOMPRESSEDTEXIMAGE2DPROC)load("glCompressedTexImage2D");
glad_glCompressedTexImage1D = (PFNGLCOMPRESSEDTEXIMAGE1DPROC)load("glCompressedTexImage1D");
glad_glCompressedTexSubImage3D = (PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC)load("glCompressedTexSubImage3D");
glad_glCompressedTexSubImage2D = (PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC)load("glCompressedTexSubImage2D");
glad_glCompressedTexSubImage1D = (PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC)load("glCompressedTexSubImage1D");
glad_glGetCompressedTexImage = (PFNGLGETCOMPRESSEDTEXIMAGEPROC)load("glGetCompressedTexImage");
}
static void load_GL_VERSION_1_4(GLADloadproc load) {
if(!GLAD_GL_VERSION_1_4) return;
glad_glBlendFuncSeparate = (PFNGLBLENDFUNCSEPARATEPROC)load("glBlendFuncSeparate");
glad_glMultiDrawArrays = (PFNGLMULTIDRAWARRAYSPROC)load("glMultiDrawArrays");
glad_glMultiDrawElements = (PFNGLMULTIDRAWELEMENTSPROC)load("glMultiDrawElements");
glad_glPointParameterf = (PFNGLPOINTPARAMETERFPROC)load("glPointParameterf");
glad_glPointParameterfv = (PFNGLPOINTPARAMETERFVPROC)load("glPointParameterfv");
glad_glPointParameteri = (PFNGLPOINTPARAMETERIPROC)load("glPointParameteri");
glad_glPointParameteriv = (PFNGLPOINTPARAMETERIVPROC)load("glPointParameteriv");
glad_glBlendColor = (PFNGLBLENDCOLORPROC)load("glBlendColor");
glad_glBlendEquation = (PFNGLBLENDEQUATIONPROC)load("glBlendEquation");
}
static void load_GL_VERSION_1_5(GLADloadproc load) {
if(!GLAD_GL_VERSION_1_5) return;
glad_glGenQueries = (PFNGLGENQUERIESPROC)load("glGenQueries");
glad_glDeleteQueries = (PFNGLDELETEQUERIESPROC)load("glDeleteQueries");
glad_glIsQuery = (PFNGLISQUERYPROC)load("glIsQuery");
glad_glBeginQuery = (PFNGLBEGINQUERYPROC)load("glBeginQuery");
glad_glEndQuery = (PFNGLENDQUERYPROC)load("glEndQuery");
glad_glGetQueryiv = (PFNGLGETQUERYIVPROC)load("glGetQueryiv");
glad_glGetQueryObjectiv = (PFNGLGETQUERYOBJECTIVPROC)load("glGetQueryObjectiv");
glad_glGetQueryObjectuiv = (PFNGLGETQUERYOBJECTUIVPROC)load("glGetQueryObjectuiv");
glad_glBindBuffer = (PFNGLBINDBUFFERPROC)load("glBindBuffer");
glad_glDeleteBuffers = (PFNGLDELETEBUFFERSPROC)load("glDeleteBuffers");
glad_glGenBuffers = (PFNGLGENBUFFERSPROC)load("glGenBuffers");
glad_glIsBuffer = (PFNGLISBUFFERPROC)load("glIsBuffer");
glad_glBufferData = (PFNGLBUFFERDATAPROC)load("glBufferData");
glad_glBufferSubData = (PFNGLBUFFERSUBDATAPROC)load("glBufferSubData");
glad_glGetBufferSubData = (PFNGLGETBUFFERSUBDATAPROC)load("glGetBufferSubData");
glad_glMapBuffer = (PFNGLMAPBUFFERPROC)load("glMapBuffer");
glad_glUnmapBuffer = (PFNGLUNMAPBUFFERPROC)load("glUnmapBuffer");
glad_glGetBufferParameteriv = (PFNGLGETBUFFERPARAMETERIVPROC)load("glGetBufferParameteriv");
glad_glGetBufferPointerv = (PFNGLGETBUFFERPOINTERVPROC)load("glGetBufferPointerv");
}
static void load_GL_VERSION_2_0(GLADloadproc load) {
if(!GLAD_GL_VERSION_2_0) return;
glad_glBlendEquationSeparate = (PFNGLBLENDEQUATIONSEPARATEPROC)load("glBlendEquationSeparate");
glad_glDrawBuffers = (PFNGLDRAWBUFFERSPROC)load("glDrawBuffers");
glad_glStencilOpSeparate = (PFNGLSTENCILOPSEPARATEPROC)load("glStencilOpSeparate");
glad_glStencilFuncSeparate = (PFNGLSTENCILFUNCSEPARATEPROC)load("glStencilFuncSeparate");
glad_glStencilMaskSeparate = (PFNGLSTENCILMASKSEPARATEPROC)load("glStencilMaskSeparate");
glad_glAttachShader = (PFNGLATTACHSHADERPROC)load("glAttachShader");
glad_glBindAttribLocation = (PFNGLBINDATTRIBLOCATIONPROC)load("glBindAttribLocation");
glad_glCompileShader = (PFNGLCOMPILESHADERPROC)load("glCompileShader");
glad_glCreateProgram = (PFNGLCREATEPROGRAMPROC)load("glCreateProgram");
glad_glCreateShader = (PFNGLCREATESHADERPROC)load("glCreateShader");
glad_glDeleteProgram = (PFNGLDELETEPROGRAMPROC)load("glDeleteProgram");
glad_glDeleteShader = (PFNGLDELETESHADERPROC)load("glDeleteShader");
glad_glDetachShader = (PFNGLDETACHSHADERPROC)load("glDetachShader");
glad_glDisableVertexAttribArray = (PFNGLDISABLEVERTEXATTRIBARRAYPROC)load("glDisableVertexAttribArray");
glad_glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC)load("glEnableVertexAttribArray");
glad_glGetActiveAttrib = (PFNGLGETACTIVEATTRIBPROC)load("glGetActiveAttrib");
glad_glGetActiveUniform = (PFNGLGETACTIVEUNIFORMPROC)load("glGetActiveUniform");
glad_glGetAttachedShaders = (PFNGLGETATTACHEDSHADERSPROC)load("glGetAttachedShaders");
glad_glGetAttribLocation = (PFNGLGETATTRIBLOCATIONPROC)load("glGetAttribLocation");
glad_glGetProgramiv = (PFNGLGETPROGRAMIVPROC)load("glGetProgramiv");
glad_glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC)load("glGetProgramInfoLog");
glad_glGetShaderiv = (PFNGLGETSHADERIVPROC)load("glGetShaderiv");
glad_glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC)load("glGetShaderInfoLog");
glad_glGetShaderSource = (PFNGLGETSHADERSOURCEPROC)load("glGetShaderSource");
glad_glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)load("glGetUniformLocation");
glad_glGetUniformfv = (PFNGLGETUNIFORMFVPROC)load("glGetUniformfv");
glad_glGetUniformiv = (PFNGLGETUNIFORMIVPROC)load("glGetUniformiv");
glad_glGetVertexAttribdv = (PFNGLGETVERTEXATTRIBDVPROC)load("glGetVertexAttribdv");
glad_glGetVertexAttribfv = (PFNGLGETVERTEXATTRIBFVPROC)load("glGetVertexAttribfv");
glad_glGetVertexAttribiv = (PFNGLGETVERTEXATTRIBIVPROC)load("glGetVertexAttribiv");
glad_glGetVertexAttribPointerv = (PFNGLGETVERTEXATTRIBPOINTERVPROC)load("glGetVertexAttribPointerv");
glad_glIsProgram = (PFNGLISPROGRAMPROC)load("glIsProgram");
glad_glIsShader = (PFNGLISSHADERPROC)load("glIsShader");
glad_glLinkProgram = (PFNGLLINKPROGRAMPROC)load("glLinkProgram");
glad_glShaderSource = (PFNGLSHADERSOURCEPROC)load("glShaderSource");
glad_glUseProgram = (PFNGLUSEPROGRAMPROC)load("glUseProgram");
glad_glUniform1f = (PFNGLUNIFORM1FPROC)load("glUniform1f");
glad_glUniform2f = (PFNGLUNIFORM2FPROC)load("glUniform2f");
glad_glUniform3f = (PFNGLUNIFORM3FPROC)load("glUniform3f");
glad_glUniform4f = (PFNGLUNIFORM4FPROC)load("glUniform4f");
glad_glUniform1i = (PFNGLUNIFORM1IPROC)load("glUniform1i");
glad_glUniform2i = (PFNGLUNIFORM2IPROC)load("glUniform2i");
glad_glUniform3i = (PFNGLUNIFORM3IPROC)load("glUniform3i");
glad_glUniform4i = (PFNGLUNIFORM4IPROC)load("glUniform4i");
glad_glUniform1fv = (PFNGLUNIFORM1FVPROC)load("glUniform1fv");
glad_glUniform2fv = (PFNGLUNIFORM2FVPROC)load("glUniform2fv");
glad_glUniform3fv = (PFNGLUNIFORM3FVPROC)load("glUniform3fv");
glad_glUniform4fv = (PFNGLUNIFORM4FVPROC)load("glUniform4fv");
glad_glUniform1iv = (PFNGLUNIFORM1IVPROC)load("glUniform1iv");
glad_glUniform2iv = (PFNGLUNIFORM2IVPROC)load("glUniform2iv");
glad_glUniform3iv = (PFNGLUNIFORM3IVPROC)load("glUniform3iv");
glad_glUniform4iv = (PFNGLUNIFORM4IVPROC)load("glUniform4iv");
glad_glUniformMatrix2fv = (PFNGLUNIFORMMATRIX2FVPROC)load("glUniformMatrix2fv");
glad_glUniformMatrix3fv = (PFNGLUNIFORMMATRIX3FVPROC)load("glUniformMatrix3fv");
glad_glUniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC)load("glUniformMatrix4fv");
glad_glValidateProgram = (PFNGLVALIDATEPROGRAMPROC)load("glValidateProgram");
glad_glVertexAttrib1d = (PFNGLVERTEXATTRIB1DPROC)load("glVertexAttrib1d");
glad_glVertexAttrib1dv = (PFNGLVERTEXATTRIB1DVPROC)load("glVertexAttrib1dv");
glad_glVertexAttrib1f = (PFNGLVERTEXATTRIB1FPROC)load("glVertexAttrib1f");
glad_glVertexAttrib1fv = (PFNGLVERTEXATTRIB1FVPROC)load("glVertexAttrib1fv");
glad_glVertexAttrib1s = (PFNGLVERTEXATTRIB1SPROC)load("glVertexAttrib1s");
glad_glVertexAttrib1sv = (PFNGLVERTEXATTRIB1SVPROC)load("glVertexAttrib1sv");
glad_glVertexAttrib2d = (PFNGLVERTEXATTRIB2DPROC)load("glVertexAttrib2d");
glad_glVertexAttrib2dv = (PFNGLVERTEXATTRIB2DVPROC)load("glVertexAttrib2dv");
glad_glVertexAttrib2f = (PFNGLVERTEXATTRIB2FPROC)load("glVertexAttrib2f");
glad_glVertexAttrib2fv = (PFNGLVERTEXATTRIB2FVPROC)load("glVertexAttrib2fv");
glad_glVertexAttrib2s = (PFNGLVERTEXATTRIB2SPROC)load("glVertexAttrib2s");
glad_glVertexAttrib2sv = (PFNGLVERTEXATTRIB2SVPROC)load("glVertexAttrib2sv");
glad_glVertexAttrib3d = (PFNGLVERTEXATTRIB3DPROC)load("glVertexAttrib3d");
glad_glVertexAttrib3dv = (PFNGLVERTEXATTRIB3DVPROC)load("glVertexAttrib3dv");
glad_glVertexAttrib3f = (PFNGLVERTEXATTRIB3FPROC)load("glVertexAttrib3f");
glad_glVertexAttrib3fv = (PFNGLVERTEXATTRIB3FVPROC)load("glVertexAttrib3fv");
glad_glVertexAttrib3s = (PFNGLVERTEXATTRIB3SPROC)load("glVertexAttrib3s");
glad_glVertexAttrib3sv = (PFNGLVERTEXATTRIB3SVPROC)load("glVertexAttrib3sv");
glad_glVertexAttrib4Nbv = (PFNGLVERTEXATTRIB4NBVPROC)load("glVertexAttrib4Nbv");
glad_glVertexAttrib4Niv = (PFNGLVERTEXATTRIB4NIVPROC)load("glVertexAttrib4Niv");
glad_glVertexAttrib4Nsv = (PFNGLVERTEXATTRIB4NSVPROC)load("glVertexAttrib4Nsv");
glad_glVertexAttrib4Nub = (PFNGLVERTEXATTRIB4NUBPROC)load("glVertexAttrib4Nub");
glad_glVertexAttrib4Nubv = (PFNGLVERTEXATTRIB4NUBVPROC)load("glVertexAttrib4Nubv");
glad_glVertexAttrib4Nuiv = (PFNGLVERTEXATTRIB4NUIVPROC)load("glVertexAttrib4Nuiv");
glad_glVertexAttrib4Nusv = (PFNGLVERTEXATTRIB4NUSVPROC)load("glVertexAttrib4Nusv");
glad_glVertexAttrib4bv = (PFNGLVERTEXATTRIB4BVPROC)load("glVertexAttrib4bv");
glad_glVertexAttrib4d = (PFNGLVERTEXATTRIB4DPROC)load("glVertexAttrib4d");
glad_glVertexAttrib4dv = (PFNGLVERTEXATTRIB4DVPROC)load("glVertexAttrib4dv");
glad_glVertexAttrib4f = (PFNGLVERTEXATTRIB4FPROC)load("glVertexAttrib4f");
glad_glVertexAttrib4fv = (PFNGLVERTEXATTRIB4FVPROC)load("glVertexAttrib4fv");
glad_glVertexAttrib4iv = (PFNGLVERTEXATTRIB4IVPROC)load("glVertexAttrib4iv");
glad_glVertexAttrib4s = (PFNGLVERTEXATTRIB4SPROC)load("glVertexAttrib4s");
glad_glVertexAttrib4sv = (PFNGLVERTEXATTRIB4SVPROC)load("glVertexAttrib4sv");
glad_glVertexAttrib4ubv = (PFNGLVERTEXATTRIB4UBVPROC)load("glVertexAttrib4ubv");
glad_glVertexAttrib4uiv = (PFNGLVERTEXATTRIB4UIVPROC)load("glVertexAttrib4uiv");
glad_glVertexAttrib4usv = (PFNGLVERTEXATTRIB4USVPROC)load("glVertexAttrib4usv");
glad_glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC)load("glVertexAttribPointer");
}
static void load_GL_VERSION_2_1(GLADloadproc load) {
if(!GLAD_GL_VERSION_2_1) return;
glad_glUniformMatrix2x3fv = (PFNGLUNIFORMMATRIX2X3FVPROC)load("glUniformMatrix2x3fv");
glad_glUniformMatrix3x2fv = (PFNGLUNIFORMMATRIX3X2FVPROC)load("glUniformMatrix3x2fv");
glad_glUniformMatrix2x4fv = (PFNGLUNIFORMMATRIX2X4FVPROC)load("glUniformMatrix2x4fv");
glad_glUniformMatrix4x2fv = (PFNGLUNIFORMMATRIX4X2FVPROC)load("glUniformMatrix4x2fv");
glad_glUniformMatrix3x4fv = (PFNGLUNIFORMMATRIX3X4FVPROC)load("glUniformMatrix3x4fv");
glad_glUniformMatrix4x3fv = (PFNGLUNIFORMMATRIX4X3FVPROC)load("glUniformMatrix4x3fv");
}
static void load_GL_VERSION_3_0(GLADloadproc load) {
if(!GLAD_GL_VERSION_3_0) return;
glad_glColorMaski = (PFNGLCOLORMASKIPROC)load("glColorMaski");
glad_glGetBooleani_v = (PFNGLGETBOOLEANI_VPROC)load("glGetBooleani_v");
glad_glGetIntegeri_v = (PFNGLGETINTEGERI_VPROC)load("glGetIntegeri_v");
glad_glEnablei = (PFNGLENABLEIPROC)load("glEnablei");
glad_glDisablei = (PFNGLDISABLEIPROC)load("glDisablei");
glad_glIsEnabledi = (PFNGLISENABLEDIPROC)load("glIsEnabledi");
glad_glBeginTransformFeedback = (PFNGLBEGINTRANSFORMFEEDBACKPROC)load("glBeginTransformFeedback");
glad_glEndTransformFeedback = (PFNGLENDTRANSFORMFEEDBACKPROC)load("glEndTransformFeedback");
glad_glBindBufferRange = (PFNGLBINDBUFFERRANGEPROC)load("glBindBufferRange");
glad_glBindBufferBase = (PFNGLBINDBUFFERBASEPROC)load("glBindBufferBase");
glad_glTransformFeedbackVaryings = (PFNGLTRANSFORMFEEDBACKVARYINGSPROC)load("glTransformFeedbackVaryings");
glad_glGetTransformFeedbackVarying = (PFNGLGETTRANSFORMFEEDBACKVARYINGPROC)load("glGetTransformFeedbackVarying");
glad_glClampColor = (PFNGLCLAMPCOLORPROC)load("glClampColor");
glad_glBeginConditionalRender = (PFNGLBEGINCONDITIONALRENDERPROC)load("glBeginConditionalRender");
glad_glEndConditionalRender = (PFNGLENDCONDITIONALRENDERPROC)load("glEndConditionalRender");
glad_glVertexAttribIPointer = (PFNGLVERTEXATTRIBIPOINTERPROC)load("glVertexAttribIPointer");
glad_glGetVertexAttribIiv = (PFNGLGETVERTEXATTRIBIIVPROC)load("glGetVertexAttribIiv");
glad_glGetVertexAttribIuiv = (PFNGLGETVERTEXATTRIBIUIVPROC)load("glGetVertexAttribIuiv");
glad_glVertexAttribI1i = (PFNGLVERTEXATTRIBI1IPROC)load("glVertexAttribI1i");
glad_glVertexAttribI2i = (PFNGLVERTEXATTRIBI2IPROC)load("glVertexAttribI2i");
glad_glVertexAttribI3i = (PFNGLVERTEXATTRIBI3IPROC)load("glVertexAttribI3i");
glad_glVertexAttribI4i = (PFNGLVERTEXATTRIBI4IPROC)load("glVertexAttribI4i");
glad_glVertexAttribI1ui = (PFNGLVERTEXATTRIBI1UIPROC)load("glVertexAttribI1ui");
glad_glVertexAttribI2ui = (PFNGLVERTEXATTRIBI2UIPROC)load("glVertexAttribI2ui");
glad_glVertexAttribI3ui = (PFNGLVERTEXATTRIBI3UIPROC)load("glVertexAttribI3ui");
glad_glVertexAttribI4ui = (PFNGLVERTEXATTRIBI4UIPROC)load("glVertexAttribI4ui");
glad_glVertexAttribI1iv = (PFNGLVERTEXATTRIBI1IVPROC)load("glVertexAttribI1iv");
glad_glVertexAttribI2iv = (PFNGLVERTEXATTRIBI2IVPROC)load("glVertexAttribI2iv");
glad_glVertexAttribI3iv = (PFNGLVERTEXATTRIBI3IVPROC)load("glVertexAttribI3iv");
glad_glVertexAttribI4iv = (PFNGLVERTEXATTRIBI4IVPROC)load("glVertexAttribI4iv");
glad_glVertexAttribI1uiv = (PFNGLVERTEXATTRIBI1UIVPROC)load("glVertexAttribI1uiv");
glad_glVertexAttribI2uiv = (PFNGLVERTEXATTRIBI2UIVPROC)load("glVertexAttribI2uiv");
glad_glVertexAttribI3uiv = (PFNGLVERTEXATTRIBI3UIVPROC)load("glVertexAttribI3uiv");
glad_glVertexAttribI4uiv = (PFNGLVERTEXATTRIBI4UIVPROC)load("glVertexAttribI4uiv");
glad_glVertexAttribI4bv = (PFNGLVERTEXATTRIBI4BVPROC)load("glVertexAttribI4bv");
glad_glVertexAttribI4sv = (PFNGLVERTEXATTRIBI4SVPROC)load("glVertexAttribI4sv");
glad_glVertexAttribI4ubv = (PFNGLVERTEXATTRIBI4UBVPROC)load("glVertexAttribI4ubv");
glad_glVertexAttribI4usv = (PFNGLVERTEXATTRIBI4USVPROC)load("glVertexAttribI4usv");
glad_glGetUniformuiv = (PFNGLGETUNIFORMUIVPROC)load("glGetUniformuiv");
glad_glBindFragDataLocation = (PFNGLBINDFRAGDATALOCATIONPROC)load("glBindFragDataLocation");
glad_glGetFragDataLocation = (PFNGLGETFRAGDATALOCATIONPROC)load("glGetFragDataLocation");
glad_glUniform1ui = (PFNGLUNIFORM1UIPROC)load("glUniform1ui");
glad_glUniform2ui = (PFNGLUNIFORM2UIPROC)load("glUniform2ui");
glad_glUniform3ui = (PFNGLUNIFORM3UIPROC)load("glUniform3ui");
glad_glUniform4ui = (PFNGLUNIFORM4UIPROC)load("glUniform4ui");
glad_glUniform1uiv = (PFNGLUNIFORM1UIVPROC)load("glUniform1uiv");
glad_glUniform2uiv = (PFNGLUNIFORM2UIVPROC)load("glUniform2uiv");
glad_glUniform3uiv = (PFNGLUNIFORM3UIVPROC)load("glUniform3uiv");
glad_glUniform4uiv = (PFNGLUNIFORM4UIVPROC)load("glUniform4uiv");
glad_glTexParameterIiv = (PFNGLTEXPARAMETERIIVPROC)load("glTexParameterIiv");
glad_glTexParameterIuiv = (PFNGLTEXPARAMETERIUIVPROC)load("glTexParameterIuiv");
glad_glGetTexParameterIiv = (PFNGLGETTEXPARAMETERIIVPROC)load("glGetTexParameterIiv");
glad_glGetTexParameterIuiv = (PFNGLGETTEXPARAMETERIUIVPROC)load("glGetTexParameterIuiv");
glad_glClearBufferiv = (PFNGLCLEARBUFFERIVPROC)load("glClearBufferiv");
glad_glClearBufferuiv = (PFNGLCLEARBUFFERUIVPROC)load("glClearBufferuiv");
glad_glClearBufferfv = (PFNGLCLEARBUFFERFVPROC)load("glClearBufferfv");
glad_glClearBufferfi = (PFNGLCLEARBUFFERFIPROC)load("glClearBufferfi");
glad_glGetStringi = (PFNGLGETSTRINGIPROC)load("glGetStringi");
glad_glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC)load("glIsRenderbuffer");
glad_glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)load("glBindRenderbuffer");
glad_glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC)load("glDeleteRenderbuffers");
glad_glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC)load("glGenRenderbuffers");
glad_glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC)load("glRenderbufferStorage");
glad_glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC)load("glGetRenderbufferParameteriv");
glad_glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC)load("glIsFramebuffer");
glad_glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)load("glBindFramebuffer");
glad_glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)load("glDeleteFramebuffers");
glad_glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)load("glGenFramebuffers");
glad_glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)load("glCheckFramebufferStatus");
glad_glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC)load("glFramebufferTexture1D");
glad_glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)load("glFramebufferTexture2D");
glad_glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC)load("glFramebufferTexture3D");
glad_glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC)load("glFramebufferRenderbuffer");
glad_glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC)load("glGetFramebufferAttachmentParameteriv");
glad_glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC)load("glGenerateMipmap");
glad_glBlitFramebuffer = (PFNGLBLITFRAMEBUFFERPROC)load("glBlitFramebuffer");
glad_glRenderbufferStorageMultisample = (PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC)load("glRenderbufferStorageMultisample");
glad_glFramebufferTextureLayer = (PFNGLFRAMEBUFFERTEXTURELAYERPROC)load("glFramebufferTextureLayer");
glad_glMapBufferRange = (PFNGLMAPBUFFERRANGEPROC)load("glMapBufferRange");
glad_glFlushMappedBufferRange = (PFNGLFLUSHMAPPEDBUFFERRANGEPROC)load("glFlushMappedBufferRange");
glad_glBindVertexArray = (PFNGLBINDVERTEXARRAYPROC)load("glBindVertexArray");
glad_glDeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSPROC)load("glDeleteVertexArrays");
glad_glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC)load("glGenVertexArrays");
glad_glIsVertexArray = (PFNGLISVERTEXARRAYPROC)load("glIsVertexArray");
}
static void load_GL_VERSION_3_1(GLADloadproc load) {
if(!GLAD_GL_VERSION_3_1) return;
glad_glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDPROC)load("glDrawArraysInstanced");
glad_glDrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDPROC)load("glDrawElementsInstanced");
glad_glTexBuffer = (PFNGLTEXBUFFERPROC)load("glTexBuffer");
glad_glPrimitiveRestartIndex = (PFNGLPRIMITIVERESTARTINDEXPROC)load("glPrimitiveRestartIndex");
glad_glCopyBufferSubData = (PFNGLCOPYBUFFERSUBDATAPROC)load("glCopyBufferSubData");
glad_glGetUniformIndices = (PFNGLGETUNIFORMINDICESPROC)load("glGetUniformIndices");
glad_glGetActiveUniformsiv = (PFNGLGETACTIVEUNIFORMSIVPROC)load("glGetActiveUniformsiv");
glad_glGetActiveUniformName = (PFNGLGETACTIVEUNIFORMNAMEPROC)load("glGetActiveUniformName");
glad_glGetUniformBlockIndex = (PFNGLGETUNIFORMBLOCKINDEXPROC)load("glGetUniformBlockIndex");
glad_glGetActiveUniformBlockiv = (PFNGLGETACTIVEUNIFORMBLOCKIVPROC)load("glGetActiveUniformBlockiv");
glad_glGetActiveUniformBlockName = (PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC)load("glGetActiveUniformBlockName");
glad_glUniformBlockBinding = (PFNGLUNIFORMBLOCKBINDINGPROC)load("glUniformBlockBinding");
glad_glBindBufferRange = (PFNGLBINDBUFFERRANGEPROC)load("glBindBufferRange");
glad_glBindBufferBase = (PFNGLBINDBUFFERBASEPROC)load("glBindBufferBase");
glad_glGetIntegeri_v = (PFNGLGETINTEGERI_VPROC)load("glGetIntegeri_v");
}
static void load_GL_VERSION_3_2(GLADloadproc load) {
if(!GLAD_GL_VERSION_3_2) return;
glad_glDrawElementsBaseVertex = (PFNGLDRAWELEMENTSBASEVERTEXPROC)load("glDrawElementsBaseVertex");
glad_glDrawRangeElementsBaseVertex = (PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC)load("glDrawRangeElementsBaseVertex");
glad_glDrawElementsInstancedBaseVertex = (PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC)load("glDrawElementsInstancedBaseVertex");
glad_glMultiDrawElementsBaseVertex = (PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC)load("glMultiDrawElementsBaseVertex");
glad_glProvokingVertex = (PFNGLPROVOKINGVERTEXPROC)load("glProvokingVertex");
glad_glFenceSync = (PFNGLFENCESYNCPROC)load("glFenceSync");
glad_glIsSync = (PFNGLISSYNCPROC)load("glIsSync");
glad_glDeleteSync = (PFNGLDELETESYNCPROC)load("glDeleteSync");
glad_glClientWaitSync = (PFNGLCLIENTWAITSYNCPROC)load("glClientWaitSync");
glad_glWaitSync = (PFNGLWAITSYNCPROC)load("glWaitSync");
glad_glGetInteger64v = (PFNGLGETINTEGER64VPROC)load("glGetInteger64v");
glad_glGetSynciv = (PFNGLGETSYNCIVPROC)load("glGetSynciv");
glad_glGetInteger64i_v = (PFNGLGETINTEGER64I_VPROC)load("glGetInteger64i_v");
glad_glGetBufferParameteri64v = (PFNGLGETBUFFERPARAMETERI64VPROC)load("glGetBufferParameteri64v");
glad_glFramebufferTexture = (PFNGLFRAMEBUFFERTEXTUREPROC)load("glFramebufferTexture");
glad_glTexImage2DMultisample = (PFNGLTEXIMAGE2DMULTISAMPLEPROC)load("glTexImage2DMultisample");
glad_glTexImage3DMultisample = (PFNGLTEXIMAGE3DMULTISAMPLEPROC)load("glTexImage3DMultisample");
glad_glGetMultisamplefv = (PFNGLGETMULTISAMPLEFVPROC)load("glGetMultisamplefv");
glad_glSampleMaski = (PFNGLSAMPLEMASKIPROC)load("glSampleMaski");
}
static void load_GL_VERSION_3_3(GLADloadproc load) {
if(!GLAD_GL_VERSION_3_3) return;
glad_glBindFragDataLocationIndexed = (PFNGLBINDFRAGDATALOCATIONINDEXEDPROC)load("glBindFragDataLocationIndexed");
glad_glGetFragDataIndex = (PFNGLGETFRAGDATAINDEXPROC)load("glGetFragDataIndex");
glad_glGenSamplers = (PFNGLGENSAMPLERSPROC)load("glGenSamplers");
glad_glDeleteSamplers = (PFNGLDELETESAMPLERSPROC)load("glDeleteSamplers");
glad_glIsSampler = (PFNGLISSAMPLERPROC)load("glIsSampler");
glad_glBindSampler = (PFNGLBINDSAMPLERPROC)load("glBindSampler");
glad_glSamplerParameteri = (PFNGLSAMPLERPARAMETERIPROC)load("glSamplerParameteri");
glad_glSamplerParameteriv = (PFNGLSAMPLERPARAMETERIVPROC)load("glSamplerParameteriv");
glad_glSamplerParameterf = (PFNGLSAMPLERPARAMETERFPROC)load("glSamplerParameterf");
glad_glSamplerParameterfv = (PFNGLSAMPLERPARAMETERFVPROC)load("glSamplerParameterfv");
glad_glSamplerParameterIiv = (PFNGLSAMPLERPARAMETERIIVPROC)load("glSamplerParameterIiv");
glad_glSamplerParameterIuiv = (PFNGLSAMPLERPARAMETERIUIVPROC)load("glSamplerParameterIuiv");
glad_glGetSamplerParameteriv = (PFNGLGETSAMPLERPARAMETERIVPROC)load("glGetSamplerParameteriv");
glad_glGetSamplerParameterIiv = (PFNGLGETSAMPLERPARAMETERIIVPROC)load("glGetSamplerParameterIiv");
glad_glGetSamplerParameterfv = (PFNGLGETSAMPLERPARAMETERFVPROC)load("glGetSamplerParameterfv");
glad_glGetSamplerParameterIuiv = (PFNGLGETSAMPLERPARAMETERIUIVPROC)load("glGetSamplerParameterIuiv");
glad_glQueryCounter = (PFNGLQUERYCOUNTERPROC)load("glQueryCounter");
glad_glGetQueryObjecti64v = (PFNGLGETQUERYOBJECTI64VPROC)load("glGetQueryObjecti64v");
glad_glGetQueryObjectui64v = (PFNGLGETQUERYOBJECTUI64VPROC)load("glGetQueryObjectui64v");
glad_glVertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISORPROC)load("glVertexAttribDivisor");
glad_glVertexAttribP1ui = (PFNGLVERTEXATTRIBP1UIPROC)load("glVertexAttribP1ui");
glad_glVertexAttribP1uiv = (PFNGLVERTEXATTRIBP1UIVPROC)load("glVertexAttribP1uiv");
glad_glVertexAttribP2ui = (PFNGLVERTEXATTRIBP2UIPROC)load("glVertexAttribP2ui");
glad_glVertexAttribP2uiv = (PFNGLVERTEXATTRIBP2UIVPROC)load("glVertexAttribP2uiv");
glad_glVertexAttribP3ui = (PFNGLVERTEXATTRIBP3UIPROC)load("glVertexAttribP3ui");
glad_glVertexAttribP3uiv = (PFNGLVERTEXATTRIBP3UIVPROC)load("glVertexAttribP3uiv");
glad_glVertexAttribP4ui = (PFNGLVERTEXATTRIBP4UIPROC)load("glVertexAttribP4ui");
glad_glVertexAttribP4uiv = (PFNGLVERTEXATTRIBP4UIVPROC)load("glVertexAttribP4uiv");
glad_glVertexP2ui = (PFNGLVERTEXP2UIPROC)load("glVertexP2ui");
glad_glVertexP2uiv = (PFNGLVERTEXP2UIVPROC)load("glVertexP2uiv");
glad_glVertexP3ui = (PFNGLVERTEXP3UIPROC)load("glVertexP3ui");
glad_glVertexP3uiv = (PFNGLVERTEXP3UIVPROC)load("glVertexP3uiv");
glad_glVertexP4ui = (PFNGLVERTEXP4UIPROC)load("glVertexP4ui");
glad_glVertexP4uiv = (PFNGLVERTEXP4UIVPROC)load("glVertexP4uiv");
glad_glTexCoordP1ui = (PFNGLTEXCOORDP1UIPROC)load("glTexCoordP1ui");
glad_glTexCoordP1uiv = (PFNGLTEXCOORDP1UIVPROC)load("glTexCoordP1uiv");
glad_glTexCoordP2ui = (PFNGLTEXCOORDP2UIPROC)load("glTexCoordP2ui");
glad_glTexCoordP2uiv = (PFNGLTEXCOORDP2UIVPROC)load("glTexCoordP2uiv");
glad_glTexCoordP3ui = (PFNGLTEXCOORDP3UIPROC)load("glTexCoordP3ui");
glad_glTexCoordP3uiv = (PFNGLTEXCOORDP3UIVPROC)load("glTexCoordP3uiv");
glad_glTexCoordP4ui = (PFNGLTEXCOORDP4UIPROC)load("glTexCoordP4ui");
glad_glTexCoordP4uiv = (PFNGLTEXCOORDP4UIVPROC)load("glTexCoordP4uiv");
glad_glMultiTexCoordP1ui = (PFNGLMULTITEXCOORDP1UIPROC)load("glMultiTexCoordP1ui");
glad_glMultiTexCoordP1uiv = (PFNGLMULTITEXCOORDP1UIVPROC)load("glMultiTexCoordP1uiv");
glad_glMultiTexCoordP2ui = (PFNGLMULTITEXCOORDP2UIPROC)load("glMultiTexCoordP2ui");
glad_glMultiTexCoordP2uiv = (PFNGLMULTITEXCOORDP2UIVPROC)load("glMultiTexCoordP2uiv");
glad_glMultiTexCoordP3ui = (PFNGLMULTITEXCOORDP3UIPROC)load("glMultiTexCoordP3ui");
glad_glMultiTexCoordP3uiv = (PFNGLMULTITEXCOORDP3UIVPROC)load("glMultiTexCoordP3uiv");
glad_glMultiTexCoordP4ui = (PFNGLMULTITEXCOORDP4UIPROC)load("glMultiTexCoordP4ui");
glad_glMultiTexCoordP4uiv = (PFNGLMULTITEXCOORDP4UIVPROC)load("glMultiTexCoordP4uiv");
glad_glNormalP3ui = (PFNGLNORMALP3UIPROC)load("glNormalP3ui");
glad_glNormalP3uiv = (PFNGLNORMALP3UIVPROC)load("glNormalP3uiv");
glad_glColorP3ui = (PFNGLCOLORP3UIPROC)load("glColorP3ui");
glad_glColorP3uiv = (PFNGLCOLORP3UIVPROC)load("glColorP3uiv");
glad_glColorP4ui = (PFNGLCOLORP4UIPROC)load("glColorP4ui");
glad_glColorP4uiv = (PFNGLCOLORP4UIVPROC)load("glColorP4uiv");
glad_glSecondaryColorP3ui = (PFNGLSECONDARYCOLORP3UIPROC)load("glSecondaryColorP3ui");
glad_glSecondaryColorP3uiv = (PFNGLSECONDARYCOLORP3UIVPROC)load("glSecondaryColorP3uiv");
}
static int find_extensionsGL(void) {
if (!get_exts()) return 0;
(void)&has_ext;
free_exts();
return 1;
}
static void find_coreGL(void) {
/* Thank you @elmindreda
* https://github.com/elmindreda/greg/blob/master/templates/greg.c.in#L176
* https://github.com/glfw/glfw/blob/master/src/context.c#L36
*/
int i, major, minor;
const char* version;
const char* prefixes[] = {
"OpenGL ES-CM ",
"OpenGL ES-CL ",
"OpenGL ES ",
NULL
};
version = (const char*) glGetString(GL_VERSION);
if (!version) return;
for (i = 0; prefixes[i]; i++) {
const size_t length = strlen(prefixes[i]);
if (strncmp(version, prefixes[i], length) == 0) {
version += length;
break;
}
}
/* PR #18 */
#ifdef _MSC_VER
sscanf_s(version, "%d.%d", &major, &minor);
#else
sscanf(version, "%d.%d", &major, &minor);
#endif
GLVersion.major = major; GLVersion.minor = minor;
max_loaded_major = major; max_loaded_minor = minor;
GLAD_GL_VERSION_1_0 = (major == 1 && minor >= 0) || major > 1;
GLAD_GL_VERSION_1_1 = (major == 1 && minor >= 1) || major > 1;
GLAD_GL_VERSION_1_2 = (major == 1 && minor >= 2) || major > 1;
GLAD_GL_VERSION_1_3 = (major == 1 && minor >= 3) || major > 1;
GLAD_GL_VERSION_1_4 = (major == 1 && minor >= 4) || major > 1;
GLAD_GL_VERSION_1_5 = (major == 1 && minor >= 5) || major > 1;
GLAD_GL_VERSION_2_0 = (major == 2 && minor >= 0) || major > 2;
GLAD_GL_VERSION_2_1 = (major == 2 && minor >= 1) || major > 2;
GLAD_GL_VERSION_3_0 = (major == 3 && minor >= 0) || major > 3;
GLAD_GL_VERSION_3_1 = (major == 3 && minor >= 1) || major > 3;
GLAD_GL_VERSION_3_2 = (major == 3 && minor >= 2) || major > 3;
GLAD_GL_VERSION_3_3 = (major == 3 && minor >= 3) || major > 3;
if (GLVersion.major > 3 || (GLVersion.major >= 3 && GLVersion.minor >= 3)) {
max_loaded_major = 3;
max_loaded_minor = 3;
}
}
int gladLoadGLLoader(GLADloadproc load) {
GLVersion.major = 0; GLVersion.minor = 0;
glGetString = (PFNGLGETSTRINGPROC)load("glGetString");
if(glGetString == NULL) return 0;
if(glGetString(GL_VERSION) == NULL) return 0;
find_coreGL();
load_GL_VERSION_1_0(load);
load_GL_VERSION_1_1(load);
load_GL_VERSION_1_2(load);
load_GL_VERSION_1_3(load);
load_GL_VERSION_1_4(load);
load_GL_VERSION_1_5(load);
load_GL_VERSION_2_0(load);
load_GL_VERSION_2_1(load);
load_GL_VERSION_3_0(load);
load_GL_VERSION_3_1(load);
load_GL_VERSION_3_2(load);
load_GL_VERSION_3_3(load);
if (!find_extensionsGL()) return 0;
return GLVersion.major != 0 || GLVersion.minor != 0;
}
Angel.h
//
//
// --- Angel.h ---
//
// The main header file for all examples from Angel 6th Edition
//
//
#ifndef __ANGEL_H__
#define __ANGEL_H__
//----------------------------------------------------------------------------
//
// --- Include system headers ---
//
#include <cmath>
#include <iostream>
// Define M_PI in the case it's not defined in the math header file
#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif
//----------------------------------------------------------------------------
//
// --- Include OpenGL header files and helpers ---
//
// The location of these files vary by operating system. We've included
// copies of open-soruce project headers in the "GL" directory local
// this this "include" directory.
//
#define GL_SILENCE_DEPRECATION
#include<glad/glad.h>
#include<GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
// Define a helpful macro for handling offsets into buffer objects
#define BUFFER_OFFSET( offset ) ((GLvoid*) (offset))
//----------------------------------------------------------------------------
//
// --- Include our class libraries and constants ---
//
namespace Angel {
// Helper function to load vertex and fragment shader files
GLuint InitShader( const char* vertexShaderFile,
const char* fragmentShaderFile );
// Defined constant for when numbers are too small to be used in the
// denominator of a division operation. This is only used if the
// DEBUG macro is defined.
const GLfloat DivideByZeroTolerance = GLfloat(1.0e-07);
// Degrees-to-radians constant
const GLfloat DegreesToRadians = M_PI / 180.0;
} // namespace Angel
//#include "vec.h"
//#include "mat.h"
#include "CheckError.h"
#define Print(x) do { std::cerr << #x " = " << (x) << std::endl; } while(0)
// Globally use our namespace in our example programs.
using namespace Angel;
#endif // __ANGEL_H__
Camera.h
#ifndef _CAMERA_H_
#define _CAMERA_H_
#include "Angel.h"
class Camera
{
public:
Camera();
~Camera();
glm::mat4 getViewMatrix();
glm::mat4 getProjectionMatrix( bool isOrtho );
glm::mat4 lookAt(const glm::vec4& eye, const glm::vec4& at, const glm::vec4& up);
glm::mat4 ortho(const GLfloat left, const GLfloat right,
const GLfloat bottom, const GLfloat top,
const GLfloat zNear, const GLfloat zFar);
glm::mat4 perspective(const GLfloat fovy, const GLfloat aspect,
const GLfloat zNear, const GLfloat zFar);
glm::mat4 frustum(const GLfloat left, const GLfloat right,
const GLfloat bottom, const GLfloat top,
const GLfloat zNear, const GLfloat zFar);
// 每次更改相机参数后更新一下相关的数值
void updateCamera();
void initCamera();
// 处理相机的键盘操作
void keyboard(int key, int action, int mode);
// 模视矩阵
glm::mat4 viewMatrix;
glm::mat4 projMatrix;
// 相机位置参数
float radius; //前后远近变动视角角度
float rotateAngle; //环绕中心左右转动视角角度
float upAngle; //环绕中心上下转动视角角度
glm::vec4 eye;
glm::vec4 at;
glm::vec4 up;
// 投影参数
float zNear;
float zFar;
// 透视投影参数
float fovy;
float aspect;
// 正交投影参数
float scale;
};
#endif
CheckError.h
//
//
// --- CheckError.h ---
//
//
#ifndef __CHECKERROR_H__
#define __CHECKERROR_H__
#include <stdio.h>
#define GL_SILENCE_DEPRECATION
#ifdef __APPLE__ // include Mac OS X verions of headers
# include <glad/glad.h>
# include <GLFW/glfw3.h>
#else // non-Mac OS X operating systems
# include <GL/gl.h>
#endif // __APPLE__
//----------------------------------------------------------------------------
static const char*
ErrorString( GLenum error )
{
const char* msg;
switch( error ) {
#define Case( Token ) case Token: msg = #Token; break;
Case( GL_NO_ERROR );
Case( GL_INVALID_VALUE );
Case( GL_INVALID_ENUM );
Case( GL_INVALID_OPERATION );
// Case( GL_STACK_OVERFLOW );
// Case( GL_STACK_UNDERFLOW );
Case( GL_OUT_OF_MEMORY );
#undef Case
}
return msg;
}
//----------------------------------------------------------------------------
static void
_CheckError( const char* file, int line )
{
GLenum error = glGetError();
do {
fprintf( stderr, "[%s:%d] %s\n", file, line, ErrorString(error) );
} while ((error = glGetError()) != GL_NO_ERROR );
}
//----------------------------------------------------------------------------
#define CheckError() _CheckError( __FILE__, __LINE__ )
//----------------------------------------------------------------------------
#endif // !__CHECKERROR_H__
MeshPainter.h
#ifndef _MESH_PAINTER_H_
#define _MESH_PAINTER_H_
#include "TriMesh.h"
#include "Angel.h"
#include "Camera.h"
#include <vector>
struct openGLObject
{
// 顶点数组对象
GLuint vao;
// 顶点缓存对象
GLuint vbo;
// 着色器程序
GLuint program;
// 着色器文件
std::string vshader;
std::string fshader;
// 着色器变量
GLuint pLocation;
GLuint cLocation;
GLuint nLocation;
GLuint tLocation;
// 纹理
std::string texture_image;
GLuint texture;
// 投影变换变量
GLuint modelLocation;
GLuint viewLocation;
GLuint projectionLocation;
// 阴影变量
GLuint shadowLocation;
};
class MeshPainter
{
public:
MeshPainter();
~MeshPainter();
std::vector<std::string> getMeshNames();
std::vector<TriMesh *> getMeshes();
std::vector<openGLObject> getOpenGLObj();
// 读取纹理文件
void load_texture_STBImage(const std::string &file_name, GLuint& texture);
// 传递光线材质数据的
// void bindLightAndMaterial( int mesh_id, int light_id, Camera* camera );
void bindLightAndMaterial(TriMesh* mesh, openGLObject& object, Light* light, Camera* camera);
void bindObjectAndData(TriMesh *mesh, openGLObject &object, const std::string &texture_image, const std::string &vshader, const std::string &fshader);
// 添加物体
void addMesh( TriMesh* mesh, const std::string &name, const std::string &texture_image, const std::string &vshader, const std::string &fshader );
// 绘制物体
void drawMesh(TriMesh* mesh, openGLObject &object, Light *light, Camera* camera,int flag);
// 绘制多个物体
void drawMeshes(Light *light, Camera* camera,int flag);
// 清空数据
void cleanMeshes();
private:
std::vector<std::string> mesh_names;
std::vector<TriMesh *> meshes;
std::vector<openGLObject> opengl_objects;
};
#endif
TriMesh.h
#ifndef _TRI_MESH_H_
#define _TRI_MESH_H_
#include "Angel.h"
#include <fstream>
#include <sstream>
#include <iostream>
#include <vector>
#include <string>
// 三角面片中的顶点序列
typedef struct vIndex {
unsigned int x, y, z;
vIndex(int ix, int iy, int iz) : x(ix), y(iy), z(iz) {}
} vec3i;
class TriMesh
{
public:
TriMesh();
~TriMesh();
std::vector<glm::vec3> getVertexPositions();
std::vector<glm::vec3> getVertexColors();
std::vector<glm::vec3> getVertexNormals();
std::vector<vec3i> getFaces();
std::vector<glm::vec3> getPoints();
std::vector<glm::vec3> getColors();
std::vector<glm::vec3> getNormals();
std::vector<glm::vec2> getTextures();
void computeTriangleNormals();
void computeVertexNormals();
// 获取和设置物体的旋转平移变化
glm::vec3 getTranslation();
glm::vec3 getRotation();
glm::vec3 getScale();
glm::mat4 getModelMatrix();
void setTranslation(glm::vec3 translation);
void setRotation(glm::vec3 rotation);
void setScale(glm::vec3 scale);
void setNormalize(bool do_norm);
bool getNormalize();
float getDiagonalLength();
// 设置物体材质
glm::vec4 getAmbient();
glm::vec4 getDiffuse();
glm::vec4 getSpecular();
float getShininess();
void setAmbient(glm::vec4 _ambient );
void setDiffuse(glm::vec4 _diffuse);
void setSpecular(glm::vec4 _specular);
void setShininess(float shininess);
// 这里添加各种形状的、模型的读取顶点的函数
void generateCube(glm::vec3 color= glm::vec3(-1, -1, -1));
void generateTriangle(glm::vec3 color);
void generateSquare(glm::vec3 color);
void generateCylinder(int num_division, float radius, float height);
void readOff(const std::string& filename);
void readObj(const std::string& filename);
// 将读取的顶点根据三角面片上的顶点下标逐个加入
// 要传递给GPU的points等容器内
void storeFacesPoints();
void storeFacesPoints_1();
void norm();
// 清除数据
void cleanData();
protected:
std::vector<glm::vec3> vertex_positions; // 顶点坐标
std::vector<glm::vec3> vertex_colors; // 顶点颜色
std::vector<glm::vec3> vertex_normals; // 顶点法向量
std::vector<glm::vec2> vertex_textures; // 顶点纹理坐标,注意是vec2
std::vector<vec3i> faces; // 三角面片上每个顶点对应的顶点坐标的下标
std::vector<vec3i> normal_index; // 每个三角面片的顶点对应的顶点法向量的下标
std::vector<vec3i> color_index; // 每个三角面片的顶点对应的顶点颜色的下标
std::vector<vec3i> texture_index; // 每个三角面片的顶点对应纹理坐标的下标
std::vector<glm::vec3> face_normals; // 每个三角面片的法向量
std::vector<glm::vec3> points; // 传入着色器的绘制点
std::vector<glm::vec3> colors; // 传入着色器的颜色
std::vector<glm::vec3> normals; // 传入着色器的法向量
std::vector<glm::vec2> textures; // 传入着色器的纹理坐标,注意是vec2
bool do_normalize_size; // 是否将物体大小归一化
float diagonal_length; // 物体包围盒对角线长度,作为物体归一化系数
glm::vec3 up_corner; // 物体包围盒的上对角顶点
glm::vec3 down_corner; // 物体包围盒的下对角顶点
glm::vec3 center; // 物体的包围盒中心
glm::vec3 translation; // 物体的平移参数
glm::vec3 rotation; // 物体的旋转参数
glm::vec3 scale; // 物体的缩放参数
glm::vec4 ambient; // 环境光
glm::vec4 diffuse; // 漫反射
glm::vec4 specular; // 镜面反射
float shininess; // 高光系数
};
class Light: public TriMesh {
public:
// 把实验3.2的阴影投影矩阵也加到Light类中
glm::mat4 getShadowProjectionMatrix();
inline void setAttenuation(float _constant, float _linear, float _quadratic);
inline float getConstant();
inline float getLinear();
inline float getQuadratic();
protected:
// 光源衰减系数的三个参数
float constant; // 常数项
float linear; // 一次项
float quadratic;// 二次项
};
// 设置衰减系数的参数
void Light::setAttenuation(float _constant, float _linear, float _quadratic)
{
constant = _constant;
linear = _linear;
quadratic = _quadratic;
}
float Light::getConstant() { return constant; };
float Light::getLinear() { return linear; };
float Light::getQuadratic() { return quadratic; };
#endif
(by 归忆)
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)