Texture shenanigans

This commit is contained in:
Tulpen 2023-05-30 17:00:39 +01:00
parent 9c76df4faa
commit eedca45463
13 changed files with 9143 additions and 14 deletions

View file

@ -1,3 +1,5 @@
#pragma once #pragma once
#define HIBIS_VERSION "@version@" namespace hibis {
#define HIBIS_VERSION "@version@"
}

View file

@ -3,7 +3,7 @@
// TODO: pragma // TODO: pragma
#define PRAGMA(x) _Pragma(#x) #define PRAGMA(x) _Pragma(#x)
#define MESSAGE(x) PRAGMA(message(x)) #define MESSAGE(x) PRAGMA(message x)
#define TODO(x) PRAGMA(message("TODO: " x)) #define TODO(x) PRAGMA(message "TODO: " x)
#define WARNING(x) PRAGMA(GCC warning x) #define WARNING(x) PRAGMA(GCC warning x)
#define ERROR(x) PRAGMA(GCC error x) #define ERROR(x) PRAGMA(GCC error x)

View file

@ -2,6 +2,7 @@
#include "../math/types.hpp" #include "../math/types.hpp"
#include "../resources/resource.hpp" #include "../resources/resource.hpp"
#include "../resources/texture.hpp"
#include <string> #include <string>
namespace hibis { namespace hibis {
@ -12,6 +13,7 @@ namespace hibis {
virtual void renderCurrent() = 0; virtual void renderCurrent() = 0;
virtual void drawText(Resource* resource, std::string text, IntVec2 pos, Color color) = 0; virtual void drawText(Resource* resource, std::string text, IntVec2 pos, Color color) = 0;
virtual void drawTexture(Texture* resource, float scale, IntVec2 pos) = 0;
// Pre and Post draw // Pre and Post draw
virtual void preDraw() = 0; virtual void preDraw() = 0;

View file

@ -0,0 +1,20 @@
#include "texture.hpp"
namespace hibis {
Texture::Texture(char* path) : mData(), mImageWidth(0), mImageHeight(0), mBuffer() {
unsigned int error = lodepng::load_file(mBuffer, path);
if (error) {
TODO("error message")
return;
}
error = lodepng::decode(mData, mImageWidth, mImageHeight, mBuffer);
if (error) {
TODO("error message")
return;
}
}
Texture::~Texture() {}
}

View file

@ -1,11 +1,21 @@
#pragma once #pragma once
#include <vector>
#include <lodepng/lodepng.h>
#include "resource.hpp" #include "resource.hpp"
#include "../pragmautil.hpp" #include "../pragmautil.hpp"
namespace hibis { namespace hibis {
TODO("Make this function") TODO("Make this function")
class Texture : Resource { class Texture : Resource {
void* mData; public:
Texture(char* path);
~Texture();
std::vector<unsigned char> mData;
unsigned int mImageWidth, mImageHeight;
private:
std::vector<unsigned char> mBuffer;
}; };
} }

1
external/.kdev_ignore vendored Normal file
View file

@ -0,0 +1 @@
ignore

1
external/CImg vendored Submodule

@ -0,0 +1 @@
Subproject commit 63e1732c18305951a8a25d1d78138cce31da8c9c

6991
external/lodepng/lodepng.cpp vendored Normal file

File diff suppressed because it is too large Load diff

2089
external/lodepng/lodepng.h vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -8,11 +8,12 @@ confdata.set('version', meson.project_version())
configure_file(input: 'core/enginever.in.hpp', output: 'enginever.hpp', configuration: confdata) configure_file(input: 'core/enginever.in.hpp', output: 'enginever.hpp', configuration: confdata)
# Include Directory # Include Directory
include_dirs = [] # include_directories('./include') include_dirs = include_directories('./external')
# Files # Files
libhibis_src_core = files('core/engine/engine.cpp') libhibis_src_core = files('core/engine/engine.cpp')
libhibis_src = [libhibis_src_core] libhibis_src_resources = files('core/resources/texture.cpp')
libhibis_src = [libhibis_src_core, libhibis_src_resources]
libhibis_rsdl_src = files('renderer/rsdl/rsdl.cpp', 'renderer/rsdl/resources/font.cpp') libhibis_rsdl_src = files('renderer/rsdl/rsdl.cpp', 'renderer/rsdl/resources/font.cpp')
libhibis_test_src = files('test/app.cpp') libhibis_test_src = files('test/app.cpp')
@ -21,8 +22,9 @@ libhibis_test_src = files('test/app.cpp')
libsdl2 = dependency('SDL2') libsdl2 = dependency('SDL2')
libsdl2_ttf = dependency('SDL2_ttf') libsdl2_ttf = dependency('SDL2_ttf')
libfmt = dependency('fmt') libfmt = dependency('fmt')
liblodepng = static_library('lodepng', 'external/lodepng/lodepng.cpp')
# Compile # Compile
libhibis = library('hibis', libhibis_src, include_directories: include_dirs) libhibis = library('hibis', libhibis_src, include_directories: include_dirs, link_with: liblodepng)
libhibis_rsdl = library('hibis_rsdl', libhibis_rsdl_src, include_directories: [include_dirs, './core'], link_with: libhibis, dependencies: [libsdl2, libsdl2_ttf, libfmt]) libhibis_rsdl = library('hibis_rsdl', libhibis_rsdl_src, include_directories: [include_dirs, './core'], link_with: libhibis, dependencies: [libsdl2, libsdl2_ttf, libfmt])
hibistest = executable('hibistest.exec', libhibis_test_src, include_directories: [include_dirs, './core', './renderer/rsdl'], link_with: [libhibis, libhibis_rsdl], dependencies: [libsdl2, libsdl2_ttf, libfmt]) hibistest = executable('hibistest.exec', libhibis_test_src, include_directories: [include_dirs, './core', './renderer/rsdl'], link_with: [libhibis, libhibis_rsdl], dependencies: [libsdl2, libsdl2_ttf, libfmt])

View file

@ -77,6 +77,13 @@ namespace hibis::rsdl {
} }
} }
void RSDL::drawTexture(Texture* resource, float scale, hibis::IntVec2 pos) {
if (resource->mData.empty()) return;
TODO("this nonsense")
return;
}
void RSDL::preDraw() {} void RSDL::preDraw() {}
void RSDL::postDraw() {} void RSDL::postDraw() {}

View file

@ -19,18 +19,19 @@ namespace hibis::rsdl {
~RSDL(); ~RSDL();
void clearScreen(Color col = Color {0, 0, 0, 255}); void clearScreen(Color col = Color {0, 0, 0, 255}) override;
void renderCurrent(); void renderCurrent() override;
void drawText(Resource* resource, std::string text, IntVec2 pos, Color color); void drawText(Resource* resource, std::string text, IntVec2 pos, Color color) override;
void drawTexture(Texture* resource, float scale, hibis::IntVec2 pos) override;
void preDraw(); void preDraw() override;
void postDraw(); void postDraw() override;
void update(); void update() override;
void setWindowTitle(std::string title); void setWindowTitle(std::string title) override;
private: private:
SDL_Window* mWindow; SDL_Window* mWindow;

View file

@ -53,6 +53,8 @@ int main() {
Font font = Font("/usr/share/fonts/noto/NotoSans-Light.ttf", 16); Font font = Font("/usr/share/fonts/noto/NotoSans-Light.ttf", 16);
#endif #endif
Texture image = Texture((char*)"test.png");
unsigned char red = 0; unsigned char red = 0;
bool increaseRed = true; bool increaseRed = true;
bool increaseSize = true; bool increaseSize = true;
@ -84,6 +86,7 @@ int main() {
// Clear screen then sleep for ~16ms // Clear screen then sleep for ~16ms
renderer.clearScreen(Color {red, 0, 0, 255}); renderer.clearScreen(Color {red, 0, 0, 255});
renderer.drawText(&font, "Testing Text", IntVec2 {0, 0}, Color {255, 255, 255, 255}); renderer.drawText(&font, "Testing Text", IntVec2 {0, 0}, Color {255, 255, 255, 255});
renderer.drawTexture(&image, 1.0f, IntVec2 {10, 10});
engine.drawNodes(); engine.drawNodes();
renderer.renderCurrent(); renderer.renderCurrent();