mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-12 07:03:34 +00:00
working textures
This commit is contained in:
@@ -6,11 +6,12 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
|
||||
/* Updated: 2022/12/19 00:40:17 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/04/01 15:34:00 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "application.h"
|
||||
#include <renderer/images/texture.h>
|
||||
|
||||
namespace mlx::core
|
||||
{
|
||||
@@ -29,4 +30,29 @@ namespace mlx::core
|
||||
win->endFrame();
|
||||
}
|
||||
}
|
||||
|
||||
void* Application::new_stb_texture(char* file, int* w, int* h)
|
||||
{
|
||||
std::shared_ptr<Texture> texture = std::make_shared<Texture>(stb_texture_load(file, w, h));
|
||||
TextureID id = _texture_lib.addTextureToLibrary(texture);
|
||||
_texture_ids.push_back(id);
|
||||
return &_texture_ids.back();
|
||||
}
|
||||
|
||||
void Application::texture_put(void* win, void* img, int x, int y)
|
||||
{
|
||||
std::shared_ptr<Texture> texture = _texture_lib.getTexture(*static_cast<TextureID*>(img));
|
||||
_wins[*static_cast<int*>(win)]->texture_put(texture, x, y);
|
||||
}
|
||||
|
||||
void Application::destroy_texture(void* ptr)
|
||||
{
|
||||
TextureID id = *static_cast<TextureID*>(ptr);
|
||||
_texture_lib.removeTextureFromLibrary(id);
|
||||
}
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
_texture_lib.clearLibrary();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
|
||||
/* Updated: 2022/12/18 23:10:17 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/04/01 14:46:14 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#include <platform/inputs.h>
|
||||
#include <platform/window.h>
|
||||
|
||||
#include <renderer/texture_library.h>
|
||||
|
||||
namespace mlx::core
|
||||
{
|
||||
class Application
|
||||
@@ -46,15 +48,21 @@ namespace mlx::core
|
||||
inline void loop_end() noexcept { _in.finish(); }
|
||||
|
||||
inline void pixel_put(void* win_ptr, int x, int y, int color) const noexcept { _wins[*static_cast<int*>(win_ptr)]->pixel_put(x, y, color); }
|
||||
|
||||
void* new_stb_texture(char* file, int* w, int* h); // stb textures are format managed by stb image (png, jpg, bpm, ...)
|
||||
void texture_put(void* win, void* img, int x, int y);
|
||||
void destroy_texture(void* ptr);
|
||||
|
||||
inline void destroy_window(void* win_ptr) { _wins[*static_cast<int*>(win_ptr)].reset(); }
|
||||
|
||||
void run() noexcept;
|
||||
|
||||
~Application() = default;
|
||||
~Application();
|
||||
|
||||
private:
|
||||
Input _in;
|
||||
TextureLibrary _texture_lib;
|
||||
std::vector<TextureID> _texture_ids;
|
||||
std::vector<std::shared_ptr<MLX_Window>> _wins;
|
||||
std::function<int(void*)> _loop_hook;
|
||||
void* _param = nullptr;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */
|
||||
/* Updated: 2022/12/18 22:24:25 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/04/01 15:32:57 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -58,10 +58,29 @@ extern "C"
|
||||
|
||||
int mlx_mouse_move(void* win_ptr, int x, int y)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mlx_mouse_get_pos(void* win_ptr, int* x, int* y)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mlx_put_image_to_window(void* mlx_ptr, void* win_ptr, void* img_ptr, int x, int y)
|
||||
{
|
||||
static_cast<mlx::core::Application*>(mlx_ptr)->texture_put(win_ptr, img_ptr, x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mlx_destroy_image(void* mlx_ptr, void* img_ptr)
|
||||
{
|
||||
static_cast<mlx::core::Application*>(mlx_ptr)->destroy_texture(img_ptr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* mlx_png_file_to_image(void* mlx_ptr, char* filename, int* width, int* height)
|
||||
{
|
||||
return static_cast<mlx::core::Application*>(mlx_ptr)->new_stb_texture(filename, width, height);
|
||||
}
|
||||
|
||||
int mlx_pixel_put(void* mlx, void* win_ptr, int x, int y, int color)
|
||||
|
||||
Reference in New Issue
Block a user