[testing] shader ddoesnt work, still on it

This commit is contained in:
Lars
2021-05-28 12:08:12 +02:00
parent 51cdc520e0
commit 93b3223737
11 changed files with 259 additions and 27 deletions

View File

@@ -1,5 +1,5 @@
#pragma once
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/gtc/matrix_transform.hpp>

View File

@@ -1,3 +1,4 @@
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include "gui_interactable.h"

View File

@@ -3,6 +3,7 @@
#include <glm/gtc/matrix_transform.hpp>
#define STB_IMAGE_IMPLEMENTATION
#include <iostream>
#include <map>
#include "stb_image.h"
#include <ostream>
@@ -16,6 +17,9 @@
#include "renderEngine/renderer.h"
#include "shaders/entity_shader.h"
#include "toolbox/toolbox.h"
#include "scenes/scene.h"
#include "scenes/in_Game_Scene.h"
#include "scenes/startup_Scene.h"
#pragma comment(lib, "glfw3.lib")
#pragma comment(lib, "glew32s.lib")
@@ -23,8 +27,9 @@
static double UpdateDelta();
static GLFWwindow* window;
GLFWwindow* window;
std::map<scene::Scenes, scene::Scene*> scenes;
scene::Scene* current_scene = nullptr;
int main(void)
{
@@ -44,42 +49,48 @@ int main(void)
glfwSetKeyCallback(window, [](GLFWwindow* window, int key, int scancode, int action, int mods)
{
current_scene->onKey(key, scancode, action, mods);
if (key == GLFW_KEY_ESCAPE)
glfwSetWindowShouldClose(window, true);
});
scenes[scene::Scenes::STARTUP] = new scene::Startup_Scene();
scenes[scene::Scenes::INGAME] = new scene::In_Game_Scene();
current_scene = scenes[scene::Scenes::STARTUP];
models::RawModel raw_model = render_engine::LoadObjModel("res/House.obj");
/* models::RawModel raw_model = render_engine::LoadObjModel("res/House.obj");
models::ModelTexture texture = { render_engine::loader::LoadTexture("res/Texture.png") };
texture.shine_damper = 10;
texture.reflectivity = 0;
models::TexturedModel model = { raw_model, texture };
models::TexturedModel model = { raw_model, texture };*/
/**
* load and add some models (in this case some level sections) to the entities list.
* */
std::vector<entities::Entity> entities;
/*std::vector<entities::Entity> entities;
int z = 0;
for (int i = 0; i < 5; ++i)
{
entities.push_back(entities::Entity(model, glm::vec3(0, -50, -50 - z), glm::vec3(0, 90, 0), 20));
z += (raw_model.model_size.x * 20);
}
}*/
std::vector<entities::Light> lights;
/* std::vector<entities::Light> lights;
lights.push_back(entities::Light(glm::vec3(0, 1000, -7000), glm::vec3(5, 5, 5)));
lights.push_back(entities::Light(glm::vec3(0, 0, -30), glm::vec3(2, 0, 2), glm::vec3(0.0001f, 0.0001f, 0.0001f)));
lights.push_back(entities::Light(glm::vec3(0, 0, -200), glm::vec3(0, 2, 0), glm::vec3(0.0001f, 0.0001f, 0.0001f)));
lights.push_back(entities::Light(glm::vec3(0, 0, -200), glm::vec3(0, 2, 0), glm::vec3(0.0001f, 0.0001f, 0.0001f)));*/
shaders::EntityShader shader;
/*shaders::EntityShader shader;
shader.Init();
render_engine::renderer::Init(shader);
render_engine::renderer::Init(shader);*/
entities::Camera camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0));
//entities::Camera camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0));
// GUI stuff
shaders::GuiShader gui_shader;
/* shaders::GuiShader gui_shader;
gui_shader.Init();
std::vector<gui::GuiTexture*> guis;
@@ -91,36 +102,38 @@ int main(void)
std::cout << "I got clicked on!" << std::endl;
});
guis.push_back(&button);
*/
// Main game loop
while (!glfwWindowShouldClose(window))
{
// Update
const double delta = UpdateDelta();
camera.Move(window);
button.Update(window);
//camera.Move(window);
current_scene->update();
// button.Update(window);
current_scene->render();
// Render
render_engine::renderer::Prepare();
//render_engine::renderer::Prepare();
// Start rendering the entities
shader.Start();
shader.LoadSkyColor(render_engine::renderer::SKY_COLOR);
shader.LoadLights(lights);
shader.LoadViewMatrix(camera);
//shader.Start();
//shader.LoadSkyColor(render_engine::renderer::SKY_COLOR);
//shader.LoadLights(lights);
//shader.LoadViewMatrix(camera);
// Renders each entity in the entities list
for (entities::Entity& entity : entities)
/* for (entities::Entity& entity : entities)
{
render_engine::renderer::Render(entity, shader);
}
}*/
// Stop rendering the entities
shader.Stop();
//shader.Stop();
// Render GUI items
render_engine::renderer::Render(guis, gui_shader);
//render_engine::renderer::Render(guis, gui_shader);
// Finish up
glfwSwapBuffers(window);
@@ -128,8 +141,8 @@ int main(void)
}
// Clean up
shader.CleanUp();
gui_shader.CleanUp();
//shader.CleanUp();
// gui_shader.CleanUp();
render_engine::loader::CleanUp();
glfwTerminate();
return 0;

View File

@@ -0,0 +1,79 @@
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include "in_Game_Scene.h"
#include "startup_Scene.h"
#include "../gui/gui_interactable.h"
#include "../models/model.h"
#include "../renderEngine/loader.h"
#include "../renderEngine/obj_loader.h"
#include "../renderEngine/renderer.h"
#include "../shaders/entity_shader.h"
#include "../toolbox/toolbox.h"
namespace scene
{
std::vector<entities::Entity> entities;
std::vector<entities::Light> lights;
models::RawModel raw_model;
models::ModelTexture texture;
shaders::EntityShader shader;
entities::Camera camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0));
extern GLFWwindow* window;
void scene::In_Game_Scene::start()
{
raw_model = render_engine::LoadObjModel("res/House.obj");
texture = { render_engine::loader::LoadTexture("res/Texture.png") };
texture.shine_damper = 10;
texture.reflectivity = 0;
models::TexturedModel model = { raw_model, texture };
int z = 0;
for (int i = 0; i < 5; ++i)
{
entities.push_back(entities::Entity(model, glm::vec3(0, -50, -50 - z), glm::vec3(0, 90, 0), 20));
z += (raw_model.model_size.x * 20);
}
shader.Init();
render_engine::renderer::Init(shader);
lights.push_back(entities::Light(glm::vec3(0, 1000, -7000), glm::vec3(5, 5, 5)));
lights.push_back(entities::Light(glm::vec3(0, 0, -30), glm::vec3(2, 0, 2), glm::vec3(0.0001f, 0.0001f, 0.0001f)));
lights.push_back(entities::Light(glm::vec3(0, 0, -200), glm::vec3(0, 2, 0), glm::vec3(0.0001f, 0.0001f, 0.0001f)));
}
void scene::In_Game_Scene::render()
{
// Render
render_engine::renderer::Prepare();
shader.Start();
shader.LoadSkyColor(render_engine::renderer::SKY_COLOR);
shader.LoadLights(lights);
shader.LoadViewMatrix(camera);
// Renders each entity in the entities list
for (entities::Entity& entity : entities)
{
render_engine::renderer::Render(entity, shader);
}
// Stop rendering the entities
shader.Stop();
}
void scene::In_Game_Scene::update()
{
camera.Move(window);
}
void scene::In_Game_Scene::onKey(int key, int scancode, int action, int mods)
{
}
}

View File

@@ -0,0 +1,19 @@
#pragma once
#include "scene.h"
namespace scene
{
class In_Game_Scene : public scene::Scene
{
private:
public:
virtual void start() override;
virtual void render() override;
virtual void update() override;
virtual void onKey(int key, int scancode, int action, int mods) override;
};
}

7
src/scenes/scene.cpp Normal file
View File

@@ -0,0 +1,7 @@
#include "scene.h"
namespace scene
{
}

34
src/scenes/scene.h Normal file
View File

@@ -0,0 +1,34 @@
#pragma once
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <map>
namespace scene {
class Scene
{
public:
virtual void start() = 0;
virtual void render() = 0;
virtual void update() = 0;
virtual void onKey(int key, int scancode, int action, int mods) {};
};
enum class Scenes
{
STARTUP,
INGAME,
GAMEOVER,
CALIBRATION
};
extern std::map<Scenes, Scene*> scenes;
extern Scene* current_scene;
extern GLFWwindow* window;
}

View File

@@ -0,0 +1,35 @@
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <map>
#include "startup_Scene.h"
namespace scene
{
std::map<Scenes, Scene*> scenes;
Scene* current_scene;
GLFWwindow* window;
void scene::Startup_Scene::start()
{
}
void scene::Startup_Scene::render()
{
}
void scene::Startup_Scene::update()
{
}
void scene::Startup_Scene::onKey(int key, int scancode, int action, int mods)
{
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
{
current_scene = scenes[Scenes::INGAME];
current_scene->start();
}
}
}

View File

@@ -0,0 +1,20 @@
#pragma once
#include "scene.h"
#include <map>
namespace scene
{
class Startup_Scene : public scene::Scene
{
private:
public:
virtual void start() override;
virtual void render() override;
virtual void update() override;
virtual void onKey(int key, int scancode, int action, int mods) override;
};
}

View File

@@ -19,6 +19,8 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\scenes\in_Game_Scene.cpp" />
<ClCompile Include="src\scenes\scene.cpp" />
<ClCompile Include="src\entities\camera.cpp" />
<ClCompile Include="src\entities\entity.cpp" />
<ClCompile Include="src\gui\gui_interactable.cpp" />
@@ -30,8 +32,11 @@
<ClCompile Include="src\shaders\shader_program.cpp" />
<ClCompile Include="src\shaders\entity_shader.cpp" />
<ClCompile Include="src\toolbox\toolbox.cpp" />
<ClCompile Include="src\scenes\startup_Scene.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\scenes\in_Game_Scene.h" />
<ClInclude Include="src\scenes\scene.h" />
<ClInclude Include="src\entities\camera.h" />
<ClInclude Include="src\entities\entity.h" />
<ClInclude Include="src\entities\light.h" />
@@ -46,6 +51,7 @@
<ClInclude Include="src\shaders\entity_shader.h" />
<ClInclude Include="src\stb_image.h" />
<ClInclude Include="src\toolbox\toolbox.h" />
<ClInclude Include="src\scenes\startup_Scene.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>

View File

@@ -48,6 +48,15 @@
<ClCompile Include="src\gui\gui_interactable.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\scenes\scene.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\scenes\in_Game_Scene.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\scenes\startup_Scene.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\entities\Camera.h">
@@ -92,5 +101,14 @@
<ClInclude Include="src\gui\gui_interactable.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\scenes\scene.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\scenes\in_Game_Scene.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\scenes\startup_Scene.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>