diff --git a/includes/mlx.h b/includes/mlx.h index 3fa5114..e896ee0 100644 --- a/includes/mlx.h +++ b/includes/mlx.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/04 16:56:35 by maldavid #+# #+# */ -/* Updated: 2023/04/12 19:33:39 by maldavid ### ########.fr */ +/* Updated: 2023/04/19 11:35:30 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/core/application.h b/src/core/application.h index fb46936..e49b51d 100644 --- a/src/core/application.h +++ b/src/core/application.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */ -/* Updated: 2023/04/13 10:56:19 by maldavid ### ########.fr */ +/* Updated: 2023/04/19 11:31:51 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -48,7 +48,7 @@ namespace mlx::core inline void clearGraphicsSupport(void* win); inline void destroyGraphicsSupport(void* win); - inline void pixelPut(void* win, int x, int y, int color) const noexcept; + inline void pixelPut(void* win, int x, int y, uint32_t color) const noexcept; inline void stringPut(void* win, int x, int y, int color, char* str); void* newTexture(int w, int h); diff --git a/src/core/application.inl b/src/core/application.inl index 5111fb2..c343e7c 100644 --- a/src/core/application.inl +++ b/src/core/application.inl @@ -67,7 +67,7 @@ namespace mlx::core _graphics[*static_cast(win)].reset(); } - void Application::pixelPut(void* win, int x, int y, int color) const noexcept + void Application::pixelPut(void* win, int x, int y, uint32_t color) const noexcept { _graphics[*static_cast(win)]->pixelPut(x, y, color); } diff --git a/src/core/bridge.cpp b/src/core/bridge.cpp index b26e490..a41511b 100644 --- a/src/core/bridge.cpp +++ b/src/core/bridge.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */ -/* Updated: 2023/04/12 19:34:22 by maldavid ### ########.fr */ +/* Updated: 2023/04/19 11:49:40 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -144,13 +144,23 @@ extern "C" int mlx_pixel_put(void* mlx, void* win, int x, int y, int color) { - static_cast(mlx)->pixelPut(win, x, y, color); + unsigned char color_bits[4]; + color_bits[0] = (color & 0x00FF0000) >> 16; + color_bits[1] = (color & 0x0000FF00) >> 8; + color_bits[2] = color & 0x000000FF; + color_bits[3] = 0xFF; + static_cast(mlx)->pixelPut(win, x, y, *reinterpret_cast(color_bits)); return 0; } int mlx_string_put(void* mlx, void* win, int x, int y, int color, char* str) { - static_cast(mlx)->stringPut(win, x, y, color, str); + unsigned char color_bits[4]; + color_bits[0] = (color & 0x00FF0000) >> 16; + color_bits[1] = (color & 0x0000FF00) >> 8; + color_bits[2] = color & 0x000000FF; + color_bits[3] = 0xFF; + static_cast(mlx)->stringPut(win, x, y, *reinterpret_cast(color_bits), str); return 0; } diff --git a/src/core/graphics.h b/src/core/graphics.h index bac82f5..b3edab5 100644 --- a/src/core/graphics.h +++ b/src/core/graphics.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/02 14:49:49 by maldavid #+# #+# */ -/* Updated: 2023/04/11 18:37:11 by maldavid ### ########.fr */ +/* Updated: 2023/04/19 11:32:16 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,7 +40,7 @@ namespace mlx inline void beginRender() noexcept; inline void clearRenderData() noexcept; - inline void pixelPut(int x, int y, int color) noexcept; + inline void pixelPut(int x, int y, uint32_t color) noexcept; inline void stringPut(int x, int y, int color, std::string str); inline void texturePut(std::shared_ptr texture, int x, int y); diff --git a/src/core/graphics.inl b/src/core/graphics.inl index 9bfa1f6..f28aa38 100644 --- a/src/core/graphics.inl +++ b/src/core/graphics.inl @@ -32,7 +32,7 @@ namespace mlx _text_put_pipeline->clear(); } - void GraphicsSupport::pixelPut(int x, int y, int color) noexcept + void GraphicsSupport::pixelPut(int x, int y, uint32_t color) noexcept { _pixel_put_pipeline.setPixel(x, y, color); } diff --git a/src/renderer/pixel_put.cpp b/src/renderer/pixel_put.cpp index 0902329..2956935 100644 --- a/src/renderer/pixel_put.cpp +++ b/src/renderer/pixel_put.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/31 15:14:50 by maldavid #+# #+# */ -/* Updated: 2023/04/13 14:51:37 by maldavid ### ########.fr */ +/* Updated: 2023/04/19 11:32:54 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,17 +30,14 @@ namespace mlx return _texture.getSet(); } - void PixelPutPipeline::setPixel(uint32_t x, uint32_t y, int color) noexcept + void PixelPutPipeline::setPixel(uint32_t x, uint32_t y, uint32_t color) noexcept { if(x < 0 || y < 0 || x > _width || y > _height) return; if(!_buffer.isMapped()) _buffer.mapMem(&_map); unsigned char* mem = static_cast(_map) + (y * _width * sizeof(uint32_t)) + (x * sizeof(uint32_t)); - uint32_t new_color = color & 0xFFFFFF00; - new_color >>= 8; - new_color |= (color << 24) & 0xFF000000; - *reinterpret_cast(mem) = new_color; + *reinterpret_cast(mem) = color; _has_been_modified = true; } diff --git a/src/renderer/pixel_put.h b/src/renderer/pixel_put.h index d030b23..d1108de 100644 --- a/src/renderer/pixel_put.h +++ b/src/renderer/pixel_put.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/31 13:18:50 by maldavid #+# #+# */ -/* Updated: 2023/04/03 14:22:35 by maldavid ### ########.fr */ +/* Updated: 2023/04/19 11:32:34 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,7 @@ namespace mlx void init(uint32_t width, uint32_t height, class Renderer& renderer) noexcept; - void setPixel(uint32_t x, uint32_t y, int color) noexcept; + void setPixel(uint32_t x, uint32_t y, uint32_t color) noexcept; void present() noexcept; void render(class Renderer& renderer) noexcept; VkDescriptorSet getDescriptorSet() noexcept; diff --git a/test/main.c b/test/main.c index ab12830..1684887 100644 --- a/test/main.c +++ b/test/main.c @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */ -/* Updated: 2023/04/13 14:59:32 by maldavid ### ########.fr */ +/* Updated: 2023/04/19 11:49:56 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,14 +24,18 @@ int update(t_mlx *mlx) { static int i = 0; int j; + int k; mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->logo, 100, 100); mlx_string_put(mlx->mlx, mlx->win, 20, 50, 0xFFFFFFFF, "that's a text"); j = 0; + k = 0; while (j < 400) { - mlx_pixel_put(mlx->mlx, mlx->win, j, j, 0xFF00FF01); + mlx_pixel_put(mlx->mlx, mlx->win, j, j, 0xFFFF0000 + k); mlx_pixel_put(mlx->mlx, mlx->win, 399 - j, j, 0xFF0000FF); + if (k < 255) + k++; j++; } i++;