Fixed whatever was wrong with my shader
This commit is contained in:
@ -43,6 +43,20 @@ void TilesetAsset::updateAsync() {
|
|||||||
this->state = 0x04;
|
this->state = 0x04;
|
||||||
assertTrue(this->tileset.rows > 0);
|
assertTrue(this->tileset.rows > 0);
|
||||||
|
|
||||||
|
strCurrent = strNext+1;
|
||||||
|
strNext = strchr(strCurrent, '|');
|
||||||
|
*strNext = '\0';
|
||||||
|
this->tileset.divX = atoi(strCurrent);
|
||||||
|
this->state = 0x05;
|
||||||
|
assertTrue(this->tileset.rows > 0);
|
||||||
|
|
||||||
|
strCurrent = strNext+1;
|
||||||
|
strNext = strchr(strCurrent, '|');
|
||||||
|
*strNext = '\0';
|
||||||
|
this->tileset.divY = atoi(strCurrent);
|
||||||
|
this->state = 0x06;
|
||||||
|
assertTrue(this->tileset.rows > 0);
|
||||||
|
|
||||||
// Begin reading tiles.
|
// Begin reading tiles.
|
||||||
int32_t done = 0;
|
int32_t done = 0;
|
||||||
int32_t count = this->tileset.columns * this->tileset.rows;
|
int32_t count = this->tileset.columns * this->tileset.rows;
|
||||||
@ -79,7 +93,7 @@ void TilesetAsset::updateAsync() {
|
|||||||
done++;
|
done++;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->state = 0x05;
|
this->state = 0x07;
|
||||||
this->loaded = true;
|
this->loaded = true;
|
||||||
this->eventLoaded.invoke();
|
this->eventLoaded.invoke();
|
||||||
|
|
||||||
|
@ -126,10 +126,6 @@ void RenderPipeline::renderUI(
|
|||||||
|
|
||||||
// Clear / Bind / Update the render target.
|
// Clear / Bind / Update the render target.
|
||||||
renderTarget->bind();
|
renderTarget->bind();
|
||||||
renderTarget->clear(
|
|
||||||
RENDER_TARGET_CLEAR_FLAG_DEPTH |
|
|
||||||
RENDER_TARGET_CLEAR_FLAG_COLOR
|
|
||||||
);
|
|
||||||
this->renderManager->setRenderFlags(
|
this->renderManager->setRenderFlags(
|
||||||
RENDER_MANAGER_RENDER_FLAG_BLEND |
|
RENDER_MANAGER_RENDER_FLAG_BLEND |
|
||||||
RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST
|
RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST
|
||||||
|
@ -16,12 +16,20 @@ namespace Dawn {
|
|||||||
struct Tileset {
|
struct Tileset {
|
||||||
public:
|
public:
|
||||||
std::vector<struct Tile> tiles;
|
std::vector<struct Tile> tiles;
|
||||||
|
|
||||||
|
struct Tile getTile(int32_t tile) {
|
||||||
|
assertTrue(tile >= 0);
|
||||||
|
assertTrue(tile < this->tiles.size());
|
||||||
|
return this->tiles[tile];
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TilesetGrid : public Tileset{
|
struct TilesetGrid : public Tileset{
|
||||||
public:
|
public:
|
||||||
int32_t rows;
|
int32_t rows;
|
||||||
int32_t columns;
|
int32_t columns;
|
||||||
|
int32_t divX;
|
||||||
|
int32_t divY;
|
||||||
|
|
||||||
TilesetGrid() {
|
TilesetGrid() {
|
||||||
|
|
||||||
@ -30,8 +38,8 @@ namespace Dawn {
|
|||||||
TilesetGrid(
|
TilesetGrid(
|
||||||
int32_t columns,
|
int32_t columns,
|
||||||
int32_t rows,
|
int32_t rows,
|
||||||
int32_t width,
|
int32_t w,
|
||||||
int32_t height,
|
int32_t h,
|
||||||
int32_t gapX,
|
int32_t gapX,
|
||||||
int32_t gapY,
|
int32_t gapY,
|
||||||
int32_t borderX,
|
int32_t borderX,
|
||||||
@ -39,49 +47,43 @@ namespace Dawn {
|
|||||||
) {
|
) {
|
||||||
assertTrue(columns >= 1);
|
assertTrue(columns >= 1);
|
||||||
assertTrue(rows >= 1);
|
assertTrue(rows >= 1);
|
||||||
assertTrue(width >= 1);
|
assertTrue(w >= 1);
|
||||||
assertTrue(height >= 1);
|
assertTrue(h >= 1);
|
||||||
assertTrue(gapX >= 0);
|
assertTrue(gapX >= 0);
|
||||||
assertTrue(gapY >= 0);
|
assertTrue(gapY >= 0);
|
||||||
assertTrue(borderX >= 0);
|
assertTrue(borderX >= 0);
|
||||||
assertTrue(borderY >= 0);
|
assertTrue(borderY >= 0);
|
||||||
assertTrue(width >= (columns + (gapX * columns) + borderX + borderX));
|
assertTrue(w >= (columns + (gapX * columns) + borderX + borderX));
|
||||||
assertTrue(height >= (rows + (gapY * rows) + borderY + borderY));
|
assertTrue(h >= (rows + (gapY * rows) + borderY + borderY));
|
||||||
|
|
||||||
this->rows = rows;
|
this->rows = rows;
|
||||||
this->columns = columns;
|
this->columns = columns;
|
||||||
|
|
||||||
// Calculate division sizes (pixels)
|
// Calculate division sizes (pixels)
|
||||||
float_t divX = (
|
this->divX = (w - (borderX * 2.0f) - (gapX * (columns - 1))) / columns;
|
||||||
(float_t)width - ((float_t)borderX * 2.0f) -
|
this->divY = (h - (borderY * 2.0f) - (gapY * (rows - 1))) / rows;
|
||||||
((float_t)gapX * ((float_t)columns - 1))
|
|
||||||
) / columns;
|
|
||||||
float_t divY = (
|
|
||||||
(float_t)height - ((float_t)borderY * 2.0f) -
|
|
||||||
((float_t)gapY * ((float_t)rows - 1))
|
|
||||||
) / rows;
|
|
||||||
|
|
||||||
// Calculate the division sizes (units)
|
// Calculate the division sizes (units)
|
||||||
float_t tdivX = divX / (float_t)width;
|
float_t tdivX = (float_t)this->divX / (float_t)w;
|
||||||
float_t tdivY = divY / (float_t)height;
|
float_t tdivY = (float_t)this->divY / (float_t)h;
|
||||||
|
|
||||||
for(int32_t y = 0; y < rows; y++) {
|
for(int32_t y = 0; y < rows; y++) {
|
||||||
for(int32_t x = 0; x < columns; x++) {
|
for(int32_t x = 0; x < columns; x++) {
|
||||||
struct Tile tile;
|
struct Tile tile;
|
||||||
tile.uv0.x = (borderX + (divX * x) + (gapX * x)) / width;
|
tile.uv0.x = (borderX + ((float_t)this->divX * x) + (gapX * x)) / w;
|
||||||
tile.uv1.x = tile.uv0.x + tdivX;
|
tile.uv1.x = tile.uv0.x + tdivX;
|
||||||
|
|
||||||
tile.uv0.y = (borderY + (divY * y) + (gapY * y)) / height;
|
tile.uv0.y = (borderY + ((float_t)this->divY * y) + (gapY * y)) / h;
|
||||||
tile.uv1.y = tile.uv0.y + tdivY;
|
tile.uv1.y = tile.uv0.y + tdivY;
|
||||||
this->tiles.push_back(tile);
|
this->tiles.push_back(tile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Tile getTile(int32_t row, int32_t column) {
|
struct Tile getTileFromGrid(int32_t row, int32_t column) {
|
||||||
assertTrue(row > 0 && row < this->rows);
|
assertTrue(row > 0 && row < this->rows);
|
||||||
assertTrue(column > 0 && column < this->columns);
|
assertTrue(column > 0 && column < this->columns);
|
||||||
return this->tiles[row + (column * this->rows)];
|
return this->getTile(row + (column * this->rows));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -50,6 +50,33 @@ void QuadMesh::bufferQuadMesh(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QuadMesh::bufferCoordinates(
|
||||||
|
Mesh *mesh,
|
||||||
|
glm::vec2 uv0, glm::vec2 uv1,
|
||||||
|
int32_t verticeStart
|
||||||
|
) {
|
||||||
|
assertNotNull(mesh);
|
||||||
|
mesh->bufferCoordinates(verticeStart, std::array<glm::vec2, QUAD_VERTICE_COUNT>{{
|
||||||
|
uv0, glm::vec2(uv1.x, uv0.y),
|
||||||
|
glm::vec2(uv0.x, uv1.y), uv1
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
void QuadMesh::bufferPositions(
|
||||||
|
Mesh *mesh,
|
||||||
|
glm::vec2 xy0, glm::vec2 xy1,
|
||||||
|
int32_t verticeStart
|
||||||
|
) {
|
||||||
|
mesh->bufferPositions(
|
||||||
|
verticeStart, std::array<glm::vec3, QUAD_VERTICE_COUNT>{{
|
||||||
|
glm::vec3(xy0, 0),
|
||||||
|
glm::vec3(xy1.x, xy0.y, 0),
|
||||||
|
glm::vec3(xy0.x, xy1.y, 0),
|
||||||
|
glm::vec3(xy1, 0)
|
||||||
|
}}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void QuadMesh::initQuadMesh(
|
void QuadMesh::initQuadMesh(
|
||||||
Mesh *mesh,
|
Mesh *mesh,
|
||||||
glm::vec2 xy0, glm::vec2 uv0,
|
glm::vec2 xy0, glm::vec2 uv0,
|
||||||
|
@ -16,7 +16,7 @@ namespace Dawn {
|
|||||||
/**
|
/**
|
||||||
* Buffers the vertices of a quad onto a primitive.
|
* Buffers the vertices of a quad onto a primitive.
|
||||||
*
|
*
|
||||||
* @param primitive The primitive to buffer to.
|
* @param mesh The primitive to buffer to.
|
||||||
* @param xy0 The lower X and Y coordinate.
|
* @param xy0 The lower X and Y coordinate.
|
||||||
* @param uv0 The lower Xand Y texture coordinate.
|
* @param uv0 The lower Xand Y texture coordinate.
|
||||||
* @param xy1 The higher X and Y coordinate.
|
* @param xy1 The higher X and Y coordinate.
|
||||||
@ -35,7 +35,7 @@ namespace Dawn {
|
|||||||
/**
|
/**
|
||||||
* Buffers the vertices of a quad onto a primitive.
|
* Buffers the vertices of a quad onto a primitive.
|
||||||
*
|
*
|
||||||
* @param primitive The primitive to buffer to.
|
* @param mesh The primitive to buffer to.
|
||||||
* @param xy0 The lower X and Y coordinate.
|
* @param xy0 The lower X and Y coordinate.
|
||||||
* @param uv0 The lower Xand Y texture coordinate.
|
* @param uv0 The lower Xand Y texture coordinate.
|
||||||
* @param xy1 The higher X and Y coordinate.
|
* @param xy1 The higher X and Y coordinate.
|
||||||
@ -50,6 +50,44 @@ namespace Dawn {
|
|||||||
int32_t verticeStart, int32_t indiceStart
|
int32_t verticeStart, int32_t indiceStart
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Buffers texture coordinates on to an already initialized quad mesh.
|
||||||
|
*
|
||||||
|
* @param mesh Mesh to buffer the texture coordinates on to.
|
||||||
|
* @param uv0 Lower X and Y coordinates.
|
||||||
|
* @param uv1 Upper X and Y coordinates.
|
||||||
|
* @param verticeStart Start vertice to buffer in to.
|
||||||
|
*/
|
||||||
|
static void bufferCoordinates(
|
||||||
|
Mesh *mesh,
|
||||||
|
glm::vec2 uv0, glm::vec2 uv1,
|
||||||
|
int32_t verticeStart
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Buffers the positions of a quad onto a primitive.
|
||||||
|
*
|
||||||
|
* @param mesh The primitive to buffer to.
|
||||||
|
* @param xy0 The lower X and Y coordinate.
|
||||||
|
* @param xy1 The higher X and Y coordinate.
|
||||||
|
* @param verticeStart Start vertice to buffer to.
|
||||||
|
*/
|
||||||
|
static void bufferPositions(
|
||||||
|
Mesh *mesh,
|
||||||
|
glm::vec2 xy0, glm::vec2 xy1,
|
||||||
|
int32_t verticeStart
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes a mesh to be a single quad.
|
||||||
|
*
|
||||||
|
* @param mesh The primitive to buffer to.
|
||||||
|
* @param xy0 The lower X and Y coordinate.
|
||||||
|
* @param uv0 The lower Xand Y texture coordinate.
|
||||||
|
* @param xy1 The higher X and Y coordinate.
|
||||||
|
* @param uv1 The higher X and Y texture coordinate.
|
||||||
|
* @param z The Z position of the coordinates.
|
||||||
|
*/
|
||||||
static void initQuadMesh(
|
static void initQuadMesh(
|
||||||
Mesh *mesh,
|
Mesh *mesh,
|
||||||
glm::vec2 xy0, glm::vec2 uv0,
|
glm::vec2 xy0, glm::vec2 uv0,
|
||||||
|
@ -36,8 +36,8 @@ void SceneItem::init() {
|
|||||||
auto it2 = deps.begin();
|
auto it2 = deps.begin();
|
||||||
while(it2 != deps.end()) {
|
while(it2 != deps.end()) {
|
||||||
if(*it2 == nullptr) {
|
if(*it2 == nullptr) {
|
||||||
continue;
|
|
||||||
++it2;
|
++it2;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Has the dep not yet inited?
|
// Has the dep not yet inited?
|
||||||
|
@ -5,4 +5,5 @@
|
|||||||
|
|
||||||
# Subdirs
|
# Subdirs
|
||||||
add_subdirectory(display)
|
add_subdirectory(display)
|
||||||
|
add_subdirectory(example)
|
||||||
add_subdirectory(ui)
|
add_subdirectory(ui)
|
@ -10,4 +10,6 @@
|
|||||||
#include "scene/components/display/Material.hpp"
|
#include "scene/components/display/Material.hpp"
|
||||||
#include "scene/components/display/TiledSprite.hpp"
|
#include "scene/components/display/TiledSprite.hpp"
|
||||||
|
|
||||||
|
#include "scene/components/example/ExampleSpin.hpp"
|
||||||
|
|
||||||
#include "scene/components/ui/UICanvas.hpp"
|
#include "scene/components/ui/UICanvas.hpp"
|
@ -12,7 +12,7 @@ namespace Dawn {
|
|||||||
|
|
||||||
class Material : public SceneItemComponent {
|
class Material : public SceneItemComponent {
|
||||||
private:
|
private:
|
||||||
Shader *shader;
|
Shader *shader = nullptr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal method that will be invoked to go through and update all of
|
* Internal method that will be invoked to go through and update all of
|
||||||
|
@ -14,15 +14,14 @@ MeshRenderer::MeshRenderer(SceneItem *item) : SceneItemComponent(item) {
|
|||||||
|
|
||||||
std::vector<SceneItemComponent*> MeshRenderer::getDependencies() {
|
std::vector<SceneItemComponent*> MeshRenderer::getDependencies() {
|
||||||
return std::vector<SceneItemComponent*>{
|
return std::vector<SceneItemComponent*>{
|
||||||
this->item->getComponent<MeshHost>()
|
this->meshHost = this->item->getComponent<MeshHost>()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshRenderer::onStart() {
|
void MeshRenderer::onStart() {
|
||||||
SceneItemComponent::onStart();
|
SceneItemComponent::onStart();
|
||||||
|
|
||||||
if(mesh == nullptr) {
|
if(this->mesh == nullptr && this->meshHost != nullptr) {
|
||||||
auto host = this->item->getComponent<MeshHost>();
|
this->mesh = &this->meshHost->mesh;
|
||||||
if(host != nullptr) this->mesh = &host->mesh;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,7 +8,12 @@
|
|||||||
#include "display/mesh/Mesh.hpp"
|
#include "display/mesh/Mesh.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
|
class MeshHost;
|
||||||
|
|
||||||
class MeshRenderer : public SceneItemComponent {
|
class MeshRenderer : public SceneItemComponent {
|
||||||
|
protected:
|
||||||
|
MeshHost *meshHost = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Mesh * mesh = nullptr;
|
Mesh * mesh = nullptr;
|
||||||
|
|
||||||
|
@ -12,6 +12,52 @@ TiledSprite::TiledSprite(SceneItem *item) : SceneItemComponent(item) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::vec2 TiledSprite::getUV0() {
|
||||||
|
auto tile = this->tileset->getTile(tileIndex);
|
||||||
|
return glm::vec2(
|
||||||
|
(this->flipState & TILED_SPRITE_FLIP_X) == 0 ? tile.uv0.x : tile.uv1.x,
|
||||||
|
(this->flipState & TILED_SPRITE_FLIP_Y) == 0 ? tile.uv0.y : tile.uv1.y
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec2 TiledSprite::getUV1() {
|
||||||
|
auto tile = this->tileset->getTile(tileIndex);
|
||||||
|
return glm::vec2(
|
||||||
|
(this->flipState & TILED_SPRITE_FLIP_X) == 0 ? tile.uv1.x : tile.uv0.x,
|
||||||
|
(this->flipState & TILED_SPRITE_FLIP_Y) == 0 ? tile.uv1.y : tile.uv0.y
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TiledSprite::setTileset(Tileset *tileset) {
|
||||||
|
assertNotNull(tileset);
|
||||||
|
this->tileset = tileset;
|
||||||
|
this->setTile(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TiledSprite::setTile(int32_t tileIndex) {
|
||||||
|
assertNotNull(this->tileset);
|
||||||
|
this->tileIndex = tileIndex;
|
||||||
|
if(this->host != nullptr) {
|
||||||
|
QuadMesh::bufferCoordinates(
|
||||||
|
&this->host->mesh, this->getUV0(), this->getUV1(), 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TiledSprite::setSize(glm::vec2 size, glm::vec2 center) {
|
||||||
|
this->xy0 = -center;
|
||||||
|
this->xy1 = size - center;
|
||||||
|
if(this->host != nullptr) {
|
||||||
|
QuadMesh::bufferPositions(
|
||||||
|
&this->host->mesh, this->xy0, this->xy1, 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TiledSprite::setSize(glm::vec2 size) {
|
||||||
|
this->setSize(size, size / 2.0f);
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<SceneItemComponent*> TiledSprite::getDependencies() {
|
std::vector<SceneItemComponent*> TiledSprite::getDependencies() {
|
||||||
this->renderer = this->item->getComponent<MeshRenderer>();
|
this->renderer = this->item->getComponent<MeshRenderer>();
|
||||||
this->host = this->item->getComponent<MeshHost>();
|
this->host = this->item->getComponent<MeshHost>();
|
||||||
@ -24,12 +70,12 @@ std::vector<SceneItemComponent*> TiledSprite::getDependencies() {
|
|||||||
|
|
||||||
void TiledSprite::onStart() {
|
void TiledSprite::onStart() {
|
||||||
SceneItemComponent::onStart();
|
SceneItemComponent::onStart();
|
||||||
|
|
||||||
assertNotNull(this->host);
|
assertNotNull(this->host);
|
||||||
|
assertNotNull(this->tileset);
|
||||||
|
|
||||||
QuadMesh::initQuadMesh(&this->host->mesh,
|
QuadMesh::initQuadMesh(&this->host->mesh,
|
||||||
glm::vec2(0, 0), glm::vec2(0, 0),
|
this->xy0, this->getUV0(),
|
||||||
glm::vec2(1, 1), glm::vec2(0.125f, 0.125f),
|
this->xy1, this->getUV1(),
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
}
|
}
|
@ -10,15 +10,32 @@
|
|||||||
#include "display/mesh/QuadMesh.hpp"
|
#include "display/mesh/QuadMesh.hpp"
|
||||||
#include "display/Tileset.hpp"
|
#include "display/Tileset.hpp"
|
||||||
|
|
||||||
|
#define TILED_SPRITE_FLIP_Y FLAG_DEFINE(0)
|
||||||
|
#define TILED_SPRITE_FLIP_X FLAG_DEFINE(1)
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class TiledSprite : public SceneItemComponent {
|
class TiledSprite : public SceneItemComponent {
|
||||||
protected:
|
protected:
|
||||||
MeshRenderer *renderer;
|
MeshRenderer *renderer = nullptr;
|
||||||
MeshHost *host;
|
MeshHost *host = nullptr;
|
||||||
|
Tileset *tileset = nullptr;
|
||||||
|
flag_t flipState = TILED_SPRITE_FLIP_Y;
|
||||||
|
int32_t tileIndex;
|
||||||
|
glm::vec2 xy0 = glm::vec2(0, 0);
|
||||||
|
glm::vec2 xy1 = glm::vec2(1, 1);
|
||||||
|
|
||||||
|
glm::vec2 getUV0();
|
||||||
|
glm::vec2 getUV1();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TiledSprite(SceneItem *item);
|
TiledSprite(SceneItem *item);
|
||||||
|
|
||||||
|
void setTileset(Tileset *tileset);
|
||||||
|
void setTile(int32_t tile);
|
||||||
|
void setFlippedState(flag_t flippedState);
|
||||||
|
void setSize(glm::vec2 size, glm::vec2 center);
|
||||||
|
void setSize(glm::vec2 size);
|
||||||
|
|
||||||
std::vector<SceneItemComponent*> getDependencies() override;
|
std::vector<SceneItemComponent*> getDependencies() override;
|
||||||
void onStart() override;
|
void onStart() override;
|
||||||
};
|
};
|
||||||
|
10
src/dawn/scene/components/example/CMakeLists.txt
Normal file
10
src/dawn/scene/components/example/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
|
||||||
|
ExampleSpin.cpp
|
||||||
|
)
|
44
src/dawn/scene/components/example/ExampleSpin.cpp
Normal file
44
src/dawn/scene/components/example/ExampleSpin.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// Copyright (c) 2022 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#include "ExampleSpin.hpp"
|
||||||
|
#include "scene/Scene.hpp"
|
||||||
|
#include "game/DawnGame.hpp"
|
||||||
|
#include "scene/components/display/MeshRenderer.hpp"
|
||||||
|
#include "display/mesh/CubeMesh.hpp"
|
||||||
|
|
||||||
|
using namespace Dawn;
|
||||||
|
|
||||||
|
SceneItem * ExampleSpin::create(Scene *scene) {
|
||||||
|
auto item = scene->createSceneItem();
|
||||||
|
auto mr = item->addComponent<MeshRenderer>();
|
||||||
|
mr->mesh = new Mesh();
|
||||||
|
mr->mesh->createBuffers(CUBE_VERTICE_COUNT, CUBE_INDICE_COUNT);
|
||||||
|
CubeMesh::buffer(mr->mesh, glm::vec3(-0.5f, -0.5f, -0.5f), glm::vec3(1, 1, 1), 0, 0);
|
||||||
|
auto mat = item->addComponent<Material>();
|
||||||
|
item->addComponent<ExampleSpin>();
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
ExampleSpin::ExampleSpin(SceneItem *item) :
|
||||||
|
SceneItemComponent(item)
|
||||||
|
{
|
||||||
|
getScene()->eventSceneUnpausedUpdate.addListener(this, &ExampleSpin::onUnpausedUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ExampleSpin::onUnpausedUpdate() {
|
||||||
|
auto quat = this->transform->getLocalRotation();
|
||||||
|
quat = glm::rotate(quat, getGame()->timeManager.delta, glm::vec3(0, 1, 0));
|
||||||
|
quat = glm::rotate(quat, getGame()->timeManager.delta / 2.0f, glm::vec3(1, 0, 0));
|
||||||
|
quat = glm::rotate(quat, getGame()->timeManager.delta / 4.0f, glm::vec3(0, 0, 1));
|
||||||
|
|
||||||
|
this->transform->setLocalRotation(quat);
|
||||||
|
}
|
||||||
|
|
||||||
|
ExampleSpin::~ExampleSpin() {
|
||||||
|
getScene()->eventSceneUnpausedUpdate.removeListener(this, &ExampleSpin::onUnpausedUpdate);
|
||||||
|
}
|
19
src/dawn/scene/components/example/ExampleSpin.hpp
Normal file
19
src/dawn/scene/components/example/ExampleSpin.hpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (c) 2022 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "scene/SceneItemComponent.hpp"
|
||||||
|
#include "display/shader/Shader.hpp"
|
||||||
|
|
||||||
|
namespace Dawn {
|
||||||
|
class ExampleSpin : public SceneItemComponent {
|
||||||
|
public:
|
||||||
|
static SceneItem * create(Scene *scene);
|
||||||
|
|
||||||
|
ExampleSpin(SceneItem *item);
|
||||||
|
void onUnpausedUpdate();
|
||||||
|
~ExampleSpin();
|
||||||
|
};
|
||||||
|
}
|
@ -30,6 +30,7 @@ namespace Dawn {
|
|||||||
|
|
||||||
void setDefaultParameters(Material *material) override {
|
void setDefaultParameters(Material *material) override {
|
||||||
material->colorValues[this->paramColor] = COLOR_WHITE;
|
material->colorValues[this->paramColor] = COLOR_WHITE;
|
||||||
|
material->textureValues[this->paramTexture] = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setGlobalParameters(glm::mat4 proj, glm::mat4 view) override {
|
void setGlobalParameters(glm::mat4 proj, glm::mat4 view) override {
|
||||||
@ -45,12 +46,12 @@ namespace Dawn {
|
|||||||
shaderparameter_t param,
|
shaderparameter_t param,
|
||||||
Texture *texture
|
Texture *texture
|
||||||
) override {
|
) override {
|
||||||
if(texture == nullptr) {
|
if(texture == nullptr || !texture->isReady()) {
|
||||||
this->setBoolean(this->paramHasTexture, false);
|
this->setBoolean(this->paramHasTexture, false);
|
||||||
} else {
|
} else {
|
||||||
this->setBoolean(this->paramHasTexture, true);
|
this->setBoolean(this->paramHasTexture, true);
|
||||||
this->setTextureSlot(param, 0x00);
|
this->setTextureSlot(param, 0x01);
|
||||||
texture->bind(0x00);
|
texture->bind(0x01);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,11 +74,11 @@ namespace Dawn {
|
|||||||
|
|
||||||
// Fragment Shader
|
// Fragment Shader
|
||||||
"#version 330 core\n"
|
"#version 330 core\n"
|
||||||
"out vec4 o_Color;\n"
|
|
||||||
"in vec2 o_TextCoord;\n"
|
"in vec2 o_TextCoord;\n"
|
||||||
|
"out vec4 o_Color;\n"
|
||||||
"uniform vec4 u_Color;\n"
|
"uniform vec4 u_Color;\n"
|
||||||
"uniform sampler2D u_Text;\n"
|
|
||||||
"uniform bool u_HasTexture;\n"
|
"uniform bool u_HasTexture;\n"
|
||||||
|
"uniform sampler2D u_Text;\n"
|
||||||
|
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
"if(u_HasTexture) {\n"
|
"if(u_HasTexture) {\n"
|
||||||
|
@ -30,6 +30,7 @@ namespace Dawn {
|
|||||||
|
|
||||||
void setDefaultParameters(Material *material) override {
|
void setDefaultParameters(Material *material) override {
|
||||||
material->colorValues[this->paramColor] = COLOR_WHITE;
|
material->colorValues[this->paramColor] = COLOR_WHITE;
|
||||||
|
material->textureValues[this->paramTexture] = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setGlobalParameters(glm::mat4 proj, glm::mat4 view) override {
|
void setGlobalParameters(glm::mat4 proj, glm::mat4 view) override {
|
||||||
@ -73,11 +74,11 @@ namespace Dawn {
|
|||||||
|
|
||||||
// Fragment Shader
|
// Fragment Shader
|
||||||
"#version 330 core\n"
|
"#version 330 core\n"
|
||||||
"out vec4 o_Color;\n"
|
|
||||||
"in vec2 o_TextCoord;\n"
|
"in vec2 o_TextCoord;\n"
|
||||||
|
"out vec4 o_Color;\n"
|
||||||
"uniform vec4 u_Color;\n"
|
"uniform vec4 u_Color;\n"
|
||||||
"uniform sampler2D u_Text;\n"
|
|
||||||
"uniform bool u_HasTexture;\n"
|
"uniform bool u_HasTexture;\n"
|
||||||
|
"uniform sampler2D u_Text;\n"
|
||||||
|
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
"if(u_HasTexture) {\n"
|
"if(u_HasTexture) {\n"
|
||||||
@ -98,7 +99,6 @@ namespace Dawn {
|
|||||||
this->setBoolean(this->paramHasTexture, false);
|
this->setBoolean(this->paramHasTexture, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void setUICamera(glm::mat4 view, glm::mat4 projection) {
|
void setUICamera(glm::mat4 view, glm::mat4 projection) {
|
||||||
this->setMatrix(this->paramView, view);
|
this->setMatrix(this->paramView, view);
|
||||||
this->setMatrix(this->paramProjection, projection);
|
this->setMatrix(this->paramProjection, projection);
|
||||||
|
@ -22,9 +22,17 @@ namespace Dawn {
|
|||||||
auto item = scene->createSceneItem();
|
auto item = scene->createSceneItem();
|
||||||
|
|
||||||
auto meshRenderer = item->addComponent<MeshRenderer>();
|
auto meshRenderer = item->addComponent<MeshRenderer>();
|
||||||
|
|
||||||
auto material = item->addComponent<Material>();
|
auto material = item->addComponent<Material>();
|
||||||
|
auto asset = scene->game->assetManager.get<TextureAsset>("texture_penny");
|
||||||
|
auto param = material->getShader()->getParameterByName("u_Text");
|
||||||
|
material->textureValues[param] = &asset->texture;
|
||||||
|
|
||||||
auto meshHost = item->addComponent<MeshHost>();
|
auto meshHost = item->addComponent<MeshHost>();
|
||||||
auto tiledSprite = item->addComponent<TiledSprite>();
|
auto tiledSprite = item->addComponent<TiledSprite>();
|
||||||
|
tiledSprite->setTileset(&scene->game->assetManager.get<TilesetAsset>("tileset_penny")->tileset);
|
||||||
|
tiledSprite->setSize(glm::vec2(2, 2));
|
||||||
|
|
||||||
auto pokerPlayer = item->addComponent<PokerPlayer>();
|
auto pokerPlayer = item->addComponent<PokerPlayer>();
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
|
@ -39,8 +39,8 @@ namespace Dawn {
|
|||||||
void stage() override {
|
void stage() override {
|
||||||
// Camera
|
// Camera
|
||||||
auto camera = Camera::create(this);
|
auto camera = Camera::create(this);
|
||||||
camera->transform->lookAt(glm::vec3(50, 50, 50), glm::vec3(0, 0, 0));
|
camera->transform->lookAt(glm::vec3(3, 3, 3), glm::vec3(0, 0, 0));
|
||||||
|
|
||||||
// UI
|
// UI
|
||||||
auto canvas = UICanvas::createCanvas(this);
|
auto canvas = UICanvas::createCanvas(this);
|
||||||
auto textbox = PokerGameTextbox::create(canvas);
|
auto textbox = PokerGameTextbox::create(canvas);
|
||||||
|
@ -105,31 +105,25 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate division sizes (pixels)
|
// Calculate division sizes (pixels)
|
||||||
float divX = (
|
int divX = (w - (borderX * 2) - (gapX * (cols - 1))) / cols;
|
||||||
(float)w - ((float)borderX * 2.0f) -
|
int divY = (h - (borderY * 2) - (gapY * (rows - 1))) / rows;
|
||||||
((float)gapX * ((float)cols - 1))
|
|
||||||
) / cols;
|
|
||||||
float divY = (
|
|
||||||
(float)h - ((float)borderY * 2.0f) -
|
|
||||||
((float)gapY * ((float)rows - 1))
|
|
||||||
) / rows;
|
|
||||||
|
|
||||||
// Calculate the division sizes (units)
|
// Calculate the division sizes (units)
|
||||||
float tdivX = divX / (float)w;
|
float tdivX = (float)divX / (float)w;
|
||||||
float tdivY = divY / (float)h;
|
float tdivY = (float)divY / (float)h;
|
||||||
|
|
||||||
// Output buffer prep
|
// Output buffer prep
|
||||||
char *buffer = malloc(sizeof(char) * (cols * rows * 48 + 48 + 48));
|
char *buffer = malloc(sizeof(char) * (cols * rows * 48 + 48 + 48));
|
||||||
buffer[0] = '\0';
|
buffer[0] = '\0';
|
||||||
|
|
||||||
sprintf(buffer, "%i|%i|", cols, rows);
|
sprintf(buffer, "%i|%i|%i|%i|", cols, rows, divX, divY);
|
||||||
|
|
||||||
// Now prep tileset.
|
// Now prep tileset.
|
||||||
for(int y = 0; y < rows; y++) {
|
for(int y = 0; y < rows; y++) {
|
||||||
for(int x = 0; x < cols; x++) {
|
for(int x = 0; x < cols; x++) {
|
||||||
float ux0 = (borderX + (divX * x) + (gapX * x)) / w;
|
float ux0 = (borderX + ((float)divX * x) + ((float)gapX * x)) / w;
|
||||||
float ux1 = ux0 + tdivX;
|
float ux1 = ux0 + tdivX;
|
||||||
float uy0 = (borderY + (divY * y) + (gapY * y)) / h;
|
float uy0 = (borderY + ((float)divY * y) + ((float)gapY * y)) / h;
|
||||||
float uy1 = uy0 + tdivY;
|
float uy1 = uy0 + tdivY;
|
||||||
sprintf(buffer, "%s%f,%f,%f,%f|", buffer, ux0, ux1, uy0, uy1);
|
sprintf(buffer, "%s%f,%f,%f,%f|", buffer, ux0, ux1, uy0, uy1);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user