1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| Shader* myShader = new Shader("vertexSource-Depth.vert", "fragmentSource-Depth.frag"); Shader* skyboxShader = new Shader("Skybox.vert", "Skybox.frag");
unsigned int cubeVAO, cubeVBO; glGenVertexArrays(1, &cubeVAO); glGenBuffers(1, &cubeVBO); glBindVertexArray(cubeVAO); glBindBuffer(GL_ARRAY_BUFFER, cubeVBO); glBufferData(GL_ARRAY_BUFFER, sizeof(cubeVertices), &cubeVertices, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
unsigned int skyboxVAO, skyboxVBO; glGenVertexArrays(1, &skyboxVAO); glGenBuffers(1, &skyboxVBO); glBindVertexArray(skyboxVAO); glBindBuffer(GL_ARRAY_BUFFER, skyboxVBO); glBufferData(GL_ARRAY_BUFFER, sizeof(skyboxVertices), &skyboxVertices, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
myShader->use(); glm::mat4 model = glm::mat4(1.0f); viewMat = camera.GetViewMatrix(); projMat = glm::perspective(glm::radians(45.0f), 800.0f / 600.0f, 0.1f, 100.0f);
glUniformMatrix4fv(glad_glGetUniformLocation(myShader->ID, "model"), 1, GL_FALSE, glm::value_ptr(model)); glUniformMatrix4fv(glad_glGetUniformLocation(myShader->ID, "view"), 1, GL_FALSE, glm::value_ptr(viewMat)); glUniformMatrix4fv(glad_glGetUniformLocation(myShader->ID, "projection"), 1, GL_FALSE, glm::value_ptr(projMat));
glBindVertexArray(cubeVAO); glUniform1i(glGetUniformLocation(myShader->ID, "texture1"), 1); glDrawArrays(GL_TRIANGLES, 0, 36);
glDepthFunc(GL_LEQUAL); skyboxShader->use(); viewMat = glm::mat4(glm::mat3(camera.GetViewMatrix())); glUniformMatrix4fv(glad_glGetUniformLocation(skyboxShader->ID, "view"), 1, GL_FALSE, glm::value_ptr(viewMat)); glUniformMatrix4fv(glad_glGetUniformLocation(skyboxShader->ID, "projection"), 1, GL_FALSE, glm::value_ptr(projMat));
glUniform1i(glGetUniformLocation(skyboxShader->ID, "skybox"), 1); glBindVertexArray(skyboxVAO); glDrawArrays(GL_TRIANGLES, 0, 36); glDepthFunc(GL_LESS);
|