diff --git a/assets/textures/meep.jpg b/assets/textures/meep.jpg new file mode 100644 index 0000000..1ab7289 Binary files /dev/null and b/assets/textures/meep.jpg differ diff --git a/src/main.cpp b/src/main.cpp index 652675e..4c5eff8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -58,17 +58,89 @@ int main() { return 1; } + // std::vector verts({ + // 0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + // 0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, + // -0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, + // -0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, + // }); + std::vector verts({ - 0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, - 0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, - -0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, - -0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f + -0.5f, -0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, + 0.5f, -0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, + 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + -0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, + -0.5f, -0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, + + -0.5f, -0.5f, 0.5f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, + 0.5f, -0.5f, 0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, + 0.5f, 0.5f, 0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,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f, 1.0f, + + -0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, + 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, + 0.5f, 0.5f, 0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, + 0.5f, 0.5f, 0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, + -0.5f, 0.5f, 0.5f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, + -0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f }); // Vert struc: x y z r g b tx ty std::vector indices({ 0, 1, 3, - 1, 2, 3 + 3, 4, 5, + 5, 6, 7, + 7, 8, 9, + 9, 10, 11, + 11, 12, 13, + 0, 1, 3, + 3, 4, 5, + 5, 6, 7, + 7, 8, 9, + 9, 10, 11, + 11, 12, 13, + 0, 1, 3, + 3, 4, 5, + 5, 6, 7, + 7, 8, 9, + 9, 10, 11, + 11, 12, 13, + 0, 1, 3, + 3, 4, 5, + 5, 6, 7, + 7, 8, 9, + 9, 10, 11, + 11, 12, 13, + 0, 1, 3, + 3, 4, 5, + 5, 6, 7, + 7, 8, 9, + 9, 10, 11, + 11, 12, 13, }); glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); @@ -78,10 +150,15 @@ int main() { glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); Renderer::Obj2D ro(verts, indices); - renderer.spawnObject(ro); - renderer.setCamera(glm::vec3(0.0f, 0.0f, -8.0f)); + Renderer::Obj2D ro2(verts, indices); + + ro2.setTexture("assets/textures/meep.jpg"); ro.setTexture(RUSTY_METAL_TEXTURE); + renderer.spawnObject(ro); + renderer.spawnObject(ro2); + renderer.setCamera(glm::vec3(0.0f, 0.0f, -4.0f)); + // Window width & height while (!glfwWindowShouldClose(win)) { // Handle input @@ -93,7 +170,7 @@ int main() { /* OBJECT RENDERING */ float time = glfwGetTime(); float gVal = sin(time) / 10.5f; - renderer.setCamera(glm::vec3(0.0f, 0.0f, -gVal)); + renderer.setCamera(glm::vec3(0.0f, 0.0f, gVal/10.0f)); // Transformation float rotang = time; diff --git a/src/renderer.cpp b/src/renderer.cpp index bdfa2df..ae4f80d 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -91,7 +91,8 @@ namespace Renderer { preRenderHook(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); - glDrawElements(GL_TRIANGLES, indicesVec.size(), GL_UNSIGNED_INT, 0); + // glDrawElements(GL_TRIANGLES, indicesVec.size(), GL_UNSIGNED_INT, 0); + glDrawArrays(GL_TRIANGLES, 0, indicesVec.size()); } void RenderObject::transform(glm::mat4 T) { @@ -106,6 +107,7 @@ namespace Renderer { void Obj2D::preRenderHook() { printf("OBJ2D was here!\n"); + printf("Now has texture: %s", texture.texture_src); if (texture.loaded) texture.bind(); } diff --git a/src/textures.cpp b/src/textures.cpp index a8528ec..8841ed5 100644 --- a/src/textures.cpp +++ b/src/textures.cpp @@ -19,7 +19,7 @@ namespace Textures { void Texture2D::load() { // Bind this texture glGenTextures(1, &id); - glBindTexture(GL_TEXTURE_2D, id); + bind(); // Repeat/bounded etc glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);