# 创建基础的光照场景（环境光和漫反射）

void main()
{
float ambientStrength = 0.1;
vec3 ambient = ambientStrength * lightColor;

vec3 result = ambient * objectColor;
FragColor = vec4(result, 1.0);
}

1.法向量：一个垂直于顶点表面的向量

2.定向的光线：作为光源的位置与片段的位置之间向量差的方向向量。为了计算这个光线，我们需要光的位置向量和片段的位置向量。

 vec3 norm = normalize(Normal);
vec3 lightDir = normalize(sunPos - FragPos);
float diff = max(dot(norm, lightDir), 0.0);
vec3 diffuse = diff * sunColor;


#include "stdio.h"
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <soil/SOIL.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>

#include <iostream>
#include "wrapperWindow.h"
#include "data.h"

const int design_w = 800;
const int design_h = 600;

int main()
{
GLFWwindow *window = wrapperWindow(design_w, design_h).getWindow();

int arr_group_nun = 6;

GLuint vao, vbo;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER,vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(cubeNormalArr), cubeNormalArr, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, arr_group_nun* sizeof(GLfloat), (GLvoid *)0);
glEnableVertexAttribArray(0);

glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, arr_group_nun* sizeof(GLfloat), (GLvoid *)(3 * sizeof(GLfloat)));
glEnableVertexAttribArray(1);
//--
GLuint lightVao;
glGenVertexArrays(1, &lightVao);
glBindVertexArray(lightVao);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, arr_group_nun* sizeof(GLfloat), (GLvoid *)0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
//-----------
//启用深度测试
glEnable(GL_DEPTH_TEST);
glm::vec3 lightPos(1.2f, 1.0f, 2.0f);
while (!glfwWindowShouldClose(window))
{
glfwPollEvents();

glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glm::mat4 view;
view = glm::translate(view, glm::vec3(0.0f, 0.0f, -3.0f));

glm::mat4 projection;
projection = glm::perspective(glm::radians(45.0f), (float)(design_w*1.0 / design_h), 0.1f, 100.0f);

glm::mat4 model;
model = glm::rotate(model, (float)glfwGetTime()*glm::radians(25.0f), glm::vec3(1.0f, -1.0f, 0.0f));

glBindVertexArray(vao);
//glBindTexture(GL_TEXTURE_2D,tex);
glDrawArrays(GL_TRIANGLES, 0, 36);
glBindVertexArray(0);

//--
view = glm::translate(view, glm::vec3(0.0f, 0.0f, -3.0f));
projection = glm::perspective(glm::radians(45.0f), (float)(design_w*1.0 / design_h), 0.1f, 100.0f);

model = glm::mat4();
model = glm::translate(model, lightPos);
model = glm::scale(model, glm::vec3(0.2f));

glBindVertexArray(lightVao);
glDrawArrays(GL_TRIANGLES, 0, 36);
glBindVertexArray(0);

glfwSwapBuffers(window);
}

glfwTerminate();
return 0;
}