diff --git a/src/buffer.cpp b/src/buffer.cpp index 1e53907..9f59f08 100644 --- a/src/buffer.cpp +++ b/src/buffer.cpp @@ -8,7 +8,8 @@ #include "vertex.h" -Buffer::Buffer(const std::vector& vertices, const std::vector& indices) +Buffer::Buffer(const std::vector& vertices, + const std::vector& indices) { index_count_ = static_cast(indices.size()); @@ -19,12 +20,15 @@ Buffer::Buffer(const std::vector& vertices, const std::vector& glBindVertexArray(vao_); glBindBuffer(GL_ARRAY_BUFFER, vbo_); - glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(Vertex), vertices.data(), GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(Vertex), + vertices.data(), GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo_); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(uint16_t), indices.data(), GL_STATIC_DRAW); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(uint16_t), + indices.data(), GL_STATIC_DRAW); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), nullptr); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), + nullptr); glEnableVertexAttribArray(0); } @@ -42,4 +46,4 @@ void Buffer::Draw(const Shader& shader) const glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo_); shader.SetupAttribs(); glDrawElements(GL_TRIANGLES, index_count_, GL_UNSIGNED_SHORT, nullptr); -} \ No newline at end of file +} diff --git a/src/buffer.h b/src/buffer.h index 972d3c2..c0eea64 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -10,14 +10,15 @@ class Buffer { public: - Buffer(const std::vector& vertices, const std::vector& indices); + Buffer(const std::vector& vertices, + const std::vector& indices); ~Buffer(); void Draw(const Shader& shader) const; private: uint32_t vao_, vbo_, ebo_; - GLsizei index_count_; + GLsizei index_count_; }; -#endif // BUFFER_H_ \ No newline at end of file +#endif // BUFFER_H_ diff --git a/src/shader.cpp b/src/shader.cpp index e9452b4..72fe60b 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -13,7 +13,8 @@ Shader::Shader(const std::string& vertexPath, const std::string& fragmentPath) { const uint32_t vshader = CompileShader(GL_VERTEX_SHADER, vertexPath); - const uint32_t fshader = CompileShader(GL_FRAGMENT_SHADER, fragmentPath); + const uint32_t fshader = + CompileShader(GL_FRAGMENT_SHADER, fragmentPath); if (vshader == 0 || fshader == 0) { program_id_ = 0; @@ -30,7 +31,8 @@ Shader::Shader(const std::string& vertexPath, const std::string& fragmentPath) glGetProgramiv(program_id_, GL_LINK_STATUS, &ret); if (ret == GL_FALSE) { char buffer[1024]; - glGetProgramInfoLog(program_id_, sizeof(buffer), nullptr, buffer); + glGetProgramInfoLog(program_id_, sizeof(buffer), nullptr, + buffer); error_ = buffer; glDeleteProgram(program_id_); program_id_ = 0; @@ -51,13 +53,17 @@ void Shader::SetupAttribs() const int loc = glGetAttribLocation(program_id_, "vpos"); if (loc != -1) { glEnableVertexAttribArray(loc); - glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast(offsetof(Vertex, position))); + glVertexAttribPointer( + loc, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), + reinterpret_cast(offsetof(Vertex, position))); } loc = glGetAttribLocation(program_id_, "vcolor"); if (loc != -1) { glEnableVertexAttribArray(loc); - glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast(offsetof(Vertex, color))); + glVertexAttribPointer( + loc, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), + reinterpret_cast(offsetof(Vertex, color))); } } @@ -112,12 +118,12 @@ std::string Shader::ReadShaderFile(const std::string& filename) uint32_t Shader::CompileShader(uint32_t type, const std::string& source_path) { std::string source = ReadShaderFile(source_path); - //std::cout << "SHADER FILE: " << source << "\n"; + // std::cout << "SHADER FILE: " << source << "\n"; if (source.empty()) return 0; - const uint32_t shader = glCreateShader(type); - const char* shader_code = source.c_str(); + const uint32_t shader = glCreateShader(type); + const char* shader_code = source.c_str(); glShaderSource(shader, 1, &shader_code, nullptr); glCompileShader(shader); diff --git a/src/shader.h b/src/shader.h index a0232d0..76a93e1 100644 --- a/src/shader.h +++ b/src/shader.h @@ -9,13 +9,20 @@ class Shader { public: - Shader(const std::string& vertex_path, const std::string& fragment_path); + Shader(const std::string& vertex_path, + const std::string& fragment_path); void Use() const; void SetupAttribs() const; - uint32_t getId() const { return program_id_; } - const char* getError() const { return error_.c_str(); } + uint32_t getId() const + { + return program_id_; + } + const char* getError() const + { + return error_.c_str(); + } int getLocation(const char* key) const; @@ -26,12 +33,11 @@ public: static void setMat4(int loc, const glm::mat4& value); private: - uint32_t program_id_; + uint32_t program_id_; std::string error_; std::string ReadShaderFile(const std::string& filename); uint32_t CompileShader(uint32_t type, const std::string& source_path); }; - -#endif // SHADER_H_ \ No newline at end of file +#endif // SHADER_H_ diff --git a/src/vertex.cpp b/src/vertex.cpp index a649f17..9a1554d 100644 --- a/src/vertex.cpp +++ b/src/vertex.cpp @@ -1 +1 @@ -#include "vertex.h" \ No newline at end of file +#include "vertex.h" diff --git a/src/vertex.h b/src/vertex.h index 7ecc077..c6be704 100644 --- a/src/vertex.h +++ b/src/vertex.h @@ -4,8 +4,8 @@ #include "../lib/glm/glm.hpp" struct Vertex { - glm::vec3 position{ 0.0f, 0.0f, 0.0f }; - glm::vec3 color{ 0.0f, 0.0f, 0.0f }; + glm::vec3 position{0.0f, 0.0f, 0.0f}; + glm::vec3 color{0.0f, 0.0f, 0.0f}; }; -#endif // VERTEX_H_ \ No newline at end of file +#endif // VERTEX_H_