Rendering FIXED :D
This commit is contained in:
+2
-3
@@ -1,6 +1,6 @@
|
||||
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
|
||||
bin
|
||||
obj
|
||||
bin/
|
||||
obj/
|
||||
|
||||
# Visual Studio files
|
||||
*.[Oo]bj
|
||||
@@ -25,7 +25,6 @@ obj
|
||||
*.opensdf
|
||||
*.unsuccessfulbuild
|
||||
ipch/
|
||||
obj/
|
||||
[Bb]in
|
||||
[Dd]ebug*/
|
||||
[Rr]elease*/
|
||||
|
||||
@@ -52,7 +52,19 @@ void GameWorld::Initialize()
|
||||
{
|
||||
World::Initialize();
|
||||
|
||||
//AddSystem("LevelGenerationSystem");
|
||||
AddSystem("InputSystem");
|
||||
//AddSystem("CollisionSystem");
|
||||
//AddSystem("ParticleSystem");
|
||||
//AddSystem("PlayerSystem");
|
||||
//AddSystem("SoundSystem");
|
||||
AddSystem("RenderSystem");
|
||||
|
||||
EntityID ent = CreateEntity();
|
||||
auto transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||
transform->Position = glm::vec3(0.f, 0.f, 0.f);
|
||||
auto model = AddComponent<Components::Model>(ent, "Model");
|
||||
model->ModelFile = "ship.obj";
|
||||
}
|
||||
|
||||
void GameWorld::RegisterSystems()
|
||||
@@ -63,7 +75,7 @@ void GameWorld::RegisterSystems()
|
||||
//m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this); });
|
||||
//m_SystemFactory.Register("PlayerSystem", [this]() { return new Systems::PlayerSystem(this); });
|
||||
//m_SystemFactory.Register("SoundSystem", [this]() { return new Systems::SoundSystem(this); });
|
||||
//m_SystemFactory.Register("RenderSystem", [this]() { return new Systems::RenderSystem(this, m_Renderer); });
|
||||
m_SystemFactory.Register("RenderSystem", [this]() { return new Systems::RenderSystem(this, m_Renderer); });
|
||||
}
|
||||
|
||||
void GameWorld::RegisterComponents()
|
||||
|
||||
@@ -101,7 +101,7 @@ bool Model::Loadobj(const char* path, std::vector <glm::vec3> & out_vertices, st
|
||||
else if ( strcmp( lineHeader, "mtllib" ) == 0 )
|
||||
{
|
||||
|
||||
const char* fileName;
|
||||
char fileName[512];
|
||||
fscanf(file, "%s\n", &fileName);
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ bool Model::Loadobj(const char* path, std::vector <glm::vec3> & out_vertices, st
|
||||
}
|
||||
else if ( strcmp( mtllineHeader, "map_Kd" ) == 0 )
|
||||
{
|
||||
const char* textureFileName;
|
||||
char textureFileName[512];
|
||||
fscanf(mtlfile, "%s", textureFileName);
|
||||
texture.push_back(std::make_shared<Texture>(textureFileName));
|
||||
LOG_INFO("Texture Loaded\n");
|
||||
@@ -170,15 +170,15 @@ void Model::CreateBuffers( std::vector<glm::vec3> _Vertices, std::vector<glm::ve
|
||||
GLERROR("GLEW: BufferFail4");
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VertexBuffer);
|
||||
glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
GLERROR("GLEW: BufferFail5");
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, NormalBuffer);
|
||||
glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
GLERROR("GLEW: BufferFail5");
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, TextureCoordBuffer);
|
||||
glVertexAttribPointer(2, 1, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
GLERROR("GLEW: BufferFail5");
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
@@ -42,7 +42,8 @@ void Renderer::Initialize()
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
// Create Camera
|
||||
m_Camera = std::make_shared<Camera>(90.f, WIDTH / HEIGHT, 0.01f, 1000.f);
|
||||
m_Camera = std::make_shared<Camera>(45.f, (float)WIDTH / HEIGHT, 0.01f, 1000.f);
|
||||
m_Camera->Position(glm::vec3(0.0f, 0.0f, 2.f));
|
||||
|
||||
LoadContent();
|
||||
}
|
||||
@@ -65,6 +66,7 @@ void Renderer::Draw(double _dt)
|
||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||
glBindVertexArray(ModelsToRender[i]->model->VAO);
|
||||
glDrawArrays(GL_TRIANGLES, 0, ModelsToRender[i]->model->Vertices.size());
|
||||
GLERROR("DRAW");
|
||||
}
|
||||
ModelsToRender.clear();
|
||||
|
||||
@@ -97,6 +99,4 @@ void Renderer::LoadContent()
|
||||
m_ShaderProgram.AddShader(std::unique_ptr<Shader>(new FragmentShader("Shaders/Fragment.glsl")));
|
||||
m_ShaderProgram.Compile();
|
||||
m_ShaderProgram.Link();
|
||||
|
||||
projectionMatrix = glm::perspective(45.0f, (float)WIDTH / HEIGHT, 0.01f, 100.0f);
|
||||
}
|
||||
|
||||
@@ -64,6 +64,8 @@ private:
|
||||
GLchar* m_glVendor;
|
||||
|
||||
std::shared_ptr<Camera> m_Camera;
|
||||
|
||||
GLuint vertexArrayObject;
|
||||
};
|
||||
|
||||
#endif // Renderer_h__
|
||||
@@ -1,18 +1,12 @@
|
||||
#include "RenderSystem.h"
|
||||
#include "World.h"
|
||||
|
||||
|
||||
|
||||
void Systems::RenderSystem::OnComponentCreated( std::string type, std:: shared_ptr<Component> component )
|
||||
{
|
||||
if(type == "Model")
|
||||
{
|
||||
auto modelComponent = std::static_pointer_cast<Components::Model>(component);
|
||||
|
||||
if (m_CachedModels.find(modelComponent->ModelFile) != m_CachedModels.end()) {
|
||||
m_CachedModels[modelComponent->ModelFile] = new Model(modelComponent->ModelFile);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +19,10 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
|
||||
if (transformComponent == nullptr)
|
||||
return;
|
||||
|
||||
if (m_CachedModels.find(modelComponent->ModelFile) == m_CachedModels.end()) {
|
||||
m_CachedModels[modelComponent->ModelFile] = new Model(modelComponent->ModelFile);
|
||||
}
|
||||
Model* model = m_CachedModels[modelComponent->ModelFile];
|
||||
|
||||
|
||||
|
||||
m_Renderer->AddModelToDraw(model, transformComponent->Position, transformComponent->Orientation);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,14 +18,10 @@ namespace Systems
|
||||
RenderSystem(World* world, std::shared_ptr<Renderer> renderer)
|
||||
: System(world), m_Renderer(renderer) {}
|
||||
|
||||
|
||||
std::unordered_map<std::string, Model*> m_CachedModels;
|
||||
|
||||
|
||||
void AddModelToDraw();
|
||||
void OnComponentCreated(std::string type, std:: shared_ptr<Component> component) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
void Update(double dt) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Renderer> m_Renderer;
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
# Blender MTL File: 'tobbeljus.blend'
|
||||
# Material Count: 2
|
||||
|
||||
newmtl Material
|
||||
Ns 96.078431
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 1.000000 1.000000 1.000000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
map_Kd shiptexture.png
|
||||
|
||||
newmtl Material.001
|
||||
Ns 96.078431
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.000000 0.185023 0.800000
|
||||
Ks 1.000000 1.000000 1.000000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
map_Kd shiptexture.png
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 879 KiB |
Reference in New Issue
Block a user