WE GOT TEXTURES BABY
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
#include "glm/gtx/transform.hpp"
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
App::App(): renderer{meshCache} {
|
||||
App::App(): renderer{meshCache, materialCache} {
|
||||
}
|
||||
|
||||
void App::init(const AppParams& params) {
|
||||
@@ -34,6 +34,7 @@ void App::init(const AppParams& params) {
|
||||
}
|
||||
|
||||
gfxDevice.init(window, params.appName, false);
|
||||
materialCache.init(gfxDevice);
|
||||
renderer.init(gfxDevice, params.renderSize);
|
||||
|
||||
//Read whole file
|
||||
@@ -47,14 +48,22 @@ void App::init(const AppParams& params) {
|
||||
testMeshID = meshCache.addMesh(gfxDevice, testMesh);
|
||||
spdlog::info("TestMesh uploaded with id: {}", testMeshID);
|
||||
|
||||
const auto testimgpath = AssetFS::GetInstance().GetFullPath("engine://textures/kobe.png");
|
||||
auto testimgID = gfxDevice.loadImageFromFile(testimgpath);
|
||||
spdlog::info("Test image loaded with id: {}", testimgID);
|
||||
testMaterialID = materialCache.addMaterial(gfxDevice, {
|
||||
.baseColor = glm::vec3(1.f),
|
||||
.diffuseTexture = testimgID,
|
||||
});
|
||||
spdlog::info("Test material created with id: {}", testMaterialID);
|
||||
|
||||
float aspectRatio = static_cast<float>(params.renderSize.x) / static_cast<float>(params.renderSize.y);
|
||||
camera.setAspectRatio(aspectRatio);
|
||||
|
||||
//Look 90 deg to the right
|
||||
camera.SetRotation(glm::radians(glm::vec2(90.f, 0.f)));
|
||||
|
||||
inputManager.Init();
|
||||
|
||||
InputManager::GetInstance().Init();
|
||||
}
|
||||
|
||||
void App::run() {
|
||||
@@ -90,7 +99,7 @@ void App::run() {
|
||||
}
|
||||
|
||||
while (accumulator >= dt) {
|
||||
inputManager.BeginFrame();
|
||||
InputManager::GetInstance().BeginFrame();
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
if (event.type == SDL_QUIT) {
|
||||
@@ -106,39 +115,12 @@ void App::run() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
inputManager.ProcessEvent(event);
|
||||
InputManager::GetInstance().ProcessEvent(event);
|
||||
|
||||
if (inputManager.IsKeyDown(SDL_SCANCODE_W)) {
|
||||
camera.m_position += camera.GetForward() * dt * 5.f;
|
||||
}
|
||||
if (inputManager.IsKeyDown(SDL_SCANCODE_S)) {
|
||||
camera.m_position -= camera.GetForward() * dt * 5.f;
|
||||
}
|
||||
if (inputManager.IsKeyDown(SDL_SCANCODE_A)) {
|
||||
camera.m_position -= camera.GetRight() * dt * 5.f;
|
||||
}
|
||||
if (inputManager.IsKeyDown(SDL_SCANCODE_D)) {
|
||||
camera.m_position += camera.GetRight() * dt * 5.f;
|
||||
}
|
||||
|
||||
// rotation
|
||||
if (inputManager.IsKeyDown(SDL_SCANCODE_LEFT)) {
|
||||
camera.SetRotation(camera.GetYaw() - glm::radians(90.f) * dt, camera.GetPitch());
|
||||
}
|
||||
if (inputManager.IsKeyDown(SDL_SCANCODE_RIGHT)) {
|
||||
camera.SetRotation(camera.GetYaw() + glm::radians(90.f) * dt, camera.GetPitch());
|
||||
}
|
||||
if (inputManager.IsKeyDown(SDL_SCANCODE_UP)) {
|
||||
camera.SetRotation(camera.GetYaw(), camera.GetPitch() + glm::radians(90.f) * dt);
|
||||
}
|
||||
if (inputManager.IsKeyDown(SDL_SCANCODE_DOWN)) {
|
||||
camera.SetRotation(camera.GetYaw(), camera.GetPitch() - glm::radians(90.f) * dt);
|
||||
}
|
||||
|
||||
camera.Update(dt);
|
||||
|
||||
}
|
||||
|
||||
camera.Update(dt);
|
||||
if (gfxDevice.needsSwapchainRecreate()) {
|
||||
spdlog::info("Recreating swapchain to size: {}x{}", m_params.windowSize.x, m_params.windowSize.y);
|
||||
gfxDevice.recreateSwapchain(m_params.windowSize.x, m_params.windowSize.y);
|
||||
@@ -154,7 +136,7 @@ void App::run() {
|
||||
glm::mat4 objMatrix = glm::mat4(1.f);
|
||||
objMatrix = glm::translate(objMatrix, glm::vec3(0.f, -3.0f, 0.f));
|
||||
renderer.beginDrawing(gfxDevice);
|
||||
renderer.drawMesh(testMeshID, glm::mat4(1.f), 0);
|
||||
renderer.drawMesh(testMeshID, glm::mat4(1.f), testMaterialID);
|
||||
renderer.drawMesh(testMeshID, objMatrix, 0);
|
||||
renderer.endDrawing();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user