Add MLX42 V3
This commit is contained in:
parent
bc5fc2fc59
commit
baab9b52cd
8
MLX42/.gitattributes
vendored
8
MLX42/.gitattributes
vendored
@ -1,8 +0,0 @@
|
|||||||
# See https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings
|
|
||||||
|
|
||||||
# Set the default behavior, in case people don't have core.autocrlf set
|
|
||||||
* text=auto
|
|
||||||
|
|
||||||
# Declare files that will always have a certain EOL
|
|
||||||
*.sh text eol=lf
|
|
||||||
shaders/** text eol=lf
|
|
34
MLX42/.github/ISSUE_TEMPLATE/bug_report.md
vendored
34
MLX42/.github/ISSUE_TEMPLATE/bug_report.md
vendored
@ -1,34 +0,0 @@
|
|||||||
---
|
|
||||||
name: Bug report
|
|
||||||
about: Create a report to help us improve
|
|
||||||
title: "[BUG]"
|
|
||||||
labels: ''
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**NOTE**
|
|
||||||
Before creating a bug report! Make sure you git pull from master and check if the bug still exists!
|
|
||||||
|
|
||||||
**Describe the bug**
|
|
||||||
A clear and concise description of what the bug is.
|
|
||||||
|
|
||||||
**To Reproduce**
|
|
||||||
Steps to reproduce the behavior:
|
|
||||||
1. Go to '...'
|
|
||||||
2. Click on '...'
|
|
||||||
3. Scroll down to '...'
|
|
||||||
4. See error
|
|
||||||
|
|
||||||
**Expected behavior**
|
|
||||||
A clear and concise description of what you expected to happen.
|
|
||||||
|
|
||||||
**Screenshots**
|
|
||||||
If applicable, add screenshots to help explain your problem.
|
|
||||||
|
|
||||||
**Desktop (please complete the following information):**
|
|
||||||
- OS: [e.g. MacOS]
|
|
||||||
- Version: [e.g. BigSur]
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
Add any other context about the problem here.
|
|
20
MLX42/.github/ISSUE_TEMPLATE/feature_request.md
vendored
20
MLX42/.github/ISSUE_TEMPLATE/feature_request.md
vendored
@ -1,20 +0,0 @@
|
|||||||
---
|
|
||||||
name: Feature request
|
|
||||||
about: Suggest an idea for this project
|
|
||||||
title: "[REQUEST]"
|
|
||||||
labels: ''
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Is your feature request related to a problem? Please describe.**
|
|
||||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
|
||||||
|
|
||||||
**Describe the solution you'd like**
|
|
||||||
A clear and concise description of what you want to happen.
|
|
||||||
|
|
||||||
**Describe alternatives you've considered**
|
|
||||||
A clear and concise description of any alternative solutions or features you've considered.
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
Add any other context or screenshots about the feature request here.
|
|
78
MLX42/.github/workflows/ci.yml
vendored
78
MLX42/.github/workflows/ci.yml
vendored
@ -1,78 +0,0 @@
|
|||||||
# -----------------------------------------------------------------------------
|
|
||||||
# Codam Coding College, Amsterdam @ 2022-2023-2023 by W2Wizard.
|
|
||||||
# See README in the root project for more information.
|
|
||||||
# -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
name: Build
|
|
||||||
|
|
||||||
#=============================================================================#
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ master ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ master ]
|
|
||||||
|
|
||||||
#=============================================================================#
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
|
|
||||||
# Tests
|
|
||||||
#=============================================================================#
|
|
||||||
|
|
||||||
unit-test:
|
|
||||||
timeout-minutes: 10
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
env:
|
|
||||||
DISPLAY: ":99"
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Clone repository
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Install Dependencies
|
|
||||||
run: |
|
|
||||||
sudo apt-get update -qq
|
|
||||||
sudo apt-get install -y -qq xorg-dev xvfb
|
|
||||||
|
|
||||||
- name: Setup virtual screen
|
|
||||||
run: Xvfb $DISPLAY -screen 0 1280x1024x24 &
|
|
||||||
|
|
||||||
- name: Build MLX42 & tests
|
|
||||||
run: cmake -DBUILD_TESTS=YES -B ${{github.workspace}}/build && cmake --build ${{github.workspace}}/build --parallel
|
|
||||||
|
|
||||||
- name: Run tests
|
|
||||||
run: ctest --output-on-failure --test-dir ${{github.workspace}}/build
|
|
||||||
|
|
||||||
# Unix
|
|
||||||
#=============================================================================#
|
|
||||||
|
|
||||||
build:
|
|
||||||
timeout-minutes: 10
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Clone repository
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
# Windows will just fetch glfw with cmake automatically.
|
|
||||||
# This avoids doing extra work like installing a package manager.
|
|
||||||
- name: Install Dependencies
|
|
||||||
if: matrix.os != 'windows-latest'
|
|
||||||
run: |
|
|
||||||
set -x
|
|
||||||
if [ "$RUNNER_OS" == "Linux" ]; then
|
|
||||||
sudo apt-get update -qq
|
|
||||||
sudo apt-get install -y -qq xorg-dev
|
|
||||||
elif [ "$RUNNER_OS" == "macOS" ]; then
|
|
||||||
brew update
|
|
||||||
brew install glfw
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
run: cmake -B build && cmake --build build --parallel
|
|
||||||
|
|
||||||
#=============================================================================#
|
|
68
MLX42/.gitignore
vendored
68
MLX42/.gitignore
vendored
@ -1,68 +0,0 @@
|
|||||||
# Prerequisites
|
|
||||||
*.d
|
|
||||||
|
|
||||||
# Object files
|
|
||||||
*.o
|
|
||||||
*.ko
|
|
||||||
*.obj
|
|
||||||
*.elf
|
|
||||||
|
|
||||||
# Linker output
|
|
||||||
*.ilk
|
|
||||||
*.map
|
|
||||||
*.exp
|
|
||||||
|
|
||||||
# Precompiled Headers
|
|
||||||
*.gch
|
|
||||||
*.pch
|
|
||||||
|
|
||||||
# Libraries
|
|
||||||
*.lib
|
|
||||||
*.a
|
|
||||||
*.la
|
|
||||||
*.lo
|
|
||||||
|
|
||||||
# Shared objects (inc. Windows DLLs)
|
|
||||||
*.dll
|
|
||||||
*.so
|
|
||||||
*.so.*
|
|
||||||
*.dylib
|
|
||||||
|
|
||||||
# Executables
|
|
||||||
*.exe
|
|
||||||
*.out
|
|
||||||
*.app
|
|
||||||
*.i*86
|
|
||||||
*.x86_64
|
|
||||||
*.hex
|
|
||||||
|
|
||||||
# Debug files
|
|
||||||
*.dSYM/
|
|
||||||
*.su
|
|
||||||
*.idb
|
|
||||||
*.pdb
|
|
||||||
|
|
||||||
# Kernel Module Compile Results
|
|
||||||
*.mod*
|
|
||||||
*.cmd
|
|
||||||
.tmp_versions/
|
|
||||||
modules.order
|
|
||||||
Module.symvers
|
|
||||||
Mkfile.old
|
|
||||||
dkms.conf
|
|
||||||
|
|
||||||
# Misc
|
|
||||||
main.c
|
|
||||||
temp/
|
|
||||||
.vscode/
|
|
||||||
lib/glfw/
|
|
||||||
.DS_Store
|
|
||||||
|
|
||||||
# Special shader files
|
|
||||||
mlx_*_shader.c
|
|
||||||
build/
|
|
||||||
main.c
|
|
||||||
test
|
|
||||||
|
|
||||||
# Automatic downloaded deps
|
|
||||||
_deps/
|
|
@ -5,8 +5,8 @@
|
|||||||
|
|
||||||
# CMake specifications
|
# CMake specifications
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
cmake_minimum_required (VERSION 3.18.0)
|
cmake_minimum_required (VERSION 3.16.0)
|
||||||
project(mlx42 VERSION 2.3.1)
|
project(mlx42 VERSION 2.3.0)
|
||||||
message(STATUS "MLX42 @ ${CMAKE_PROJECT_VERSION}")
|
message(STATUS "MLX42 @ ${CMAKE_PROJECT_VERSION}")
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
|
@ -79,6 +79,11 @@ Then simply run them with:
|
|||||||
ctest --output-on-failure --test-dir build
|
ctest --output-on-failure --test-dir build
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Available Options
|
||||||
|
|
||||||
|
You can pass build options to cmake ... `cmake -DDEBUG=1 -DGLFW_FETCH=0` ... to customise the install, more at [installation](./docs/index.md#available-options).
|
||||||
|
You can find an example makefile in the documentation [here](https://github.com/codam-coding-college/MLX42/blob/master/docs/Basics.md).
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
## Download and build - MLX42
|
## Download and build - MLX42
|
||||||
@ -92,12 +97,6 @@ ctest --output-on-failure --test-dir build
|
|||||||
|
|
||||||
The output library file is called `libmlx42.a` and is located in the `build` folder that you specified.
|
The output library file is called `libmlx42.a` and is located in the `build` folder that you specified.
|
||||||
|
|
||||||
### Available Options
|
|
||||||
|
|
||||||
You can pass build [options](./docs/index.md#available-options) to cmake, e.g: `cmake -DDEBUG=1 -DGLFW_FETCH=0...`. These will for instance let you build it in DEBUG mode or alter any sort of behaviour at build-time.
|
|
||||||
|
|
||||||
You can find an example makefile in the documentation [here](https://github.com/codam-coding-college/MLX42/blob/master/docs/Basics.md).
|
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
## For MacOS:
|
## For MacOS:
|
||||||
@ -250,7 +249,7 @@ int32_t ft_pixel(int32_t r, int32_t g, int32_t b, int32_t a)
|
|||||||
return (r << 24 | g << 16 | b << 8 | a);
|
return (r << 24 | g << 16 | b << 8 | a);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_randomize(void* param)
|
void ft_randomize(void* img)
|
||||||
{
|
{
|
||||||
for (int32_t i = 0; i < image->width; ++i)
|
for (int32_t i = 0; i < image->width; ++i)
|
||||||
{
|
{
|
||||||
|
1
MLX42/Testing/Temporary/CTestCostData.txt
Normal file
1
MLX42/Testing/Temporary/CTestCostData.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
---
|
3
MLX42/Testing/Temporary/LastTest.log
Normal file
3
MLX42/Testing/Temporary/LastTest.log
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Start testing: Mar 03 14:00 CET
|
||||||
|
----------------------------------------------------------
|
||||||
|
End testing: Mar 03 14:00 CET
|
@ -13,9 +13,8 @@
|
|||||||
set(_glfw3_HEADER_SEARCH_DIRS
|
set(_glfw3_HEADER_SEARCH_DIRS
|
||||||
"/usr/include"
|
"/usr/include"
|
||||||
"/usr/local/include"
|
"/usr/local/include"
|
||||||
"C:/Program Files/GLFW/include"
|
"C:/Program Files/GLFW"
|
||||||
"C:/Program Files (x86)/GLFW/include"
|
"$ENV{HOME}/.brew/lib/"
|
||||||
"$ENV{HOME}/.brew/include/"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Possbile library locations
|
# Possbile library locations
|
||||||
@ -23,7 +22,6 @@ set(_glfw3_LIB_SEARCH_DIRS
|
|||||||
"/usr/lib"
|
"/usr/lib"
|
||||||
"/usr/local/lib"
|
"/usr/local/lib"
|
||||||
"C:/Program Files/GLFW"
|
"C:/Program Files/GLFW"
|
||||||
"C:/Program Files (x86)/GLFW"
|
|
||||||
"$ENV{HOME}/.brew/lib/"
|
"$ENV{HOME}/.brew/lib/"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -120,8 +120,6 @@ Q: **_"Are the libraries 1:1 identical?"_**
|
|||||||
|
|
||||||
A: No, there are 100% breaking changes, and changing from miniLibX to MLX42 will not be a simple drop-in replacement. As in their API is slightly different. That was not the idea eitherway, as it would be impossible to fix the problems present in the current miniLibX.
|
A: No, there are 100% breaking changes, and changing from miniLibX to MLX42 will not be a simple drop-in replacement. As in their API is slightly different. That was not the idea eitherway, as it would be impossible to fix the problems present in the current miniLibX.
|
||||||
|
|
||||||
In terms of usage, it's practically identical, while the API Prototypes are slightly different, the usage is roughly the same and the only core difference is the way images are handled.
|
|
||||||
|
|
||||||
My suggestion is for students who are using miniLibX to keep using it to finish their project and for new students to prefer the new one or until they reach the next graphical project.
|
My suggestion is for students who are using miniLibX to keep using it to finish their project and for new students to prefer the new one or until they reach the next graphical project.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* :::::::: */
|
/* :::::::: */
|
||||||
/* MLX42_Keys.h :+: :+: */
|
/* MLX42.h :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ */
|
||||||
/* By: W2Wizard <main@w2wizard.dev> +#+ */
|
/* By: W2Wizard <main@w2wizard.dev> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2021/12/28 02:29:06 by W2Wizard #+# #+# */
|
/* Created: 2021/12/28 00:33:01 by W2Wizard #+# #+# */
|
||||||
/* Updated: 2023/03/30 16:23:19 by ntamayo- ######## odam.nl */
|
/* Updated: 2023/02/01 11:33:26 by W2Wizard ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -469,13 +469,6 @@ mlx_win_cursor_t* mlx_create_std_cursor(cursor_t type);
|
|||||||
*/
|
*/
|
||||||
mlx_win_cursor_t* mlx_create_cursor(mlx_texture_t* texture);
|
mlx_win_cursor_t* mlx_create_cursor(mlx_texture_t* texture);
|
||||||
|
|
||||||
/**
|
|
||||||
* Destroys the given cursor object.
|
|
||||||
*
|
|
||||||
* @param[in] cursor The cursor object to destroy.
|
|
||||||
*/
|
|
||||||
void mlx_destroy_cursor(mlx_win_cursor_t* cursor);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the current cursor to the given custom cursor.
|
* Sets the current cursor to the given custom cursor.
|
||||||
*
|
*
|
||||||
@ -601,6 +594,31 @@ void mlx_delete_xpm42(xpm_t* xpm);
|
|||||||
*/
|
*/
|
||||||
mlx_image_t* mlx_texture_to_image(mlx_t* mlx, mlx_texture_t* texture);
|
mlx_image_t* mlx_texture_to_image(mlx_t* mlx, mlx_texture_t* texture);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given an X & Y coordinate and a Width and Height from a section of a
|
||||||
|
* texture a new image is created, useful for texture atlases.
|
||||||
|
*
|
||||||
|
* Basically a cropping tool.
|
||||||
|
*
|
||||||
|
* @param[in] mlx The MLX instance handle.
|
||||||
|
* @param[in] texture The texture to use to create the image from.
|
||||||
|
* @param[in] xy The X & Y location.
|
||||||
|
* @param[in] wh The Width & Height.
|
||||||
|
* @return mlx_image_t* The image created from the texture area.
|
||||||
|
*/
|
||||||
|
mlx_image_t* mlx_texture_area_to_image(mlx_t* mlx, mlx_texture_t* texture, uint32_t xy[2], uint32_t wh[2]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the texture on an already existing image.
|
||||||
|
*
|
||||||
|
* @param[in] image The image to draw on.
|
||||||
|
* @param[in] texture The texture to use to draw on the image.
|
||||||
|
* @param[in] x X position relative to the image.
|
||||||
|
* @param[in] y Y position relative to the image.
|
||||||
|
* @return In case of any issues false, else true.
|
||||||
|
*/
|
||||||
|
bool mlx_draw_texture(mlx_image_t* image, mlx_texture_t* texture, uint32_t x, uint32_t y);
|
||||||
|
|
||||||
//= Image Functions =//
|
//= Image Functions =//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -659,8 +677,8 @@ int32_t mlx_image_to_window(mlx_t* mlx, mlx_image_t* img, int32_t x, int32_t y);
|
|||||||
void mlx_delete_image(mlx_t* mlx, mlx_image_t* image);
|
void mlx_delete_image(mlx_t* mlx, mlx_image_t* image);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows you to resize an image, a new pixel buffer is allocated
|
* Allows you to resize an image, the pixel buffer is re-allocated
|
||||||
* to fit & the previous data is scaled to fit the new size.
|
* to fit & the previous data is copied over. New pixels are zeroed.
|
||||||
*
|
*
|
||||||
* @param[in] img The image to resize.
|
* @param[in] img The image to resize.
|
||||||
* @param[in] nwidth The new width.
|
* @param[in] nwidth The new width.
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* :::::::: */
|
/* :::::::: */
|
||||||
/* MLX42_Int.h :+: :+: */
|
/* MLX42_Int.h :+: :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ */
|
||||||
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
|
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2021/12/27 23:55:34 by W2Wizard #+# #+# */
|
/* Created: 2021/12/27 23:55:34 by W2Wizard #+# #+# */
|
||||||
/* Updated: 2022/07/21 10:46:43 by sbos ######## odam.nl */
|
/* Updated: 2023/03/03 11:13:25 by ulayus ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef MLX42_INT_H
|
#ifndef MLX42_INT_H
|
||||||
# define MLX42_INT_H
|
# define MLX42_INT_H
|
||||||
# define LODEPNG_NO_COMPILE_ALLOCATORS
|
# define LODEPNG_NO_COMPILE_ALLOCATORS
|
||||||
# include "MLX42/MLX42.h"
|
# include "MLX42.h"
|
||||||
# include "lodepng/lodepng.h"
|
# include "lodepng/lodepng.h"
|
||||||
# include "glad/glad.h"
|
# include "glad/glad.h"
|
||||||
# include "KHR/khrplatform.h"
|
# include "KHR/khrplatform.h"
|
||||||
|
@ -22,7 +22,7 @@ static struct s_font
|
|||||||
uint32_t width;
|
uint32_t width;
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
uint32_t bpp;
|
uint32_t bpp;
|
||||||
char* pixels;
|
uint8_t pixels[1140 * 20 * 4 + 1];
|
||||||
} font_atlas = {
|
} font_atlas = {
|
||||||
1140, 20, 4,
|
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"
|
"\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"
|
||||||
|
@ -31,7 +31,7 @@ static void mlx_draw_char(mlx_image_t* image, int32_t texoffset, int32_t imgoffs
|
|||||||
if (texoffset < 0)
|
if (texoffset < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
char* pixelx;
|
uint8_t* pixelx;
|
||||||
uint8_t* pixeli;
|
uint8_t* pixeli;
|
||||||
for (uint32_t y = 0; y < FONT_HEIGHT; y++)
|
for (uint32_t y = 0; y < FONT_HEIGHT; y++)
|
||||||
{
|
{
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
/* :::::::: */
|
/* :::::::: */
|
||||||
/* mlx_cursor.c :+: :+: */
|
/* mlx_cursor.c :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ */
|
||||||
/* By: W2Wizard <main@w2wizard.dev> +#+ */
|
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2022/01/18 20:10:54 by W2Wizard #+# #+# */
|
/* 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 =//
|
//= 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");
|
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));
|
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);
|
MLX_NONNULL(texture);
|
||||||
|
|
||||||
@ -40,14 +40,7 @@ mlx_win_cursor_t* mlx_create_cursor(mlx_texture_t* texture)
|
|||||||
return ((void *)mlx_error(MLX_MEMFAIL));
|
return ((void *)mlx_error(MLX_MEMFAIL));
|
||||||
}
|
}
|
||||||
|
|
||||||
void mlx_destroy_cursor(mlx_win_cursor_t* cursor)
|
void mlx_set_cursor(mlx_t* mlx, void* cursor)
|
||||||
{
|
|
||||||
MLX_NONNULL(cursor);
|
|
||||||
|
|
||||||
glfwDestroyCursor(cursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
void mlx_set_cursor(mlx_t* mlx, mlx_win_cursor_t* cursor)
|
|
||||||
{
|
{
|
||||||
MLX_NONNULL(mlx);
|
MLX_NONNULL(mlx);
|
||||||
MLX_NONNULL(cursor);
|
MLX_NONNULL(cursor);
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
/* :::::::: */
|
/* :::::::: */
|
||||||
/* mlx_images.c :+: :+: */
|
/* mlx_images.c :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ */
|
||||||
/* By: W2Wizard <main@w2wizard.dev> +#+ */
|
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2021/12/28 02:29:06 by W2Wizard #+# #+# */
|
/* Created: 2022/01/21 15:34:45 by W2Wizard #+# #+# */
|
||||||
/* Updated: 2023/03/30 16:36:39 by ntamayo- ######## odam.nl */
|
/* 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));
|
return (mlx_error(MLX_INVDIM));
|
||||||
if (nwidth != img->width || nheight != img->height)
|
if (nwidth != img->width || nheight != img->height)
|
||||||
{
|
{
|
||||||
uint32_t* origin = (uint32_t*)img->pixels;
|
uint8_t* tempbuff = realloc(img->pixels, (nwidth * nheight) * BPP);
|
||||||
float wstep = (float)img->width / nwidth;
|
|
||||||
float hstep = (float)img->height / nheight;
|
|
||||||
|
|
||||||
uint8_t* tempbuff = calloc(nwidth * nheight, BPP);
|
|
||||||
if (!tempbuff)
|
if (!tempbuff)
|
||||||
return (mlx_error(MLX_MEMFAIL));
|
return (mlx_error(MLX_MEMFAIL));
|
||||||
img->pixels = tempbuff;
|
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->width) = nwidth;
|
||||||
(*(uint32_t*)&img->height) = nheight;
|
(*(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);
|
return (true);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: W2Wizard <main@w2wizard.dev> +#+ */
|
/* By: W2Wizard <main@w2wizard.dev> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2021/12/28 01:24:36 by W2Wizard #+# #+# */
|
/* 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)
|
while (imglst)
|
||||||
{
|
{
|
||||||
mlx_image_t* image;
|
mlx_image_t* image;
|
||||||
if (!(image = imglst->content)) {
|
if (!(image = imglst->content))
|
||||||
mlx_error(MLX_INVIMG);
|
return ((void)mlx_error(MLX_INVIMG));
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, ((mlx_image_ctx_t*)image->context)->texture);
|
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);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->width, image->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);
|
||||||
imglst = imglst->next;
|
imglst = imglst->next;
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
/* :::::::: */
|
/* :::::::: */
|
||||||
/* mlx_texture.c :+: :+: */
|
/* mlx_texture.c :+: :+: */
|
||||||
/* +:+ */
|
/* +:+ */
|
||||||
/* By: W2Wizard <main@w2wizard.dev> +#+ */
|
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2022/02/17 01:02:24 by W2Wizard #+# #+# */
|
/* 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 =//
|
//= 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_image_t* mlx_texture_to_image(mlx_t* mlx, mlx_texture_t* texture)
|
||||||
{
|
{
|
||||||
MLX_NONNULL(mlx);
|
MLX_NONNULL(mlx);
|
||||||
MLX_NONNULL(texture);
|
MLX_NONNULL(texture);
|
||||||
|
|
||||||
mlx_image_t* image = mlx_new_image(mlx, texture->width, texture->height);
|
mlx_image_t* img;
|
||||||
if (image == NULL)
|
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 (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* pixelx;
|
||||||
uint8_t* pixeli;
|
uint8_t* pixeli;
|
||||||
for (uint32_t i = 0; i < texture->height; i++)
|
for (uint32_t i = 0; i < texture->height; i++)
|
||||||
{
|
{
|
||||||
pixelx = &texture->pixels[(i * texture->width) * texture->bytes_per_pixel];
|
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);
|
memmove(pixeli, pixelx, texture->width * texture->bytes_per_pixel);
|
||||||
}
|
}
|
||||||
return (image);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mlx_delete_texture(mlx_texture_t* texture)
|
void mlx_delete_texture(mlx_texture_t* texture)
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# Codam Coding College, Amsterdam @ 2022-2023 by Jelle van Kraaij.
|
# Codam Coding College, Amsterdam @ 2022-2023 by W2Wizard.
|
||||||
# See README in the root project for more information.
|
# See README in the root project for more information.
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
set(TEST_EXECUTABLE_NAME unit_tests)
|
set(TEST_EXECUTABLE_NAME unit_tests)
|
||||||
|
|
||||||
# Download GoogleTest
|
# Download GoogleTest
|
||||||
# -----------------------------------------------------------------------------
|
# --------------------------------------------------
|
||||||
include(GoogleTest)
|
include(GoogleTest)
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ FetchContent_Declare(
|
|||||||
|
|
||||||
FetchContent_MakeAvailable(googletest)
|
FetchContent_MakeAvailable(googletest)
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# --------------------------------------------------
|
||||||
add_executable(
|
add_executable(
|
||||||
${TEST_EXECUTABLE_NAME}
|
${TEST_EXECUTABLE_NAME}
|
||||||
tests.cpp
|
tests.cpp
|
||||||
@ -35,6 +35,6 @@ set_property(TARGET ${TEST_EXECUTABLE_NAME} PROPERTY CXX_STANDARD 14)
|
|||||||
|
|
||||||
# Add tests to CTest
|
# Add tests to CTest
|
||||||
# Set working directory to the the testing folder so that the test can find their test files
|
# Set working directory to the the testing folder so that the test can find their test files
|
||||||
# -----------------------------------------------------------------------------
|
# --------------------------------------------------
|
||||||
gtest_discover_tests(${TEST_EXECUTABLE_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} TEST_PREFIX "MLX42.")
|
gtest_discover_tests(${TEST_EXECUTABLE_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} TEST_PREFIX "MLX42.")
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
@ -1,17 +1,13 @@
|
|||||||
// -----------------------------------------------------------------------------
|
|
||||||
// Codam Coding College, Amsterdam @ 2022-2023 by Jelle van Kraaij.
|
|
||||||
// See README in the root project for more information.
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
# pragma once
|
# pragma once
|
||||||
|
|
||||||
# include <gtest/gtest.h>
|
# include <gtest/gtest.h>
|
||||||
|
|
||||||
# include <MLX42/MLX42.h>
|
# include <MLX42/MLX42.h>
|
||||||
|
|
||||||
class Window : public ::testing::Test
|
class Window : public ::testing::Test
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
mlx_t* mlx = nullptr;
|
mlx_t* mlx = NULL;
|
||||||
|
|
||||||
static constexpr const char* name = "MLX42";
|
static constexpr const char* name = "MLX42";
|
||||||
static const int32_t height = 400;
|
static const int32_t height = 400;
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
// -----------------------------------------------------------------------------
|
#include <gtest/gtest.h>
|
||||||
// Codam Coding College, Amsterdam @ 2022-2023 by Jelle van Kraaij.
|
#include <MLX42/MLX42.h>
|
||||||
// See README in the root project for more information.
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
// --------------------------------------------
|
||||||
// If your new to gtest follow the following documentation:
|
// If your new to gtest follow the following documentation:
|
||||||
// http://google.github.io/googletest/primer.html
|
// http://google.github.io/googletest/primer.html
|
||||||
|
// --------------------------------------------
|
||||||
|
|
||||||
#include "WindowFixture.hpp"
|
#include "WindowFixture.hpp"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user