aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/build.sh7
-rw-r--r--src/crepe/CMakeLists.txt3
-rw-r--r--src/crepe/api/AudioSource.cpp2
-rw-r--r--src/crepe/api/CMakeLists.txt1
-rw-r--r--src/crepe/api/Color.cpp53
-rw-r--r--src/crepe/api/Color.h34
-rw-r--r--src/crepe/api/Point.h14
-rw-r--r--src/crepe/api/Sprite.h28
-rw-r--r--src/crepe/api/Transform.h13
-rw-r--r--src/crepe/api/baseResource.h11
-rw-r--r--src/crepe/api/game.cpp30
-rw-r--r--src/crepe/api/game.h17
-rw-r--r--src/crepe/api/map_asset.cpp12
-rw-r--r--src/crepe/api/map_asset.h14
-rw-r--r--src/crepe/api/resource_manager.cpp25
-rw-r--r--src/crepe/api/resource_manager.h57
-rw-r--r--src/crepe/api/spritesheet.cpp38
-rw-r--r--src/crepe/api/spritesheet.h34
-rw-r--r--src/crepe/core/CMakeLists.txt8
-rw-r--r--src/crepe/core/renderSystem.cpp37
-rw-r--r--src/crepe/core/renderSystem.h13
-rw-r--r--src/crepe/fabricator/CMakeLists.txt8
-rw-r--r--src/crepe/fabricator/resource_fabricator.cpp26
-rw-r--r--src/crepe/fabricator/resource_fabricator.h29
-rw-r--r--src/crepe/facade/CMakeLists.txt13
-rw-r--r--src/crepe/facade/SdlContext.cpp213
-rw-r--r--src/crepe/facade/SdlContext.h43
-rw-r--r--src/crepe/facade/Sound.cpp (renamed from src/crepe/Sound.cpp)0
-rw-r--r--src/crepe/facade/Sound.h (renamed from src/crepe/Sound.h)2
-rw-r--r--src/crepe/facade/SoundContext.cpp (renamed from src/crepe/SoundContext.cpp)0
-rw-r--r--src/crepe/facade/SoundContext.h (renamed from src/crepe/SoundContext.h)0
-rw-r--r--src/crepe/facade/Texture.cpp39
-rw-r--r--src/crepe/facade/Texture.h31
-rw-r--r--src/crepe/facade/touch0
-rw-r--r--src/dummy_rendering.cpp19
-rw-r--r--src/dummy_resource_manager.cpp38
36 files changed, 909 insertions, 3 deletions
diff --git a/src/build.sh b/src/build.sh
new file mode 100755
index 0000000..e987bc1
--- /dev/null
+++ b/src/build.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+# creates the build dir and runs CMake with Ninja
+cmake -B build -G Ninja
+
+# build the project
+cmake --build build \ No newline at end of file
diff --git a/src/crepe/CMakeLists.txt b/src/crepe/CMakeLists.txt
index d85aef0..addb9dd 100644
--- a/src/crepe/CMakeLists.txt
+++ b/src/crepe/CMakeLists.txt
@@ -30,4 +30,7 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES
add_subdirectory(api)
add_subdirectory(util)
+add_subdirectory(fabricator)
+add_subdirectory(facade)
+add_subdirectory(core)
diff --git a/src/crepe/api/AudioSource.cpp b/src/crepe/api/AudioSource.cpp
index b512d27..a5b6d6a 100644
--- a/src/crepe/api/AudioSource.cpp
+++ b/src/crepe/api/AudioSource.cpp
@@ -1,6 +1,6 @@
#include "AudioSource.h"
-#include "../Sound.h"
+#include "facade/Sound.h"
#include <memory>
using namespace crepe::api;
diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt
index 86623de..cecc2f1 100644
--- a/src/crepe/api/CMakeLists.txt
+++ b/src/crepe/api/CMakeLists.txt
@@ -7,4 +7,3 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES
# AudioSource.h
BehaviorScript.h
)
-
diff --git a/src/crepe/api/Color.cpp b/src/crepe/api/Color.cpp
new file mode 100644
index 0000000..c73ce6c
--- /dev/null
+++ b/src/crepe/api/Color.cpp
@@ -0,0 +1,53 @@
+
+
+#include "Color.h"
+
+
+using namespace crepe::api;
+
+Color Color::white = Color(255,255,255,0);
+Color Color::red = Color(255,0,0,0);
+Color Color::green = Color(0,255,0,0);
+Color Color::blue = Color(0,0,255,0);
+Color Color::black = Color(0,0,0,0);
+Color Color::cyan = Color(0,255,255,0);
+Color Color::yellow = Color(255,255,0,0);
+Color Color::magenta= Color(255,0,255,0);
+
+Color::Color(double red, double green, double blue, double alpha){
+ this->a = alpha;
+ this->r = red;
+ this->g = green;
+ this->b = blue;
+};
+
+const Color& Color::get_white(){
+ return Color::white;
+};
+
+const Color& Color::get_red(){
+ return Color::red;
+};
+const Color& Color::get_green(){
+ return Color::green;
+};
+const Color& Color::get_blue(){
+ return Color::blue;
+};
+
+const Color& Color::get_black(){
+ return Color::black;
+};
+
+const Color& Color::get_cyan(){
+ return Color::cyan;
+};
+
+const Color& Color::get_yellow(){
+ return Color::yellow;
+};
+
+const Color& Color::get_magenta(){
+ return Color::magenta;
+};
+
diff --git a/src/crepe/api/Color.h b/src/crepe/api/Color.h
new file mode 100644
index 0000000..207434e
--- /dev/null
+++ b/src/crepe/api/Color.h
@@ -0,0 +1,34 @@
+#pragma once
+
+namespace crepe::api {
+
+class Color {
+
+public:
+ Color(double red, double green, double blue, double alpha);
+ static const Color & get_white();
+ static const Color & get_red();
+ static const Color & get_green();
+ static const Color & get_blue();
+ static const Color & get_cyan();
+ static const Color & get_magenta();
+ static const Color & get_yellow();
+ static const Color & get_black();
+
+private:
+ double r;
+ double g;
+ double b;
+ double a;
+
+ static Color white;
+ static Color red;
+ static Color green;
+ static Color blue;
+ static Color cyan;
+ static Color magenta;
+ static Color yellow;
+ static Color black;
+};
+
+} // namespace crepe::api
diff --git a/src/crepe/api/Point.h b/src/crepe/api/Point.h
new file mode 100644
index 0000000..463aa7c
--- /dev/null
+++ b/src/crepe/api/Point.h
@@ -0,0 +1,14 @@
+#pragma once
+
+
+
+namespace crepe::api {
+
+class Point {
+public:
+ double x;
+ double y;
+};
+
+
+}
diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h
new file mode 100644
index 0000000..84eeb83
--- /dev/null
+++ b/src/crepe/api/Sprite.h
@@ -0,0 +1,28 @@
+#pragma once
+
+#include "Component.h"
+#include "api/Color.h"
+#include "facade/Texture.h"
+#include <cstdint>
+
+
+namespace crepe::api {
+
+struct flip_settings{
+ bool flipX : 1;
+ bool flipY : 1;
+};
+class Sprite : public Component {
+
+public:
+ Sprite(crepe::Texture& image, const Color& color, const flip_settings& flip ) : sprite_image(&image), color(color), flip(flip){}
+ crepe::Texture* sprite_image;
+ Color color;
+ flip_settings flip;
+ uint8_t sortingLayer;
+ uint8_t orderInLayer;
+
+
+};
+
+}
diff --git a/src/crepe/api/Transform.h b/src/crepe/api/Transform.h
new file mode 100644
index 0000000..d4dfafc
--- /dev/null
+++ b/src/crepe/api/Transform.h
@@ -0,0 +1,13 @@
+#pragma once
+
+#include "api/Component.h"
+#include "api/Point.h"
+namespace crepe::api {
+
+class Transform : public Component {
+public:
+ Point position; // Translation (shift)
+ double rotation; // Rotation, in radians
+ double scale; // Multiplication factoh
+};
+} // namespace crepe::api
diff --git a/src/crepe/api/baseResource.h b/src/crepe/api/baseResource.h
new file mode 100644
index 0000000..2513f4d
--- /dev/null
+++ b/src/crepe/api/baseResource.h
@@ -0,0 +1,11 @@
+#pragma once
+
+namespace crepe::api {
+
+class BaseResource {
+public:
+ virtual ~BaseResource() = default;
+};
+
+}
+
diff --git a/src/crepe/api/game.cpp b/src/crepe/api/game.cpp
new file mode 100644
index 0000000..01920a9
--- /dev/null
+++ b/src/crepe/api/game.cpp
@@ -0,0 +1,30 @@
+
+
+
+#include "game.h"
+#include "core/renderSystem.h"
+#include "facade/SdlContext.h"
+
+
+Engine::Engine(int windowHeight, int window_with){
+ crepe::SdlContext& ctx = crepe::SdlContext::get_instance();
+}
+
+
+
+void Engine::loop() {
+
+ bool running = true;
+ crepe::SdlContext& ctx = crepe::SdlContext::get_instance();
+ RenderSystem rendering;
+
+ while (running) {
+ ctx.handleEvents(running);
+
+ ctx.clearScreen();
+
+ rendering.render();
+
+ ctx.presentScreen();
+ }
+}
diff --git a/src/crepe/api/game.h b/src/crepe/api/game.h
new file mode 100644
index 0000000..64027fa
--- /dev/null
+++ b/src/crepe/api/game.h
@@ -0,0 +1,17 @@
+#pragma once
+
+
+
+class Engine{
+
+public:
+ Engine(int windowWith, int windowHeight);
+ ~Engine() = default;
+
+ void loop();
+
+
+private:
+ int window_height;
+ int window_width;
+};
diff --git a/src/crepe/api/map_asset.cpp b/src/crepe/api/map_asset.cpp
new file mode 100644
index 0000000..bbabe2b
--- /dev/null
+++ b/src/crepe/api/map_asset.cpp
@@ -0,0 +1,12 @@
+
+
+
+
+#include "map_asset.h"
+
+Map::Map(const std::string& content){
+ this->m_content = content;
+}
+
+Map::~Map(){
+}
diff --git a/src/crepe/api/map_asset.h b/src/crepe/api/map_asset.h
new file mode 100644
index 0000000..a4f3df7
--- /dev/null
+++ b/src/crepe/api/map_asset.h
@@ -0,0 +1,14 @@
+#pragma once
+
+#include "Resource.h"
+#include <string>
+
+
+using namespace crepe::api;
+
+class Map : public Resource {
+
+public:
+ Map(const std::string& );
+ ~Map();
+};
diff --git a/src/crepe/api/resource_manager.cpp b/src/crepe/api/resource_manager.cpp
new file mode 100644
index 0000000..0ecdae5
--- /dev/null
+++ b/src/crepe/api/resource_manager.cpp
@@ -0,0 +1,25 @@
+
+
+#include "resource_manager.h"
+#include <string>
+#include <unordered_map>
+
+using namespace crepe::api;
+
+ResourceManager& ResourceManager::get_instance(){
+ static ResourceManager instance;
+ return instance;
+}
+
+
+ResourceManager::~ResourceManager(){
+ m_resources.clear();
+}
+
+
+void ResourceManager::Unload(const std::string& file_path){
+ if(m_resources.find(file_path) != m_resources.end()){
+ m_resources.erase(file_path);
+ }
+}
+
diff --git a/src/crepe/api/resource_manager.h b/src/crepe/api/resource_manager.h
new file mode 100644
index 0000000..a646d95
--- /dev/null
+++ b/src/crepe/api/resource_manager.h
@@ -0,0 +1,57 @@
+#pragma once
+
+
+
+#include <memory>
+#include <string>
+#include <unordered_map>
+#include <utility>
+
+#include "api/baseResource.h"
+
+
+namespace crepe::api{
+
+class ResourceManager{
+
+
+private:
+
+ std::unordered_map< std::string, std::unique_ptr<BaseResource>> m_resources;
+
+
+protected:
+ ResourceManager() = default;
+ ~ResourceManager();
+
+public:
+ ResourceManager(const ResourceManager &) = delete;
+ ResourceManager(ResourceManager &&) = delete;
+ ResourceManager &operator=(const ResourceManager &) = delete;
+ ResourceManager &operator=(ResourceManager &&) = delete;
+
+ static ResourceManager& get_instance();
+
+
+
+public:
+ template<typename T>
+ T* Load(const std::string& file_path){
+
+ if (m_resources.find(file_path) != m_resources.end()) {
+ return static_cast<T*>(m_resources[file_path].get());
+ }
+
+ auto resource = std::make_unique<T>(file_path.c_str());
+ if (resource) {
+ m_resources[file_path] = std::move(resource);
+ return static_cast<T*>(m_resources[file_path].get() );
+ }
+
+ return nullptr;
+ }
+
+ void Unload(const std::string& file_path);
+
+};
+}
diff --git a/src/crepe/api/spritesheet.cpp b/src/crepe/api/spritesheet.cpp
new file mode 100644
index 0000000..7f5da38
--- /dev/null
+++ b/src/crepe/api/spritesheet.cpp
@@ -0,0 +1,38 @@
+
+
+#include "spritesheet.h"
+#include "SDL_rect.h"
+#include "SDL_render.h"
+#include "api/Resource.h"
+#include "facade/SdlContext.h"
+#include <memory>
+
+
+using namespace crepe::api;
+
+Spritesheet::Spritesheet(const char* src, const int row, const int col){
+ this->load(std::make_unique<api::Resource>(src), row, col);
+}
+
+Spritesheet::Spritesheet(std::unique_ptr<api::Resource> res, const int row, const int col){
+ this->load(std::move(res), row, col);
+}
+
+Spritesheet::~Spritesheet(){
+
+ if (this->m_spritesheet) {
+ SDL_DestroyTexture(this->m_spritesheet);
+ }
+}
+
+void Spritesheet::select_sprite(const int x, const int y){
+ m_clip.x = x * m_clip.w;
+ m_clip.y = y * m_clip.h;
+}
+
+void Spritesheet::load(std::unique_ptr<api::Resource> res, const int row, const int col){
+ auto& ctx = SdlContext::get_instance();
+
+ this->m_spritesheet = ctx.setTextureFromPath(res->canonical(), this->m_clip, row, col);
+}
+
diff --git a/src/crepe/api/spritesheet.h b/src/crepe/api/spritesheet.h
new file mode 100644
index 0000000..503dcef
--- /dev/null
+++ b/src/crepe/api/spritesheet.h
@@ -0,0 +1,34 @@
+#pragma once
+
+
+
+
+#include "Resource.h"
+#include "SDL_rect.h"
+#include "SDL_render.h"
+#include <memory>
+
+
+namespace crepe::api {
+
+class Spritesheet{
+
+public:
+ Spritesheet(const char * src, const int row , const int col);
+ Spritesheet(std::unique_ptr<api::Resource> res, const int row, const int col);
+ ~Spritesheet();
+
+ void select_sprite(const int x, const int y);
+ void draw_selected_sprite(const int x, const int y);
+private:
+ void load(std::unique_ptr<api::Resource> res, const int row, const int col);;
+ SDL_Texture* get_texture() const;
+
+private:
+
+ SDL_Texture* m_spritesheet;
+ SDL_Rect m_clip;
+};
+
+}
+
diff --git a/src/crepe/core/CMakeLists.txt b/src/crepe/core/CMakeLists.txt
new file mode 100644
index 0000000..c44f0f6
--- /dev/null
+++ b/src/crepe/core/CMakeLists.txt
@@ -0,0 +1,8 @@
+target_sources(crepe PUBLIC
+ renderSystem.cpp
+)
+
+target_sources(crepe PUBLIC FILE_SET HEADERS FILES
+ renderSystem.h
+)
+
diff --git a/src/crepe/core/renderSystem.cpp b/src/crepe/core/renderSystem.cpp
new file mode 100644
index 0000000..a06aeba
--- /dev/null
+++ b/src/crepe/core/renderSystem.cpp
@@ -0,0 +1,37 @@
+
+
+
+#include "renderSystem.h"
+#include <vector>
+
+#include "api/Color.h"
+#include "api/Sprite.h"
+#include "api/Transform.h"
+#include "facade/SdlContext.h"
+#include "facade/Texture.h"
+
+using namespace crepe::api;
+
+
+static crepe::Texture player("../asset/texture/img.png");
+
+
+void RenderSystem::render(){
+
+ Sprite sprite(player, Color::get_red(), {1,1});
+ Transform transform ={
+ .position = {0,0},
+ .rotation = 0,
+ .scale = 1,
+ };
+
+ // this will get changed to ecs getter of componets
+ crepe::SdlContext& ctx = crepe::SdlContext::get_instance();
+
+ ctx.draw(sprite, transform);
+ /*
+ for(const auto& S : test_objects){
+ ctx.draw(S, const api::Transform &)
+ }
+ */
+}
diff --git a/src/crepe/core/renderSystem.h b/src/crepe/core/renderSystem.h
new file mode 100644
index 0000000..9011b30
--- /dev/null
+++ b/src/crepe/core/renderSystem.h
@@ -0,0 +1,13 @@
+
+#pragma once
+
+
+
+class RenderSystem {
+
+public:
+ RenderSystem() = default;
+ ~RenderSystem() = default;
+
+ void render();
+};
diff --git a/src/crepe/fabricator/CMakeLists.txt b/src/crepe/fabricator/CMakeLists.txt
new file mode 100644
index 0000000..4fd7eea
--- /dev/null
+++ b/src/crepe/fabricator/CMakeLists.txt
@@ -0,0 +1,8 @@
+target_sources(crepe PUBLIC
+ resource_fabricator.cpp
+)
+
+target_sources(crepe PUBLIC FILE_SET HEADERS FILES
+ resource_fabricator.h
+)
+
diff --git a/src/crepe/fabricator/resource_fabricator.cpp b/src/crepe/fabricator/resource_fabricator.cpp
new file mode 100644
index 0000000..0633a40
--- /dev/null
+++ b/src/crepe/fabricator/resource_fabricator.cpp
@@ -0,0 +1,26 @@
+
+
+#include "resource_fabricator.h"
+#include <fstream>
+#include <iostream>
+#include <string>
+#include <vector>
+
+
+
+
+std::string ResourceFactory::convert_file_to_string(const std::string& path){
+ std::ifstream file(path, std::ios::binary | std::ios::ate);
+ if (!file.is_open()) {
+ std::cerr << "Failed to open file: " << path << std::endl;
+ return "";
+ }
+
+ std::ifstream::pos_type fileSize = file.tellg();
+ file.seekg(0, std::ios::beg);
+
+ std::vector<char> bytes(fileSize);
+ file.read(bytes.data(), fileSize);
+
+ return std::string(bytes.begin(), bytes.end());
+}
diff --git a/src/crepe/fabricator/resource_fabricator.h b/src/crepe/fabricator/resource_fabricator.h
new file mode 100644
index 0000000..2b0030d
--- /dev/null
+++ b/src/crepe/fabricator/resource_fabricator.h
@@ -0,0 +1,29 @@
+#pragma once
+
+
+
+#include "api/Resource.h"
+#include <memory>
+#include <string>
+
+
+
+
+class ResourceFactory {
+
+public:
+
+ template<typename T>
+ static std::unique_ptr<crepe::api::Resource> create_resource(const std::string& file_path){
+
+ return std::make_unique<T>(convert_file_to_string(file_path));
+ }
+
+private:
+ static std::string convert_file_to_string(const std::string& path);
+
+};
+
+
+
+
diff --git a/src/crepe/facade/CMakeLists.txt b/src/crepe/facade/CMakeLists.txt
new file mode 100644
index 0000000..1263683
--- /dev/null
+++ b/src/crepe/facade/CMakeLists.txt
@@ -0,0 +1,13 @@
+target_sources(crepe PUBLIC
+ Sound.cpp
+ SoundContext.cpp
+ Texture.cpp
+ SdlContext.cpp
+)
+
+target_sources(crepe PUBLIC FILE_SET HEADERS FILES
+ Sound.h
+ SoundContext.h
+ Texture.h
+ SdlContext.h
+)
diff --git a/src/crepe/facade/SdlContext.cpp b/src/crepe/facade/SdlContext.cpp
new file mode 100644
index 0000000..44d1bdf
--- /dev/null
+++ b/src/crepe/facade/SdlContext.cpp
@@ -0,0 +1,213 @@
+
+
+#include "SdlContext.h"
+#include "SDL_hints.h"
+#include "SDL_rect.h"
+#include "SDL_stdinc.h"
+#include "api/Sprite.h"
+#include "api/Transform.h"
+#include "facade/Texture.h"
+#include "util/log.h"
+#include <SDL2/SDL.h>
+#include <SDL2/SDL_image.h>
+#include <SDL2/SDL_render.h>
+#include <SDL2/SDL_surface.h>
+#include <SDL2/SDL_video.h>
+#include <cstddef>
+#include <iostream>
+#include <ostream>
+
+using namespace crepe;
+
+SdlContext & SdlContext::get_instance() {
+ static SdlContext instance;
+ return instance;
+}
+
+void SdlContext::handleEvents(bool & running) {
+ SDL_Event event;
+ while (SDL_PollEvent(&event)) {
+ if (event.type == SDL_QUIT) {
+ running = false;
+ }
+ }
+}
+void SdlContext::clearScreen() { SDL_RenderClear(this->m_game_renderer); }
+
+void SdlContext::presentScreen() { SDL_RenderPresent(this->m_game_renderer); }
+
+void SdlContext::draw(const api::Sprite & sprite,
+ const api::Transform & transform) {
+ static SDL_RendererFlip renderFlip
+ = (SDL_RendererFlip) ((SDL_FLIP_HORIZONTAL * sprite.flip.flipX)
+ | (SDL_FLIP_VERTICAL * sprite.flip.flipY));
+
+ // needs maybe camera for position
+ static SDL_Rect dstrect = {
+ .x = static_cast<int>(transform.position.x),
+ .y = static_cast<int>(transform.position.y),
+ .w
+ = static_cast<int>(sprite.sprite_image->get_rect().w * transform.scale),
+ .h
+ = static_cast<int>(sprite.sprite_image->get_rect().h * transform.scale),
+ };
+
+ SDL_RenderCopyEx(this->m_game_renderer, sprite.sprite_image->get_texture(),
+ &sprite.sprite_image->get_rect(), &dstrect, 0, NULL,
+ renderFlip);
+}
+
+SdlContext::SdlContext() {
+ if (SDL_Init(SDL_INIT_VIDEO) < 0) {
+ std::cerr << "SDL could not initialize! SDL_Error: " << SDL_GetError()
+ << std::endl;
+ return;
+ }
+
+ m_game_window = SDL_CreateWindow(
+ "Crepe Game Engine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
+ 1920, 1080, SDL_WINDOW_SHOWN);
+ if (!m_game_window) {
+ std::cerr << "Window could not be created! SDL_Error: "
+ << SDL_GetError() << std::endl;
+ }
+
+ m_game_renderer
+ = SDL_CreateRenderer(m_game_window, -1, SDL_RENDERER_ACCELERATED);
+ if (!m_game_renderer) {
+ std::cerr << "Renderer could not be created! SDL_Error: "
+ << SDL_GetError() << std::endl;
+ SDL_DestroyWindow(m_game_window);
+ return;
+ }
+ int imgFlags = IMG_INIT_PNG;
+ if (!(IMG_Init(imgFlags) & imgFlags)) {
+ std::cout << "SDL_image could not initialize! SDL_image Error: "
+ << IMG_GetError() << std::endl;
+ }
+
+ SDL_SetHint(SDL_HINT_RENDER_BATCHING, "1");
+ SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");
+ //SDL_SetHint(SDL_HINT_RENDER_OPENGL_SHADERS, "1");
+ SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, "X");
+
+
+
+
+ const char * hint = SDL_GetHint(SDL_HINT_RENDER_BATCHING);
+ if (hint != NULL) {
+ std::cout << "SDL_HINT_RENDER_BATCHING: " << hint << std::endl;
+ }
+
+ hint = SDL_GetHint(SDL_HINT_RENDER_DRIVER);
+ if (hint != NULL) {
+ std::cout << "SDL_HINT_RENDER_DRIVER: " << hint << std::endl;
+ }
+
+ hint = SDL_GetHint(SDL_HINT_RENDER_OPENGL_SHADERS);
+ if (hint != NULL) {
+ std::cout << "SDL_HINT_RENDER_OPENGL_SHADERS: " << hint << std::endl;
+ }
+
+ hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
+ if (hint != NULL) {
+ std::cout << "SDL_HINT_RENDER_SCALE_QUALITY: " << hint << std::endl;
+ }
+
+ hint = SDL_GetHint(SDL_HINT_RENDER_VSYNC);
+ if (hint != NULL) {
+ std::cout << "SDL_HINT_RENDER_VSYNC: " << hint << std::endl;
+ }
+
+ hint = SDL_GetHint(SDL_HINT_TIMER_RESOLUTION);
+ if (hint != NULL) {
+ std::cout << "SDL_HINT_TIMER_RESOLUTION: " << hint << std::endl;
+ }
+
+ hint = SDL_GetHint(SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT);
+ if (hint != NULL) {
+ std::cout << "SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT: " << hint
+ << std::endl;
+ }
+
+ hint = SDL_GetHint(SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN);
+ if (hint != NULL) {
+ std::cout << "SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN: "
+ << hint << std::endl;
+ }
+
+ hint = SDL_GetHint(SDL_HINT_RENDER_LOGICAL_SIZE_MODE);
+ if (hint != NULL) {
+ std::cout << "SDL_HINT_RENDER_LOGICAL_SIZE_MODE: " << hint << std::endl;
+ }
+
+ hint = SDL_GetHint(SDL_HINT_VIDEO_DOUBLE_BUFFER);
+ if (hint != NULL) {
+ std::cout << "SDL_HINT_VIDEO_DOUBLE_BUFFER: " << hint << std::endl;
+ }
+
+ hint = SDL_GetHint(SDL_HINT_OPENGL_ES_DRIVER);
+ if (hint != NULL) {
+ std::cout << "SDL_HINT_OPENGL_ES_DRIVER: " << hint << std::endl;
+ }
+
+ hint = SDL_GetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION);
+ if (hint != NULL) {
+ std::cout << "SDL_HINT_FRAMEBUFFER_ACCELERATION: " << hint << std::endl;
+ }
+
+ std::cout << "HALLO " << std::endl;
+}
+
+SdlContext::~SdlContext() {
+ if (m_game_renderer) SDL_DestroyRenderer(m_game_renderer);
+
+ if (m_game_window) {
+ SDL_DestroyWindow(m_game_window);
+ }
+ IMG_Quit();
+ SDL_Quit();
+}
+
+SDL_Texture * SdlContext::setTextureFromPath(const char * path, SDL_Rect & clip,
+ const int row, const int col) {
+ dbg_trace();
+
+ SDL_Surface * tmp = IMG_Load(path);
+ if (!tmp) {
+ std::cerr << "Error surface " << IMG_GetError << std::endl;
+ }
+
+ clip.w = tmp->w / col;
+ clip.h = tmp->h / row;
+
+ SDL_Texture * CreatedTexture
+ = SDL_CreateTextureFromSurface(m_game_renderer, tmp);
+
+ if (!CreatedTexture) {
+ std::cerr << "Error could not create texture " << IMG_GetError
+ << std::endl;
+ }
+ SDL_FreeSurface(tmp);
+
+ return CreatedTexture;
+}
+
+SDL_Texture * SdlContext::setTextureFromPath(const char * path) {
+ dbg_trace();
+
+ SDL_Surface * tmp = IMG_Load(path);
+ if (!tmp) {
+ std::cerr << "Error surface " << IMG_GetError << std::endl;
+ }
+ SDL_Texture * CreatedTexture
+ = SDL_CreateTextureFromSurface(m_game_renderer, tmp);
+
+ if (!CreatedTexture) {
+ std::cerr << "Error could not create texture " << IMG_GetError
+ << std::endl;
+ }
+ SDL_FreeSurface(tmp);
+
+ return CreatedTexture;
+}
diff --git a/src/crepe/facade/SdlContext.h b/src/crepe/facade/SdlContext.h
new file mode 100644
index 0000000..c8f1304
--- /dev/null
+++ b/src/crepe/facade/SdlContext.h
@@ -0,0 +1,43 @@
+#pragma once
+
+#include "SDL_rect.h"
+#include "api/Sprite.h"
+#include "api/Transform.h"
+#include <SDL2/SDL_render.h>
+#include <SDL2/SDL_video.h>
+
+namespace crepe {
+
+
+class SdlContext {
+
+public:
+
+ void handleEvents(bool& running);
+ void clearScreen();
+ void presentScreen();
+ void draw(const api::Sprite&, const api::Transform&);
+
+ // singleton
+ static SdlContext & get_instance();
+ SDL_Texture* setTextureFromPath(const char*);
+ SDL_Texture* setTextureFromPath(const char*, SDL_Rect& clip, const int row, const int col);
+
+private:
+ SdlContext();
+ virtual ~SdlContext();
+
+ SdlContext(const SdlContext &) = delete;
+ SdlContext(SdlContext &&) = delete;
+ SdlContext & operator=(const SdlContext &) = delete;
+ SdlContext & operator=(SdlContext &&) = delete;
+
+
+private:
+
+ SDL_Window* m_game_window;
+ SDL_Renderer* m_game_renderer;
+};
+
+} //
+
diff --git a/src/crepe/Sound.cpp b/src/crepe/facade/Sound.cpp
index 64fa281..64fa281 100644
--- a/src/crepe/Sound.cpp
+++ b/src/crepe/facade/Sound.cpp
diff --git a/src/crepe/Sound.h b/src/crepe/facade/Sound.h
index b7cfbb8..b11f871 100644
--- a/src/crepe/Sound.h
+++ b/src/crepe/facade/Sound.h
@@ -9,7 +9,7 @@
namespace crepe {
-class Sound {
+class Sound{
public:
/**
* \brief Pause this sample
diff --git a/src/crepe/SoundContext.cpp b/src/crepe/facade/SoundContext.cpp
index 72047d2..72047d2 100644
--- a/src/crepe/SoundContext.cpp
+++ b/src/crepe/facade/SoundContext.cpp
diff --git a/src/crepe/SoundContext.h b/src/crepe/facade/SoundContext.h
index d3123d2..d3123d2 100644
--- a/src/crepe/SoundContext.h
+++ b/src/crepe/facade/SoundContext.h
diff --git a/src/crepe/facade/Texture.cpp b/src/crepe/facade/Texture.cpp
new file mode 100644
index 0000000..b4e3aa8
--- /dev/null
+++ b/src/crepe/facade/Texture.cpp
@@ -0,0 +1,39 @@
+
+
+#include "util/log.h"
+
+#include "Texture.h"
+#include "SdlContext.h"
+#include <SDL2/SDL_render.h>
+
+using namespace crepe;
+
+Texture::Texture(std::unique_ptr<api::Resource> res) {
+ dbg_trace();
+ this->load(std::move(res));
+}
+
+Texture::Texture(const char * src) {
+ dbg_trace();
+ this->load(std::make_unique<api::Resource>(src));
+}
+
+Texture::~Texture(){
+ dbg_trace();
+ if(this->m_texture){
+ SDL_DestroyTexture(m_texture);
+ }
+}
+void Texture::load(std::unique_ptr<api::Resource> res) {
+ dbg_trace();
+ SdlContext& ctx = SdlContext::get_instance();
+ m_texture = ctx.setTextureFromPath(res->canonical(), srcrect, 1, 1);
+}
+
+SDL_Texture* Texture::get_texture() const{
+ return m_texture;
+}
+
+SDL_Rect& Texture::get_rect() {
+ return srcrect;
+}
diff --git a/src/crepe/facade/Texture.h b/src/crepe/facade/Texture.h
new file mode 100644
index 0000000..db2f1f9
--- /dev/null
+++ b/src/crepe/facade/Texture.h
@@ -0,0 +1,31 @@
+#pragma once
+
+#include "SDL_rect.h"
+#include "api/baseResource.h"
+#include "api/Resource.h"
+#include <SDL2/SDL_render.h>
+#include <memory>
+
+namespace crepe {
+
+
+
+class Texture : public api::BaseResource{
+
+public:
+ Texture(const char * src);
+ Texture(std::unique_ptr<api::Resource> res);
+ ~Texture();
+
+ SDL_Texture* get_texture() const;
+ SDL_Rect& get_rect() ;
+private:
+ void load(std::unique_ptr<api::Resource> res);
+
+private:
+ SDL_Texture* m_texture;
+ SDL_Rect srcrect;
+};
+
+} // namespace crepe
+
diff --git a/src/crepe/facade/touch b/src/crepe/facade/touch
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/crepe/facade/touch
diff --git a/src/dummy_rendering.cpp b/src/dummy_rendering.cpp
new file mode 100644
index 0000000..e00ab7f
--- /dev/null
+++ b/src/dummy_rendering.cpp
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+#include "api/game.h"
+#include <SDL2/SDL_hints.h>
+int main(){
+
+
+
+ Engine engine(800,600);
+
+ // engine.loop();
+
+}
diff --git a/src/dummy_resource_manager.cpp b/src/dummy_resource_manager.cpp
new file mode 100644
index 0000000..bb0b7af
--- /dev/null
+++ b/src/dummy_resource_manager.cpp
@@ -0,0 +1,38 @@
+
+
+
+
+#include "api/game.h"
+#include "api/resource_manager.h"
+#include "api/spritesheet.h"
+#include "facade/Texture.h"
+#include "util/log.h"
+#include <vector>
+
+using namespace crepe;
+
+int main(){
+
+
+ dbg_trace();
+
+ // get instance of resource manager
+ //api::ResourceManager& c_ResMan = api::ResourceManager::get_instance();
+
+
+ game engine;
+
+ api::ResourceManager& c_ResMan = api::ResourceManager::get_instance();
+
+ auto test = c_ResMan.Load<Texture>("../asset/texture/img.png");
+
+ auto img = Texture("../asset/texture/img.png");
+
+ auto SS = api::Spritesheet("../asset/spritesheet/spritesheet_test.png", 1 , 4);
+
+ std::vector<Texture*> t = {test};
+ std::vector<api::Spritesheet*> s = {&SS};
+
+ engine.render(t, s);
+
+}