mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-30 20:13:22 +08:00
New debugging tutorial source code w/ artificial errors.
This commit is contained in:
@@ -46,7 +46,7 @@ void APIENTRY glDebugOutput(GLenum source,
|
|||||||
const GLchar *message,
|
const GLchar *message,
|
||||||
void *userParam)
|
void *userParam)
|
||||||
{
|
{
|
||||||
if(id == 131169 || id == 131185 || id == 131218) return; // ignore these non-significant error codes
|
if(id == 131169 || id == 131185 || id == 131218 || id == 131204) return; // ignore these non-significant error codes
|
||||||
|
|
||||||
std::cout << "---------------" << std::endl;
|
std::cout << "---------------" << std::endl;
|
||||||
std::cout << "Debug message (" << id << "): " << message << std::endl;
|
std::cout << "Debug message (" << id << "): " << message << std::endl;
|
||||||
@@ -130,47 +130,47 @@ int main()
|
|||||||
GLuint cubeVAO, cubeVBO;
|
GLuint cubeVAO, cubeVBO;
|
||||||
GLfloat vertices[] = {
|
GLfloat vertices[] = {
|
||||||
// Back face
|
// Back face
|
||||||
-0.5f, -0.5f, -0.5f, // Bottom-left
|
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, // Bottom-left
|
||||||
0.5f, 0.5f, -0.5f, // top-right
|
0.5f, 0.5f, -0.5f, 1.0f, 1.0f, // top-right
|
||||||
0.5f, -0.5f, -0.5f, // bottom-right
|
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, // bottom-right
|
||||||
0.5f, 0.5f, -0.5f, // top-right
|
0.5f, 0.5f, -0.5f, 1.0f, 1.0f, // top-right
|
||||||
-0.5f, -0.5f, -0.5f, // bottom-left
|
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, // bottom-left
|
||||||
-0.5f, 0.5f, -0.5f, // top-left
|
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, // top-left
|
||||||
// Front face
|
// Front face
|
||||||
-0.5f, -0.5f, 0.5f, // bottom-left
|
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, // bottom-left
|
||||||
0.5f, -0.5f, 0.5f, // bottom-right
|
0.5f, -0.5f, 0.5f, 1.0f, 0.0f, // bottom-right
|
||||||
0.5f, 0.5f, 0.5f, // top-right
|
0.5f, 0.5f, 0.5f, 1.0f, 1.0f, // top-right
|
||||||
0.5f, 0.5f, 0.5f, // top-right
|
0.5f, 0.5f, 0.5f, 1.0f, 1.0f, // top-right
|
||||||
-0.5f, 0.5f, 0.5f, // top-left
|
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, // top-left
|
||||||
-0.5f, -0.5f, 0.5f, // bottom-left
|
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, // bottom-left
|
||||||
// Left face
|
// Left face
|
||||||
-0.5f, 0.5f, 0.5f, // top-right
|
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, // top-right
|
||||||
-0.5f, 0.5f, -0.5f, // top-left
|
-0.5f, 0.5f, -0.5f, -1.0f, 1.0f, // top-left
|
||||||
-0.5f, -0.5f, -0.5f, // bottom-left
|
-0.5f, -0.5f, -0.5f, -0.0f, 1.0f, // bottom-left
|
||||||
-0.5f, -0.5f, -0.5f, // bottom-left
|
-0.5f, -0.5f, -0.5f, -0.0f, 1.0f, // bottom-left
|
||||||
-0.5f, -0.5f, 0.5f, // bottom-right
|
-0.5f, -0.5f, 0.5f, -0.0f, 0.0f, // bottom-right
|
||||||
-0.5f, 0.5f, 0.5f, // top-right
|
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, // top-right
|
||||||
// Right face
|
// Right face
|
||||||
0.5f, 0.5f, 0.5f, // top-left
|
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, // top-left
|
||||||
0.5f, -0.5f, -0.5f, // bottom-right
|
0.5f, -0.5f, -0.5f, 0.0f, 1.0f, // bottom-right
|
||||||
0.5f, 0.5f, -0.5f, // top-right
|
0.5f, 0.5f, -0.5f, 1.0f, 1.0f, // top-right
|
||||||
0.5f, -0.5f, -0.5f, // bottom-right
|
0.5f, -0.5f, -0.5f, 0.0f, 1.0f, // bottom-right
|
||||||
0.5f, 0.5f, 0.5f, // top-left
|
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, // top-left
|
||||||
0.5f, -0.5f, 0.5f, // bottom-left
|
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, // bottom-left
|
||||||
// Bottom face
|
// Bottom face
|
||||||
-0.5f, -0.5f, -0.5f, // top-right
|
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f, // top-right
|
||||||
0.5f, -0.5f, -0.5f, // top-left
|
0.5f, -0.5f, -0.5f, 1.0f, 1.0f, // top-left
|
||||||
0.5f, -0.5f, 0.5f, // bottom-left
|
0.5f, -0.5f, 0.5f, 1.0f, 0.0f, // bottom-left
|
||||||
0.5f, -0.5f, 0.5f, // bottom-left
|
0.5f, -0.5f, 0.5f, 1.0f, 0.0f, // bottom-left
|
||||||
-0.5f, -0.5f, 0.5f, // bottom-right
|
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, // bottom-right
|
||||||
-0.5f, -0.5f, -0.5f, // top-right
|
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f, // top-right
|
||||||
// Top face
|
// Top face
|
||||||
-0.5f, 0.5f, -0.5f, // top-left
|
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, // top-left
|
||||||
0.5f, 0.5f, 0.5f, // bottom-right
|
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, // bottom-right
|
||||||
0.5f, 0.5f, -0.5f, // top-right
|
0.5f, 0.5f, -0.5f, 1.0f, 1.0f, // top-right
|
||||||
0.5f, 0.5f, 0.5f, // bottom-right
|
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, // bottom-right
|
||||||
-0.5f, 0.5f, -0.5f, // top-left
|
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, // top-left
|
||||||
-0.5f, 0.5f, 0.5f // bottom-left
|
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f // bottom-left
|
||||||
};
|
};
|
||||||
glGenVertexArrays(1, &cubeVAO);
|
glGenVertexArrays(1, &cubeVAO);
|
||||||
glGenBuffers(1, &cubeVBO);
|
glGenBuffers(1, &cubeVBO);
|
||||||
@@ -193,10 +193,10 @@ int main()
|
|||||||
unsigned char *image = SOIL_load_image(FileSystem::getPath("resources/textures/wood.png").c_str(), &texWidth, &texHeight, 0, SOIL_LOAD_RGB);
|
unsigned char *image = SOIL_load_image(FileSystem::getPath("resources/textures/wood.png").c_str(), &texWidth, &texHeight, 0, SOIL_LOAD_RGB);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, textureID);
|
glBindTexture(GL_TEXTURE_2D, textureID);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texWidth, texHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
|
glTexImage2D(GL_FRAMEBUFFER, 0, GL_RGB, texWidth, texHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
|
||||||
glTexParameteri(GL_FRAMEBUFFER, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
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_WRAP_T, GL_REPEAT);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
@@ -204,12 +204,9 @@ int main()
|
|||||||
SOIL_free_image_data(image);
|
SOIL_free_image_data(image);
|
||||||
|
|
||||||
// Set up projection matrix
|
// Set up projection matrix
|
||||||
// TODO(Joey): check with new version of GLM and then use glm::radians
|
glm::mat4 projection = glm::perspective(glm::radians(45.0f), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 10.0f);
|
||||||
glm::mat4 projection = glm::perspective(45.0f, (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 10.0f);
|
|
||||||
shader.Use(); // use before setting uniforms
|
|
||||||
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);
|
||||||
glCheckError();
|
|
||||||
|
|
||||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
@@ -219,15 +216,17 @@ int main()
|
|||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
shader.Use();
|
||||||
GLfloat rotationSpeed = 10.0f;
|
GLfloat rotationSpeed = 10.0f;
|
||||||
GLfloat angle = (float)glfwGetTime() * rotationSpeed;
|
GLfloat angle = (float)glfwGetTime() * rotationSpeed;
|
||||||
glm::mat4 model;
|
glm::mat4 model;
|
||||||
model = glm::translate(model, glm::vec3(0.0, 0.0f, -2.5));
|
model = glm::translate(model, glm::vec3(0.0, 0.0f, -2.5));
|
||||||
model = glm::rotate(model, angle, glm::vec3(1.0f, 1.0f, 1.0f));
|
model = glm::rotate(model, glm::radians(angle), glm::vec3(1.0f, 1.0f, 1.0f));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shader.Program, "model"), 1, GL_FALSE, glm::value_ptr(model));
|
glUniformMatrix4fv(glGetUniformLocation(shader.Program, "model"), 1, GL_FALSE, glm::value_ptr(model));
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_2D, textureID);
|
||||||
glBindVertexArray(cubeVAO);
|
glBindVertexArray(cubeVAO);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
|
||||||
// Swap the buffers
|
// Swap the buffers
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
#version 330 core
|
#version 330 core
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
in vec2 TexCoords;
|
||||||
|
|
||||||
|
uniform sampler2D tex;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
FragColor = vec4(1.0f, 0.0f, 0.0f, 1.0f);
|
FragColor = texture(tex, TexCoords);
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,14 @@
|
|||||||
#version 330 core
|
#version 330 core
|
||||||
layout (location = 0) in vec3 position;
|
layout (location = 0) in vec3 position;
|
||||||
|
layout (location = 1) in vec2 texCoords;
|
||||||
|
|
||||||
uniform mat4 projection;
|
uniform mat4 projection;
|
||||||
uniform mat4 model;
|
uniform mat4 model;
|
||||||
|
|
||||||
|
out vec2 TexCoords;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = projection * model * vec4(position, 1.0f);
|
gl_Position = projection * model * vec4(position, 1.0f);
|
||||||
|
TexCoords = texCoords;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user