From 5a9765b111612a2bfc7006ef2c65e3bebec5ef82 Mon Sep 17 00:00:00 2001 From: Elipzer Date: Tue, 9 Oct 2018 19:58:26 -0400 Subject: [PATCH] Image Rendering almost works! There is an OpenGL error (1282) invalid operation that is getting caught when switching to the imagescene. This needs to get fixed and then hopefully the whole thing will work. --- OpenGLEngine/ImageScene.cpp | 6 +-- OpenGLEngine/ImageTypes.h | 2 +- OpenGLEngine/MeshGenerator.h | 9 ++-- OpenGLEngine/OpenGLEngine.vcxproj | 2 + OpenGLEngine/OpenGLEngine.vcxproj.filters | 6 +++ OpenGLEngine/SpriteBatch.h | 7 +-- OpenGLEngine/TextureFactory.cpp | 7 +++ OpenGLEngine/TextureFactory.h | 3 -- OpenGLEngine/TextureGenerator.cpp | 60 +++++++++++++++++++++++ OpenGLEngine/TextureGenerator.h | 49 +----------------- 10 files changed, 91 insertions(+), 60 deletions(-) create mode 100644 OpenGLEngine/TextureFactory.cpp create mode 100644 OpenGLEngine/TextureGenerator.cpp diff --git a/OpenGLEngine/ImageScene.cpp b/OpenGLEngine/ImageScene.cpp index 15777a5..54ed2f8 100644 --- a/OpenGLEngine/ImageScene.cpp +++ b/OpenGLEngine/ImageScene.cpp @@ -1,4 +1,4 @@ -#include "TexturedScene.h" +#include "ImageScene.h" #include "stdafx.h" @@ -9,7 +9,7 @@ namespace charcoal { namespace builtin { - namespace textured + namespace image { void Scene::init() { @@ -37,7 +37,7 @@ namespace charcoal { glutil::clear_screen(); m_shader_program.use(); - glutil::uniform_matrix(0, m_p_camera->get_world_to_view_matrix()); + glutil::uniform_matrix(0, get_camera()->get_world_to_view_matrix()); glutil::uniform_int(4, 0); // The textured batch uses GL_TEXTURE0 for (auto iter = m_batches.begin(); iter != m_batches.end(); ++iter) { diff --git a/OpenGLEngine/ImageTypes.h b/OpenGLEngine/ImageTypes.h index b12a904..3f41753 100644 --- a/OpenGLEngine/ImageTypes.h +++ b/OpenGLEngine/ImageTypes.h @@ -13,7 +13,7 @@ namespace charcoal typedef PTVertex Vertex; typedef Index Index; typedef TextureRenderable Renderable; - typedef SpriteBatch Batch; + typedef SpriteBatch Batch; } } } \ No newline at end of file diff --git a/OpenGLEngine/MeshGenerator.h b/OpenGLEngine/MeshGenerator.h index 5f75c52..d343071 100644 --- a/OpenGLEngine/MeshGenerator.h +++ b/OpenGLEngine/MeshGenerator.h @@ -688,7 +688,8 @@ namespace charcoal mesh->indices[3] = 0; mesh->indices[4] = 3; mesh->indices[5] = 2; - break; + + return mesh; case DrawMode::DRAW_TRIANGLE_STRIP: mesh = MeshFactory::create_mesh(4, 4); @@ -706,7 +707,8 @@ namespace charcoal mesh->indices[1] = 3; mesh->indices[2] = 0; mesh->indices[3] = 2; - break; + + return mesh; case DrawMode::DRAW_TRIANGLE_FAN: mesh = MeshFactory::create_mesh(4, 4); @@ -724,7 +726,8 @@ namespace charcoal mesh->indices[1] = 3; mesh->indices[2] = 2; mesh->indices[3] = 0; - break; + + return mesh; case DrawMode::DRAW_POINTS: case DrawMode::DRAW_LINES: case DrawMode::DRAW_LINE_STRIP: diff --git a/OpenGLEngine/OpenGLEngine.vcxproj b/OpenGLEngine/OpenGLEngine.vcxproj index b4bc08d..be692ad 100644 --- a/OpenGLEngine/OpenGLEngine.vcxproj +++ b/OpenGLEngine/OpenGLEngine.vcxproj @@ -191,6 +191,8 @@ + + diff --git a/OpenGLEngine/OpenGLEngine.vcxproj.filters b/OpenGLEngine/OpenGLEngine.vcxproj.filters index 70f0871..77d52af 100644 --- a/OpenGLEngine/OpenGLEngine.vcxproj.filters +++ b/OpenGLEngine/OpenGLEngine.vcxproj.filters @@ -258,6 +258,12 @@ Source Files\Example\Application + + Source Files\Engine\builtin\General + + + Source Files\Engine\Baseline + diff --git a/OpenGLEngine/SpriteBatch.h b/OpenGLEngine/SpriteBatch.h index 00a849d..bbf835f 100644 --- a/OpenGLEngine/SpriteBatch.h +++ b/OpenGLEngine/SpriteBatch.h @@ -8,9 +8,10 @@ namespace charcoal { namespace builtin { - template + template class SpriteBatch : public Poseable2DBatch > { + public: // Note: This is VERY similar to builtin::textured::Batch // TODO: Use Poseable2D for each sprite's position // TODO: Have a texture @@ -43,8 +44,8 @@ namespace charcoal glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); // TODO: Figure out how to do this without offsetof :( - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(VertexType), (void*)offsetof(VertexType, position)); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(VertexType), (void*)offsetof(VertexType, uv)); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(VertexType), (void*)position_offset); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(VertexType), (void*)uv_offset); glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch >::m_element_buffers[0]); glEnableVertexAttribArray(2); glEnableVertexAttribArray(3); diff --git a/OpenGLEngine/TextureFactory.cpp b/OpenGLEngine/TextureFactory.cpp new file mode 100644 index 0000000..6c16aac --- /dev/null +++ b/OpenGLEngine/TextureFactory.cpp @@ -0,0 +1,7 @@ +#include "TextureFactory.h" + +namespace charcoal +{ + std::vector TextureFactory::m_textures; + std::vector TextureFactory::m_samplers; +} \ No newline at end of file diff --git a/OpenGLEngine/TextureFactory.h b/OpenGLEngine/TextureFactory.h index 2a15d9e..2327e68 100644 --- a/OpenGLEngine/TextureFactory.h +++ b/OpenGLEngine/TextureFactory.h @@ -52,7 +52,4 @@ namespace charcoal static std::vector m_textures; static std::vector m_samplers; }; - - std::vector TextureFactory::m_textures; - std::vector TextureFactory::m_samplers; } diff --git a/OpenGLEngine/TextureGenerator.cpp b/OpenGLEngine/TextureGenerator.cpp new file mode 100644 index 0000000..eb717ff --- /dev/null +++ b/OpenGLEngine/TextureGenerator.cpp @@ -0,0 +1,60 @@ +#include "TextureGenerator.h" + +#include "TextureFactory.h" + +namespace charcoal +{ + namespace builtin + { + namespace texturegenerator + { + Texture* gen_quick_cube_texture() + { + std::vector values; + + // Front + values.emplace_back(255); + values.emplace_back(255); + values.emplace_back(255); + values.emplace_back(255); + + // Right + values.emplace_back(255); + values.emplace_back(255); + values.emplace_back(0); + values.emplace_back(255); + + // Back + values.emplace_back(255); + values.emplace_back(0); + values.emplace_back(255); + values.emplace_back(255); + + // Left + values.emplace_back(0); + values.emplace_back(255); + values.emplace_back(255); + values.emplace_back(255); + + // Top + values.emplace_back(255); + values.emplace_back(0); + values.emplace_back(0); + values.emplace_back(255); + + // Bottom + values.emplace_back(0); + values.emplace_back(255); + values.emplace_back(0); + values.emplace_back(255); + + return TextureFactory::gen_texture(Texture::Format::RGBA, Texture::Type::UNSIGNED_BYTE, 6, 1, values, Texture::InternalFormat::RGBA); + } + + Sampler* gen_quick_sampler() + { + return TextureFactory::gen_sampler(Sampler::Wrap::REPEAT, Sampler::Wrap::REPEAT, Sampler::MagFilter::NEAREST, Sampler::MinFilter::NEAREST); + } + } + } +} \ No newline at end of file diff --git a/OpenGLEngine/TextureGenerator.h b/OpenGLEngine/TextureGenerator.h index 4f7c0b8..6362f8c 100644 --- a/OpenGLEngine/TextureGenerator.h +++ b/OpenGLEngine/TextureGenerator.h @@ -4,7 +4,6 @@ #include "Texture.h" #include "Sampler.h" -#include "TextureFactory.h" namespace charcoal { @@ -12,53 +11,9 @@ namespace charcoal { namespace texturegenerator { - Texture* gen_quick_cube_texture() - { - std::vector values; - - // Front - values.emplace_back(255); - values.emplace_back(255); - values.emplace_back(255); - values.emplace_back(255); - - // Right - values.emplace_back(255); - values.emplace_back(255); - values.emplace_back(0); - values.emplace_back(255); - - // Back - values.emplace_back(255); - values.emplace_back(0); - values.emplace_back(255); - values.emplace_back(255); - - // Left - values.emplace_back(0); - values.emplace_back(255); - values.emplace_back(255); - values.emplace_back(255); - - // Top - values.emplace_back(255); - values.emplace_back(0); - values.emplace_back(0); - values.emplace_back(255); - - // Bottom - values.emplace_back(0); - values.emplace_back(255); - values.emplace_back(0); - values.emplace_back(255); - - return TextureFactory::gen_texture(Texture::Format::RGBA, Texture::Type::UNSIGNED_BYTE, 6, 1, values, Texture::InternalFormat::RGBA); - } + Texture* gen_quick_cube_texture(); - Sampler* gen_quick_sampler() - { - return TextureFactory::gen_sampler(Sampler::Wrap::REPEAT, Sampler::Wrap::REPEAT, Sampler::MagFilter::NEAREST, Sampler::MinFilter::NEAREST); - } + Sampler* gen_quick_sampler(); } } } \ No newline at end of file