diff --git a/OpenGL/main.cpp b/OpenGL/main.cpp index 1c02248..22df4fc 100644 --- a/OpenGL/main.cpp +++ b/OpenGL/main.cpp @@ -14,10 +14,17 @@ int main(int argc, char** argv) { GLfloat vertices[] = { // positions // colors // texture coords - 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, // top right - 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // bottom right - -0.5f,-0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom left - -0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f // top left + 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // 1.0f, 1.0f, // top right + 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // 1.0f, 0.0f, // bottom right + -0.5f,-0.5f, 0.0f, 0.0f, 0.0f, 1.0f, // 0.0f, 0.0f, // bottom left + + 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // 1.0f, 1.0f, // top right + -0.5f,-0.5f, 0.0f, 0.0f, 0.0f, 1.0f, // 0.0f, 0.0f, // bottom left + -0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f // 0.0f, 1.0f // top left + + // 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom right + //-0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // bottom left + // 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f // top }; unsigned int indices[] = { diff --git a/OpenGL/mesh.cpp b/OpenGL/mesh.cpp index 1818fa5..7a109fc 100644 --- a/OpenGL/mesh.cpp +++ b/OpenGL/mesh.cpp @@ -4,28 +4,18 @@ Mesh::Mesh(GLfloat *vertices, unsigned int *indices, unsigned int numVerticies) m_drawCount = numVerticies; glGenVertexArrays(1, &m_VAO); - glGenBuffers(1, &m_VBO); - glGenBuffers(1, &m_EBO); - glBindVertexArray(m_VAO); - glBindBuffer(GL_ARRAY_BUFFER, m_VBO); - glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); - - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_EBO); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); + glGenBuffers(NUM_BUFFERS, m_VBO); + glBindBuffer(GL_ARRAY_BUFFER, m_VBO[POSITION_VB]); + glBufferData(GL_ARRAY_BUFFER, numVerticies * sizeof(vertices[0]), vertices, GL_STATIC_DRAW); // position attribute - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0); glEnableVertexAttribArray(0); // color attribute - glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float))); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)(3 * sizeof(float))); glEnableVertexAttribArray(1); - // texture coord attribute - glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float))); - glEnableVertexAttribArray(2); - - glBindVertexArray(0); std::cout << "Mesh loaded successfully" << std::endl; } diff --git a/OpenGL/mesh.h b/OpenGL/mesh.h index f11f711..4c98ceb 100644 --- a/OpenGL/mesh.h +++ b/OpenGL/mesh.h @@ -13,13 +13,11 @@ public: private: enum { POSITION_VB, - NUM_BUFFERS, - TEXCOORD_VB + NUM_BUFFERS }; unsigned int m_VAO; - unsigned int m_VBO; - unsigned int m_EBO; + unsigned int m_VBO[NUM_BUFFERS]; unsigned int m_drawCount; }; diff --git a/OpenGL/shader.cpp b/OpenGL/shader.cpp index 891cbb7..a0a90e0 100644 --- a/OpenGL/shader.cpp +++ b/OpenGL/shader.cpp @@ -13,6 +13,9 @@ Shader::Shader(std::string path) { std::cout << "Shader successfully attatched" << std::endl; } + glBindAttribLocation(m_program, 0, "aPos"); + glBindAttribLocation(m_program, 1, "aColor"); + glLinkProgram(m_program); int success; diff --git a/enc_temp_folder/5551d2a54452ad9e5ef6510d4fdefe5/main.cpp b/enc_temp_folder/5551d2a54452ad9e5ef6510d4fdefe5/main.cpp new file mode 100644 index 0000000..917c786 --- /dev/null +++ b/enc_temp_folder/5551d2a54452ad9e5ef6510d4fdefe5/main.cpp @@ -0,0 +1,50 @@ +#include +#include + +#include "display.h" +#include "mesh.h" +#include "shader.h" +#include "texture.h" + +#undef main + +int main(int argc, char** argv) { + Display display(600, 600, "Crumpet Engine"); + glClearColor(0.1f, 0.45f, 0.9f, 1.0f); + + GLfloat vertices[] = { + // positions // colors // texture coords + 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // 1.0f, 1.0f, // top right + 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // 1.0f, 0.0f, // bottom right + -0.5f,-0.5f, 0.0f, 0.0f, 0.0f, 1.0f, // 0.0f, 0.0f, // bottom left + + 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // 1.0f, 1.0f, // top right + -0.5f,-0.5f, 0.0f, 0.0f, 0.0f, 1.0f, // 0.0f, 0.0f, // bottom left + -0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f // 0.0f, 1.0f // top left + + // 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom right + //-0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // bottom left + // 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f // top + }; + + unsigned int indices[] = { + 0, 1, 3, // first triangle + 1, 2, 3 // second triangle + }; + + Mesh mesh(vertices, indices, sizeof(vertices) / sizeof(vertices[0])); + Shader shader("C:/Users/Ben/Desktop/crumpet-engine/resources/shaders/simple2d"); + Texture chanceCube("C:/Users/Ben/Desktop/crumpet-engine/resources/textures/chance-cube.jpg"); + + while(!display.isClosed()) { + glClear(GL_COLOR_BUFFER_BIT); + + shader.Bind(); + chanceCube.Bind(0); + mesh.Draw(); + + display.Update(); + } + + return 0; +} diff --git a/resources/shaders/simple2d_fragment.glsl b/resources/shaders/simple2d_fragment.glsl index c244f30..f48619c 100644 --- a/resources/shaders/simple2d_fragment.glsl +++ b/resources/shaders/simple2d_fragment.glsl @@ -1,11 +1,8 @@ #version 330 core -out vec4 FragColor; - + in vec3 ourColor; -in vec2 TexCoord; +out vec4 FragColor; -uniform sampler2D ourTexture; - -void main() { - FragColor = texture(ourTexture, TexCoord); +void main () { + FragColor = vec4(ourColor, 1.0f); } diff --git a/resources/shaders/simple2d_vertex.glsl b/resources/shaders/simple2d_vertex.glsl index 7bb7d54..127522c 100644 --- a/resources/shaders/simple2d_vertex.glsl +++ b/resources/shaders/simple2d_vertex.glsl @@ -1,13 +1,11 @@ #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; void main() { - gl_Position = vec4(aPos, 1.0); - ourColor = aColor; - TexCoord = aTexCoord; -} + gl_Position = vec4(aPos, 1.0); + ourColor = aColor; +} \ No newline at end of file