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.
This commit is contained in:
parent
b7456401e0
commit
5a9765b111
@ -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)
|
||||
{
|
||||
|
@ -13,7 +13,7 @@ namespace charcoal
|
||||
typedef PTVertex Vertex;
|
||||
typedef Index Index;
|
||||
typedef TextureRenderable<Vertex, Index> Renderable;
|
||||
typedef SpriteBatch<Vertex, Index> Batch;
|
||||
typedef SpriteBatch<Vertex, Index, offsetof(Vertex, position), offsetof(Vertex, uv)> Batch;
|
||||
}
|
||||
}
|
||||
}
|
@ -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<VertexType, IndexType>::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<VertexType, IndexType>::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:
|
||||
|
@ -191,6 +191,8 @@
|
||||
</ClCompile>
|
||||
<ClCompile Include="TexturedBatch.cpp" />
|
||||
<ClCompile Include="TexturedScene.cpp" />
|
||||
<ClCompile Include="TextureFactory.cpp" />
|
||||
<ClCompile Include="TextureGenerator.cpp" />
|
||||
<ClCompile Include="Util.cpp" />
|
||||
<ClCompile Include="VertexFragmentShaderProgram.cpp" />
|
||||
</ItemGroup>
|
||||
|
@ -258,6 +258,12 @@
|
||||
<ClCompile Include="MyBuiltinImageScene.cpp">
|
||||
<Filter>Source Files\Example\Application</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="TextureGenerator.cpp">
|
||||
<Filter>Source Files\Engine\builtin\General</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="TextureFactory.cpp">
|
||||
<Filter>Source Files\Engine\Baseline</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Application.h">
|
||||
|
@ -8,9 +8,10 @@ namespace charcoal
|
||||
{
|
||||
namespace builtin
|
||||
{
|
||||
template <typename VertexType, typename IndexType>
|
||||
template <typename VertexType, typename IndexType, int position_offset, int uv_offset>
|
||||
class SpriteBatch : public Poseable2DBatch<VertexType, IndexType, TextureRenderable<VertexType, IndexType> >
|
||||
{
|
||||
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<VertexType, IndexType, 1, TextureRenderable<VertexType, IndexType> >::m_element_buffers[0]);
|
||||
glEnableVertexAttribArray(2);
|
||||
glEnableVertexAttribArray(3);
|
||||
|
7
OpenGLEngine/TextureFactory.cpp
Normal file
7
OpenGLEngine/TextureFactory.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
#include "TextureFactory.h"
|
||||
|
||||
namespace charcoal
|
||||
{
|
||||
std::vector<Texture> TextureFactory::m_textures;
|
||||
std::vector<Sampler> TextureFactory::m_samplers;
|
||||
}
|
@ -52,7 +52,4 @@ namespace charcoal
|
||||
static std::vector<Texture> m_textures;
|
||||
static std::vector<Sampler> m_samplers;
|
||||
};
|
||||
|
||||
std::vector<Texture> TextureFactory::m_textures;
|
||||
std::vector<Sampler> TextureFactory::m_samplers;
|
||||
}
|
||||
|
60
OpenGLEngine/TextureGenerator.cpp
Normal file
60
OpenGLEngine/TextureGenerator.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
#include "TextureGenerator.h"
|
||||
|
||||
#include "TextureFactory.h"
|
||||
|
||||
namespace charcoal
|
||||
{
|
||||
namespace builtin
|
||||
{
|
||||
namespace texturegenerator
|
||||
{
|
||||
Texture* gen_quick_cube_texture()
|
||||
{
|
||||
std::vector<unsigned char> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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<unsigned char> 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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user