diff --git a/headers/shader.hpp b/headers/shader.hpp index 7271488..74691ae 100644 --- a/headers/shader.hpp +++ b/headers/shader.hpp @@ -1,7 +1,6 @@ #ifndef SHADER_H #define SHADER_H #include -#include #include class Shader { @@ -11,7 +10,6 @@ public: void use(); void setInt(const std::string &name, int value); void setFloat(const std::string &name, float value); - void setMat4(const std::string &name, glm::mat4 value); private: unsigned int ID; diff --git a/headers/shapes.h b/headers/shapes.h index c19cf05..9a110e6 100644 --- a/headers/shapes.h +++ b/headers/shapes.h @@ -26,51 +26,6 @@ float sqr_tex_vertices[] = { -0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f /*top left*/ }; -float cube_vertices[] = { - /*positions*texture cords*/ - -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, - 0.5f, -0.5f, -0.5f, 1.0f, 0.0f, - 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, - 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, - -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, - -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, - - -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, - 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, - 0.5f, 0.5f, 0.5f, 1.0f, 1.0f, - 0.5f, 0.5f, 0.5f, 1.0f, 1.0f, - -0.5f, 0.5f, 0.5f, 0.0f, 1.0f, - -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, - - -0.5f, 0.5f, 0.5f, 1.0f, 0.0f, - -0.5f, 0.5f, -0.5f, 1.0f, 1.0f, - -0.5f, -0.5f, -0.5f, 0.0f, 1.0f, - -0.5f, -0.5f, -0.5f, 0.0f, 1.0f, - -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, - -0.5f, 0.5f, 0.5f, 1.0f, 0.0f, - - 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, - 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, - 0.5f, -0.5f, -0.5f, 0.0f, 1.0f, - 0.5f, -0.5f, -0.5f, 0.0f, 1.0f, - 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, - 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, - - -0.5f, -0.5f, -0.5f, 0.0f, 1.0f, - 0.5f, -0.5f, -0.5f, 1.0f, 1.0f, - 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, - 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, - -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, - -0.5f, -0.5f, -0.5f, 0.0f, 1.0f, - - -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, - 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, - 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, - 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, - -0.5f, 0.5f, 0.5f, 0.0f, 0.0f, - -0.5f, 0.5f, -0.5f, 0.0f, 1.0f -}; - const char *basicVertexShaderSource = "#version 330 core\n" "layout (location = 0) in vec3 aPos;\n" diff --git a/shaders/MVPTexVert.glsl b/shaders/MVPTexVert.glsl deleted file mode 100644 index c96031d..0000000 --- a/shaders/MVPTexVert.glsl +++ /dev/null @@ -1,18 +0,0 @@ -#version 330 core -layout (location = 0) in vec3 aPos; -layout (location = 1) in vec3 aColor; -layout (location = 2) in vec2 aTexCoord; - -out vec3 ourColor; -out vec2 TexCoord; - -uniform mat4 model; -uniform mat4 view; -uniform mat4 projection; - -void main() -{ - gl_Position = projection * view * model * vec4(aPos, 1.0); - ourColor = aColor; - TexCoord = aTexCoord; -} diff --git a/shaders/TexFrag.glsl b/shaders/TexFrag.glsl index 4fdf5e5..206c686 100644 --- a/shaders/TexFrag.glsl +++ b/shaders/TexFrag.glsl @@ -8,5 +8,5 @@ uniform sampler2D tex0; void main() { - FragColor = texture(tex0, TexCoord) * vec4(ourColor, 1.0); + FragColor = texture(Tex0, TexCoord) * vec4(ourColor, 1.0); } diff --git a/src/main.cpp b/src/main.cpp index a26678f..ff7d785 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,5 @@ #include #include -#include -#include -#include #include #include #include @@ -14,19 +11,6 @@ void processInput(GLFWwindow *window); void framebuffer_size_callback(GLFWwindow *window, int width, int height); -glm::vec3 cubePositions[] = { - glm::vec3( 0.0f, 0.0f, 0.0f), - glm::vec3( 2.0f, 5.0f, -15.0f), - glm::vec3(-1.5f, -2.2f, -2.5f), - glm::vec3(-3.8f, -2.0f, -12.3f), - glm::vec3( 2.4f, -0.4f, -3.5f), - glm::vec3(-1.7f, 3.0f, -7.5f), - glm::vec3( 1.3f, -2.0f, -2.5f), - glm::vec3( 1.5f, 2.0f, -2.5f), - glm::vec3( 1.5f, 0.2f, -1.5f), - glm::vec3(-1.3f, 1.0f, -1.5f) -}; - int main(void) { int tmp = 0; @@ -52,26 +36,25 @@ int main(void) { glGenBuffers(1, &VBO); glBindBuffer(GL_ARRAY_BUFFER, VBO); - glBufferData(GL_ARRAY_BUFFER, sizeof(cube_vertices),cube_vertices, + glBufferData(GL_ARRAY_BUFFER, sizeof(sqr_tex_vertices), sqr_tex_vertices, GL_STATIC_DRAW); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void *)0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void *)0); glEnableVertexAttribArray(0); - - glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), - (void *)0); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), + (void *)(3 * sizeof(float))); glEnableVertexAttribArray(1); - glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), - (void *)(3 * sizeof(float))); + glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), + (void *)(6 * sizeof(float))); glEnableVertexAttribArray(2); - // glGenBuffers(1, &EBO); - // glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); - // glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(sqr_indices), sqr_indices, - // GL_STATIC_DRAW); + glGenBuffers(1, &EBO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(sqr_indices), sqr_indices, + GL_STATIC_DRAW); Shader *shaderProgram = - new Shader("./shaders/MVPTexVert.glsl", "./shaders/TexFrag.glsl"); + new Shader("./shaders/TexVert.glsl", "./shaders/TexFrag.glsl"); unsigned int texture; glGenTextures(1, &texture); @@ -97,40 +80,18 @@ int main(void) { stbi_image_free(data); while (!glfwWindowShouldClose(window)) { - glm::mat4 view = glm::mat4(1.0f); /*move camera*/ - view = glm::translate(view, glm::vec3(0.0f, 0.0f, -3.0f)); - glm::mat4 projection = glm::perspective(glm::radians(45.0f), 800.0f / 600.0f, 0.1f, 100.0f); /*camera settings*/ - processInput(window); glClearColor(0.2f, 0.3f, 0.3f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT); shaderProgram->use(); shaderProgram->setInt("Tex0",0); - shaderProgram->setMat4("view",view); - shaderProgram->setMat4("projection",projection); - glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture); glBindVertexArray(VAO); - glEnable(GL_DEPTH_TEST); - for(unsigned int i = 0; i < 10; i++) - { - glm::mat4 model = glm::mat4(1.0f); - model = glm::translate(model, cubePositions[i]); - float angle = 20.0f * i; - model = glm::rotate(model, glm::radians(angle), - glm::vec3(1.0f, 0.3f, 0.5f)); - model = glm::rotate(model, (float)glfwGetTime() * glm::radians(55.0f), - glm::vec3(1.0f, 0.5f, 0.0f)); - shaderProgram->setMat4("model", model); - glDrawArrays(GL_TRIANGLES, 0, 36); - } - - glDrawArrays(GL_TRIANGLES, 0, 36); - //glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); + glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); glfwSwapBuffers(window); glfwPollEvents(); diff --git a/src/shader.cpp b/src/shader.cpp index e9aa33b..608d134 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -45,11 +44,6 @@ void Shader::setFloat(const std::string &name, float value) { glUniform1f(glGetUniformLocation(ID, name.c_str()), value); } -void Shader::setMat4(const std::string &name, glm::mat4 value) { - glUniformMatrix4fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, glm::value_ptr(value)); - -} - /*priv*/ unsigned int Shader::shaderCMPL(GLenum type, const char *src) { unsigned int shader;