Testing some crap

This commit is contained in:
2022-10-30 00:39:07 -07:00
parent 37eaa706b7
commit 928b4b5447
19 changed files with 264 additions and 20 deletions

View File

@ -0,0 +1,20 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Set up the executable
set(DAWN_TARGET_NAME "DawnOS" CACHE INTERNAL ${DAWN_CACHE_TARGET})
# Build Project
add_executable(${DAWN_TARGET_NAME})
# Includes
target_include_directories(${DAWN_TARGET_NAME}
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
)
# Subdirs
add_subdirectory(game)
add_subdirectory(display)

View File

@ -0,0 +1,7 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Subdirs
add_subdirectory(shader)

View File

@ -0,0 +1,6 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources

View File

@ -0,0 +1,94 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "display/shader/Shader.hpp"
#include "scene/components/Components.hpp"
namespace Dawn {
class TestBackgroundShader : public Shader {
public:
shaderparameter_t paramProjection;
shaderparameter_t paramView;
shaderparameter_t paramTime;
std::map<shaderparameter_t, enum ShaderParameterType>
getParameters() override {
std::map<shaderparameter_t, enum ShaderParameterType> ps;
ps[paramTime] = SHADER_PARAMETER_TYPE_FLOAT;
return ps;
}
void setDefaultParameters(Material &material) override {
material.floatValues[this->paramTime] = 0.0f;
}
void setGlobalParameters(glm::mat4 proj, glm::mat4 view) override {
this->setMatrix(this->paramProjection, proj);
this->setMatrix(this->paramView, view);
}
void setMeshParameters(glm::mat4 transform) override {}
void bindTexture(
shaderparameter_t param,
Texture *texture
) override {}
void compile() override {
this->compileShader(R"GLSL(
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec2 aTexCoord;
uniform mat4 u_Proj;
uniform mat4 u_View;
out vec2 o_TextCoord;
void main() {
gl_Position = u_Proj * u_View * vec4(aPos, 1.0);
o_TextCoord = vec2(aTexCoord.x, aTexCoord.y);
}
)GLSL", R"GLSL(
#version 330 core
out vec4 o_Color;
in vec2 o_TextCoord;
uniform float u_Time;
void main() {
highp float tSpan = 4.0;
highp float halfTSpan = tSpan / 2.0;
highp float t = mod(u_Time, tSpan);
if(t > halfTSpan) {
t = halfTSpan + (halfTSpan - t);
}
t = t / halfTSpan;
highp float x = o_TextCoord.x;
highp float y = o_TextCoord.y;
float h = sin(x + u_Time) / 4 + 0.5;
highp float r = (0.6 + ((y * t) / 5.0));
highp float g = 0.4 + ((x * t) / (10 + (t * 3)));
highp float b = 0.8 + ((0.2 * t) - (x / 5));
highp float global = 0.7 + ((0.1 + (y * 0.6)) / h / 4.0);
o_Color = vec4(
r * global,
g * global,
b * global,
1.0
);
}
)GLSL"
);
this->paramProjection = this->getParameterByName("u_Proj");
this->paramView = this->getParameterByName("u_View");
this->paramTime = this->getParameterByName("u_Time");
}
};
}

View File

@ -0,0 +1,10 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
DawnPokerGame.cpp
)

View File

@ -0,0 +1,69 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "DawnPokerGame.hpp"
using namespace Dawn;
std::shared_ptr<Material> material;
std::shared_ptr<TestBackgroundShader> shader;
DawnGame::DawnGame(DawnHost &host) :
host(host),
renderManager(*this),
inputManager(*this)
{
}
int32_t DawnGame::init() {
this->assetManager.init();
this->renderManager.init();
this->scene = std::make_shared<Scene>(*this);
auto cameraObject = this->scene->createSceneItem();
auto camera = cameraObject->addComponent<Camera>();
camera->type = CAMERA_TYPE_ORTHONOGRAPHIC;
camera->orthoLeft = 0.0f;
camera->orthoRight = 1.0f;
camera->orthoTop = 0.0f;
camera->orthoBottom = 1.0f;
camera->transform.lookAt(glm::vec3(0, 0, 10), glm::vec3(0, 0, 0));
// camera->transform.lookAt(glm::vec3(50, 50, 50), glm::vec3(0, 0, 0));
auto quad = this->scene->createSceneItem();
auto meshRenderer = quad->addComponent<MeshRenderer>();
meshRenderer->mesh = std::make_shared<Mesh>();
meshRenderer->mesh->createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT);
QuadMesh::bufferQuadMesh(meshRenderer->mesh.get(),
glm::vec2(0, 0), glm::vec2(0, 0),
glm::vec2(1.0f, 1.0f), glm::vec2(1.0f, 1.0f),
0, 0
);
shader = std::make_shared<TestBackgroundShader>();
shader->compile();
material = quad->addComponent<Material>();
material->setShader(shader);
return DAWN_GAME_INIT_RESULT_SUCCESS;
}
int32_t DawnGame::update(float_t delta) {
this->assetManager.update();
this->inputManager.update();
this->timeManager.update(delta);
if(this->scene != nullptr) this->scene->update();
material->floatValues[shader->paramTime] = this->timeManager.time;
this->renderManager.update();
return DAWN_GAME_UPDATE_RESULT_SUCCESS;
}
DawnGame::~DawnGame() {
}

View File

@ -0,0 +1,10 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "game/DawnGame.hpp"
#include "scene/components/Components.hpp"
#include "display/mesh/QuadMesh.hpp"
#include "display/shader/TestBackgroundShader.hpp"

View File

@ -0,0 +1,9 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "input/InputManager.hpp"
#define INPUT_BIND_ACCEPT ((inputbind_t)1)