Testing some crap
This commit is contained in:
@ -4,7 +4,7 @@
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# DEBUG
|
||||
set(DAWN_BUILDING dawnpokergame)
|
||||
set(DAWN_BUILDING dawnosui)
|
||||
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
|
@ -162,7 +162,7 @@ void TrueTypeFont::buffer(
|
||||
info->height = mathMax<float_t>(info->height, quad->y1);
|
||||
|
||||
// Buffer the quad.
|
||||
QuadMesh::bufferQuadMesh(mesh,
|
||||
QuadMesh::bufferQuadMesh(&mesh,
|
||||
glm::vec2(quad->x0, quad->y0), glm::vec2(quad->s0, quad->t0),
|
||||
glm::vec2(quad->x1, quad->y1), glm::vec2(quad->s1, quad->t1),
|
||||
j * QUAD_VERTICE_COUNT, j * QUAD_INDICE_COUNT
|
||||
|
@ -8,12 +8,12 @@
|
||||
using namespace Dawn;
|
||||
|
||||
void QuadMesh::bufferQuadMeshWithZ(
|
||||
Mesh &mesh,
|
||||
Mesh *mesh,
|
||||
glm::vec2 xy0, glm::vec2 uv0,
|
||||
glm::vec2 xy1, glm::vec2 uv1,
|
||||
float_t z, int32_t verticeStart, int32_t indiceStart
|
||||
) {
|
||||
mesh.bufferPositions(
|
||||
mesh->bufferPositions(
|
||||
verticeStart, std::array<glm::vec3, QUAD_VERTICE_COUNT>{{
|
||||
glm::vec3(xy0, z),
|
||||
glm::vec3(xy1.x, xy0.y, z),
|
||||
@ -22,14 +22,14 @@ void QuadMesh::bufferQuadMeshWithZ(
|
||||
}}
|
||||
);
|
||||
|
||||
mesh.bufferCoordinates(
|
||||
mesh->bufferCoordinates(
|
||||
verticeStart, std::array<glm::vec2, QUAD_VERTICE_COUNT>{{
|
||||
uv0, glm::vec2(uv1.x, uv0.y),
|
||||
glm::vec2(uv0.x, uv1.y), uv1
|
||||
}}
|
||||
);
|
||||
|
||||
mesh.bufferIndices(
|
||||
mesh->bufferIndices(
|
||||
indiceStart, std::array<meshindice_t, QUAD_INDICE_COUNT>{{
|
||||
verticeStart, verticeStart + 1, verticeStart + 2,
|
||||
verticeStart + 1, verticeStart + 2, verticeStart + 3
|
||||
@ -38,7 +38,7 @@ void QuadMesh::bufferQuadMeshWithZ(
|
||||
}
|
||||
|
||||
void QuadMesh::bufferQuadMesh(
|
||||
Mesh &mesh,
|
||||
Mesh *mesh,
|
||||
glm::vec2 xy0, glm::vec2 uv0,
|
||||
glm::vec2 xy1, glm::vec2 uv1,
|
||||
int32_t verticeStart, int32_t indiceStart
|
||||
|
@ -26,7 +26,7 @@ namespace Dawn {
|
||||
* @param indiceStart Start indice to buffer to.
|
||||
*/
|
||||
static void bufferQuadMeshWithZ(
|
||||
Mesh &mesh,
|
||||
Mesh *mesh,
|
||||
glm::vec2 xy0, glm::vec2 uv0,
|
||||
glm::vec2 xy1, glm::vec2 uv1,
|
||||
float_t z, int32_t verticeStart, int32_t indiceStart
|
||||
@ -44,7 +44,7 @@ namespace Dawn {
|
||||
* @param indiceStart Start indice to buffer to.
|
||||
*/
|
||||
static void bufferQuadMesh(
|
||||
Mesh &mesh,
|
||||
Mesh *mesh,
|
||||
glm::vec2 xy0, glm::vec2 uv0,
|
||||
glm::vec2 xy1, glm::vec2 uv1,
|
||||
int32_t verticeStart, int32_t indiceStart
|
||||
|
@ -14,7 +14,8 @@ namespace Dawn {
|
||||
SHADER_PARAMETER_TYPE_BOOLEAN,
|
||||
SHADER_PARAMETER_TYPE_COLOR,
|
||||
SHADER_PARAMETER_TYPE_VECTOR3,
|
||||
SHADER_PARAMETER_TYPE_TEXTURE
|
||||
SHADER_PARAMETER_TYPE_TEXTURE,
|
||||
SHADER_PARAMETER_TYPE_FLOAT
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@ -102,5 +103,13 @@ namespace Dawn {
|
||||
* @param texture Texture to bind to the parameter.
|
||||
*/
|
||||
virtual void setTexture(T parameter, Texture *texture) = 0;
|
||||
|
||||
/**
|
||||
* Sets a floating point value to the shader.
|
||||
*
|
||||
* @param parameter Paramater to set the float ont o.
|
||||
* @param float Float to bind.
|
||||
*/
|
||||
virtual void setFloat(T parameter, float_t value) = 0;
|
||||
};
|
||||
}
|
@ -51,6 +51,10 @@ void Material::setShaderParameters() {
|
||||
this->shader->setTexture(it->first, this->textureValues[it->first]);
|
||||
break;
|
||||
|
||||
case SHADER_PARAMETER_TYPE_FLOAT:
|
||||
this->shader->setFloat(it->first, this->floatValues[it->first]);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw "An unsupported or invalid shader parameter type was supplied.";
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ namespace Dawn {
|
||||
std::map<shaderparameter_t, glm::mat4> matrixValues;
|
||||
std::map<shaderparameter_t, glm::vec3> vec3Values;
|
||||
std::map<shaderparameter_t, Texture*> textureValues;
|
||||
std::map<shaderparameter_t, float_t> floatValues;
|
||||
|
||||
/**
|
||||
* Material component constructor.
|
||||
|
@ -30,7 +30,7 @@ void UIBorder::updatePositions() {
|
||||
glm::vec2 innerDimensions = overallDimensions - (this->edgeDimensions * 2.0f);
|
||||
|
||||
// Top Left.
|
||||
QuadMesh::bufferQuadMesh(this->mesh,
|
||||
QuadMesh::bufferQuadMesh(&this->mesh,
|
||||
glm::vec2(0, 0),
|
||||
this->uv0,
|
||||
edgeDimensions,
|
||||
@ -39,7 +39,7 @@ void UIBorder::updatePositions() {
|
||||
);
|
||||
|
||||
// Top Center
|
||||
QuadMesh::bufferQuadMesh(this->mesh,
|
||||
QuadMesh::bufferQuadMesh(&this->mesh,
|
||||
glm::vec2(edgeDimensions.x, 0),
|
||||
this->uv0 + glm::vec2(oneThird.x, 0),
|
||||
glm::vec2(edgeDimensions.x + innerDimensions.x, edgeDimensions.y),
|
||||
@ -48,7 +48,7 @@ void UIBorder::updatePositions() {
|
||||
);
|
||||
|
||||
// Top Right
|
||||
QuadMesh::bufferQuadMesh(this->mesh,
|
||||
QuadMesh::bufferQuadMesh(&this->mesh,
|
||||
glm::vec2(edgeDimensions.x + innerDimensions.x, 0),
|
||||
this->uv0 + glm::vec2(oneThird.x * 2.0f, 0),
|
||||
glm::vec2(overallDimensions.x, edgeDimensions.y),
|
||||
@ -57,7 +57,7 @@ void UIBorder::updatePositions() {
|
||||
);
|
||||
|
||||
// Middle Left
|
||||
QuadMesh::bufferQuadMesh(this->mesh,
|
||||
QuadMesh::bufferQuadMesh(&this->mesh,
|
||||
glm::vec2(0, edgeDimensions.y),
|
||||
this->uv0 + glm::vec2(0, oneThird.y),
|
||||
glm::vec2(edgeDimensions.x, edgeDimensions.y + innerDimensions.y),
|
||||
@ -66,7 +66,7 @@ void UIBorder::updatePositions() {
|
||||
);
|
||||
|
||||
// Center
|
||||
QuadMesh::bufferQuadMesh(this->mesh,
|
||||
QuadMesh::bufferQuadMesh(&this->mesh,
|
||||
edgeDimensions,
|
||||
this->uv0 + oneThird,
|
||||
edgeDimensions + innerDimensions,
|
||||
@ -75,7 +75,7 @@ void UIBorder::updatePositions() {
|
||||
);
|
||||
|
||||
// Middle Right
|
||||
QuadMesh::bufferQuadMesh(this->mesh,
|
||||
QuadMesh::bufferQuadMesh(&this->mesh,
|
||||
edgeDimensions + glm::vec2(innerDimensions.x, 0),
|
||||
this->uv0 + glm::vec2(oneThird.x * 2.0f, oneThird.y),
|
||||
edgeDimensions + innerDimensions + glm::vec2(edgeDimensions.x, 0),
|
||||
@ -84,7 +84,7 @@ void UIBorder::updatePositions() {
|
||||
);
|
||||
|
||||
// Bottom Left
|
||||
QuadMesh::bufferQuadMesh(this->mesh,
|
||||
QuadMesh::bufferQuadMesh(&this->mesh,
|
||||
glm::vec2(0.0f, edgeDimensions.y + innerDimensions.y),
|
||||
this->uv0 + glm::vec2(0.0f, uv1.y - oneThird.y),
|
||||
glm::vec2(edgeDimensions.x, overallDimensions.y),
|
||||
@ -93,7 +93,7 @@ void UIBorder::updatePositions() {
|
||||
);
|
||||
|
||||
// Bottom Center
|
||||
QuadMesh::bufferQuadMesh(this->mesh,
|
||||
QuadMesh::bufferQuadMesh(&this->mesh,
|
||||
edgeDimensions + glm::vec2(0.0f, innerDimensions.y),
|
||||
this->uv1 - oneThird,
|
||||
overallDimensions - glm::vec2(edgeDimensions.x, 0.0f),
|
||||
@ -102,7 +102,7 @@ void UIBorder::updatePositions() {
|
||||
);
|
||||
|
||||
// Bottom Right
|
||||
QuadMesh::bufferQuadMesh(this->mesh,
|
||||
QuadMesh::bufferQuadMesh(&this->mesh,
|
||||
overallDimensions - edgeDimensions,
|
||||
this->uv1 - oneThird,
|
||||
overallDimensions,
|
||||
|
@ -15,7 +15,7 @@ void UISprite::updatePositions() {
|
||||
UIComponent::updatePositions();
|
||||
|
||||
QuadMesh::bufferQuadMesh(
|
||||
this->mesh,
|
||||
&this->mesh,
|
||||
glm::vec2(0, 0), glm::vec2(0, 0),
|
||||
glm::vec2(this->width, this->height), glm::vec2(1, 1),
|
||||
0, 0
|
||||
|
@ -96,6 +96,10 @@ void Shader::setTexture(
|
||||
this->bindTexture(param, texture);
|
||||
}
|
||||
|
||||
void Shader::setFloat(shaderparameter_t param, float_t value) {
|
||||
glUniform1f(param, value);
|
||||
}
|
||||
|
||||
void Shader::bind() {
|
||||
if(this->shaderProgram == -1) throw "Shader has not yet been compiled";
|
||||
glUseProgram(this->shaderProgram);
|
||||
|
@ -76,6 +76,7 @@ namespace Dawn {
|
||||
void setColor(shaderparameter_t parameter, struct Color color) override;
|
||||
void setVector3(shaderparameter_t parameter, glm::vec3 vector) override;
|
||||
void setTexture(shaderparameter_t parameter, Texture *texture) override;
|
||||
void setFloat(shaderparameter_t parameter, float_t value) override;
|
||||
|
||||
/**
|
||||
* Destroys and deletes the shader from the GPU.
|
||||
|
20
src/dawnosui/CMakeLists.txt
Normal file
20
src/dawnosui/CMakeLists.txt
Normal 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)
|
7
src/dawnosui/display/CMakeLists.txt
Normal file
7
src/dawnosui/display/CMakeLists.txt
Normal 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)
|
6
src/dawnosui/display/shader/CMakeLists.txt
Normal file
6
src/dawnosui/display/shader/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
94
src/dawnosui/display/shader/TestBackgroundShader.hpp
Normal file
94
src/dawnosui/display/shader/TestBackgroundShader.hpp
Normal 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");
|
||||
}
|
||||
};
|
||||
}
|
10
src/dawnosui/game/CMakeLists.txt
Normal file
10
src/dawnosui/game/CMakeLists.txt
Normal 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
|
||||
)
|
69
src/dawnosui/game/DawnPokerGame.cpp
Normal file
69
src/dawnosui/game/DawnPokerGame.cpp
Normal 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() {
|
||||
|
||||
}
|
10
src/dawnosui/game/DawnPokerGame.hpp
Normal file
10
src/dawnosui/game/DawnPokerGame.hpp
Normal 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"
|
9
src/dawnosui/input/InputBinds.hpp
Normal file
9
src/dawnosui/input/InputBinds.hpp
Normal 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)
|
Reference in New Issue
Block a user