learnopengl“入门”的全部代码

projection 里的角度,角度越大,物体离摄像机越远;角度越小,物体离摄像机越近,这个角度表示视野(fov),视野越大,看到的物体就越小

头文件

  1 #ifndef SHADER_H_INCLUDE
  2 #define SHADER_H_INCLUDE
  3
  4 #include <iostream>
  5 #include <string>
  6 #include <sstream>
  7 #include <fstream>
  8
  9 #include <GL/glew.h>
 10 #include <GLFW/glfw3.h>
 11 #include <glm/glm.hpp>
 12 #include <glm/gtc/matrix_transform.hpp>
 13 #include <glm/gtc/type_ptr.hpp>
 14 #include <typeinfo>
 15 class Shader {
 16 public:
 17     unsigned int ID;
 18
 19     Shader(const GLchar* vertexPath, const GLchar* fragmentPath)
 20     {
 21         std::string vertexCode;
 22         std::string fragmentCode;
 23         std::ifstream vShaderFile;
 24         std::ifstream fShaderFile;
 25
 26         vShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
 27         fShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
 28
 29         try {
 30             //open files
 31             vShaderFile.open(vertexPath);
 32             fShaderFile.open(fragmentPath);
 33
 34             std::stringstream vShaderStream, fShaderStream;
 35
 36             //read file‘s buffer contents into streams
 37             vShaderStream << vShaderFile.rdbuf();
 38             fShaderStream << fShaderFile.rdbuf();
 39
 40             //close file handlers
 41             vShaderFile.close();
 42             fShaderFile.close();
 43
 44             //convert stream into string
 45             vertexCode = vShaderStream.str();
 46             fragmentCode = fShaderStream.str();
 47         }
 48         catch (std::ifstream::failure e)
 49         {
 50             std::cout << "ERROR::SHADER::FILE_NOT_SUCCESSFULLY_READ" << std::endl;
 51         }
 52         const char* vShaderCode = vertexCode.c_str();
 53         const char* fShaderCode = fragmentCode.c_str();
 54
 55         //2.compile shaders
 56         unsigned int vertex, fragment;
 57         int success;
 58         char infoLog[512];
 59
 60         //vertex shader
 61         vertex = glCreateShader(GL_VERTEX_SHADER);
 62         glShaderSource(vertex, 1, &vShaderCode, NULL);
 63         glCompileShader(vertex);
 64         glGetShaderiv(vertex, GL_COMPILE_STATUS, &success);
 65         if (!success)
 66         {
 67             glGetShaderInfoLog(vertex, 512, NULL, infoLog);
 68             std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED!" << std::endl;
 69         }
 70
 71         fragment = glCreateShader(GL_FRAGMENT_SHADER);
 72         glShaderSource(fragment, 1, &fShaderCode, NULL);
 73         glCompileShader(fragment);
 74         glGetShaderiv(fragment, GL_COMPILE_STATUS, &success);
 75         if (!success)
 76         {
 77             glGetShaderInfoLog(fragment, 512, NULL, infoLog);
 78             std::cout << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED!" << std::endl;
 79         }
 80
 81         ID = glCreateProgram();
 82         glAttachShader(ID, vertex);
 83         glAttachShader(ID, fragment);
 84         glLinkProgram(ID);
 85         glGetProgramiv(ID, GL_LINK_STATUS, &success);
 86         if (!success)
 87         {
 88             glGetProgramInfoLog(ID, 512, NULL, infoLog);
 89             std::cout << "ERROR::SHADER::PROGRAM::LINKTING_FAILED!" << std::endl;
 90         }
 91
 92         //delete the shaders sa they are linked into our program now and no long necessary
 93         glDeleteShader(vertex);
 94         glDeleteShader(fragment);
 95     }
 96
 97     //activate the shader
 98     void use()
 99     {
100         glUseProgram(ID);
101     }
102
103     //utility uniform functions
104     void setBool(const std::string &name, bool value) const
105     {
106         glUniform1i(glGetUniformLocation(ID, name.c_str()), value);
107     }
108
109     void setInt(const std::string &name, int value) const
110     {
111         glUniform1i(glGetUniformLocation(ID, name.c_str()), value);
112     }
113
114     void setFloat(const std::string &name, float value) const
115     {
116         glUniform1f(glGetUniformLocation(ID, name.c_str()), value);
117     }
118
119     void setMat4(const std::string &name, glm::mat4 &trans) const
120     {
121
122         glUniformMatrix4fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &trans[0][0]);
123     }
124
125     /*void setMat4(const std::string &name, glm::mat4 trans) const
126     {
127
128         //‘trans‘: formal parameter with requested alignment of 16 won‘t be aligned,请求对齐的16的形式参数不会对齐
129         glUniformMatrix4fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, glm::value_ptr(trans));
130     }*/
131
132 };
133
134 #endif

.cpp源文件

  1 //projection 里的角度,角度越大,物体离摄像机越远;角度越小,物体离摄像机越近,这个角度表示视野(fov)
  2 //视野越大,看到的物体就越小
  3 #include <iostream>
  4 using namespace std;
  5 #define GLEW_STATIC
  6 #include <GL/glew.h>
  7 #include <GLFW/glfw3.h>
  8 #define STB_IMAGE_IMPLEMENTATION
  9 #include "stb_image.h"
 10 #include "Shader.h"
 11 #include <glm/glm.hpp>
 12 #include <glm/gtc/matrix_transform.hpp>
 13 #include <glm/gtc/type_ptr.hpp>
 14
 15
 16 void framebuffer_size_callback(GLFWwindow* window, int width, int height);
 17 void mouse_callback(GLFWwindow* window, GLdouble xpos, GLdouble ypos);
 18 void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
 19 //void scroll_callback(GLFWwindow* window, GLdouble xoffset, GLdouble yoffset);
 20 void processInput(GLFWwindow *window);
 21
 22 glm::vec3 cameraPos = glm::vec3(0.0f, 0.0f, 3.0f);
 23 glm::vec3 cameraFront = glm::vec3(0.0f, 0.0f, -1.0f);
 24 glm::vec3 cameraUp = glm::vec3(0.0f, 1.0f, 0.0f);
 25
 26 float deltaTime = 0.0f;
 27 float lastFrame = 0.0f;
 28 float mixValue = 0.3f;
 29 float SCR_WIDTH = 800;
 30 float SCR_HEIGHT = 600;
 31 float Left = 0.0f;
 32 float Up = 0.0f;
 33 float lastX = 400, lastY = 300;
 34 float yaw = -90.0f, pitch = 0.0f;//yaw是偏航角,pitch是俯仰角
 35 GLboolean firstMouse = true;
 36 float fov = 45.0f;
 37
 38
 39
 40 int main()
 41 {
 42     glfwInit();
 43     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
 44     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
 45     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
 46     GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
 47     if (!window)
 48     {
 49         cout << "Failed to create window!\n" << endl;
 50         glfwTerminate();
 51         return -1;
 52     }
 53     glfwMakeContextCurrent(window);
 54
 55     glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
 56     glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);    //隐藏并捕捉光标
 57     glfwSetCursorPosCallback(window, mouse_callback);    //回调鼠标事件
 58     glfwSetScrollCallback(window, scroll_callback);    //滚轮回调事件
 59
 60     glewExperimental = GL_TRUE;
 61     if (glewInit() != GLEW_OK)
 62     {
 63         cout << "Failed to initialize GLEW!" << endl;
 64         return -1;
 65     }
 66
 67
 68     //glfwSetCursorPosCallback(window, mouse_callback);
 69     //glfwSetScrollCallback(window, scroll_callback);
 70
 71     //tell GLFW to capture our mouse
 72     //glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
 73
 74     //configure global opengl state, z buffer
 75     glEnable(GL_DEPTH_TEST);//Z缓冲,深度缓冲
 76
 77     //build and compile our shader program
 78     Shader ourShader("E:\\C++\\3.txt", "E:\\C++\\4.txt");
 79
 80     float vertices[] = {
 81         -0.5f, -0.5f, -0.5f,  0.0f, 0.0f,
 82         0.5f, -0.5f, -0.5f,  1.0f, 0.0f,
 83         0.5f,  0.5f, -0.5f,  1.0f, 1.0f,
 84         0.5f,  0.5f, -0.5f,  1.0f, 1.0f,
 85         -0.5f,  0.5f, -0.5f,  0.0f, 1.0f,
 86         -0.5f, -0.5f, -0.5f,  0.0f, 0.0f,
 87
 88         -0.5f, -0.5f,  0.5f,  0.0f, 0.0f,
 89         0.5f, -0.5f,  0.5f,  1.0f, 0.0f,
 90         0.5f,  0.5f,  0.5f,  1.0f, 1.0f,
 91         0.5f,  0.5f,  0.5f,  1.0f, 1.0f,
 92         -0.5f,  0.5f,  0.5f,  0.0f, 1.0f,
 93         -0.5f, -0.5f,  0.5f,  0.0f, 0.0f,
 94
 95         -0.5f,  0.5f,  0.5f,  1.0f, 0.0f,
 96         -0.5f,  0.5f, -0.5f,  1.0f, 1.0f,
 97         -0.5f, -0.5f, -0.5f,  0.0f, 1.0f,
 98         -0.5f, -0.5f, -0.5f,  0.0f, 1.0f,
 99         -0.5f, -0.5f,  0.5f,  0.0f, 0.0f,
100         -0.5f,  0.5f,  0.5f,  1.0f, 0.0f,
101
102         0.5f,  0.5f,  0.5f,  1.0f, 0.0f,
103         0.5f,  0.5f, -0.5f,  1.0f, 1.0f,
104         0.5f, -0.5f, -0.5f,  0.0f, 1.0f,
105         0.5f, -0.5f, -0.5f,  0.0f, 1.0f,
106         0.5f, -0.5f,  0.5f,  0.0f, 0.0f,
107         0.5f,  0.5f,  0.5f,  1.0f, 0.0f,
108
109         -0.5f, -0.5f, -0.5f,  0.0f, 1.0f,
110         0.5f, -0.5f, -0.5f,  1.0f, 1.0f,
111         0.5f, -0.5f,  0.5f,  1.0f, 0.0f,
112         0.5f, -0.5f,  0.5f,  1.0f, 0.0f,
113         -0.5f, -0.5f,  0.5f,  0.0f, 0.0f,
114         -0.5f, -0.5f, -0.5f,  0.0f, 1.0f,
115
116         -0.5f,  0.5f, -0.5f,  0.0f, 1.0f,
117         0.5f,  0.5f, -0.5f,  1.0f, 1.0f,
118         0.5f,  0.5f,  0.5f,  1.0f, 0.0f,
119         0.5f,  0.5f,  0.5f,  1.0f, 0.0f,
120         -0.5f,  0.5f,  0.5f,  0.0f, 0.0f,
121         -0.5f,  0.5f, -0.5f,  0.0f, 1.0f
122     };
123
124     glm::vec3 cubePositions[] = {
125         glm::vec3(0.0f,  0.0f,  0.0f),
126         glm::vec3(2.0f,  5.0f, -15.0f),
127         glm::vec3(-1.5f, -2.2f, -2.5f),
128         glm::vec3(-3.8f, -2.0f, -12.3f),
129         glm::vec3(2.4f, -0.4f, -3.5f),
130         glm::vec3(-1.7f,  3.0f, -7.5f),
131         glm::vec3(1.3f, -2.0f, -2.5f),
132         glm::vec3(1.5f,  2.0f, -2.5f),
133         glm::vec3(1.5f,  0.2f, -1.5f),
134         glm::vec3(-1.3f,  1.0f, -1.5f)
135     };
136
137
138     unsigned int indeices[] = {
139         0, 1, 2,
140         2, 3, 0
141     };
142     unsigned int VBO, VAO, EBO;
143     glGenVertexArrays(1, &VAO);
144     glGenBuffers(1, &VBO);
145     glGenBuffers(1, &EBO);
146
147     glBindVertexArray(VAO);
148     glBindBuffer(GL_ARRAY_BUFFER, VBO);
149     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
150
151     glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
152     //glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indeices), indeices, GL_STATIC_DRAW);
153
154     glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
155     glEnableVertexAttribArray(0);
156
157     glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
158     glEnableVertexAttribArray(1);
159
160     //glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float)));
161     //glEnableVertexAttribArray(2);
162
163     unsigned int texture1, texture2;
164     glGenTextures(1, &texture1);
165     glBindTexture(GL_TEXTURE_2D, texture1);
166
167     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
168     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
169
170     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
171     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
172
173     int width, height, nrChannels;//Channels通道
174     stbi_set_flip_vertically_on_load(true);    //tell stb_image.h to flip load texture‘s on the y-axis    //flip翻转
175     unsigned char *data = stbi_load("wall.jpg", &width, &height, &nrChannels, 0);    //加载图像
176     if (data)
177     {
178         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);    //创建一个纹理
179         glGenerateMipmap(GL_TEXTURE_2D);        //承担创建一个纹理后接下来的全部工作,为当前绑定的纹理自动生成所有需要的多级渐远纹理
180     }
181     else
182     {
183         cout << "Failed to load texture1!" << endl;
184     }
185     stbi_image_free(data);        //为绑定的纹理生辰多级渐远纹理之后释放图像的内存
186
187     //texture2
188     glGenTextures(1, &texture2);
189     glBindTexture(GL_TEXTURE_2D, texture2);
190
191     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
192     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
193
194     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
195     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
196
197     data = stbi_load("timg.jpg", &width, &height, &nrChannels, 0);
198     if (data)
199     {
200         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
201         glGenerateMipmap(GL_TEXTURE_2D);
202     }
203     else
204     {
205         cout << "Failed to load texture2!" << endl;
206     }
207     stbi_image_free(data);
208
209     ourShader.use();
210     glUniform1i(glGetUniformLocation(ourShader.ID, "texture1"), 0);
211 glUniform1i(glGetUniformLocation(ourShader.ID, "texture2"), 1);
212
213
214 //trans = glm::rotate(trans, glm::radians(90.0f), glm::vec3(0.0f, 0.0f, 1.0f));
215 //trans = glm::scale(trans, glm::vec3(0.5f, -0.5f, 1.0f));
216 //第二个参数是传递的矩阵的数量,第三个是是否希望矩阵被置换(行与列交换),第四个是要传递的矩阵
217
218
219 float axis;
220
221 //render loop
222 while (!glfwWindowShouldClose(window))
223 {
224     //per-frame time logic 每帧的时间增量
225     GLfloat currentFrame = glfwGetTime();
226     deltaTime = currentFrame - lastFrame;
227     lastFrame = currentFrame;
228
229     processInput(window);
230
231     glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
232     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
233
234     glActiveTexture(GL_TEXTURE0);
235     glBindTexture(GL_TEXTURE_2D, texture1);
236     glActiveTexture(GL_TEXTURE1);
237     glBindTexture(GL_TEXTURE_2D, texture2);
238
239     ourShader.setFloat("mixValue", mixValue);
240
241     glm::mat4 trans;
242
243     //trans = glm::translate(trans, glm::vec3(0.5f, -0.5f, 0.0f));
244     //trans = glm::rotate(trans, glm::radians(15.0f), glm::vec3(1.0f, 0.0f, 0.0f));
245     //trans = glm::rotate(trans, (float)glfwGetTime(), glm::vec3(0.0f, 0.0f, 1.0f));
246     glUniformMatrix4fv(glGetUniformLocation(ourShader.ID, "transform"), 1, GL_FALSE, glm::value_ptr(trans));
247
248     glUseProgram(ourShader.ID);
249     glm::mat4 transform;
250     transform = glm::translate(trans, glm::vec3(Left, Up, 0.0f));
251     ourShader.setMat4("transform", transform);
252
253     //glm::mat4 model;
254     glm::mat4 view;
255     glm::mat4 projection;
256     //model = glm::rotate(model, glm::radians(45.0f), glm::vec3(0.0f, 1.0f, 0.0f));
257     //model = glm::rotate(model, (float)glfwGetTime() * glm::radians(50.0f), glm::vec3(0.5f, 1.0f, 0.0f));
258     //view = glm::translate(view, glm::vec3(0.0f, 0.0f, -3.0f));
259     view = glm::lookAt(cameraPos, cameraPos + cameraFront, cameraUp);
260
261     //摄像机的lookAt矩阵就是观察矩阵
262     //glm::mat4 view;
263     float radius = 10.0f;
264     float camX = sin(glfwGetTime()) * radius;
265     float camZ = cos(glfwGetTime()) * radius;
266     //view = glm::lookAt(glm::vec3(camX, 0.0f, camZ), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
267
268
269     //projection = glm::ortho(0.0f, 800.0f, 0.0f, 600.0f, 0.1f, 100.0f);
270     projection = glm::perspective(glm::radians(fov), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);    //
271     //glUniformMatrix4fv(glGetUniformLocation(ourShader.ID, "model"), 1, GL_FALSE, glm::value_ptr(model));
272     glUniformMatrix4fv(glGetUniformLocation(ourShader.ID, "view"), 1, GL_FALSE, glm::value_ptr(view));
273     ourShader.setMat4("projection", projection);
274
275     glBindVertexArray(VAO);
276
277
278     for (unsigned int i = 0; i < 10; i++)
279     {
280         glm::mat4 model;
281         model = glm::translate(model, cubePositions[i]);
282         float angle = 20.0f * i;
283
284         angle = glfwGetTime() * 25.0f;
285
286         //axis = sin(glfwGetTime());
287         model = glm::rotate(model, glm::radians(angle), glm::vec3(0.2f * i, 0.1* i, 0.3));
288         ourShader.setMat4("model", model);
289         glDrawArrays(GL_TRIANGLES, 0, 36);
290     }
291
292     //glDrawArrays(GL_TRIANGLES, 0, 36);
293     //glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
294
295     //trans = glm::mat4();    //trans必须是与上面的trans是同一个,一个uniform在同一个程序中只能被绑定一次
296     //trans = glm::translate(trans, glm::vec3(-0.5f, 0.5f, 0.0f));
297     //trans = glm::scale(trans, glm::vec3(sin(glfwGetTime()), sin(glfwGetTime()), sin(glfwGetTime())));
298     //glUniformMatrix4fv(glGetUniformLocation(ourShader.ID, "transform"), 1, GL_FALSE,glm::value_ptr(trans));
299     ////glBindVertexArray(VAO);
300     //glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
301
302
303     glfwSwapBuffers(window);
304     glfwPollEvents();
305 }
306
307 glDeleteVertexArrays(1, &VAO);
308 glDeleteBuffers(1, &VBO);
309
310 glfwTerminate();
311 return 0;
312
313
314 return 0;
315 }
316
317 void framebuffer_size_callback(GLFWwindow* window, int width, int height)
318 {
319     glViewport(0, 0, width, height);
320 }
321
322 void processInput(GLFWwindow* window)
323 {
324     if (glfwGetKey(window, GLFW_KEY_ENTER) == GLFW_PRESS)
325         glfwSetWindowShouldClose(window, true);
326     if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS)
327     {
328         mixValue += 0.001f;
329         if (mixValue >= 1.0f)
330             mixValue = 1.0f;
331     }
332     if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS)
333     {
334         mixValue -= 0.001f;
335         if (mixValue <= 0.0f)
336             mixValue = 0.0f;
337     }
338
339     if (glfwGetKey(window, GLFW_KEY_4) == GLFW_PRESS)
340     {
341         Left -= 0.001;
342     }
343
344     if (glfwGetKey(window, GLFW_KEY_6) == GLFW_PRESS)
345     {
346         Left += 0.001f;
347     }
348     if (glfwGetKey(window, GLFW_KEY_8) == GLFW_PRESS)
349     {
350         Up += 0.001f;
351     }
352
353     if (glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS)
354     {
355         Up -= 0.001f;
356     }
357
358     float cameraSpeed = 2.5 * deltaTime;
359     if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
360         cameraPos += cameraSpeed * cameraFront;
361     if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
362         cameraPos -= cameraSpeed * cameraFront;
363     if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
364         cameraPos -= glm::normalize(glm::cross(cameraFront, cameraUp)) * cameraSpeed;
365     if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
366         cameraPos += glm::normalize(glm::cross(cameraFront, cameraUp)) * cameraSpeed;
367 }
368
369 void mouse_callback(GLFWwindow* window, double xpos, double ypos)
370 {
371     if (firstMouse)
372     {
373         lastX = xpos;
374         lastY = ypos;
375         firstMouse = false;
376     }
377
378     float xoffset = xpos - lastX;
379     float yoffset = lastY - ypos;
380
381     lastX = xpos;
382     lastY = ypos;
383     float sensitivity = 0.0005f;
384     xoffset *= sensitivity;
385     yoffset *= sensitivity;
386     yaw += xoffset;
387     pitch += yoffset;
388
389     if (pitch > 89.0f)
390         pitch = 89.0f;
391     if (pitch < -89.0f)
392         pitch = -89.0f;
393
394     glm::vec3 front;
395     front.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
396     front.y = sin(glm::radians(pitch));
397     front.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch));
398     cameraFront = glm::normalize(front);
399
400 }
401
402 void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
403 {
404     if (fov >= 1.0f && fov <= 45.0f)
405         fov -= yoffset;
406     if (fov <= 1.0f)
407         fov = 1.0f;
408     if (fov >= 45.0f)
409         fov = 45.0f;
410 }

timg.jpg文件

wall.jpg文件

原文地址:https://www.cnblogs.com/hi3254014978/p/9608056.html

时间: 2024-11-01 00:08:21

learnopengl“入门”的全部代码的相关文章

Ajax入门学习原始代码

<script type="text/javascript">        window.onload = function () {            //1.创建xmlhttprequest对象            var xhr = createXHR();            function createXHR() {//为了兼容新老IE的版本                var request;                if (typeof(X

Spring MVC注解配置结合Hibernate的入门教程及其代码实例

原文:Spring MVC注解配置结合Hibernate的入门教程及其代码实例 源代码下载地址:http://www.zuidaima.com/share/1787210045197312.htm 1.概述 本文旨在搭建Spring MVC+Hibernate开发框架,通过一个简单的demo讲解Spring MVC的相关配置文件,以及通过注解方式实现简单功能. 开发框架:Spring+Spring MVC+Hibernate(Spring所用的版本为3.0.5). 数据库:MySQL(数据库名称

java操作memcached入门教程demo代码

原文:java操作memcached入门教程demo代码 源代码下载地址:http://www.zuidaima.com/share/1550463754996736.htm 参考地址: http://www.open-open.com/lib/view/open1357831114183.html http://tech.idv2.com/2008/07/10/memcached-001/ 感谢 京-java牛-ID号1  感谢 锡-SuperPrivate-195 在网上搜索了部分代码,一个

Core Graphics快速入门——从一行代码说起

Core Graphics入门 想必每个第一次接触Core Graphics的开发者都被无数的API.混乱的代码逻辑折腾得头疼不已,甚至望而却步.即使是绘制一个简单的矩形也看上去非常繁琐.本文换一个角度,整理一下有关Core Graphics的知识,也算作是这段时间学习的总结. Core Graphics和UIKit的区别 首先从概念上了解一下: 根据苹果的描述,UIKit是我们最容易也是最常接触到的框架.绝大多数图形界面都由UIKit完成.但是UIKit依赖于Core Graphics框架,也

对比《Keras图像深度学习实战》PDF+《深度学习技术图像处理入门》PDF代码分析

将深度学习技术应用于图像处理,推荐阅读<深度学习技术图像处理入门>,基于理论讲解,由浅入深地引出若干个经典案例,讲解当前深度神经网络在图像处理领域的应用.提供了基于云GPU容器(Docker)的完整在线开发环境,方便初学者直接学习核心代码. <深度学习技术图像处理入门>以通俗易懂的语言简要讲解机器学习的核心概念,通过比较传统机器学习和深度神经网络的区别,引入深度神经网络的应用领域,将一个完整的深度神经网络的复杂结构拆成输入处理.模型元件以及模型优化三个子块,并详细说明如何将深度神经

Java中23种设计模式--超快速入门及举例代码

在网上看了一些设计模式的文章后,感觉还是印象不太深刻,决定好好记录记录. 原文地址:http://blog.csdn.net/doymm2008/article/details/13288067 注:本文代码基本都有很多没有初始化等等问题,主要是为了减少代码量,达到一眼就能了解大概情况的目的. java的设计模式大体上分为三大类: 创建型模式(5种):工厂方法模式,抽象工厂模式,单例模式,建造者模式,原型模式. 结构型模式(7种):适配器模式,装饰器模式,代理模式,外观模式,桥接模式,组合模式,

JavaWeb快速入门Session&amp;Cookie代码思路篇(七)

Cookie练习 简介 尝试了n种分享代码,最终没有找到好办法.我觉得贴代码,很难看下去.还不如写思路,今后代码篇改成思路篇 Session代码练习 1. 购物车思路 1. ListBookServlet类 1.1 显示该网站所有商品,每个商品加上购买链接(BuyServlet) 用Map集合存储Book对象 map.put("1", new Book("1","JavaWeb开发","老张","一本好书"

C#零基础入门08:代码规范

一:前言 没有规矩,不成方圆.在代码的世界中,尤其这样.作为程序员,我们不想让我们的代码写出去之后被人耻笑:看,连个换行都换的这么不专业.作为开发主管,我们则不想我们的组员写出来的代码各类风格都有,五颜六色的,极其丑陋.写出规范的代码,首先需要训练,其次,也有一定的手段或者工具来进行辅助.本小节,我们就要从这两方面入手,讲讲如何规范我们的代码.当然,由于我们现在学到的编码知识还有限,最为规范来讲,本小节也将仅仅会设计那些最基本,最常用的编码的规范,但是即便如此,学完本小节之后,也会让我们的代码看

理解SVM(一)——入门SVM和代码实现

这篇博客我们来理解一下SVM.其实,之前好多大牛的博客已经对SVM做了很好的理论描述.例如CSDN上july的那篇三层境界介绍SVM的博文,连接如下: http://blog.csdn.net/v_july_v/article/details/7624837 那么我这里抛去一些复杂的公式推导,给出一些SVM核心思想,以及用Python实现代码,再加上我自己的理解注释. 1. SVM的核心思想 SVM的分类思想本质上和线性回归LR分类方法类似,就是求出一组权重系数,在线性表示之后可以分类.我们先使