Compare commits
No commits in common. "472a16dd2e20f4d8a3b817a1fc99d90fcb47c5fb" and "b640791963ea0bbecf4cf700bc05348f45fb9126" have entirely different histories.
472a16dd2e
...
b640791963
79
README.md
79
README.md
|
|
@ -4,85 +4,6 @@
|
|||
## Description
|
||||
A multi-platform 2D_Engine made in C.
|
||||
|
||||
## Summary
|
||||
|
||||
1. [Licenses](#licences)
|
||||
2. [Building](#building)
|
||||
|
||||
## Licences
|
||||
- This program is open-source : you can redistribute and/or modify it under the term of the **GNU GPLv3**.
|
||||
Copyright (C) 2025 - 2026 Ulysse Cura. See [LICENSE](LICENSE.txt) or [gnu.org/licenses/gpl-3.0.html](https://www.gnu.org/licenses/gpl-3.0.html).
|
||||
|
||||
## Building
|
||||
|
||||
### Setup
|
||||
|
||||
### Linux
|
||||
|
||||
The only tools needed are :
|
||||
- gcc
|
||||
- make
|
||||
- pkg-config
|
||||
|
||||
With the librairies (tested with version) :
|
||||
- sdl3 version >= 3.2.1O
|
||||
- libpng version >= 1.6.48
|
||||
- json-c version >= 0.18
|
||||
|
||||
On Debian, the command to install dependencies is :
|
||||
```
|
||||
sudo apt install gcc make pkg-config libsdl3-dev libpng-dev libjson-c-dev
|
||||
```
|
||||
|
||||
On Nix, the shell.nix file manage the dependencies for you, but it might not be up to date, as support for Nix is not a priority.
|
||||
|
||||
### Windows
|
||||
|
||||
To build on windows you will need MSYS2 or Cygwin.
|
||||
For the moment only MSYS2 is officialy supported.
|
||||
|
||||
The only tools needed are :
|
||||
- x86_64-w64-mingw32-gcc
|
||||
- make
|
||||
- x86_64-w64-mingw32-pkg-config
|
||||
|
||||
With the librairies (tested with version) :
|
||||
- sdl3 version >= 3.4.10
|
||||
- libpng version >= 1.6.58
|
||||
- json-c version >= 0.18
|
||||
|
||||
On MSYS2, the command to install dependencies is :
|
||||
```
|
||||
pacman -S mingw-w64-ucrt-x86_64-gcc make mingw-w64-ucrt-x86_64-pkg-config mingw-w64-ucrt-x86_64-sdl3 mingw-w64-ucrt-x86_64-libpng mingw-w64-ucrt-x86_64-json-c
|
||||
```
|
||||
|
||||
### Cross compiling
|
||||
|
||||
For the moment cross compiling from linux to windows is the only supported cross compiling option.
|
||||
To do that you will need the following tools :
|
||||
- x86_64-w64-mingw32-gcc
|
||||
- make
|
||||
- x86_64-w64-mingw32-pkg-config
|
||||
|
||||
With the librairies (tested with version) :
|
||||
- sdl3 version >= 3.4.10 (mingw devel)
|
||||
- libpng version >= 1.6.58
|
||||
- json-c version >= 0.18
|
||||
|
||||
On Debian the command to install dependencies is :
|
||||
```
|
||||
sudo apt install mingw-w64 mingw-w64-tools mingw-w64-ucrt64-dev make libpng-dev libjson-c-dev
|
||||
```
|
||||
|
||||
For the sdl3 mingw devel package you will need to install it manually.
|
||||
See [README-windows](https://wiki.libsdl.org/SDL3/README-windows).
|
||||
Or [releases](https://github.com/libsdl-org/SDL/releases).
|
||||
|
||||
### Commands
|
||||
|
||||
The [configure](configure) script automaticaly test compilers and libs versions for your target host.
|
||||
|
||||
See `./configure --help` for usage.
|
||||
|
||||
The aim is to support linux, windows and the fxcg50 calculator.
|
||||
However the option `--target-host` only officialy supports `linux` and `windows` but `fxcg50` is also an accepted option.
|
||||
|
|
|
|||
|
|
@ -15,42 +15,42 @@ int build_image(const char *input_file_name, FILE *output_file, uint32_t *asset_
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
png_struct *img = NULL;
|
||||
png_info *img_info = NULL;
|
||||
png_structp png_ptr = NULL;
|
||||
png_infop info_ptr = NULL;
|
||||
|
||||
// Check png autenticity.
|
||||
uint8_t sig[8];
|
||||
if(file_read(sig, sizeof(*sig), sizeof(sig), input_file)) goto_failure;
|
||||
png_byte sig[8];
|
||||
if(file_read(sig, sizeof(png_byte), sizeof(sig), input_file)) goto_failure;
|
||||
if(!png_check_sig(sig, 8))
|
||||
{
|
||||
error_printf("Png file is not valid.");
|
||||
goto failure;
|
||||
goto_failure;
|
||||
}
|
||||
|
||||
// PNG structs.
|
||||
img = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if(!img)
|
||||
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if(!png_ptr)
|
||||
{
|
||||
error_printf("Failed to allocate png ptr.");
|
||||
goto failure;
|
||||
goto_failure;
|
||||
}
|
||||
|
||||
img_info = png_create_info_struct(img);
|
||||
if(!img_info)
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if(!info_ptr)
|
||||
{
|
||||
error_printf("Failed to allocate png info.");
|
||||
goto failure;
|
||||
goto_failure;
|
||||
}
|
||||
|
||||
// Fill structs and load data.
|
||||
png_init_io(img, input_file);
|
||||
png_set_sig_bytes(img, 8);
|
||||
png_read_info(img, img_info);
|
||||
png_init_io(png_ptr, input_file);
|
||||
png_set_sig_bytes(png_ptr, 8);
|
||||
png_read_info(png_ptr, info_ptr);
|
||||
|
||||
{
|
||||
uint16_t width = png_get_image_width(img, img_info);
|
||||
uint16_t height = png_get_image_height(img, img_info);
|
||||
size_t row_length = png_get_rowbytes(img, img_info);
|
||||
uint16_t width = png_get_image_width(png_ptr, info_ptr);
|
||||
uint16_t height = png_get_image_height(png_ptr, info_ptr);
|
||||
size_t row_length = png_get_rowbytes(png_ptr, info_ptr);
|
||||
|
||||
// Write image size.
|
||||
if(file_write(&width, sizeof(width), 1, output_file)) goto_failure;
|
||||
|
|
@ -60,37 +60,15 @@ int build_image(const char *input_file_name, FILE *output_file, uint32_t *asset_
|
|||
*asset_size += sizeof(height);
|
||||
|
||||
// Prepare storage.
|
||||
uint8_t *src_pixels = calloc(height * row_length, sizeof(*src_pixels));
|
||||
if(!src_pixels)
|
||||
{
|
||||
error_printf("Failed to alloc memory : %d", errno);
|
||||
goto failure;
|
||||
}
|
||||
|
||||
uint8_t **src_row_ptrs = calloc(height, sizeof(*src_row_ptrs));
|
||||
if(!src_row_ptrs)
|
||||
{
|
||||
error_printf("Failed to alloc memory : %d", errno);
|
||||
free(src_pixels);
|
||||
goto failure;
|
||||
}
|
||||
|
||||
for(uint16_t i = 0; i < height; i++)
|
||||
png_byte src_pixels[height * row_length];
|
||||
png_bytep src_row_ptrs[height];
|
||||
for(png_uint_32 i = 0; i < height; i++)
|
||||
src_row_ptrs[i] = &src_pixels[i * row_length];
|
||||
|
||||
// Read pixels.
|
||||
png_read_image(img, src_row_ptrs);
|
||||
png_read_image(png_ptr, src_row_ptrs);
|
||||
|
||||
free(src_row_ptrs);
|
||||
png_destroy_read_struct(&img, &img_info, NULL);
|
||||
|
||||
uint16_t *dst_pixels = calloc(width * height, sizeof(*dst_pixels));
|
||||
if(!dst_pixels)
|
||||
{
|
||||
error_printf("Failed to alloc memory : %d", errno);
|
||||
free(src_pixels);
|
||||
goto failure;
|
||||
}
|
||||
uint16_t dst_pixels[width * height];
|
||||
|
||||
for(uint16_t i = 0; i < height; i++)
|
||||
{
|
||||
|
|
@ -111,18 +89,11 @@ int build_image(const char *input_file_name, FILE *output_file, uint32_t *asset_
|
|||
}
|
||||
}
|
||||
|
||||
free(src_pixels);
|
||||
|
||||
if(file_write(dst_pixels, sizeof(*dst_pixels), width * height, output_file))
|
||||
{
|
||||
free(dst_pixels);
|
||||
goto_failure;
|
||||
if(file_write(&dst_pixels, sizeof(*dst_pixels), width * height, output_file)) goto_failure;
|
||||
*asset_size += sizeof(dst_pixels);
|
||||
}
|
||||
|
||||
*asset_size += width * height * sizeof(*dst_pixels);
|
||||
|
||||
free(dst_pixels);
|
||||
}
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
|
||||
if(fclose(input_file))
|
||||
{
|
||||
|
|
@ -133,6 +104,8 @@ int build_image(const char *input_file_name, FILE *output_file, uint32_t *asset_
|
|||
return EXIT_SUCCESS;
|
||||
|
||||
failure:
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
|
||||
if(fclose(input_file))
|
||||
error_printf("Failed to close input file : %d", errno);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
#include "utils.h"
|
||||
#include "errors.h"
|
||||
|
||||
static int json_get_object_of_type(json_object *obj, const char *key, json_type type, json_object **result)
|
||||
static int json_get_object_of_type(const json_object *obj, const char *key, json_type type, json_object **result)
|
||||
{
|
||||
if(!json_object_object_get_ex(obj, key, result))
|
||||
{
|
||||
|
|
@ -24,7 +24,7 @@ static int json_get_object_of_type(json_object *obj, const char *key, json_type
|
|||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static inline int json_get_idx_of_type(json_object *obj, size_t idx, json_type type, json_object **result)
|
||||
static inline int json_get_idx_of_type(const json_object *obj, size_t idx, json_type type, json_object **result)
|
||||
{
|
||||
*result = json_object_array_get_idx(obj, idx);
|
||||
|
||||
|
|
|
|||
|
|
@ -31,26 +31,26 @@ texture_t *load_texture(void)
|
|||
if(!SDL_LockSurface(tmp_surface))
|
||||
{
|
||||
error_printf("Failed to lock temporary surface : %s", SDL_GetError());
|
||||
goto failure;
|
||||
goto_failure;
|
||||
}
|
||||
|
||||
if(fread(tmp_surface->pixels, sizeof(uint16_t), width * height, game.asset_manager.asset_file) != (size_t)width * (size_t)height)
|
||||
{
|
||||
error_printf("Failed to read asset file : %d", ferror(game.asset_manager.asset_file));
|
||||
goto failure;
|
||||
goto_failure;
|
||||
}
|
||||
|
||||
if(!SDL_SetSurfaceColorKey(tmp_surface, true, TEXTURE_TRANSPARENT_COLOR))
|
||||
{
|
||||
error_printf("Failed to set color key of temporary surface : %s", SDL_GetError());
|
||||
goto failure;
|
||||
goto_failure;
|
||||
}
|
||||
|
||||
texture_t *texture = SDL_CreateTextureFromSurface(game.display.renderer, tmp_surface);
|
||||
if(!texture)
|
||||
{
|
||||
error_printf("Failed to create texture from temporary surface : %s", SDL_GetError());
|
||||
goto failure;
|
||||
goto_failure;
|
||||
}
|
||||
|
||||
SDL_DestroySurface(tmp_surface);
|
||||
|
|
|
|||
Loading…
Reference in New Issue