mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-30 20:13:22 +08:00
comments fix
This commit is contained in:
@@ -9,10 +9,10 @@
|
|||||||
#include <learnopengl/filesystem.h>
|
#include <learnopengl/filesystem.h>
|
||||||
#include <learnopengl/shader.h>
|
#include <learnopengl/shader.h>
|
||||||
|
|
||||||
// Function prototypes
|
// function prototypes
|
||||||
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode);
|
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode);
|
||||||
|
|
||||||
// Properties
|
// properties
|
||||||
const GLuint SCR_WIDTH = 800, SCR_HEIGHT = 600;
|
const GLuint SCR_WIDTH = 800, SCR_HEIGHT = 600;
|
||||||
|
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ int main()
|
|||||||
// GLEW initialization
|
// GLEW initialization
|
||||||
glewExperimental = GL_TRUE;
|
glewExperimental = GL_TRUE;
|
||||||
glewInit();
|
glewInit();
|
||||||
// Due to a bug in GLEW the glewInit call always generates an OpenGL error; clear the flag(s) by calling glGetError();
|
// due to a bug in GLEW the glewInit call always generates an OpenGL error; clear the flag(s) by calling glGetError();
|
||||||
glGetError();
|
glGetError();
|
||||||
|
|
||||||
// enable OpenGL debug context if context allows for debug context
|
// enable OpenGL debug context if context allows for debug context
|
||||||
@@ -126,45 +126,45 @@ int main()
|
|||||||
// OpenGL initial state
|
// OpenGL initial state
|
||||||
Shader shader("debugging.vs", "debugging.frag");
|
Shader shader("debugging.vs", "debugging.frag");
|
||||||
|
|
||||||
// Configure 3D cube
|
// configure 3D cube
|
||||||
GLuint cubeVAO, cubeVBO;
|
GLuint cubeVAO, cubeVBO;
|
||||||
GLfloat vertices[] = {
|
GLfloat vertices[] = {
|
||||||
// Back face
|
// back face
|
||||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, // Bottom-left
|
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, // Bottom-left
|
||||||
0.5f, 0.5f, -0.5f, 1.0f, 1.0f, // top-right
|
0.5f, 0.5f, -0.5f, 1.0f, 1.0f, // top-right
|
||||||
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, // bottom-right
|
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, // bottom-right
|
||||||
0.5f, 0.5f, -0.5f, 1.0f, 1.0f, // top-right
|
0.5f, 0.5f, -0.5f, 1.0f, 1.0f, // top-right
|
||||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, // bottom-left
|
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, // bottom-left
|
||||||
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, // top-left
|
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, // top-left
|
||||||
// Front face
|
// front face
|
||||||
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, // bottom-left
|
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, // bottom-left
|
||||||
0.5f, -0.5f, 0.5f, 1.0f, 0.0f, // bottom-right
|
0.5f, -0.5f, 0.5f, 1.0f, 0.0f, // bottom-right
|
||||||
0.5f, 0.5f, 0.5f, 1.0f, 1.0f, // top-right
|
0.5f, 0.5f, 0.5f, 1.0f, 1.0f, // top-right
|
||||||
0.5f, 0.5f, 0.5f, 1.0f, 1.0f, // top-right
|
0.5f, 0.5f, 0.5f, 1.0f, 1.0f, // top-right
|
||||||
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, // top-left
|
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, // top-left
|
||||||
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, // bottom-left
|
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, // bottom-left
|
||||||
// Left face
|
// left face
|
||||||
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, // top-right
|
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, // top-right
|
||||||
-0.5f, 0.5f, -0.5f, -1.0f, 1.0f, // top-left
|
-0.5f, 0.5f, -0.5f, -1.0f, 1.0f, // top-left
|
||||||
-0.5f, -0.5f, -0.5f, -0.0f, 1.0f, // bottom-left
|
-0.5f, -0.5f, -0.5f, -0.0f, 1.0f, // bottom-left
|
||||||
-0.5f, -0.5f, -0.5f, -0.0f, 1.0f, // bottom-left
|
-0.5f, -0.5f, -0.5f, -0.0f, 1.0f, // bottom-left
|
||||||
-0.5f, -0.5f, 0.5f, -0.0f, 0.0f, // bottom-right
|
-0.5f, -0.5f, 0.5f, -0.0f, 0.0f, // bottom-right
|
||||||
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, // top-right
|
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, // top-right
|
||||||
// Right face
|
// right face
|
||||||
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, // top-left
|
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, // top-left
|
||||||
0.5f, -0.5f, -0.5f, 0.0f, 1.0f, // bottom-right
|
0.5f, -0.5f, -0.5f, 0.0f, 1.0f, // bottom-right
|
||||||
0.5f, 0.5f, -0.5f, 1.0f, 1.0f, // top-right
|
0.5f, 0.5f, -0.5f, 1.0f, 1.0f, // top-right
|
||||||
0.5f, -0.5f, -0.5f, 0.0f, 1.0f, // bottom-right
|
0.5f, -0.5f, -0.5f, 0.0f, 1.0f, // bottom-right
|
||||||
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, // top-left
|
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, // top-left
|
||||||
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, // bottom-left
|
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, // bottom-left
|
||||||
// Bottom face
|
// bottom face
|
||||||
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f, // top-right
|
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f, // top-right
|
||||||
0.5f, -0.5f, -0.5f, 1.0f, 1.0f, // top-left
|
0.5f, -0.5f, -0.5f, 1.0f, 1.0f, // top-left
|
||||||
0.5f, -0.5f, 0.5f, 1.0f, 0.0f, // bottom-left
|
0.5f, -0.5f, 0.5f, 1.0f, 0.0f, // bottom-left
|
||||||
0.5f, -0.5f, 0.5f, 1.0f, 0.0f, // bottom-left
|
0.5f, -0.5f, 0.5f, 1.0f, 0.0f, // bottom-left
|
||||||
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, // bottom-right
|
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, // bottom-right
|
||||||
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f, // top-right
|
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f, // top-right
|
||||||
// Top face
|
// top face
|
||||||
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, // top-left
|
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, // top-left
|
||||||
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, // bottom-right
|
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, // bottom-right
|
||||||
0.5f, 0.5f, -0.5f, 1.0f, 1.0f, // top-right
|
0.5f, 0.5f, -0.5f, 1.0f, 1.0f, // top-right
|
||||||
@@ -174,10 +174,10 @@ int main()
|
|||||||
};
|
};
|
||||||
glGenVertexArrays(1, &cubeVAO);
|
glGenVertexArrays(1, &cubeVAO);
|
||||||
glGenBuffers(1, &cubeVBO);
|
glGenBuffers(1, &cubeVBO);
|
||||||
// Fill buffer
|
// fill buffer
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, cubeVBO);
|
glBindBuffer(GL_ARRAY_BUFFER, cubeVBO);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||||
// Link vertex attributes
|
// link vertex attributes
|
||||||
glBindVertexArray(cubeVAO);
|
glBindVertexArray(cubeVAO);
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)0);
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)0);
|
||||||
@@ -186,7 +186,7 @@ int main()
|
|||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
|
||||||
// Load cube texture
|
// load cube texture
|
||||||
GLuint textureID;
|
GLuint textureID;
|
||||||
glGenTextures(1, &textureID);
|
glGenTextures(1, &textureID);
|
||||||
int texWidth, texHeight;
|
int texWidth, texHeight;
|
||||||
@@ -203,7 +203,7 @@ int main()
|
|||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
SOIL_free_image_data(image);
|
SOIL_free_image_data(image);
|
||||||
|
|
||||||
// Set up projection matrix
|
// set up projection matrix
|
||||||
glm::mat4 projection = glm::perspective(glm::radians(45.0f), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 10.0f);
|
glm::mat4 projection = glm::perspective(glm::radians(45.0f), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 10.0f);
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shader.Program, "projection"), 1, GL_FALSE, glm::value_ptr(projection));
|
glUniformMatrix4fv(glGetUniformLocation(shader.Program, "projection"), 1, GL_FALSE, glm::value_ptr(projection));
|
||||||
glUniform1i(glGetUniformLocation(shader.Program, "tex"), 0);
|
glUniform1i(glGetUniformLocation(shader.Program, "tex"), 0);
|
||||||
@@ -211,7 +211,7 @@ int main()
|
|||||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
// Check and call events
|
// check and call events
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
@@ -229,7 +229,7 @@ int main()
|
|||||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
|
||||||
// Swap the buffers
|
// swap the buffers
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user