根据mode变量更换显示模式,详细见运行效果

主函数 main.cpp

#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <stb_image.h>#include<glm-0.9.9.8/glm/glm.hpp>
#include<glm-0.9.9.8/glm/gtc/matrix_transform.hpp>
#include<glm-0.9.9.8/glm/gtc/type_ptr.hpp>#include<camera.h>
#include <shader3D.h>#include <iostream>
#define STB_IMAGE_IMPLEMENTATION
#include <stb-image/stb_image.h>const GLfloat PI = 3.14159265358979323846f;
//将球横纵划分成50*50的网格
const int Y_SEGMENTS = 50;
const int X_SEGMENTS = 50;int mode = 0;void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void mouse_callback(GLFWwindow* window, double xpos, double ypos);
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
void processInput(GLFWwindow* window);
unsigned int loadTexture(const char* path);// settings
const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;// camera
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
float lastX = SCR_WIDTH / 2.0f;
float lastY = SCR_HEIGHT / 2.0f;
bool firstMouse = true;// timing
float deltaTime = 0.0f;
float lastFrame = 0.0f;float translate1 = 0.0f;
float translate2 = 0.0f;
float translate3 = 0.0f;void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode) {if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS)translate1 = translate1 - 0.1;if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS)translate1 = translate1 + 0.1;if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS)translate3 = translate3 + 0.1;if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS)translate3 = translate3 - 0.1;if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)translate2 = translate2 + 0.1;if (glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS)translate2 = translate2 - 0.1;
}int main()
{// glfw: initialize and configure// ------------------------------glfwInit();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// glfw window creation// --------------------GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);if (window == NULL){std::cout << "Failed to create GLFW window" << std::endl;glfwTerminate();return -1;}glfwMakeContextCurrent(window);glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);glfwSetCursorPosCallback(window, mouse_callback);glfwSetScrollCallback(window, scroll_callback);// tell GLFW to capture our mouseglfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);// glad: load all OpenGL function pointers// ---------------------------------------if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)){std::cout << "Failed to initialize GLAD" << std::endl;return -1;}// configure global opengl state// -----------------------------glEnable(GL_DEPTH_TEST);// build and compile shaders// -------------------------Shader lightingShader("5.1.light_casters.vs", "5.1.light_casters.fs");Shader lightCubeShader("5.1.light_cube.vs", "5.1.light_cube.fs");// set up vertex data (and buffer(s)) and configure vertex attributes// ------------------------------------------------------------------float vertices[] = {// positions          // normals           // texture coords-0.5f, -0.5f, -0.5f,  0.0f,  0.0f, -1.0f,  0.0f,  0.0f,0.5f, -0.5f, -0.5f,  0.0f,  0.0f, -1.0f,  1.0f,  0.0f,0.5f,  0.5f, -0.5f,  0.0f,  0.0f, -1.0f,  1.0f,  1.0f,0.5f,  0.5f, -0.5f,  0.0f,  0.0f, -1.0f,  1.0f,  1.0f,-0.5f,  0.5f, -0.5f,  0.0f,  0.0f, -1.0f,  0.0f,  1.0f,-0.5f, -0.5f, -0.5f,  0.0f,  0.0f, -1.0f,  0.0f,  0.0f,-0.5f, -0.5f,  0.5f,  0.0f,  0.0f,  1.0f,  0.0f,  0.0f,0.5f, -0.5f,  0.5f,  0.0f,  0.0f,  1.0f,  1.0f,  0.0f,0.5f,  0.5f,  0.5f,  0.0f,  0.0f,  1.0f,  1.0f,  1.0f,0.5f,  0.5f,  0.5f,  0.0f,  0.0f,  1.0f,  1.0f,  1.0f,-0.5f,  0.5f,  0.5f,  0.0f,  0.0f,  1.0f,  0.0f,  1.0f,-0.5f, -0.5f,  0.5f,  0.0f,  0.0f,  1.0f,  0.0f,  0.0f,-0.5f,  0.5f,  0.5f, -1.0f,  0.0f,  0.0f,  1.0f,  0.0f,-0.5f,  0.5f, -0.5f, -1.0f,  0.0f,  0.0f,  1.0f,  1.0f,-0.5f, -0.5f, -0.5f, -1.0f,  0.0f,  0.0f,  0.0f,  1.0f,-0.5f, -0.5f, -0.5f, -1.0f,  0.0f,  0.0f,  0.0f,  1.0f,-0.5f, -0.5f,  0.5f, -1.0f,  0.0f,  0.0f,  0.0f,  0.0f,-0.5f,  0.5f,  0.5f, -1.0f,  0.0f,  0.0f,  1.0f,  0.0f,0.5f,  0.5f,  0.5f,  1.0f,  0.0f,  0.0f,  1.0f,  0.0f,0.5f,  0.5f, -0.5f,  1.0f,  0.0f,  0.0f,  1.0f,  1.0f,0.5f, -0.5f, -0.5f,  1.0f,  0.0f,  0.0f,  0.0f,  1.0f,0.5f, -0.5f, -0.5f,  1.0f,  0.0f,  0.0f,  0.0f,  1.0f,0.5f, -0.5f,  0.5f,  1.0f,  0.0f,  0.0f,  0.0f,  0.0f,0.5f,  0.5f,  0.5f,  1.0f,  0.0f,  0.0f,  1.0f,  0.0f,-0.5f, -0.5f, -0.5f,  0.0f, -1.0f,  0.0f,  0.0f,  1.0f,0.5f, -0.5f, -0.5f,  0.0f, -1.0f,  0.0f,  1.0f,  1.0f,0.5f, -0.5f,  0.5f,  0.0f, -1.0f,  0.0f,  1.0f,  0.0f,0.5f, -0.5f,  0.5f,  0.0f, -1.0f,  0.0f,  1.0f,  0.0f,-0.5f, -0.5f,  0.5f,  0.0f, -1.0f,  0.0f,  0.0f,  0.0f,-0.5f, -0.5f, -0.5f,  0.0f, -1.0f,  0.0f,  0.0f,  1.0f,-0.5f,  0.5f, -0.5f,  0.0f,  1.0f,  0.0f,  0.0f,  1.0f,0.5f,  0.5f, -0.5f,  0.0f,  1.0f,  0.0f,  1.0f,  1.0f,0.5f,  0.5f,  0.5f,  0.0f,  1.0f,  0.0f,  1.0f,  0.0f,0.5f,  0.5f,  0.5f,  0.0f,  1.0f,  0.0f,  1.0f,  0.0f,-0.5f,  0.5f,  0.5f,  0.0f,  1.0f,  0.0f,  0.0f,  0.0f,-0.5f,  0.5f, -0.5f,  0.0f,  1.0f,  0.0f,  0.0f,  1.0f};// positions all containersglm::vec3 cubePositions[] = {glm::vec3(0.0f,  0.0f,  0.0f),glm::vec3(2.0f,  5.0f, -15.0f),glm::vec3(-1.5f, -2.2f, -2.5f),glm::vec3(-3.8f, -2.0f, -12.3f),glm::vec3(2.4f, -0.4f, -3.5f),glm::vec3(-1.7f,  3.0f, -7.5f),glm::vec3(1.3f, -2.0f, -2.5f),glm::vec3(1.5f,  2.0f, -2.5f),glm::vec3(1.5f,  0.2f, -1.5f),glm::vec3(-1.3f,  1.0f, -1.5f)};// first, configure the cube's VAO (and VBO)unsigned int VBO[2], cubeVAO;glGenVertexArrays(1, &cubeVAO);glGenBuffers(2, VBO);glBindBuffer(GL_ARRAY_BUFFER, VBO[0]);glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);glBindVertexArray(cubeVAO);glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);glEnableVertexAttribArray(0);glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float)));glEnableVertexAttribArray(1);glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float)));glEnableVertexAttribArray(2);// second, configure the light's VAO (VBO stays the same; the vertices are the same for the light object which is also a 3D cube)unsigned int lightCubeVAO;glGenVertexArrays(1, &lightCubeVAO);glBindVertexArray(lightCubeVAO);std::vector<float> sphereVertices;std::vector<int> sphereIndices;/*2-计算球体顶点*///生成球的顶点for (int y = 0; y <= Y_SEGMENTS; y++){for (int x = 0; x <= X_SEGMENTS; x++){float xSegment = (float)x / (float)X_SEGMENTS;float ySegment = (float)y / (float)Y_SEGMENTS;float xPos = std::cos(xSegment * 2.0f * PI) * std::sin(ySegment * PI)* 0.5;float yPos = std::cos(ySegment * PI) * 0.5;float zPos = std::sin(xSegment * 2.0f * PI) * std::sin(ySegment * PI) * 0.5;sphereVertices.push_back(xPos);sphereVertices.push_back(yPos);sphereVertices.push_back(zPos);sphereVertices.push_back(xPos);sphereVertices.push_back(yPos);sphereVertices.push_back(zPos);sphereVertices.push_back(xSegment);sphereVertices.push_back(1 - ySegment);}}//生成球的Indicesfor (int i = 0; i < Y_SEGMENTS; i++){for (int j = 0; j < X_SEGMENTS; j++){sphereIndices.push_back(i * (X_SEGMENTS + 1) + j);sphereIndices.push_back((i + 1) * (X_SEGMENTS + 1) + j);sphereIndices.push_back((i + 1) * (X_SEGMENTS + 1) + j + 1);sphereIndices.push_back(i * (X_SEGMENTS + 1) + j);sphereIndices.push_back((i + 1) * (X_SEGMENTS + 1) + j + 1);sphereIndices.push_back(i * (X_SEGMENTS + 1) + j + 1);}}glBindBuffer(GL_ARRAY_BUFFER, VBO[1]);glBufferData(GL_ARRAY_BUFFER, sphereVertices.size() * sizeof(float), &sphereVertices[0], GL_STATIC_DRAW);GLuint element_buffer_object;//EBOglGenBuffers(1, &element_buffer_object);glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, element_buffer_object);glBufferData(GL_ELEMENT_ARRAY_BUFFER, sphereIndices.size() * sizeof(int), &sphereIndices[0], GL_STATIC_DRAW);//设置顶点属性指针glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8* sizeof(float), (void*)0);glEnableVertexAttribArray(0);//解绑VAO和VBOglBindBuffer(GL_ARRAY_BUFFER, 0);glBindVertexArray(0);unsigned int VBO1[3], VAO1[3];glGenVertexArrays(3, VAO1);glGenBuffers(3, VBO1);glBindVertexArray(VAO1[0]);glBindBuffer(GL_ARRAY_BUFFER, VBO1[0]);//将顶点数据绑定至当前默认的缓冲中glBufferData(GL_ARRAY_BUFFER, sphereVertices.size() * sizeof(float), &sphereVertices[0], GL_STATIC_DRAW);GLuint element_buffer_object_obj;//EBOglGenBuffers(1, &element_buffer_object_obj);glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, element_buffer_object_obj);glBufferData(GL_ELEMENT_ARRAY_BUFFER, sphereIndices.size() * sizeof(int), &sphereIndices[0], GL_STATIC_DRAW);//设置顶点属性指针glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);glEnableVertexAttribArray(0);glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float)));glEnableVertexAttribArray(1);glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float)));glEnableVertexAttribArray(2);//解绑VAO1和VBO1glBindBuffer(GL_ARRAY_BUFFER, 0);glBindVertexArray(0);// load textures (we now use a utility function to keep the code more organized)// -----------------------------------------------------------------------------unsigned int diffuseMap;unsigned int specularMap;if (mode == 1) {diffuseMap = loadTexture("container2.png");specularMap = loadTexture("container2_specular.png");}else if (mode == 2) {diffuseMap = loadTexture("1.png");specularMap = loadTexture("1.png");}else {diffuseMap = loadTexture("white.png");specularMap = loadTexture("white.png");}// shader configuration// --------------------lightingShader.use();lightingShader.setInt("material.diffuse", 0);lightingShader.setInt("material.specular", 1);// render loop// -----------while (!glfwWindowShouldClose(window)){glfwSetKeyCallback(window, key_callback);// per-frame time logic// --------------------float currentFrame = static_cast<float>(glfwGetTime());deltaTime = currentFrame - lastFrame;lastFrame = currentFrame;// input// -----processInput(window);// render// ------glClearColor(0.1f, 0.1f, 0.1f, 1.0f);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glm::vec3 lightPos(1.2f + translate1, 1.0f + translate2, 2.0f + translate3);// be sure to activate shader when setting uniforms/drawing objectslightingShader.use(); //x左右 y 上下 z前后//lightingShader.setVec3("light.direction", direction1);lightingShader.setVec3("light.position", lightPos);lightingShader.setVec3("viewPos", camera.Position);// light propertieslightingShader.setVec3("light.ambient", 0.2f, 0.2f, 0.2f);lightingShader.setVec3("light.diffuse", 0.5f, 0.5f, 0.5f);lightingShader.setVec3("light.specular", 0.5f, 0.5f, 0.5f);lightingShader.setFloat("light.constant", 1.0f);lightingShader.setFloat("light.linear", 0.09f);lightingShader.setFloat("light.quadratic", 0.032f);// material propertieslightingShader.setFloat("material.shininess", 32.0f);// view/projection transformationsglm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);glm::mat4 view = camera.GetViewMatrix();lightingShader.setMat4("projection", projection);lightingShader.setMat4("view", view);// world transformationglm::mat4 model = glm::mat4(1.0f);lightingShader.setMat4("model", model);// bind diffuse mapglActiveTexture(GL_TEXTURE0);glBindTexture(GL_TEXTURE_2D, diffuseMap);// bind specular mapglActiveTexture(GL_TEXTURE1);glBindTexture(GL_TEXTURE_2D, specularMap);// render the cube// glBindVertexArray(cubeVAO);// glDrawArrays(GL_TRIANGLES, 0, 36);*/// render containersglBindVertexArray(cubeVAO);for (unsigned int i = 0; i < 5; i++){// calculate the model matrix for each object and pass it to shader before drawingglm::mat4 model = glm::mat4(1.0f);model = glm::translate(model, cubePositions[i]);float angle = 20.0f * i;model = glm::rotate(model, glm::radians(angle), glm::vec3(1.0f, 0.3f, 0.5f));lightingShader.setMat4("model", model);glDrawArrays(GL_TRIANGLES, 0, 36);}glBindVertexArray(VAO1[0]);for (unsigned int i = 5; i < 10; i++){// calculate the model matrix for each object and pass it to shader before drawingglm::mat4 model = glm::mat4(1.0f);model = glm::translate(model, cubePositions[i]);float angle = 20.0f * i;model = glm::rotate(model, glm::radians(angle), glm::vec3(1.0f, 0.3f, 0.5f));lightingShader.setMat4("model", model);glDrawElements(GL_TRIANGLES, X_SEGMENTS * Y_SEGMENTS * 6, GL_UNSIGNED_INT, 0);}//glm::vec3 lightPos(1.2f, 1.0f, 2.0f);// a lamp object is weird when we only have a directional light, don't render the light objectlightCubeShader.use();lightCubeShader.setMat4("projection", projection);lightCubeShader.setMat4("view", view);model = glm::mat4(1.0f);model = glm::translate(model, lightPos);model = glm::scale(model, glm::vec3(0.2f)); // a smaller cubelightCubeShader.setMat4("model", model);//glm::mat4 trans_mov = glm::mat4(1.0f);// //trans_mov = glm::rotate(trans, (float)glfwGetTime(), glm::vec3(0.0f, 0.0f, 1.0f));//trans_mov = glm::translate(trans_mov, glm::vec3(translate1, translate2, translate3));glBindVertexArray(lightCubeVAO);//unsigned int transformLoc_mov = glGetUniformLocation(lightCubeShader.ID, "transform_mov");//glUniformMatrix4fv(transformLoc_mov, 1, GL_FALSE, glm::value_ptr(trans_mov));glDrawElements(GL_TRIANGLES, X_SEGMENTS * Y_SEGMENTS * 6, GL_UNSIGNED_INT, 0);// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)// -------------------------------------------------------------------------------glfwSwapBuffers(window);glfwPollEvents();}// optional: de-allocate all resources once they've outlived their purpose:// ------------------------------------------------------------------------glDeleteVertexArrays(1, &cubeVAO);glDeleteVertexArrays(1, &lightCubeVAO);//glDeleteBuffers(1, VBO);// glfw: terminate, clearing all previously allocated GLFW resources.// ------------------------------------------------------------------glfwTerminate();return 0;
}// process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly
// ---------------------------------------------------------------------------------------------------------
void processInput(GLFWwindow* window)
{if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)glfwSetWindowShouldClose(window, true);if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)camera.ProcessKeyboard(FORWARD, deltaTime);if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)camera.ProcessKeyboard(BACKWARD, deltaTime);if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)camera.ProcessKeyboard(LEFT, deltaTime);if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)camera.ProcessKeyboard(RIGHT, deltaTime);}// glfw: whenever the window size changed (by OS or user resize) this callback function executes
// ---------------------------------------------------------------------------------------------
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);
}// glfw: whenever the mouse moves, this callback is called
// -------------------------------------------------------
void mouse_callback(GLFWwindow* window, double xposIn, double yposIn)
{float xpos = static_cast<float>(xposIn);float ypos = static_cast<float>(yposIn);if (firstMouse){lastX = xpos;lastY = ypos;firstMouse = false;}float xoffset = xpos - lastX;float yoffset = lastY - ypos; // reversed since y-coordinates go from bottom to toplastX = xpos;lastY = ypos;camera.ProcessMouseMovement(xoffset, yoffset);
}// glfw: whenever the mouse scroll wheel scrolls, this callback is called
// ----------------------------------------------------------------------
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
{camera.ProcessMouseScroll(static_cast<float>(yoffset));
}// utility function for loading a 2D texture from file
// ---------------------------------------------------
unsigned int loadTexture(char const* path)
{unsigned int textureID;glGenTextures(1, &textureID);int width, height, nrComponents;unsigned char* data = stbi_load(path, &width, &height, &nrComponents, 0);if (data){GLenum format;if (nrComponents == 1)format = GL_RED;else if (nrComponents == 3)format = GL_RGB;else if (nrComponents == 4)format = GL_RGBA;glBindTexture(GL_TEXTURE_2D, textureID);glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data);glGenerateMipmap(GL_TEXTURE_2D);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);stbi_image_free(data);}else{std::cout << "Texture failed to load at path: " << path << std::endl;stbi_image_free(data);}return textureID;
}

5.1.light_casters.vs

#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
layout (location = 2) in vec2 aTexCoords;out vec3 FragPos;
out vec3 Normal;
out vec2 TexCoords;uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;void main()
{FragPos = vec3(model * vec4(aPos, 1.0));Normal = mat3(transpose(inverse(model))) * aNormal;  TexCoords = aTexCoords;gl_Position = projection * view * vec4(FragPos, 1.0);
}

5.1.light_casters.fs

#version 330 core
out vec4 FragColor;struct Material {sampler2D diffuse;sampler2D specular;    float shininess;
}; struct Light {vec3 position;  vec3 ambient;vec3 diffuse;vec3 specular;float constant;float linear;float quadratic;
};in vec3 FragPos;
in vec3 Normal;
in vec2 TexCoords;uniform vec3 viewPos;
uniform Material material;
uniform Light light;void main()
{// ambientvec3 ambient = light.ambient * texture(material.diffuse, TexCoords).rgb;// diffuse vec3 norm = normalize(Normal);vec3 lightDir = normalize(light.position - FragPos);float diff = max(dot(norm, lightDir), 0.0);vec3 diffuse = light.diffuse * diff * texture(material.diffuse, TexCoords).rgb;  // specularvec3 viewDir = normalize(viewPos - FragPos);vec3 reflectDir = reflect(-lightDir, norm);  float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);vec3 specular = light.specular * spec * texture(material.specular, TexCoords).rgb;  // attenuationfloat distance    = length(light.position - FragPos);float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));    ambient  *= attenuation;  diffuse   *= attenuation;specular *= attenuation;   vec3 result = ambient + diffuse + specular;FragColor = vec4(result, 1.0);
}

5.1.light_cube.vs

#version 330 core
layout (location = 0) in vec3 aPos;uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
uniform mat4 transform_mov;void main()
{gl_Position =  projection * view * model* vec4(aPos, 1.0);
}

5.1.light_cube.fs

#version 330 core
out vec4 FragColor;void main()
{FragColor = vec4(1.0); // set alle 4 vector values to 1.0
}

其他库

stb_image、camera.h 和 shader3D.h 见 http://t.csdn.cn/KfRuF

运行效果

  1. 无贴图状态(实际上是用纯色图片表示,因为这样只需要换贴图照片就行了,不必换片段着色起)(mode = 0)
  2. 贴图状态1:立方体展现金属和木质两种材质(mode = 1)
  3. 贴图状态2: 自定义贴图(mode = 2)

【光源漫游】OpenGL实现移动光源并改变物体的受光状态相关推荐

  1. 看图说OpenGL之三:是什么在改变物体的颜色

    1. 神秘的的六面体,却把重要的alpha给丢掉了. 2.同样是球,只因灯光不同. 3.很多特殊的效果都是由它来决定的. 4.混色Alpha的作用在此淋漓尽致    5.抗锯齿的效果非同凡响. 6.雾 ...

  2. LED光源的种类与LED光源与灯具的定义介绍

    下面为大家介绍LED光源的种类与LED光源与灯具的区别,也就是定义.LED光源的种类有很多种,LED光源表示的是LED照明行业.LED是由发光二极管简称LED.是由Ga.As.P.N(镓.砷.磷.氮) ...

  3. 请问如何在出错后能恢复到改变设置前的状态?

    安装了DotNetNuke4.4.0,有时候修改一些设置后发现出错,再刷新后就一直是出错页面了,请问如何在出错后能恢复到改变设置前的状态? 如果你改的是设置文件,如web.config,那改回来就可以 ...

  4. C#游戏开发快速入门2.2改变游戏对象的状态

    C#游戏开发快速入门2.2改变游戏对象的状态 改变游戏对象的状态,就是要改变游戏对象的位置.朝向和大小.那么,为什么要改变游戏对象的状态呢?当然是因为游戏对象的状态不合适了.在具体说明之前,读者应该先 ...

  5. 改变循环执行的状态,循环程序举例

    //  改变循环执行的状态 1.  用 break 语句提前终止循环 #include "stdafx.h" #define SUM 100000                  ...

  6. 力改变物体形状举例_人教版八年级物理下册第七章《力》知识点大全

    力是物体对物体的作用,比如推土机推动了土. 知识点1:力 1.概念:是物体对物体的作用叫做力. 2.特点:物体间力的作用是相互的. 3.力的单位和表示符号: (1)力的单位:牛顿,简称牛(N).托起一 ...

  7. 程序学3DMax之改变物体的中心轴及物体归置零点

    小白欢迎评论,共同探讨,共同进步 此系列博文为程序小白记录笔记,以防忘记. 快捷键Alt+W(最大化选中的视口)       移动改变物体的轴,点击如下图所示, 按W使其为位移模式,然后按快捷键S(点 ...

  8. 魔坊APP项目-23-种植园,宠物和种植物的状态改变、宠物的状态改动

    种植园 宠物和种植物的状态改变 1. 宠物的状态改动 2. 种植物的状态改动 3. 道具的使用 宠物的状态改动 因为宠物有多个,每个宠物会有不同的初始生命的饥饿时间,所以我们提前在mysql中进行配置 ...

  9. Mlab - 改变物体外观及鼠标选取操作

    Python科学计算三维可视化 黄天羽.嵩天 Mlab 基础 MLab reference 改变物体的外观 改变颜色 colormap 定义的颜色,也叫 LUT(Look Up Table) 常见的 ...

最新文章

  1. 计算机电缆线对成缆系数,计算机电缆绞合系数 - 无图版
  2. CVPR2020 | 反传统的无监督人脸旋转方案:旋转-渲染
  3. Python_Nginx
  4. 永洪报表工具_该怎么选BI工具
  5. pytorch学习1:pytorch 定义网络的方式
  6. 第一天,搬家到博客园
  7. java的关闭钩子(Shutdown Hook)
  8. dicom文件的后缀_DCM文件扩展名 - 什么是.dcm以及如何打开? - ReviverSoft
  9. excel快速选择数据的4种方法
  10. NLP:不要重新造轮子
  11. 通过python理解相速度和群速度
  12. c 语言加壳项目,C 加壳工具,快速完成加密保护
  13. 一、基于workflow-core强势开发审批流【已成功流转50W笔单据】
  14. 输出三位数的个十百位数
  15. 广电网络电视怎么服务器连接中断,怎么解决广电网络看电视卡
  16. 网络信息安全模型概述
  17. 立杆见影 加快Win XP启动速度的六种办法(转)
  18. mac改成类似微软键盘偏好设置
  19. IoTSharp 已支持国产松果时序数据库PinusDB
  20. 日入上万,Jack 年入百万?

热门文章

  1. 【英语语法入门】 第15讲 不定量表达法 (1)
  2. 潜龙号开启水下机器人_蛟龙、海龙、潜龙傻傻分不清?全面解密国内最先进水下机器人...
  3. Linux C/C++编程:lseek、fseek、ftell、rewind、fgetpos、fsetpos、
  4. 875用java么_LeetCode 875. Koko Eating Bananas
  5. SAP PLM官方培训教材
  6. 重庆工商大学本科毕业论文答辩和论文选题PPT模板
  7. Docker容器的详细教程(全面了解容器的使用)
  8. 使用border-radius画圆、半圆、扇形
  9. brook客户端android,Android端线上NativeCrash收集的两种方法(一)
  10. JAVA求出长方形的体积