当前位置: 首页 > news >正文

网站建设平台资讯玉石网站建设的定位

网站建设平台资讯,玉石网站建设的定位,包装设计案例,海外sns网站1. 漫反射贴图 在光照场景中#xff0c;它通常叫做一个漫反射贴图(Diffuse Map)#xff08;3D艺术家通常都这么叫它#xff09;#xff0c;它是一个表现了物体所有的漫反射颜色的纹理图像。 我们会将纹理储存为Material结构体中的一个sampler2D 。我们将之前定义的vec3漫反…1. 漫反射贴图 在光照场景中它通常叫做一个漫反射贴图(Diffuse Map)3D艺术家通常都这么叫它它是一个表现了物体所有的漫反射颜色的纹理图像。 我们会将纹理储存为Material结构体中的一个sampler2D 。我们将之前定义的vec3漫反射颜色向量替换为漫反射贴图。 注意sampler2D是所谓的不透明类型(Opaque Type)也就是说我们不能将它实例化只能通过uniform来定义它。如果我们使用除uniform以外的方法比如函数的参数实例化这个结构体GLSL会抛出一些奇怪的错误。这同样也适用于任何封装了不透明类型的结构体。 struct Material {sampler2D diffuse;vec3 specular;float shininess; }; ... in vec2 TexCoords; cube.vs**********************#version 330 core layout (location 0) in vec3 aPos; layout (location 1 ) in vec3 aNormal; layout (location2) in vec2 aTexCoords;out vec3 FragPos; out vec3 Normal; out vec2 TexCoords;uniform mat4 model; uniform mat4 view; uniform mat4 projection;void main() {FragPosvec3(model*vec4(aPos,1.0));Normalmat3(transpose(inverse(model)))*aNormal;TexCoordsaTexCoords;gl_Position projection * view * vec4(FragPos, 1.0); }cube.vs**********************#version 330 core out vec4 FragColor;in vec3 Normal; in vec3 FragPos;struct Material {sampler2D diffuse;vec3 specular;float shininess; }; in vec2 TexCoords; struct Light {vec3 position;vec3 ambient;vec3 diffuse;vec3 specular; }; uniform Material material; uniform Light light; uniform vec3 objectColor; uniform vec3 lightColor; uniform vec3 lightPos; uniform vec3 viewPos;void main() {//ambientvec3 ambientvec3(0.1)*light.ambient*vec3(texture(material.diffuse,TexCoords));//diffusevec3 normnormalize(Normal);vec3 lightDirnormalize(light.position-FragPos);//光的方向向量是光源位置向量与片段位置向量之间的向量差。//对norm和lightDir向量进行点乘计算光源对当前片段实际的漫反射影响//两个向量之间的角度越大漫反射分量就会越小点乘的几何意义也如此float diffmax(dot(norm,lightDir),0.0);vec3 diffuselight.diffuse*diff*vec3(texture(material.diffuse,TexCoords));//specular//漫反射是光源指向片段位置。现在这个是摄像机指向片段位置vec3 viewDirnormalize(viewPos-FragPos);vec3 reflectDirreflect(-lightDir,norm);//reflect第一个参数就是要片段指向摄像机位置float specpow(max(dot(viewDir,reflectDir),0.0),material.shininess);vec3 specularlight.specular*(spec*material.specular);vec3 resultambientdiffusespecular;FragColor vec4(result, 1.0); }light_cube.vs**********************#version 330 core layout (location 0) in vec3 aPos;uniform mat4 model; uniform mat4 view; uniform mat4 projection;void main() {gl_Position projection * view * model * vec4(aPos, 1.0); }light_cube.fs**********************#version 330 core out vec4 FragColor; uniform vec4 CubeFragColor; void main() { FragColor vec4(1.0); } main.cpp #include glad/glad.h #include GLFW/glfw3.h#include iostream #include stb_image.h #include cmath #include shader.h #include camera.h#include glm/glm.hpp #include glm/gtc/matrix_transform.hpp #include glm/gtc/type_ptr.hppvoid framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow* window); void mouse_callback(GLFWwindow* window, double xpos, double ypos); void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);// settings const unsigned int SCR_WIDTH 900; 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;glm::vec3 lightPos(1.2f, 1.0f, 2.0f);// 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; }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, Learn, 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 gloabl opengl state//glEnable(GL_DEPTH_TEST);//build and compile our shader zprogram//Shader lightingShader(./cube.vs, ./cube.fs);Shader lightingCubeShader(./light_cube.vs, ./light_cube.fs);//set up vertex data 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};//第一个unsigned int VBO, cubeVAO;glGenVertexArrays(1, cubeVAO);glGenBuffers(1, VBO);glBindBuffer(GL_ARRAY_BUFFER, VBO);glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);glBindVertexArray(cubeVAO);//position attributeglVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);glEnableVertexAttribArray(0);//normal attributeglVertexAttribPointer(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);//第二个unsigned int lightCubeVAO;glGenVertexArrays(1, lightCubeVAO);glBindVertexArray(lightCubeVAO);glBindBuffer(GL_ARRAY_BUFFER, VBO);glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);glEnableVertexAttribArray(0);std::string texturePath ../../Data/container2.png;unsigned int diffuseMap loadTexture(texturePath.c_str());lightingShader.use();lightingShader.setInt(material.diffuse, 0);// render loop// -----------while (!glfwWindowShouldClose(window)){// per-frame time logic// --------------------float currentFrame static_castfloat(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);// be sure to activate shader when setting uniforms/drawing objectslightingShader.use();lightingShader.setVec3(light.position, lightPos);lightingShader.setVec3(viewPos, camera.Position);//光照属性lightingShader.setVec3(light.ambient, 0.2f, 0.2f, 0.2f);lightingShader.setVec3(light.diffuse, 0.5f, 0.5f, 0.5f);lightingShader.setVec3(light.specular, 1.0f, 1.0f, 1.0f);//材质属性lightingShader.setVec3(material.specular, 0.5f,0.5f, 0.5f);lightingShader.setFloat(material.shininess, 64.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);// render the cubeglBindVertexArray(cubeVAO);glDrawArrays(GL_TRIANGLES, 0, 36);// also draw the lamp objectlightingCubeShader.use();lightingCubeShader.setMat4(projection, projection);lightingCubeShader.setMat4(view, view);model glm::mat4(1.0f);model glm::translate(model, lightPos);model glm::scale(model, glm::vec3(0.2f)); // a smaller cubelightingCubeShader.setMat4(model, model);glBindVertexArray(lightCubeVAO);glDrawArrays(GL_TRIANGLES, 0, 36);// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)// -------------------------------------------------------------------------------glfwSwapBuffers(window);glfwPollEvents();}glDeleteVertexArrays(1, cubeVAO);glDeleteVertexArrays(1, lightCubeVAO);glDeleteBuffers(1, VBO);glfwTerminate();return 0;} 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); }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_castfloat(xposIn);float ypos static_castfloat(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_castfloat(yoffset)); } 2. 镜面光照贴图 增加 cube.fs #version 330 core out vec4 FragColor;in vec3 Normal; in vec3 FragPos;struct Material {sampler2D diffuse;sampler2D specular;float shininess; }; in vec2 TexCoords; struct Light {vec3 position;vec3 ambient;vec3 diffuse;vec3 specular; }; uniform Material material; uniform Light light; uniform vec3 objectColor; uniform vec3 lightColor; uniform vec3 lightPos; uniform vec3 viewPos;void main() {//ambientvec3 ambientvec3(0.1)*light.ambient*vec3(texture(material.diffuse,TexCoords));//diffusevec3 normnormalize(Normal);vec3 lightDirnormalize(light.position-FragPos);//光的方向向量是光源位置向量与片段位置向量之间的向量差。//对norm和lightDir向量进行点乘计算光源对当前片段实际的漫反射影响//两个向量之间的角度越大漫反射分量就会越小点乘的几何意义也如此float diffmax(dot(norm,lightDir),0.0);vec3 diffuselight.diffuse*diff*vec3(texture(material.diffuse,TexCoords));//specular//漫反射是光源指向片段位置。现在这个是摄像机指向片段位置vec3 viewDirnormalize(viewPos-FragPos);vec3 reflectDirreflect(-lightDir,norm);//reflect第一个参数就是要片段指向摄像机位置float specpow(max(dot(viewDir,reflectDir),0.0),material.shininess);vec3 specularlight.specular*spec*vec3(texture(material.specular,TexCoords));vec3 resultambientdiffusespecular;FragColor vec4(result, 1.0); } main.cpp 其他文件一样 #include glad/glad.h #include GLFW/glfw3.h#include iostream #include stb_image.h #include cmath #include shader.h #include camera.h#include glm/glm.hpp #include glm/gtc/matrix_transform.hpp #include glm/gtc/type_ptr.hppvoid framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow* window); void mouse_callback(GLFWwindow* window, double xpos, double ypos); void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);// settings const unsigned int SCR_WIDTH 900; 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;glm::vec3 lightPos(1.2f, 1.0f, 2.0f);// 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; }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, Learn, 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 gloabl opengl state//glEnable(GL_DEPTH_TEST);//build and compile our shader zprogram//Shader lightingShader(./cube.vs, ./cube.fs);Shader lightingCubeShader(./light_cube.vs, ./light_cube.fs);//set up vertex data 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};//第一个unsigned int VBO, cubeVAO;glGenVertexArrays(1, cubeVAO);glGenBuffers(1, VBO);glBindBuffer(GL_ARRAY_BUFFER, VBO);glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);glBindVertexArray(cubeVAO);//position attributeglVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);glEnableVertexAttribArray(0);//normal attributeglVertexAttribPointer(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);//第二个unsigned int lightCubeVAO;glGenVertexArrays(1, lightCubeVAO);glBindVertexArray(lightCubeVAO);glBindBuffer(GL_ARRAY_BUFFER, VBO);glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);glEnableVertexAttribArray(0);//----------std::string texturePath ../../Data/container2.png;unsigned int diffuseMap loadTexture(texturePath.c_str());std::string specularPath ../../Data/container2_specular.png;unsigned int specularMap loadTexture(specularPath.c_str());lightingShader.use();lightingShader.setInt(material.diffuse, 0);lightingShader.setInt(material.specular, 1);// render loop// -----------while (!glfwWindowShouldClose(window)){// per-frame time logic// --------------------float currentFrame static_castfloat(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);// be sure to activate shader when setting uniforms/drawing objectslightingShader.use();lightingShader.setVec3(light.position, lightPos);lightingShader.setVec3(viewPos, camera.Position);//光照属性lightingShader.setVec3(light.ambient, 0.2f, 0.2f, 0.2f);lightingShader.setVec3(light.diffuse, 0.5f, 0.5f, 0.5f);lightingShader.setVec3(light.specular, 1.0f, 1.0f, 1.0f);//材质属性lightingShader.setVec3(material.specular, 0.5f,0.5f, 0.5f);lightingShader.setFloat(material.shininess, 64.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);glActiveTexture(GL_TEXTURE1);glBindTexture(GL_TEXTURE_2D, specularMap);// render the cubeglBindVertexArray(cubeVAO);glDrawArrays(GL_TRIANGLES, 0, 36);// also draw the lamp objectlightingCubeShader.use();lightingCubeShader.setMat4(projection, projection);lightingCubeShader.setMat4(view, view);model glm::mat4(1.0f);model glm::translate(model, lightPos);model glm::scale(model, glm::vec3(0.2f)); // a smaller cubelightingCubeShader.setMat4(model, model);glBindVertexArray(lightCubeVAO);glDrawArrays(GL_TRIANGLES, 0, 36);// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)// -------------------------------------------------------------------------------glfwSwapBuffers(window);glfwPollEvents();}glDeleteVertexArrays(1, cubeVAO);glDeleteVertexArrays(1, lightCubeVAO);glDeleteBuffers(1, VBO);glfwTerminate();return 0;} 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); }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_castfloat(xposIn);float ypos static_castfloat(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_castfloat(yoffset)); } 光照贴图 - LearnOpenGL CN (learnopengl-cn.github.io)
http://www.hkea.cn/news/14586217/

相关文章:

  • 旅游网站建设流程步骤绍兴企业建站模板
  • 外贸网站平台都有哪些 免费的wordpress淘宝客免费版
  • 免费微信网站开发什么网站对护肤品测评做的很好
  • 中国建设银行 网站登录网站营销推广公司
  • php整站开发 企业网站教程朋友圈推广平台
  • 校园 网站建设 知乎wordpress.conf
  • 生物公司网站建设广告建设网站
  • 做网站注册验证码电脑传奇游戏哪个好玩
  • 传奇网站制作网中壹建设工程有限公司官方网站
  • xp花生壳做自己的网站同性男做的视频网站
  • 建设商城网站视频教学建设银行官方网站广州
  • 视频网站建设的意义论文saas小程序开发费用
  • 首页网站怎么做的wordpress 用户登录
  • 钓鱼网站网站怎么做1 分析seo做的不好的网站
  • 2017做网站挣钱吗在线生成电子印章
  • 为什么要选择做花卉网站wordpress 蛋花儿收费主题
  • 长沙手机网站建设哪些内容网站搜索排名查询
  • 网站自己怎么制作网站建设中企动力最佳a4
  • 网站建设男装定位临沂哪里有做网站
  • 关于外贸公司的网站手机版在线公章制作生成
  • 上海php网站开发公司市场调研方案怎么写
  • 中山品牌网站建设推广电话销售网站建设
  • 买虚机送网站建设鞍山网页制作
  • 淄博网泰专业做网站手机网站跳转代码
  • 网站建设费会计账务处理互联网服务提供商
  • 站长网站工具郑州pc网站开发
  • 用哪个网站做相册视频文件有源码就可以自己做H5网站吗
  • 哈尔滨建站的网站网页会计专业建设规划
  • 湘潭网站建设开发做公司+网站建设价格低
  • 网站建设软件哪个最好硬件开发基础知识