Color.
This commit is contained in:
@@ -28,10 +28,12 @@ target_sources(${DAWN_TARGET_NAME}
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(assert)
|
||||
add_subdirectory(asset)
|
||||
add_subdirectory(console)
|
||||
add_subdirectory(display)
|
||||
add_subdirectory(engine)
|
||||
add_subdirectory(input)
|
||||
add_subdirectory(rpg)
|
||||
add_subdirectory(time)
|
||||
|
||||
# Platform-specific settings
|
||||
|
16
src/asset/Asset.cpp
Normal file
16
src/asset/Asset.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright (c) 2025 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Asset.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
Asset::Asset(const std::string &filename) :
|
||||
filename(filename)
|
||||
{
|
||||
}
|
||||
|
||||
Asset::~Asset() {
|
||||
}
|
19
src/asset/Asset.hpp
Normal file
19
src/asset/Asset.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright (c) 2025 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawn.hpp"
|
||||
#include <zip.h>
|
||||
|
||||
namespace Dawn {
|
||||
struct Asset {
|
||||
private:
|
||||
std::string filename;
|
||||
|
||||
public:
|
||||
Asset(const std::string &filename);
|
||||
~Asset();
|
||||
};
|
||||
}
|
21
src/asset/AssetManager.cpp
Normal file
21
src/asset/AssetManager.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) 2025 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "AssetManager.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
AssetManager::AssetManager() :
|
||||
zip(nullptr)
|
||||
{
|
||||
// Find the zip file.
|
||||
}
|
||||
|
||||
AssetManager::~AssetManager() {
|
||||
if(zip) {
|
||||
zip_close(zip);
|
||||
zip = nullptr;
|
||||
}
|
||||
}
|
25
src/asset/AssetManager.hpp
Normal file
25
src/asset/AssetManager.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright (c) 2025 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "Asset.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct AssetManager {
|
||||
private:
|
||||
zip_t *zip;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructor for the Asset manager.
|
||||
*/
|
||||
AssetManager();
|
||||
|
||||
/**
|
||||
* Destructor for the Asset manager.
|
||||
*/
|
||||
~AssetManager();
|
||||
};
|
||||
}
|
11
src/asset/CMakeLists.txt
Normal file
11
src/asset/CMakeLists.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
Asset.cpp
|
||||
AssetManager.cpp
|
||||
)
|
16
src/dawn.hpp
16
src/dawn.hpp
@@ -19,9 +19,15 @@ extern "C" {
|
||||
#include <stdarg.h>
|
||||
#include <float.h>
|
||||
|
||||
// #include <cglm/cglm.h>
|
||||
// #include <cglm/types.h>
|
||||
// #include <cglm/vec2.h>
|
||||
// #include <glm/gtc/matrix_transform.hpp>
|
||||
// #include <glm/gtc/type_ptr.hpp>
|
||||
// #include <glm/gtc/constants.hpp>
|
||||
// #include <glm/gtx/string_cast.hpp>
|
||||
// #include <glm/gtx/rotate_vector.hpp>
|
||||
// #include <glm/gtx/vector_angle.hpp>
|
||||
// #include <glm/gtx/norm.hpp>
|
||||
// #include <glm/gtx/compatibility.hpp>
|
||||
// #include <glm/gtx/color_space.hpp>
|
||||
|
||||
#if PSP
|
||||
#include <pspkernel.h>
|
||||
@@ -53,4 +59,6 @@ extern "C" {
|
||||
#include <array>
|
||||
#include <any>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <sstream>
|
||||
|
||||
#include <glm/glm.hpp>
|
@@ -7,4 +7,8 @@
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
Display.cpp
|
||||
)
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(color)
|
||||
add_subdirectory(mesh)
|
@@ -8,12 +8,19 @@
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
MeshVertex vertices[3] = {
|
||||
{ Color4B::RED, glm::vec2(0.0f, 0.0f), glm::vec3(-0.5f, -0.5f, 0.0f) },
|
||||
{ Color4B::GREEN, glm::vec2(1.0f, 0.0f), glm::vec3(0.5f, -0.5f, 0.0f) },
|
||||
{ Color4B::BLUE, glm::vec2(0.5f, 1.0f), glm::vec3(0.0f, 0.5f, 0.0f) }
|
||||
};
|
||||
|
||||
Display::Display(Engine &engine) :
|
||||
#if DAWN_SDL2
|
||||
glContext(nullptr),
|
||||
window(nullptr),
|
||||
#endif
|
||||
engine(engine)
|
||||
engine(engine),
|
||||
mesh(3, PrimitiveType::Triangles, vertices)
|
||||
{
|
||||
#if DAWN_SDL2
|
||||
uint32_t flags = SDL_INIT_VIDEO;
|
||||
@@ -99,7 +106,17 @@ void Display::update(void) {
|
||||
|
||||
SDL_GL_MakeCurrent(this->window, this->glContext);
|
||||
|
||||
glViewport(0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glClearColor(
|
||||
Color4F::CORNFLOWER_BLUE.r,
|
||||
Color4F::CORNFLOWER_BLUE.g,
|
||||
Color4F::CORNFLOWER_BLUE.b,
|
||||
Color4F::CORNFLOWER_BLUE.a
|
||||
);
|
||||
|
||||
mesh.draw(0, -1);
|
||||
|
||||
// glViewport(0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT);
|
||||
|
||||
SDL_GL_SwapWindow(this->window);
|
||||
#endif
|
||||
|
@@ -6,6 +6,8 @@
|
||||
#pragma once
|
||||
#include "dawn.hpp"
|
||||
|
||||
#include "display/mesh/Mesh.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct Engine;
|
||||
|
||||
@@ -20,6 +22,8 @@ namespace Dawn {
|
||||
public:
|
||||
static constexpr uint32_t DEFAULT_WIDTH = 800;
|
||||
static constexpr uint32_t DEFAULT_HEIGHT = 600;
|
||||
|
||||
Mesh mesh;
|
||||
|
||||
/**
|
||||
* Display constructor
|
||||
|
13
src/display/color/CMakeLists.txt
Normal file
13
src/display/color/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
Color3B.cpp
|
||||
Color4B.cpp
|
||||
Color3F.cpp
|
||||
Color4F.cpp
|
||||
)
|
11
src/display/color/Color.hpp
Normal file
11
src/display/color/Color.hpp
Normal file
@@ -0,0 +1,11 @@
|
||||
// Copyright (c) 2025 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "IColor.hpp"
|
||||
#include "Color3B.hpp"
|
||||
#include "Color3F.hpp"
|
||||
#include "Color4B.hpp"
|
||||
#include "Color4F.hpp"
|
32
src/display/color/Color3B.cpp
Normal file
32
src/display/color/Color3B.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright (c) 2025 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Color.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
Color3B::Color3B(
|
||||
const uint8_t r,
|
||||
const uint8_t g,
|
||||
const uint8_t b
|
||||
) : r(r), g(g), b(b) {
|
||||
// Constructor body (if needed)
|
||||
}
|
||||
|
||||
Color3B Color3B::toColor3B(void) const {
|
||||
return Color3B(r, g, b);
|
||||
}
|
||||
|
||||
Color4B Color3B::toColor4B(void) const {
|
||||
return Color4B(r, g, b, 255);
|
||||
}
|
||||
|
||||
Color3F Color3B::toColor3F(void) const {
|
||||
return Color3F(r / 255.0f, g / 255.0f, b / 255.0f);
|
||||
}
|
||||
|
||||
Color4F Color3B::toColor4F(void) const {
|
||||
return Color4F(r / 255.0f, g / 255.0f, b / 255.0f, 1.0f);
|
||||
}
|
46
src/display/color/Color3B.hpp
Normal file
46
src/display/color/Color3B.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright (c) 2025 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "IColor.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct Color3B : public Color {
|
||||
public:
|
||||
const uint8_t r;
|
||||
const uint8_t g;
|
||||
const uint8_t b;
|
||||
|
||||
/**
|
||||
* Color (RGB, byte) constructor
|
||||
*
|
||||
* @param r Red channel (0-255)
|
||||
* @param g Green channel (0-255)
|
||||
* @param b Blue channel (0-255)
|
||||
*/
|
||||
Color3B(const uint8_t r, const uint8_t g, const uint8_t b);
|
||||
|
||||
/**
|
||||
* Gets this color as a 3-channel byte color.
|
||||
*/
|
||||
Color3B toColor3B(void) const override;
|
||||
|
||||
/**
|
||||
* Gets this color as a 4-channel byte color. Alpha is set to 255.
|
||||
*/
|
||||
Color4B toColor4B(void) const override;
|
||||
|
||||
/**
|
||||
* Gets this color as a 3-channel float color. (0-1 range)
|
||||
*/
|
||||
Color3F toColor3F(void) const override;
|
||||
|
||||
/**
|
||||
* Gets this color as a 4-channel float color. (0-1 range), Alpha is set
|
||||
* to 1.0f
|
||||
*/
|
||||
Color4F toColor4F(void) const override;
|
||||
};
|
||||
}
|
41
src/display/color/Color3F.cpp
Normal file
41
src/display/color/Color3F.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) 2025 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Color.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
Color3F::Color3F(
|
||||
const float_t r,
|
||||
const float_t g,
|
||||
const float_t b
|
||||
) : r(r), g(g), b(b) {
|
||||
}
|
||||
|
||||
Color3B Color3F::toColor3B(void) const {
|
||||
return Color3B(
|
||||
static_cast<uint8_t>(r * 255.0f),
|
||||
static_cast<uint8_t>(g * 255.0f),
|
||||
static_cast<uint8_t>(b * 255.0f)
|
||||
);
|
||||
}
|
||||
|
||||
Color4B Color3F::toColor4B(void) const {
|
||||
return Color4B(
|
||||
static_cast<uint8_t>(r * 255.0f),
|
||||
static_cast<uint8_t>(g * 255.0f),
|
||||
static_cast<uint8_t>(b * 255.0f),
|
||||
255
|
||||
);
|
||||
}
|
||||
|
||||
Color3F Color3F::toColor3F(void) const {
|
||||
return Color3F(r, g, b);
|
||||
}
|
||||
|
||||
Color4F Color3F::toColor4F(void) const {
|
||||
return Color4F(r, g, b, 1.0f);
|
||||
}
|
||||
|
45
src/display/color/Color3F.hpp
Normal file
45
src/display/color/Color3F.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright (c) 2025 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "IColor.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct Color3F : public Color {
|
||||
public:
|
||||
const float_t r;
|
||||
const float_t g;
|
||||
const float_t b;
|
||||
|
||||
/**
|
||||
* Color (RGB, float) constructor
|
||||
*
|
||||
* @param r Red channel (0.0-1.0)
|
||||
* @param g Green channel (0.0-1.0)
|
||||
* @param b Blue channel (0.0-1.0)
|
||||
*/
|
||||
Color3F(const float_t r, const float_t g, const float_t b);
|
||||
|
||||
/**
|
||||
* Gets this color as a 3-channel byte color.
|
||||
*/
|
||||
Color3B toColor3B(void) const override;
|
||||
|
||||
/**
|
||||
* Gets this color as a 4-channel byte color. Alpha is set to 255.
|
||||
*/
|
||||
Color4B toColor4B(void) const override;
|
||||
|
||||
/**
|
||||
* Gets this color as a 3-channel float_t color.
|
||||
*/
|
||||
Color3F toColor3F(void) const override;
|
||||
|
||||
/**
|
||||
* Gets this color as a 4-channel float_t color. Alpha is set to 1.0f
|
||||
*/
|
||||
Color4F toColor4F(void) const override;
|
||||
};
|
||||
}
|
36
src/display/color/Color4B.cpp
Normal file
36
src/display/color/Color4B.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) 2025 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Color.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
const Color4B Color4B::WHITE = Color4B(255, 255, 255, 255);
|
||||
const Color4B Color4B::BLACK = Color4B(0, 0, 0, 255);
|
||||
const Color4B Color4B::RED = Color4B(255, 0, 0, 255);
|
||||
const Color4B Color4B::GREEN = Color4B(0, 255, 0, 255);
|
||||
const Color4B Color4B::BLUE = Color4B(0, 0, 255, 255);
|
||||
const Color4B Color4B::YELLOW = Color4B(255, 255, 0, 255);
|
||||
const Color4B Color4B::CYAN = Color4B(0, 255, 255, 255);
|
||||
const Color4B Color4B::MAGENTA = Color4B(255, 0, 255, 255);
|
||||
const Color4B Color4B::TRANSPARENT = Color4B(0, 0, 0, 0);
|
||||
const Color4B Color4B::CORNFLOWER_BLUE = Color4B(100, 149, 237, 255);
|
||||
|
||||
Color4B::Color4B(
|
||||
const uint8_t r,
|
||||
const uint8_t g,
|
||||
const uint8_t b,
|
||||
const uint8_t a
|
||||
) : Color3B(r, g, b), a(a) {
|
||||
// Constructor body (if needed)
|
||||
}
|
||||
|
||||
Color4B Color4B::toColor4B(void) const {
|
||||
return Color4B(r, g, b, a);
|
||||
}
|
||||
|
||||
Color4F Color4B::toColor4F(void) const {
|
||||
return Color4F(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
|
||||
}
|
50
src/display/color/Color4B.hpp
Normal file
50
src/display/color/Color4B.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
// Copyright (c) 2025 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "Color3B.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct Color4B : public Color3B {
|
||||
public:
|
||||
static const Color4B WHITE;
|
||||
static const Color4B BLACK;
|
||||
static const Color4B RED;
|
||||
static const Color4B GREEN;
|
||||
static const Color4B BLUE;
|
||||
static const Color4B YELLOW;
|
||||
static const Color4B CYAN;
|
||||
static const Color4B MAGENTA;
|
||||
static const Color4B TRANSPARENT;
|
||||
static const Color4B CORNFLOWER_BLUE;
|
||||
|
||||
const uint8_t a;
|
||||
|
||||
/**
|
||||
* Color (RGBA, byte) constructor
|
||||
*
|
||||
* @param r Red channel (0-255)
|
||||
* @param g Green channel (0-255)
|
||||
* @param b Blue channel (0-255)
|
||||
* @param a Alpha channel (0-255)
|
||||
*/
|
||||
Color4B(
|
||||
const uint8_t r,
|
||||
const uint8_t g,
|
||||
const uint8_t b,
|
||||
const uint8_t a
|
||||
);
|
||||
|
||||
/**
|
||||
* Gets this color as a 4-channel byte color.
|
||||
*/
|
||||
Color4B toColor4B(void) const override;
|
||||
|
||||
/**
|
||||
* Gets this color as a 4-channel float color. (0-1 range)
|
||||
*/
|
||||
Color4F toColor4F(void) const override;
|
||||
};
|
||||
}
|
40
src/display/color/Color4F.cpp
Normal file
40
src/display/color/Color4F.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2025 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Color.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
const Color4F Color4F::WHITE = Color4F(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
const Color4F Color4F::BLACK = Color4F(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
const Color4F Color4F::RED = Color4F(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
const Color4F Color4F::GREEN = Color4F(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
const Color4F Color4F::BLUE = Color4F(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
const Color4F Color4F::YELLOW = Color4F(1.0f, 1.0f, 0.0f, 1.0f);
|
||||
const Color4F Color4F::CYAN = Color4F(0.0f, 1.0f, 1.0f, 1.0f);
|
||||
const Color4F Color4F::MAGENTA = Color4F(1.0f, 0.0f, 1.0f, 1.0f);
|
||||
const Color4F Color4F::TRANSPARENT = Color4F(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
const Color4F Color4F::CORNFLOWER_BLUE = Color4F(0.39f, 0.58f, 0.93f, 1.0f);
|
||||
|
||||
Color4F::Color4F(
|
||||
const float_t r,
|
||||
const float_t g,
|
||||
const float_t b,
|
||||
const float_t a
|
||||
) : Color3F(r, g, b), a(a) {
|
||||
}
|
||||
|
||||
Color4B Color4F::toColor4B(void) const {
|
||||
return Color4B(
|
||||
static_cast<uint8_t>(r * 255.0f),
|
||||
static_cast<uint8_t>(g * 255.0f),
|
||||
static_cast<uint8_t>(b * 255.0f),
|
||||
static_cast<uint8_t>(a * 255.0f)
|
||||
);
|
||||
}
|
||||
|
||||
Color4F Color4F::toColor4F(void) const {
|
||||
return Color4F(r, g, b, a);
|
||||
}
|
50
src/display/color/Color4F.hpp
Normal file
50
src/display/color/Color4F.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
// Copyright (c) 2025 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "Color3F.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct Color4F : public Color3F {
|
||||
public:
|
||||
static const Color4F WHITE;
|
||||
static const Color4F BLACK;
|
||||
static const Color4F RED;
|
||||
static const Color4F GREEN;
|
||||
static const Color4F BLUE;
|
||||
static const Color4F YELLOW;
|
||||
static const Color4F CYAN;
|
||||
static const Color4F MAGENTA;
|
||||
static const Color4F TRANSPARENT;
|
||||
static const Color4F CORNFLOWER_BLUE;
|
||||
|
||||
const float_t a;
|
||||
|
||||
/**
|
||||
* Color (RGBA, float) constructor
|
||||
*
|
||||
* @param r Red channel (0.0-1.0)
|
||||
* @param g Green channel (0.0-1.0)
|
||||
* @param b Blue channel (0.0-1.0)
|
||||
* @param a Alpha channel (0.0-1.0)
|
||||
*/
|
||||
Color4F(
|
||||
const float_t r,
|
||||
const float_t g,
|
||||
const float_t b,
|
||||
const float_t a
|
||||
);
|
||||
|
||||
/**
|
||||
* Gets this color as a 4-channel byte color.
|
||||
*/
|
||||
Color4B toColor4B(void) const override;
|
||||
|
||||
/**
|
||||
* Gets this color as a 4-channel float_t color.
|
||||
*/
|
||||
Color4F toColor4F(void) const override;
|
||||
};
|
||||
}
|
37
src/display/color/IColor.hpp
Normal file
37
src/display/color/IColor.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright (c) 2025 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawn.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct Color3B;
|
||||
struct Color4B;
|
||||
struct Color3F;
|
||||
struct Color4F;
|
||||
|
||||
struct Color {
|
||||
public:
|
||||
/**
|
||||
* Gets this color as a 3-channel byte color.
|
||||
*/
|
||||
virtual Color3B toColor3B(void) const = 0;
|
||||
|
||||
/**
|
||||
* Gets this color as a 4-channel byte color.
|
||||
*/
|
||||
virtual Color4B toColor4B(void) const = 0;
|
||||
|
||||
/**
|
||||
* Gets this color as a 3-channel float color. (0-1 range)
|
||||
*/
|
||||
virtual Color3F toColor3F(void) const = 0;
|
||||
|
||||
/**
|
||||
* Gets this color as a 4-channel float color. (0-1 range)
|
||||
*/
|
||||
virtual Color4F toColor4F(void) const = 0;
|
||||
};
|
||||
}
|
10
src/display/mesh/CMakeLists.txt
Normal file
10
src/display/mesh/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
Mesh.cpp
|
||||
)
|
73
src/display/mesh/Mesh.cpp
Normal file
73
src/display/mesh/Mesh.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
// Copyright (c) 2025 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Mesh.hpp"
|
||||
#include "assert/Assert.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
Mesh::Mesh(
|
||||
const int32_t vertexCount,
|
||||
const PrimitiveType primitiveType,
|
||||
const MeshVertex *vertices
|
||||
) :
|
||||
vertexCount(vertexCount),
|
||||
primitiveType(primitiveType),
|
||||
vertices(vertices)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Mesh::draw(
|
||||
int32_t vertexOffset,
|
||||
int32_t vertexCount
|
||||
) const {
|
||||
const int32_t offset = vertexOffset == -1 ? 0 : vertexOffset;
|
||||
const int32_t count = vertexCount == -1 ? this->vertexCount : vertexCount;
|
||||
|
||||
assertNotNull(this->vertices, "Mesh cannot be NULL");
|
||||
assertTrue(offset >= 0, "Vertex offset must be non-negative");
|
||||
assertTrue(count >= 0, "Vertex count must be non-negative");
|
||||
assertTrue(
|
||||
offset + count <= this->vertexCount,
|
||||
"Vertex offset + count must not exceed vertex count"
|
||||
);
|
||||
|
||||
#if DISPLAY_SDL2
|
||||
// PSP style pointer legacy OpenGL
|
||||
const GLsizei stride = sizeof(MeshVertex);
|
||||
|
||||
glColorPointer(
|
||||
MESH_VERTEX_COLOR_SIZE,
|
||||
GL_UNSIGNED_BYTE,
|
||||
stride,
|
||||
(const GLvoid*)&this->vertices[offset].color[0]
|
||||
);
|
||||
|
||||
glTexCoordPointer(
|
||||
MESH_VERTEX_UV_SIZE,
|
||||
GL_FLOAT,
|
||||
stride,
|
||||
(const GLvoid*)&this->vertices[offset].uv[0]
|
||||
);
|
||||
|
||||
glVertexPointer(
|
||||
MESH_VERTEX_POS_SIZE,
|
||||
GL_FLOAT,
|
||||
stride,
|
||||
(const GLvoid*)&this->vertices[offset].pos[0]
|
||||
);
|
||||
|
||||
glDrawArrays(
|
||||
this->primitiveType,
|
||||
0,
|
||||
count
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
Mesh::~Mesh() {
|
||||
|
||||
}
|
56
src/display/mesh/Mesh.hpp
Normal file
56
src/display/mesh/Mesh.hpp
Normal file
@@ -0,0 +1,56 @@
|
||||
// Copyright (c) 2025 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "PrimitiveType.hpp"
|
||||
#include "display/color/Color.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct MeshVertex {
|
||||
public:
|
||||
#if DAWN_SDL2
|
||||
Color4B color;
|
||||
glm::vec2 uv;
|
||||
glm::vec3 position;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct Mesh {
|
||||
private:
|
||||
const int32_t vertexCount;
|
||||
const PrimitiveType primitiveType;
|
||||
const MeshVertex *vertices;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Mesh constructor
|
||||
*
|
||||
* @param vertexCount The number of vertices in the mesh
|
||||
* @param primitiveType The type of primitive to render
|
||||
* @param vertices The vertex data
|
||||
*/
|
||||
Mesh(
|
||||
const int32_t vertexCount,
|
||||
const PrimitiveType primitiveType,
|
||||
const MeshVertex *vertices
|
||||
);
|
||||
|
||||
/**
|
||||
* Draw this mesh.
|
||||
*
|
||||
* @param vertexOffset The offset to start drawing from (default: 0)
|
||||
* @param vertexCount The number of vertices to draw (default: all)
|
||||
*/
|
||||
void draw(
|
||||
int32_t vertexOffset = 0,
|
||||
int32_t vertexCount = -1
|
||||
) const;
|
||||
|
||||
/**
|
||||
* Destructs the mesh.
|
||||
*/
|
||||
~Mesh();
|
||||
};
|
||||
}
|
17
src/display/mesh/PrimitiveType.hpp
Normal file
17
src/display/mesh/PrimitiveType.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright (c) 2025 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawn.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum class PrimitiveType {
|
||||
#if DAWN_SDL2
|
||||
Triangles = GL_TRIANGLES,
|
||||
Lines = GL_LINES,
|
||||
Points = GL_POINTS,
|
||||
#endif
|
||||
};
|
||||
}
|
@@ -8,6 +8,7 @@
|
||||
#include "console/Console.hpp"
|
||||
#include "display/Display.hpp"
|
||||
#include "input/Input.hpp"
|
||||
#include "asset/AssetManager.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct Engine {
|
||||
@@ -21,6 +22,7 @@ namespace Dawn {
|
||||
Console console;
|
||||
Display display;
|
||||
Input input;
|
||||
AssetManager assetManager;
|
||||
|
||||
/**
|
||||
* Constructor for the Dawn engine.
|
||||
|
11
src/rpg/CMakeLists.txt
Normal file
11
src/rpg/CMakeLists.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
)
|
||||
|
||||
# Subdirs
|
Reference in New Issue
Block a user