Add MLX42 V3

This commit is contained in:
Etienne Rey-bethbeder
2023-04-26 14:03:40 +02:00
parent bc5fc2fc59
commit baab9b52cd
22 changed files with 125 additions and 298 deletions

View File

@ -19,10 +19,10 @@
// GIMP RGBA C-Source image dump (font.c)
static struct s_font
{
uint32_t width;
uint32_t height;
uint32_t bpp;
char* pixels;
uint32_t width;
uint32_t height;
uint32_t bpp;
uint8_t pixels[1140 * 20 * 4 + 1];
} font_atlas = {
1140, 20, 4,
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"

View File

@ -31,7 +31,7 @@ static void mlx_draw_char(mlx_image_t* image, int32_t texoffset, int32_t imgoffs
if (texoffset < 0)
return;
char* pixelx;
uint8_t* pixelx;
uint8_t* pixeli;
for (uint32_t y = 0; y < FONT_HEIGHT; y++)
{

View File

@ -3,10 +3,10 @@
/* :::::::: */
/* mlx_cursor.c :+: :+: */
/* +:+ */
/* By: W2Wizard <main@w2wizard.dev> +#+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* +#+ */
/* Created: 2022/01/18 20:10:54 by W2Wizard #+# #+# */
/* Updated: 2023/03/09 11:11:45 by W2Wizard ######## odam.nl */
/* Updated: 2022/11/22 08:58:23 by jvan-hal ######## odam.nl */
/* */
/* ************************************************************************** */
@ -14,7 +14,7 @@
//= Public =//
mlx_win_cursor_t* mlx_create_std_cursor(cursor_t type)
void* mlx_create_std_cursor(cursor_t type)
{
MLX_ASSERT(type >= MLX_CURSOR_ARROW && type < MLX_CURSOR_VRESIZE, "Invalid standard cursor type");
@ -24,7 +24,7 @@ mlx_win_cursor_t* mlx_create_std_cursor(cursor_t type)
return ((void *)mlx_error(MLX_MEMFAIL));
}
mlx_win_cursor_t* mlx_create_cursor(mlx_texture_t* texture)
void* mlx_create_cursor(mlx_texture_t* texture)
{
MLX_NONNULL(texture);
@ -40,14 +40,7 @@ mlx_win_cursor_t* mlx_create_cursor(mlx_texture_t* texture)
return ((void *)mlx_error(MLX_MEMFAIL));
}
void mlx_destroy_cursor(mlx_win_cursor_t* cursor)
{
MLX_NONNULL(cursor);
glfwDestroyCursor(cursor);
}
void mlx_set_cursor(mlx_t* mlx, mlx_win_cursor_t* cursor)
void mlx_set_cursor(mlx_t* mlx, void* cursor)
{
MLX_NONNULL(mlx);
MLX_NONNULL(cursor);

View File

@ -3,10 +3,10 @@
/* :::::::: */
/* mlx_images.c :+: :+: */
/* +:+ */
/* By: W2Wizard <main@w2wizard.dev> +#+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* +#+ */
/* Created: 2021/12/28 02:29:06 by W2Wizard #+# #+# */
/* Updated: 2023/03/30 16:36:39 by ntamayo- ######## odam.nl */
/* Created: 2022/01/21 15:34:45 by W2Wizard #+# #+# */
/* Updated: 2022/07/28 18:26:59 by sbos ######## odam.nl */
/* */
/* ************************************************************************** */
@ -229,23 +229,13 @@ bool mlx_resize_image(mlx_image_t* img, uint32_t nwidth, uint32_t nheight)
return (mlx_error(MLX_INVDIM));
if (nwidth != img->width || nheight != img->height)
{
uint32_t* origin = (uint32_t*)img->pixels;
float wstep = (float)img->width / nwidth;
float hstep = (float)img->height / nheight;
uint8_t* tempbuff = calloc(nwidth * nheight, BPP);
uint8_t* tempbuff = realloc(img->pixels, (nwidth * nheight) * BPP);
if (!tempbuff)
return (mlx_error(MLX_MEMFAIL));
img->pixels = tempbuff;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, nwidth, nheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, img->pixels);
uint32_t* destin = (uint32_t*)img->pixels;
for (uint32_t j = 0; j < nheight; j++)
for (uint32_t i = 0; i < nwidth; i++)
destin[j * nwidth + i] = origin[(uint32_t)(j * hstep) * img->width + (uint32_t)(i * wstep)];
(*(uint32_t*)&img->width) = nwidth;
(*(uint32_t*)&img->height) = nheight;
free(origin);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, nwidth, nheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, img->pixels);
}
return (true);
}

View File

@ -6,7 +6,7 @@
/* By: W2Wizard <main@w2wizard.dev> +#+ */
/* +#+ */
/* Created: 2021/12/28 01:24:36 by W2Wizard #+# #+# */
/* Updated: 2023/03/28 16:34:17 by W2Wizard ######## odam.nl */
/* Updated: 2023/02/13 12:26:17 by W2Wizard ######## odam.nl */
/* */
/* ************************************************************************** */
@ -42,11 +42,8 @@ static void mlx_render_images(mlx_t* mlx)
while (imglst)
{
mlx_image_t* image;
if (!(image = imglst->content)) {
mlx_error(MLX_INVIMG);
return;
}
if (!(image = imglst->content))
return ((void)mlx_error(MLX_INVIMG));
glBindTexture(GL_TEXTURE_2D, ((mlx_image_ctx_t*)image->context)->texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->width, image->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);
imglst = imglst->next;

View File

@ -3,10 +3,10 @@
/* :::::::: */
/* mlx_texture.c :+: :+: */
/* +:+ */
/* By: W2Wizard <main@w2wizard.dev> +#+ */
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* +#+ */
/* Created: 2022/02/17 01:02:24 by W2Wizard #+# #+# */
/* Updated: 2023/03/09 11:03:47 by W2Wizard ######## odam.nl */
/* Updated: 2022/06/29 15:34:25 by lde-la-h ######## odam.nl */
/* */
/* ************************************************************************** */
@ -14,24 +14,66 @@
//= Public =//
mlx_image_t* mlx_texture_area_to_image(mlx_t* mlx, mlx_texture_t* texture, uint32_t xy[2], uint32_t wh[2])
{
MLX_NONNULL(mlx);
MLX_NONNULL(texture);
MLX_NONNULL(xy);
MLX_NONNULL(wh);
if (wh[0] > texture->width || wh[1] > texture->height)
return ((void*)mlx_error(MLX_INVDIM));
if (xy[0] > texture->width || xy[1] > texture->height)
return ((void*)mlx_error(MLX_INVPOS));
mlx_image_t* image;
if (!(image = mlx_new_image(mlx, wh[0], wh[1])))
return ((void*)mlx_error(MLX_MEMFAIL));
uint8_t* pixelx;
uint8_t* pixeli;
for (uint32_t y = 0; y < wh[1]; y++)
{
pixelx = &texture->pixels[((xy[1] + y) * texture->width + xy[0]) * BPP];
pixeli = &image->pixels[y * wh[0] * BPP];
memmove(pixeli, pixelx, wh[0] * BPP);
}
return (image);
}
mlx_image_t* mlx_texture_to_image(mlx_t* mlx, mlx_texture_t* texture)
{
MLX_NONNULL(mlx);
MLX_NONNULL(texture);
mlx_image_t* image = mlx_new_image(mlx, texture->width, texture->height);
if (image == NULL)
mlx_image_t* img;
const int32_t xy[] = {0, 0};
const uint32_t wh[] = {texture->width, texture->height};
if (!(img = mlx_texture_area_to_image(mlx, texture, (uint32_t*)xy, (uint32_t*)wh)))
return (NULL);
return (img);
}
bool mlx_draw_texture(mlx_image_t* image, mlx_texture_t* texture, uint32_t x, uint32_t y)
{
MLX_NONNULL(image);
MLX_NONNULL(texture);
if (texture->width > image->width || texture->height > image->height)
return (mlx_error(MLX_INVDIM));
if (x > image->width || y > image->height)
return (mlx_error(MLX_INVPOS));
uint8_t* pixelx;
uint8_t* pixeli;
for (uint32_t i = 0; i < texture->height; i++)
{
pixelx = &texture->pixels[(i * texture->width) * texture->bytes_per_pixel];
pixeli = &image->pixels[(i * image->width) * texture->bytes_per_pixel];
pixeli = &image->pixels[((i + y) * image->width + x) * texture->bytes_per_pixel];
memmove(pixeli, pixelx, texture->width * texture->bytes_per_pixel);
}
return (image);
return (true);
}
void mlx_delete_texture(mlx_texture_t* texture)