mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 22:53:34 +00:00
working textures
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 16:56:35 by maldavid #+# #+# */
|
/* Created: 2022/10/04 16:56:35 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/03/31 12:35:21 by maldavid ### ########.fr */
|
/* Updated: 2023/04/01 13:50:52 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ extern "C" {
|
|||||||
void* mlx_init();
|
void* mlx_init();
|
||||||
void* mlx_new_window(void* mlx, int w, int h, const char* title);
|
void* mlx_new_window(void* mlx, int w, int h, const char* title);
|
||||||
|
|
||||||
int mlx_loop_hook(void* mlx, int (*f)(void*), void* param);
|
int mlx_loop_hook(void* mlx, int (*f)(void*), void* param);
|
||||||
int mlx_loop(void* mlx);
|
int mlx_loop(void* mlx);
|
||||||
int mlx_loop_end(void* mlx);
|
int mlx_loop_end(void* mlx);
|
||||||
|
|
||||||
@@ -31,6 +31,9 @@ int mlx_mouse_get_pos(void* win_ptr, int* x, int* y);
|
|||||||
|
|
||||||
int mlx_pixel_put(void* mlx, void* win_ptr, int x, int y, int color);
|
int mlx_pixel_put(void* mlx, void* win_ptr, int x, int y, int color);
|
||||||
|
|
||||||
|
int mlx_put_image_to_window(void* mlx_ptr, void* win_ptr, void* img_ptr, int x, int y);
|
||||||
|
int mlx_destroy_image(void* mlx_ptr, void* img_ptr);
|
||||||
|
|
||||||
void* mlx_png_file_to_image(void* mlx_ptr, char* filename, int* width, int* height);
|
void* mlx_png_file_to_image(void* mlx_ptr, char* filename, int* width, int* height);
|
||||||
|
|
||||||
int mlx_destroy_window(void* mlx, void* win_ptr);
|
int mlx_destroy_window(void* mlx, void* win_ptr);
|
||||||
|
|||||||
@@ -6,11 +6,12 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
|
/* 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 "application.h"
|
||||||
|
#include <renderer/images/texture.h>
|
||||||
|
|
||||||
namespace mlx::core
|
namespace mlx::core
|
||||||
{
|
{
|
||||||
@@ -29,4 +30,29 @@ namespace mlx::core
|
|||||||
win->endFrame();
|
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> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
|
/* 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/inputs.h>
|
||||||
#include <platform/window.h>
|
#include <platform/window.h>
|
||||||
|
|
||||||
|
#include <renderer/texture_library.h>
|
||||||
|
|
||||||
namespace mlx::core
|
namespace mlx::core
|
||||||
{
|
{
|
||||||
class Application
|
class Application
|
||||||
@@ -47,14 +49,20 @@ namespace mlx::core
|
|||||||
|
|
||||||
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); }
|
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(); }
|
inline void destroy_window(void* win_ptr) { _wins[*static_cast<int*>(win_ptr)].reset(); }
|
||||||
|
|
||||||
void run() noexcept;
|
void run() noexcept;
|
||||||
|
|
||||||
~Application() = default;
|
~Application();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Input _in;
|
Input _in;
|
||||||
|
TextureLibrary _texture_lib;
|
||||||
|
std::vector<TextureID> _texture_ids;
|
||||||
std::vector<std::shared_ptr<MLX_Window>> _wins;
|
std::vector<std::shared_ptr<MLX_Window>> _wins;
|
||||||
std::function<int(void*)> _loop_hook;
|
std::function<int(void*)> _loop_hook;
|
||||||
void* _param = nullptr;
|
void* _param = nullptr;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */
|
/* 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)
|
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)
|
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)
|
int mlx_pixel_put(void* mlx, void* win_ptr, int x, int y, int color)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 17:36:44 by maldavid #+# #+# */
|
/* Created: 2022/10/04 17:36:44 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/04/01 11:55:19 by maldavid ### ########.fr */
|
/* Updated: 2023/04/01 15:40:30 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -45,6 +45,18 @@ namespace mlx
|
|||||||
_renderer->getPixelPutPipeline().setPixel(x, y, color);
|
_renderer->getPixelPutPipeline().setPixel(x, y, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MLX_Window::texture_put(std::shared_ptr<Texture> texture, int x, int y)
|
||||||
|
{
|
||||||
|
if(texture->getSet() == VK_NULL_HANDLE)
|
||||||
|
texture->setDescriptor(_renderer->getFragDescriptorSet().duplicate());
|
||||||
|
texture->updateSet(0);
|
||||||
|
std::vector<VkDescriptorSet> sets;
|
||||||
|
sets.push_back(_renderer->getVertDescriptorSet().get());
|
||||||
|
sets.push_back(texture->getSet());
|
||||||
|
vkCmdBindDescriptorSets(_renderer->getActiveCmdBuffer().get(), VK_PIPELINE_BIND_POINT_GRAPHICS, _renderer->getPipeline().getPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr);
|
||||||
|
texture->render(*_renderer, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
void MLX_Window::endFrame()
|
void MLX_Window::endFrame()
|
||||||
{
|
{
|
||||||
auto cmd_buff = _renderer->getActiveCmdBuffer().get();
|
auto cmd_buff = _renderer->getActiveCmdBuffer().get();
|
||||||
@@ -54,9 +66,7 @@ namespace mlx
|
|||||||
std::vector<VkDescriptorSet> sets;
|
std::vector<VkDescriptorSet> sets;
|
||||||
sets.push_back(_renderer->getVertDescriptorSet().get());
|
sets.push_back(_renderer->getVertDescriptorSet().get());
|
||||||
sets.push_back(_renderer->getPixelPutPipeline().getDescriptorSet());
|
sets.push_back(_renderer->getPixelPutPipeline().getDescriptorSet());
|
||||||
|
|
||||||
vkCmdBindDescriptorSets(cmd_buff, VK_PIPELINE_BIND_POINT_GRAPHICS, _renderer->getPipeline().getPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr);
|
vkCmdBindDescriptorSets(cmd_buff, VK_PIPELINE_BIND_POINT_GRAPHICS, _renderer->getPipeline().getPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr);
|
||||||
|
|
||||||
_renderer->getPixelPutPipeline().render(*_renderer);
|
_renderer->getPixelPutPipeline().render(*_renderer);
|
||||||
|
|
||||||
_renderer->endFrame();
|
_renderer->endFrame();
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 21:53:12 by maldavid #+# #+# */
|
/* Created: 2022/10/04 21:53:12 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/04/01 11:54:09 by maldavid ### ########.fr */
|
/* Updated: 2023/04/01 15:27:51 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <renderer/renderer.h>
|
#include <renderer/renderer.h>
|
||||||
#include <renderer/images/vk_image.h>
|
#include <renderer/images/texture.h>
|
||||||
#include <renderer/buffers/vk_buffer.h>
|
#include <renderer/buffers/vk_buffer.h>
|
||||||
|
|
||||||
namespace mlx
|
namespace mlx
|
||||||
@@ -34,6 +34,7 @@ namespace mlx
|
|||||||
void endFrame();
|
void endFrame();
|
||||||
|
|
||||||
void pixel_put(int x, int y, int color);
|
void pixel_put(int x, int y, int color);
|
||||||
|
void texture_put(std::shared_ptr<Texture> texture, int x, int y);
|
||||||
|
|
||||||
~MLX_Window();
|
~MLX_Window();
|
||||||
|
|
||||||
|
|||||||
@@ -6,12 +6,17 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/31 18:03:35 by maldavid #+# #+# */
|
/* Created: 2023/03/31 18:03:35 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/03/31 18:06:26 by maldavid ### ########.fr */
|
/* Updated: 2023/04/01 15:39:59 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include <core/errors.h>
|
||||||
#include <renderer/images/texture.h>
|
#include <renderer/images/texture.h>
|
||||||
#include <renderer/buffers/vk_buffer.h>
|
#include <renderer/buffers/vk_buffer.h>
|
||||||
|
#include <renderer/renderer.h>
|
||||||
|
|
||||||
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
#include <stb_image.h>
|
||||||
|
|
||||||
namespace mlx
|
namespace mlx
|
||||||
{
|
{
|
||||||
@@ -26,10 +31,67 @@ namespace mlx
|
|||||||
Image::createImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
|
Image::createImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
|
||||||
Image::createSampler();
|
Image::createSampler();
|
||||||
|
|
||||||
Buffer staging_buffer;
|
std::vector<Vertex> vertexData = {
|
||||||
std::size_t size = width * height * (format == VK_FORMAT_R32G32B32A32_SFLOAT ? 16 : 4);
|
{{0, 0}, {1.f, 1.f, 1.f, 1.f}, {0.0f, 0.0f}},
|
||||||
staging_buffer.create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, pixels);
|
{{width, 0}, {1.f, 1.f, 1.f, 1.f}, {1.0f, 0.0f}},
|
||||||
Image::copyBuffer(staging_buffer);
|
{{width, height}, {1.f, 1.f, 1.f, 1.f}, {1.0f, 1.0f}},
|
||||||
staging_buffer.destroy();
|
{{0, height}, {1.f, 1.f, 1.f, 1.f}, {0.0f, 1.0f}}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<uint16_t> indexData = { 0, 1, 2, 2, 3, 0 };
|
||||||
|
|
||||||
|
_vbo.create(sizeof(Vertex) * vertexData.size(), vertexData.data());
|
||||||
|
_ibo.create(sizeof(uint16_t) * indexData.size(), indexData.data());
|
||||||
|
|
||||||
|
if(pixels != nullptr)
|
||||||
|
{
|
||||||
|
Buffer staging_buffer;
|
||||||
|
std::size_t size = width * height * (format == VK_FORMAT_R32G32B32A32_SFLOAT ? 16 : 4);
|
||||||
|
staging_buffer.create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, pixels);
|
||||||
|
Image::copyBuffer(staging_buffer);
|
||||||
|
staging_buffer.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Texture::render(Renderer& renderer, int x, int y)
|
||||||
|
{
|
||||||
|
_vbo.bind(renderer);
|
||||||
|
_ibo.bind(renderer);
|
||||||
|
auto cmd = renderer.getActiveCmdBuffer().get();
|
||||||
|
glm::vec2 translate(x, y);
|
||||||
|
vkCmdPushConstants(cmd, renderer.getPipeline().getPipelineLayout(), VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(translate), &translate);
|
||||||
|
vkCmdDrawIndexed(cmd, static_cast<uint32_t>(_ibo.getSize() / sizeof(uint16_t)), 1, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Texture::destroy() noexcept
|
||||||
|
{
|
||||||
|
Image::destroy();
|
||||||
|
_vbo.destroy();
|
||||||
|
_ibo.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
Texture stb_texture_load(std::filesystem::path file, int* w, int* h)
|
||||||
|
{
|
||||||
|
Texture texture;
|
||||||
|
int channels;
|
||||||
|
VkFormat format;
|
||||||
|
uint8_t* data = nullptr;
|
||||||
|
std::string filename = file.string();
|
||||||
|
|
||||||
|
if(!std::filesystem::exists(std::move(file)))
|
||||||
|
core::error::report(e_kind::fatal_error, "Image : file not found '%s'", filename.c_str());
|
||||||
|
if(stbi_is_hdr(filename.c_str()))
|
||||||
|
{
|
||||||
|
data = (uint8_t*)stbi_loadf(filename.c_str(), w, h, &channels, 4);
|
||||||
|
format = VK_FORMAT_R32G32B32A32_SFLOAT;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data = stbi_load(filename.c_str(), w, h, &channels, 4);
|
||||||
|
format = VK_FORMAT_R8G8B8A8_UNORM;
|
||||||
|
}
|
||||||
|
texture.create(data, *w, *h, format);
|
||||||
|
stbi_image_free(data);
|
||||||
|
return texture;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,14 +6,18 @@
|
|||||||
/* By: maldavid <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: maldavid <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/08 02:24:58 by maldavid #+# #+# */
|
/* Created: 2023/03/08 02:24:58 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/03/31 18:06:09 by maldavid ### ########.fr */
|
/* Updated: 2023/04/01 15:31:26 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef __MLX_TEXTURE__
|
#ifndef __MLX_TEXTURE__
|
||||||
#define __MLX_TEXTURE__
|
#define __MLX_TEXTURE__
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
#include <renderer/images/vk_image.h>
|
#include <renderer/images/vk_image.h>
|
||||||
|
#include <renderer/descriptors/vk_descriptor_set.h>
|
||||||
|
#include <renderer/buffers/vk_ibo.h>
|
||||||
|
#include <renderer/buffers/vk_vbo.h>
|
||||||
|
|
||||||
namespace mlx
|
namespace mlx
|
||||||
{
|
{
|
||||||
@@ -21,9 +25,24 @@ namespace mlx
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Texture() = default;
|
Texture() = default;
|
||||||
|
|
||||||
void create(uint8_t* pixels, uint32_t width, uint32_t height, VkFormat format);
|
void create(uint8_t* pixels, uint32_t width, uint32_t height, VkFormat format);
|
||||||
|
void render(class Renderer& renderer, int x, int y);
|
||||||
|
void destroy() noexcept override;
|
||||||
|
|
||||||
|
inline void setDescriptor(DescriptorSet set) noexcept { _set = std::move(set); }
|
||||||
|
inline VkDescriptorSet getSet() noexcept { return _set.isInit() ? _set.get() : VK_NULL_HANDLE; }
|
||||||
|
inline void updateSet(int binding) noexcept { _set.writeDescriptor(binding, getImageView(), getSampler());}
|
||||||
|
|
||||||
~Texture() = default;
|
~Texture() = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
C_VBO _vbo;
|
||||||
|
C_IBO _ibo;
|
||||||
|
DescriptorSet _set;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Texture stb_texture_load(std::filesystem::path file, int* w, int* h);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/01/25 11:54:21 by maldavid #+# #+# */
|
/* Created: 2023/01/25 11:54:21 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/03/31 18:04:35 by maldavid ### ########.fr */
|
/* Updated: 2023/04/01 15:22:43 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
#include <volk.h>
|
#include <volk.h>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <renderer/descriptors/vk_descriptor_set.h>
|
#include <vector>
|
||||||
|
|
||||||
namespace mlx
|
namespace mlx
|
||||||
{
|
{
|
||||||
@@ -30,7 +30,7 @@ namespace mlx
|
|||||||
void createImageView(VkImageViewType type, VkImageAspectFlags aspectFlags) noexcept;
|
void createImageView(VkImageViewType type, VkImageAspectFlags aspectFlags) noexcept;
|
||||||
void createSampler() noexcept;
|
void createSampler() noexcept;
|
||||||
void copyBuffer(class Buffer& buffer);
|
void copyBuffer(class Buffer& buffer);
|
||||||
void destroy() noexcept;
|
virtual void destroy() noexcept;
|
||||||
|
|
||||||
inline VkImage get() noexcept { return _image; }
|
inline VkImage get() noexcept { return _image; }
|
||||||
inline VkImage operator()() noexcept { return _image; }
|
inline VkImage operator()() noexcept { return _image; }
|
||||||
@@ -42,7 +42,6 @@ namespace mlx
|
|||||||
virtual ~Image() = default;
|
virtual ~Image() = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DescriptorSet _desc;
|
|
||||||
VkImage _image = VK_NULL_HANDLE;
|
VkImage _image = VK_NULL_HANDLE;
|
||||||
VkDeviceMemory _memory = VK_NULL_HANDLE;
|
VkDeviceMemory _memory = VK_NULL_HANDLE;
|
||||||
VkImageView _image_view = VK_NULL_HANDLE;
|
VkImageView _image_view = VK_NULL_HANDLE;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/12/18 21:27:38 by maldavid #+# #+# */
|
/* Created: 2022/12/18 21:27:38 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/04/01 12:53:28 by maldavid ### ########.fr */
|
/* Updated: 2023/04/01 15:21:00 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -21,19 +21,23 @@ namespace mlx
|
|||||||
#version 450 core
|
#version 450 core
|
||||||
|
|
||||||
layout(location = 0) in vec2 aPos;
|
layout(location = 0) in vec2 aPos;
|
||||||
layout(location = 1) in vec3 aColor;
|
layout(location = 1) in vec4 aColor;
|
||||||
layout(location = 2) in vec2 aUV;
|
layout(location = 2) in vec2 aUV;
|
||||||
|
|
||||||
layout(set=0, binding=0) uniform uProjection {
|
layout(set=0, binding=0) uniform uProjection {
|
||||||
mat4 mat;
|
mat4 mat;
|
||||||
} uProj;
|
} uProj;
|
||||||
|
|
||||||
|
layout(push_constant) uniform uModelPushConstant {
|
||||||
|
vec2 vec;
|
||||||
|
} uTranslate;
|
||||||
|
|
||||||
out gl_PerVertex {
|
out gl_PerVertex {
|
||||||
vec4 gl_Position;
|
vec4 gl_Position;
|
||||||
};
|
};
|
||||||
|
|
||||||
layout(location = 0) out struct {
|
layout(location = 0) out struct {
|
||||||
vec3 Color;
|
vec4 Color;
|
||||||
vec2 UV;
|
vec2 UV;
|
||||||
} Out;
|
} Out;
|
||||||
|
|
||||||
@@ -41,54 +45,63 @@ namespace mlx
|
|||||||
{
|
{
|
||||||
Out.Color = aColor;
|
Out.Color = aColor;
|
||||||
Out.UV = aUV;
|
Out.UV = aUV;
|
||||||
gl_Position = uProj.mat * vec4(aPos.x, aPos.y, 0.0, 1.0);
|
vec2 pos = aPos + uTranslate.vec;
|
||||||
|
gl_Position = uProj.mat * vec4(pos.x, pos.y, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
const std::vector<uint32_t> vertex_shader = {
|
const std::vector<uint32_t> vertex_shader = {
|
||||||
0x07230203,0x00010000,0x0008000b,0x00000033,0x00000000,0x00020011,0x00000001,0x0006000b,
|
0x07230203,0x00010000,0x0008000b,0x0000003b,0x00000000,0x00020011,0x00000001,0x0006000b,
|
||||||
0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001,
|
0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001,
|
||||||
0x000a000f,0x00000000,0x00000004,0x6e69616d,0x00000000,0x0000000b,0x0000000f,0x00000015,
|
0x000a000f,0x00000000,0x00000004,0x6e69616d,0x00000000,0x0000000b,0x0000000f,0x00000015,
|
||||||
0x0000001c,0x00000024,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d,
|
0x0000001b,0x00000026,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d,
|
||||||
0x00000000,0x00030005,0x00000009,0x00000000,0x00050006,0x00000009,0x00000000,0x6f6c6f43,
|
0x00000000,0x00030005,0x00000009,0x00000000,0x00050006,0x00000009,0x00000000,0x6f6c6f43,
|
||||||
0x00000072,0x00040006,0x00000009,0x00000001,0x00005655,0x00030005,0x0000000b,0x0074754f,
|
0x00000072,0x00040006,0x00000009,0x00000001,0x00005655,0x00030005,0x0000000b,0x0074754f,
|
||||||
0x00040005,0x0000000f,0x6c6f4361,0x0000726f,0x00030005,0x00000015,0x00565561,0x00060005,
|
0x00040005,0x0000000f,0x6c6f4361,0x0000726f,0x00030005,0x00000015,0x00565561,0x00030005,
|
||||||
0x0000001a,0x505f6c67,0x65567265,0x78657472,0x00000000,0x00060006,0x0000001a,0x00000000,
|
0x0000001a,0x00736f70,0x00040005,0x0000001b,0x736f5061,0x00000000,0x00070005,0x0000001d,
|
||||||
0x505f6c67,0x7469736f,0x006e6f69,0x00030005,0x0000001c,0x00000000,0x00050005,0x0000001e,
|
0x646f4d75,0x75506c65,0x6f436873,0x6174736e,0x0000746e,0x00040006,0x0000001d,0x00000000,
|
||||||
0x6f725075,0x7463656a,0x006e6f69,0x00040006,0x0000001e,0x00000000,0x0074616d,0x00040005,
|
0x00636576,0x00050005,0x0000001f,0x61725475,0x616c736e,0x00006574,0x00060005,0x00000024,
|
||||||
0x00000020,0x6f725075,0x0000006a,0x00040005,0x00000024,0x736f5061,0x00000000,0x00040047,
|
0x505f6c67,0x65567265,0x78657472,0x00000000,0x00060006,0x00000024,0x00000000,0x505f6c67,
|
||||||
0x0000000b,0x0000001e,0x00000000,0x00040047,0x0000000f,0x0000001e,0x00000001,0x00040047,
|
0x7469736f,0x006e6f69,0x00030005,0x00000026,0x00000000,0x00050005,0x00000028,0x6f725075,
|
||||||
0x00000015,0x0000001e,0x00000002,0x00050048,0x0000001a,0x00000000,0x0000000b,0x00000000,
|
0x7463656a,0x006e6f69,0x00040006,0x00000028,0x00000000,0x0074616d,0x00040005,0x0000002a,
|
||||||
0x00030047,0x0000001a,0x00000002,0x00040048,0x0000001e,0x00000000,0x00000005,0x00050048,
|
0x6f725075,0x0000006a,0x00040047,0x0000000b,0x0000001e,0x00000000,0x00040047,0x0000000f,
|
||||||
0x0000001e,0x00000000,0x00000023,0x00000000,0x00050048,0x0000001e,0x00000000,0x00000007,
|
0x0000001e,0x00000001,0x00040047,0x00000015,0x0000001e,0x00000002,0x00040047,0x0000001b,
|
||||||
0x00000010,0x00030047,0x0000001e,0x00000002,0x00040047,0x00000020,0x00000022,0x00000000,
|
0x0000001e,0x00000000,0x00050048,0x0000001d,0x00000000,0x00000023,0x00000000,0x00030047,
|
||||||
0x00040047,0x00000020,0x00000021,0x00000000,0x00040047,0x00000024,0x0000001e,0x00000000,
|
0x0000001d,0x00000002,0x00050048,0x00000024,0x00000000,0x0000000b,0x00000000,0x00030047,
|
||||||
0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016,0x00000006,0x00000020,
|
0x00000024,0x00000002,0x00040048,0x00000028,0x00000000,0x00000005,0x00050048,0x00000028,
|
||||||
0x00040017,0x00000007,0x00000006,0x00000003,0x00040017,0x00000008,0x00000006,0x00000002,
|
0x00000000,0x00000023,0x00000000,0x00050048,0x00000028,0x00000000,0x00000007,0x00000010,
|
||||||
0x0004001e,0x00000009,0x00000007,0x00000008,0x00040020,0x0000000a,0x00000003,0x00000009,
|
0x00030047,0x00000028,0x00000002,0x00040047,0x0000002a,0x00000022,0x00000000,0x00040047,
|
||||||
0x0004003b,0x0000000a,0x0000000b,0x00000003,0x00040015,0x0000000c,0x00000020,0x00000001,
|
0x0000002a,0x00000021,0x00000000,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,
|
||||||
0x0004002b,0x0000000c,0x0000000d,0x00000000,0x00040020,0x0000000e,0x00000001,0x00000007,
|
0x00030016,0x00000006,0x00000020,0x00040017,0x00000007,0x00000006,0x00000004,0x00040017,
|
||||||
0x0004003b,0x0000000e,0x0000000f,0x00000001,0x00040020,0x00000011,0x00000003,0x00000007,
|
0x00000008,0x00000006,0x00000002,0x0004001e,0x00000009,0x00000007,0x00000008,0x00040020,
|
||||||
0x0004002b,0x0000000c,0x00000013,0x00000001,0x00040020,0x00000014,0x00000001,0x00000008,
|
0x0000000a,0x00000003,0x00000009,0x0004003b,0x0000000a,0x0000000b,0x00000003,0x00040015,
|
||||||
0x0004003b,0x00000014,0x00000015,0x00000001,0x00040020,0x00000017,0x00000003,0x00000008,
|
0x0000000c,0x00000020,0x00000001,0x0004002b,0x0000000c,0x0000000d,0x00000000,0x00040020,
|
||||||
0x00040017,0x00000019,0x00000006,0x00000004,0x0003001e,0x0000001a,0x00000019,0x00040020,
|
0x0000000e,0x00000001,0x00000007,0x0004003b,0x0000000e,0x0000000f,0x00000001,0x00040020,
|
||||||
0x0000001b,0x00000003,0x0000001a,0x0004003b,0x0000001b,0x0000001c,0x00000003,0x00040018,
|
0x00000011,0x00000003,0x00000007,0x0004002b,0x0000000c,0x00000013,0x00000001,0x00040020,
|
||||||
0x0000001d,0x00000019,0x00000004,0x0003001e,0x0000001e,0x0000001d,0x00040020,0x0000001f,
|
0x00000014,0x00000001,0x00000008,0x0004003b,0x00000014,0x00000015,0x00000001,0x00040020,
|
||||||
0x00000002,0x0000001e,0x0004003b,0x0000001f,0x00000020,0x00000002,0x00040020,0x00000021,
|
0x00000017,0x00000003,0x00000008,0x00040020,0x00000019,0x00000007,0x00000008,0x0004003b,
|
||||||
0x00000002,0x0000001d,0x0004003b,0x00000014,0x00000024,0x00000001,0x00040015,0x00000025,
|
0x00000014,0x0000001b,0x00000001,0x0003001e,0x0000001d,0x00000008,0x00040020,0x0000001e,
|
||||||
0x00000020,0x00000000,0x0004002b,0x00000025,0x00000026,0x00000000,0x00040020,0x00000027,
|
0x00000009,0x0000001d,0x0004003b,0x0000001e,0x0000001f,0x00000009,0x00040020,0x00000020,
|
||||||
0x00000001,0x00000006,0x0004002b,0x00000025,0x0000002a,0x00000001,0x0004002b,0x00000006,
|
0x00000009,0x00000008,0x0003001e,0x00000024,0x00000007,0x00040020,0x00000025,0x00000003,
|
||||||
0x0000002d,0x00000000,0x0004002b,0x00000006,0x0000002e,0x3f800000,0x00040020,0x00000031,
|
0x00000024,0x0004003b,0x00000025,0x00000026,0x00000003,0x00040018,0x00000027,0x00000007,
|
||||||
0x00000003,0x00000019,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,
|
0x00000004,0x0003001e,0x00000028,0x00000027,0x00040020,0x00000029,0x00000002,0x00000028,
|
||||||
0x00000005,0x0004003d,0x00000007,0x00000010,0x0000000f,0x00050041,0x00000011,0x00000012,
|
0x0004003b,0x00000029,0x0000002a,0x00000002,0x00040020,0x0000002b,0x00000002,0x00000027,
|
||||||
0x0000000b,0x0000000d,0x0003003e,0x00000012,0x00000010,0x0004003d,0x00000008,0x00000016,
|
0x00040015,0x0000002e,0x00000020,0x00000000,0x0004002b,0x0000002e,0x0000002f,0x00000000,
|
||||||
0x00000015,0x00050041,0x00000017,0x00000018,0x0000000b,0x00000013,0x0003003e,0x00000018,
|
0x00040020,0x00000030,0x00000007,0x00000006,0x0004002b,0x0000002e,0x00000033,0x00000001,
|
||||||
0x00000016,0x00050041,0x00000021,0x00000022,0x00000020,0x0000000d,0x0004003d,0x0000001d,
|
0x0004002b,0x00000006,0x00000036,0x00000000,0x0004002b,0x00000006,0x00000037,0x3f800000,
|
||||||
0x00000023,0x00000022,0x00050041,0x00000027,0x00000028,0x00000024,0x00000026,0x0004003d,
|
0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005,0x0004003b,
|
||||||
0x00000006,0x00000029,0x00000028,0x00050041,0x00000027,0x0000002b,0x00000024,0x0000002a,
|
0x00000019,0x0000001a,0x00000007,0x0004003d,0x00000007,0x00000010,0x0000000f,0x00050041,
|
||||||
0x0004003d,0x00000006,0x0000002c,0x0000002b,0x00070050,0x00000019,0x0000002f,0x00000029,
|
0x00000011,0x00000012,0x0000000b,0x0000000d,0x0003003e,0x00000012,0x00000010,0x0004003d,
|
||||||
0x0000002c,0x0000002d,0x0000002e,0x00050091,0x00000019,0x00000030,0x00000023,0x0000002f,
|
0x00000008,0x00000016,0x00000015,0x00050041,0x00000017,0x00000018,0x0000000b,0x00000013,
|
||||||
0x00050041,0x00000031,0x00000032,0x0000001c,0x0000000d,0x0003003e,0x00000032,0x00000030,
|
0x0003003e,0x00000018,0x00000016,0x0004003d,0x00000008,0x0000001c,0x0000001b,0x00050041,
|
||||||
0x000100fd,0x00010038
|
0x00000020,0x00000021,0x0000001f,0x0000000d,0x0004003d,0x00000008,0x00000022,0x00000021,
|
||||||
|
0x00050081,0x00000008,0x00000023,0x0000001c,0x00000022,0x0003003e,0x0000001a,0x00000023,
|
||||||
|
0x00050041,0x0000002b,0x0000002c,0x0000002a,0x0000000d,0x0004003d,0x00000027,0x0000002d,
|
||||||
|
0x0000002c,0x00050041,0x00000030,0x00000031,0x0000001a,0x0000002f,0x0004003d,0x00000006,
|
||||||
|
0x00000032,0x00000031,0x00050041,0x00000030,0x00000034,0x0000001a,0x00000033,0x0004003d,
|
||||||
|
0x00000006,0x00000035,0x00000034,0x00070050,0x00000007,0x00000038,0x00000032,0x00000035,
|
||||||
|
0x00000036,0x00000037,0x00050091,0x00000007,0x00000039,0x0000002d,0x00000038,0x00050041,
|
||||||
|
0x00000011,0x0000003a,0x00000026,0x0000000d,0x0003003e,0x0000003a,0x00000039,0x000100fd,
|
||||||
|
0x00010038
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,44 +112,52 @@ namespace mlx
|
|||||||
layout(set=1, binding=0) uniform sampler2D sTexture;
|
layout(set=1, binding=0) uniform sampler2D sTexture;
|
||||||
|
|
||||||
layout(location = 0) in struct {
|
layout(location = 0) in struct {
|
||||||
vec3 Color;
|
vec4 Color;
|
||||||
vec2 UV;
|
vec2 UV;
|
||||||
} In;
|
} In;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
fColor = vec4(In.Color, 1.0) * texture(sTexture, In.UV.st);
|
vec4 process_color = In.Color * texture(sTexture, In.UV.st);
|
||||||
|
if(process_color.w == 0)
|
||||||
|
discard;
|
||||||
|
fColor = process_color;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
const std::vector<uint32_t> fragment_shader = {
|
const std::vector<uint32_t> fragment_shader = {
|
||||||
0x07230203,0x00010000,0x0008000b,0x00000024,0x00000000,0x00020011,0x00000001,0x0006000b,
|
0x07230203,0x00010000,0x0008000b,0x0000002c,0x00000000,0x00020011,0x00000001,0x0006000b,
|
||||||
0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001,
|
0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001,
|
||||||
0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x00000009,0x0000000e,0x00030010,
|
0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x0000000d,0x0000002a,0x00030010,
|
||||||
0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d,
|
0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d,
|
||||||
0x00000000,0x00040005,0x00000009,0x6c6f4366,0x0000726f,0x00030005,0x0000000c,0x00000000,
|
0x00000000,0x00060005,0x00000009,0x636f7270,0x5f737365,0x6f6c6f63,0x00000072,0x00030005,
|
||||||
0x00050006,0x0000000c,0x00000000,0x6f6c6f43,0x00000072,0x00040006,0x0000000c,0x00000001,
|
0x0000000b,0x00000000,0x00050006,0x0000000b,0x00000000,0x6f6c6f43,0x00000072,0x00040006,
|
||||||
0x00005655,0x00030005,0x0000000e,0x00006e49,0x00050005,0x0000001c,0x78655473,0x65727574,
|
0x0000000b,0x00000001,0x00005655,0x00030005,0x0000000d,0x00006e49,0x00050005,0x00000016,
|
||||||
0x00000000,0x00040047,0x00000009,0x0000001e,0x00000000,0x00040047,0x0000000e,0x0000001e,
|
0x78655473,0x65727574,0x00000000,0x00040005,0x0000002a,0x6c6f4366,0x0000726f,0x00040047,
|
||||||
0x00000000,0x00040047,0x0000001c,0x00000022,0x00000001,0x00040047,0x0000001c,0x00000021,
|
0x0000000d,0x0000001e,0x00000000,0x00040047,0x00000016,0x00000022,0x00000001,0x00040047,
|
||||||
0x00000000,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016,0x00000006,
|
0x00000016,0x00000021,0x00000000,0x00040047,0x0000002a,0x0000001e,0x00000000,0x00020013,
|
||||||
0x00000020,0x00040017,0x00000007,0x00000006,0x00000004,0x00040020,0x00000008,0x00000003,
|
0x00000002,0x00030021,0x00000003,0x00000002,0x00030016,0x00000006,0x00000020,0x00040017,
|
||||||
0x00000007,0x0004003b,0x00000008,0x00000009,0x00000003,0x00040017,0x0000000a,0x00000006,
|
0x00000007,0x00000006,0x00000004,0x00040020,0x00000008,0x00000007,0x00000007,0x00040017,
|
||||||
0x00000003,0x00040017,0x0000000b,0x00000006,0x00000002,0x0004001e,0x0000000c,0x0000000a,
|
0x0000000a,0x00000006,0x00000002,0x0004001e,0x0000000b,0x00000007,0x0000000a,0x00040020,
|
||||||
0x0000000b,0x00040020,0x0000000d,0x00000001,0x0000000c,0x0004003b,0x0000000d,0x0000000e,
|
0x0000000c,0x00000001,0x0000000b,0x0004003b,0x0000000c,0x0000000d,0x00000001,0x00040015,
|
||||||
0x00000001,0x00040015,0x0000000f,0x00000020,0x00000001,0x0004002b,0x0000000f,0x00000010,
|
0x0000000e,0x00000020,0x00000001,0x0004002b,0x0000000e,0x0000000f,0x00000000,0x00040020,
|
||||||
0x00000000,0x00040020,0x00000011,0x00000001,0x0000000a,0x0004002b,0x00000006,0x00000014,
|
0x00000010,0x00000001,0x00000007,0x00090019,0x00000013,0x00000006,0x00000001,0x00000000,
|
||||||
0x3f800000,0x00090019,0x00000019,0x00000006,0x00000001,0x00000000,0x00000000,0x00000000,
|
0x00000000,0x00000000,0x00000001,0x00000000,0x0003001b,0x00000014,0x00000013,0x00040020,
|
||||||
0x00000001,0x00000000,0x0003001b,0x0000001a,0x00000019,0x00040020,0x0000001b,0x00000000,
|
0x00000015,0x00000000,0x00000014,0x0004003b,0x00000015,0x00000016,0x00000000,0x0004002b,
|
||||||
0x0000001a,0x0004003b,0x0000001b,0x0000001c,0x00000000,0x0004002b,0x0000000f,0x0000001e,
|
0x0000000e,0x00000018,0x00000001,0x00040020,0x00000019,0x00000001,0x0000000a,0x00040015,
|
||||||
0x00000001,0x00040020,0x0000001f,0x00000001,0x0000000b,0x00050036,0x00000002,0x00000004,
|
0x0000001e,0x00000020,0x00000000,0x0004002b,0x0000001e,0x0000001f,0x00000003,0x00040020,
|
||||||
0x00000000,0x00000003,0x000200f8,0x00000005,0x00050041,0x00000011,0x00000012,0x0000000e,
|
0x00000020,0x00000007,0x00000006,0x0004002b,0x00000006,0x00000023,0x00000000,0x00020014,
|
||||||
0x00000010,0x0004003d,0x0000000a,0x00000013,0x00000012,0x00050051,0x00000006,0x00000015,
|
0x00000024,0x00040020,0x00000029,0x00000003,0x00000007,0x0004003b,0x00000029,0x0000002a,
|
||||||
0x00000013,0x00000000,0x00050051,0x00000006,0x00000016,0x00000013,0x00000001,0x00050051,
|
0x00000003,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005,
|
||||||
0x00000006,0x00000017,0x00000013,0x00000002,0x00070050,0x00000007,0x00000018,0x00000015,
|
0x0004003b,0x00000008,0x00000009,0x00000007,0x00050041,0x00000010,0x00000011,0x0000000d,
|
||||||
0x00000016,0x00000017,0x00000014,0x0004003d,0x0000001a,0x0000001d,0x0000001c,0x00050041,
|
0x0000000f,0x0004003d,0x00000007,0x00000012,0x00000011,0x0004003d,0x00000014,0x00000017,
|
||||||
0x0000001f,0x00000020,0x0000000e,0x0000001e,0x0004003d,0x0000000b,0x00000021,0x00000020,
|
0x00000016,0x00050041,0x00000019,0x0000001a,0x0000000d,0x00000018,0x0004003d,0x0000000a,
|
||||||
0x00050057,0x00000007,0x00000022,0x0000001d,0x00000021,0x00050085,0x00000007,0x00000023,
|
0x0000001b,0x0000001a,0x00050057,0x00000007,0x0000001c,0x00000017,0x0000001b,0x00050085,
|
||||||
0x00000018,0x00000022,0x0003003e,0x00000009,0x00000023,0x000100fd,0x00010038
|
0x00000007,0x0000001d,0x00000012,0x0000001c,0x0003003e,0x00000009,0x0000001d,0x00050041,
|
||||||
|
0x00000020,0x00000021,0x00000009,0x0000001f,0x0004003d,0x00000006,0x00000022,0x00000021,
|
||||||
|
0x000500b4,0x00000024,0x00000025,0x00000022,0x00000023,0x000300f7,0x00000027,0x00000000,
|
||||||
|
0x000400fa,0x00000025,0x00000026,0x00000027,0x000200f8,0x00000026,0x000100fc,0x000200f8,
|
||||||
|
0x00000027,0x0004003d,0x00000007,0x0000002b,0x00000009,0x0003003e,0x0000002a,0x0000002b,
|
||||||
|
0x000100fd,0x00010038
|
||||||
};
|
};
|
||||||
|
|
||||||
void GraphicPipeline::init(Renderer& renderer)
|
void GraphicPipeline::init(Renderer& renderer)
|
||||||
@@ -149,6 +170,11 @@ namespace mlx
|
|||||||
if(vkCreateShaderModule(Render_Core::get().getDevice().get(), &createInfo, nullptr, &vshader) != VK_SUCCESS)
|
if(vkCreateShaderModule(Render_Core::get().getDevice().get(), &createInfo, nullptr, &vshader) != VK_SUCCESS)
|
||||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create a vertex shader module");
|
core::error::report(e_kind::fatal_error, "Vulkan : failed to create a vertex shader module");
|
||||||
|
|
||||||
|
VkPushConstantRange push_constant;
|
||||||
|
push_constant.offset = 0;
|
||||||
|
push_constant.size = sizeof(glm::vec2);
|
||||||
|
push_constant.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
|
||||||
|
|
||||||
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
||||||
createInfo.codeSize = fragment_shader.size() * sizeof(uint32_t);
|
createInfo.codeSize = fragment_shader.size() * sizeof(uint32_t);
|
||||||
createInfo.pCode = fragment_shader.data();
|
createInfo.pCode = fragment_shader.data();
|
||||||
@@ -251,6 +277,8 @@ namespace mlx
|
|||||||
pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
|
pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
|
||||||
pipelineLayoutInfo.setLayoutCount = 2;
|
pipelineLayoutInfo.setLayoutCount = 2;
|
||||||
pipelineLayoutInfo.pSetLayouts = layouts;
|
pipelineLayoutInfo.pSetLayouts = layouts;
|
||||||
|
pipelineLayoutInfo.pushConstantRangeCount = 1;
|
||||||
|
pipelineLayoutInfo.pPushConstantRanges = &push_constant;
|
||||||
|
|
||||||
if(vkCreatePipelineLayout(Render_Core::get().getDevice().get(), &pipelineLayoutInfo, nullptr, &_pipelineLayout) != VK_SUCCESS)
|
if(vkCreatePipelineLayout(Render_Core::get().getDevice().get(), &pipelineLayoutInfo, nullptr, &_pipelineLayout) != VK_SUCCESS)
|
||||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create a graphics pipeline layout");
|
core::error::report(e_kind::fatal_error, "Vulkan : failed to create a graphics pipeline layout");
|
||||||
|
|||||||
@@ -6,13 +6,11 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/31 15:14:50 by maldavid #+# #+# */
|
/* Created: 2023/03/31 15:14:50 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/04/01 12:57:32 by maldavid ### ########.fr */
|
/* Updated: 2023/04/01 15:32:23 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include <renderer/buffers/vk_ibo.h>
|
#include <renderer/images/texture.h>
|
||||||
#include <renderer/buffers/vk_vbo.h>
|
|
||||||
#include <renderer/images/vk_image.h>
|
|
||||||
#include <renderer/pixel_put.h>
|
#include <renderer/pixel_put.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
@@ -20,11 +18,8 @@ namespace mlx
|
|||||||
{
|
{
|
||||||
struct PixelPutPipeline::_Pimpl
|
struct PixelPutPipeline::_Pimpl
|
||||||
{
|
{
|
||||||
Image image;
|
Texture texture;
|
||||||
C_VBO vbo;
|
|
||||||
C_IBO ibo;
|
|
||||||
Buffer buffer;
|
Buffer buffer;
|
||||||
DescriptorSet image_set;
|
|
||||||
void* map = nullptr;
|
void* map = nullptr;
|
||||||
uint32_t width = 0;
|
uint32_t width = 0;
|
||||||
uint32_t height = 0;
|
uint32_t height = 0;
|
||||||
@@ -34,32 +29,17 @@ namespace mlx
|
|||||||
|
|
||||||
void PixelPutPipeline::init(uint32_t width, uint32_t height, Renderer& renderer) noexcept
|
void PixelPutPipeline::init(uint32_t width, uint32_t height, Renderer& renderer) noexcept
|
||||||
{
|
{
|
||||||
_impl->image.create(width, height, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TILING_OPTIMAL,
|
_impl->texture.create(nullptr, width, height, VK_FORMAT_R8G8B8A8_UNORM);
|
||||||
VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
|
_impl->texture.setDescriptor(renderer.getFragDescriptorSet().duplicate());
|
||||||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
|
||||||
_impl->image.createImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
|
|
||||||
_impl->image.createSampler();
|
|
||||||
_impl->buffer.create(Buffer::kind::dynamic, sizeof(uint32_t) * (width * height), VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
|
_impl->buffer.create(Buffer::kind::dynamic, sizeof(uint32_t) * (width * height), VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
|
||||||
_impl->image_set = renderer.getFragDescriptorSet().duplicate();
|
|
||||||
_impl->width = width;
|
_impl->width = width;
|
||||||
_impl->height = height;
|
_impl->height = height;
|
||||||
|
|
||||||
std::vector<Vertex> vertexData = {
|
|
||||||
{{0, 0}, {1.f, 1.f, 1.f}, {0.0f, 0.0f}},
|
|
||||||
{{_impl->width, 0}, {1.f, 1.f, 1.f}, {1.0f, 0.0f}},
|
|
||||||
{{_impl->width, _impl->height}, {1.f, 1.f, 1.f}, {1.0f, 1.0f}},
|
|
||||||
{{0, _impl->height}, {1.f, 1.f, 1.0}, {0.0f, 1.0f}}
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<uint16_t> indexData = { 0, 1, 2, 2, 3, 0 };
|
|
||||||
|
|
||||||
_impl->vbo.create(sizeof(Vertex) * vertexData.size(), vertexData.data());
|
|
||||||
_impl->ibo.create(sizeof(uint16_t) * indexData.size(), indexData.data());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VkDescriptorSet& PixelPutPipeline::getDescriptorSet() noexcept
|
VkDescriptorSet PixelPutPipeline::getDescriptorSet() noexcept
|
||||||
{
|
{
|
||||||
return _impl->image_set.get();
|
return _impl->texture.getSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelPutPipeline::setPixel(uint32_t x, uint32_t y, int color) noexcept
|
void PixelPutPipeline::setPixel(uint32_t x, uint32_t y, int color) noexcept
|
||||||
@@ -77,23 +57,19 @@ namespace mlx
|
|||||||
{
|
{
|
||||||
if(_impl->buffer.isMapped())
|
if(_impl->buffer.isMapped())
|
||||||
_impl->buffer.unmapMem();
|
_impl->buffer.unmapMem();
|
||||||
_impl->image.copyBuffer(_impl->buffer);
|
_impl->texture.copyBuffer(_impl->buffer);
|
||||||
_impl->image_set.writeDescriptor(0, _impl->image.getImageView(), _impl->image.getSampler());
|
_impl->texture.updateSet(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelPutPipeline::render(Renderer& renderer) noexcept
|
void PixelPutPipeline::render(Renderer& renderer) noexcept
|
||||||
{
|
{
|
||||||
_impl->vbo.bind(renderer);
|
_impl->texture.render(renderer, 0, 0);
|
||||||
_impl->ibo.bind(renderer);
|
|
||||||
vkCmdDrawIndexed(renderer.getActiveCmdBuffer().get(), static_cast<uint32_t>(_impl->ibo.getSize() / sizeof(uint16_t)), 1, 0, 0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelPutPipeline::destroy() noexcept
|
void PixelPutPipeline::destroy() noexcept
|
||||||
{
|
{
|
||||||
_impl->vbo.destroy();
|
|
||||||
_impl->ibo.destroy();
|
|
||||||
_impl->buffer.destroy();
|
_impl->buffer.destroy();
|
||||||
_impl->image.destroy();
|
_impl->texture.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
PixelPutPipeline::~PixelPutPipeline() {}
|
PixelPutPipeline::~PixelPutPipeline() {}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/31 13:18:50 by maldavid #+# #+# */
|
/* Created: 2023/03/31 13:18:50 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/04/01 12:10:33 by maldavid ### ########.fr */
|
/* Updated: 2023/04/01 15:32:06 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ namespace mlx
|
|||||||
void setPixel(uint32_t x, uint32_t y, int color) noexcept;
|
void setPixel(uint32_t x, uint32_t y, int color) noexcept;
|
||||||
void present() noexcept;
|
void present() noexcept;
|
||||||
void render(class Renderer& renderer) noexcept;
|
void render(class Renderer& renderer) noexcept;
|
||||||
VkDescriptorSet& getDescriptorSet() noexcept;
|
VkDescriptorSet getDescriptorSet() noexcept;
|
||||||
|
|
||||||
void destroy() noexcept;
|
void destroy() noexcept;
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/12/18 17:14:45 by maldavid #+# #+# */
|
/* Created: 2022/12/18 17:14:45 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/03/31 17:59:09 by maldavid ### ########.fr */
|
/* Updated: 2023/04/01 15:37:40 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ namespace mlx
|
|||||||
struct Vertex
|
struct Vertex
|
||||||
{
|
{
|
||||||
glm::vec2 pos;
|
glm::vec2 pos;
|
||||||
glm::vec3 color;
|
glm::vec4 color;
|
||||||
glm::vec2 uv;
|
glm::vec2 uv;
|
||||||
|
|
||||||
static VkVertexInputBindingDescription getBindingDescription()
|
static VkVertexInputBindingDescription getBindingDescription()
|
||||||
@@ -64,7 +64,7 @@ namespace mlx
|
|||||||
|
|
||||||
attributeDescriptions[1].binding = 0;
|
attributeDescriptions[1].binding = 0;
|
||||||
attributeDescriptions[1].location = 1;
|
attributeDescriptions[1].location = 1;
|
||||||
attributeDescriptions[1].format = VK_FORMAT_R32G32B32_SFLOAT;
|
attributeDescriptions[1].format = VK_FORMAT_R32G32B32A32_SFLOAT;
|
||||||
attributeDescriptions[1].offset = offsetof(Vertex, color);
|
attributeDescriptions[1].offset = offsetof(Vertex, color);
|
||||||
|
|
||||||
attributeDescriptions[2].binding = 0;
|
attributeDescriptions[2].binding = 0;
|
||||||
|
|||||||
47
src/renderer/texture_library.cpp
git.filemode.normal_file
47
src/renderer/texture_library.cpp
git.filemode.normal_file
@@ -0,0 +1,47 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* texture_library.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/04/01 14:24:00 by maldavid #+# #+# */
|
||||||
|
/* Updated: 2023/04/01 15:32:35 by maldavid ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include <core/errors.h>
|
||||||
|
#include <renderer/texture_library.h>
|
||||||
|
|
||||||
|
namespace mlx
|
||||||
|
{
|
||||||
|
std::shared_ptr<Texture> TextureLibrary::getTexture(TextureID id)
|
||||||
|
{
|
||||||
|
if(!_cache.count(id))
|
||||||
|
core::error::report(e_kind::fatal_error, "Texture Library : wrong texture ID '%d'", id);
|
||||||
|
return _cache[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureID TextureLibrary::addTextureToLibrary(std::shared_ptr<Texture> texture)
|
||||||
|
{
|
||||||
|
_cache[_current_id] = texture;
|
||||||
|
_current_id++;
|
||||||
|
return _current_id - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextureLibrary::removeTextureFromLibrary(TextureID id)
|
||||||
|
{
|
||||||
|
if(_cache.count(id))
|
||||||
|
{
|
||||||
|
_cache[id]->destroy();
|
||||||
|
_cache.erase(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextureLibrary::clearLibrary()
|
||||||
|
{
|
||||||
|
for(auto [id, texture] : _cache)
|
||||||
|
texture->destroy();
|
||||||
|
_cache.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
46
src/renderer/texture_library.h
git.filemode.normal_file
46
src/renderer/texture_library.h
git.filemode.normal_file
@@ -0,0 +1,46 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* texture_library.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/04/01 14:16:13 by maldavid #+# #+# */
|
||||||
|
/* Updated: 2023/04/01 14:42:39 by maldavid ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef __MLX_TEXTURE_LIBRARY__
|
||||||
|
#define __MLX_TEXTURE_LIBRARY__
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <renderer/images/texture.h>
|
||||||
|
|
||||||
|
namespace mlx
|
||||||
|
{
|
||||||
|
using TextureID = uint32_t;
|
||||||
|
constexpr TextureID nulltexture = 0;
|
||||||
|
|
||||||
|
class TextureLibrary
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TextureLibrary() = default;
|
||||||
|
|
||||||
|
std::shared_ptr<Texture> getTexture(TextureID id);
|
||||||
|
TextureID addTextureToLibrary(std::shared_ptr<Texture> texture);
|
||||||
|
void removeTextureFromLibrary(TextureID id);
|
||||||
|
|
||||||
|
void clearLibrary();
|
||||||
|
|
||||||
|
~TextureLibrary() = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unordered_map<TextureID, std::shared_ptr<Texture>> _cache;
|
||||||
|
TextureID _current_id = 1;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
BIN
test/42_logo.png
BIN
test/42_logo.png
Binary file not shown.
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 6.2 KiB |
11
test/main.c
11
test/main.c
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */
|
/* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/04/01 13:00:56 by maldavid ### ########.fr */
|
/* Updated: 2023/04/01 13:49:21 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -17,6 +17,7 @@ typedef struct
|
|||||||
{
|
{
|
||||||
void *mlx;
|
void *mlx;
|
||||||
void *win;
|
void *win;
|
||||||
|
void *logo;
|
||||||
} t_mlx;
|
} t_mlx;
|
||||||
|
|
||||||
int update(t_mlx *mlx)
|
int update(t_mlx *mlx)
|
||||||
@@ -24,11 +25,12 @@ int update(t_mlx *mlx)
|
|||||||
static int i = 0;
|
static int i = 0;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
|
mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->logo, 100, 100);
|
||||||
j = 0;
|
j = 0;
|
||||||
while (j < 400)
|
while (j < 400)
|
||||||
{
|
{
|
||||||
mlx_pixel_put(mlx->mlx, mlx->win, j, j, 0xFFFFFFFF);
|
mlx_pixel_put(mlx->mlx, mlx->win, j, j, 0xFF0000FF);
|
||||||
mlx_pixel_put(mlx->mlx, mlx->win, 399 - j, j, 0xFFFFFFFF);
|
mlx_pixel_put(mlx->mlx, mlx->win, 399 - j, j, 0xFF0000FF);
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
@@ -40,9 +42,12 @@ int update(t_mlx *mlx)
|
|||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
t_mlx mlx;
|
t_mlx mlx;
|
||||||
|
int w;
|
||||||
|
int h;
|
||||||
|
|
||||||
mlx.mlx = mlx_init();
|
mlx.mlx = mlx_init();
|
||||||
mlx.win = mlx_new_window(mlx.mlx, 400, 400, "My window");
|
mlx.win = mlx_new_window(mlx.mlx, 400, 400, "My window");
|
||||||
|
mlx.logo = mlx_png_file_to_image(mlx.mlx, "42_logo.png", &w, &h);
|
||||||
mlx_loop_hook(mlx.mlx, update, &mlx);
|
mlx_loop_hook(mlx.mlx, update, &mlx);
|
||||||
mlx_loop(mlx.mlx);
|
mlx_loop(mlx.mlx);
|
||||||
mlx_destroy_window(mlx.mlx, mlx.win);
|
mlx_destroy_window(mlx.mlx, mlx.win);
|
||||||
|
|||||||
Reference in New Issue
Block a user