Skip to content

Commit

Permalink
Typos and cleanup (codam-coding-college#73)
Browse files Browse the repository at this point in the history
* Fixed typos

Co-authored-by: Jeroen Van Halderen <jvan-hal@f0r5s6.codam.nl>
  • Loading branch information
Jeroenvh99 and Jeroen Van Halderen authored Feb 1, 2023
1 parent ffa9b06 commit 700a209
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 42 deletions.
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ 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 '....'
2. Click on '...'
3. Scroll down to '...'
4. See error

**Expected behavior**
Expand All @@ -28,7 +28,7 @@ If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. MacOS]
- Version [e.g. BigSur]
- Version: [e.g. BigSur]

**Additional context**
Add any other context about the problem here.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ For information and documentation about MLX42 check the wiki.
## Differences to MiniLibX

#### Cross-Platform
The main idea of MLX42 is to be a cross-platform graphics interface. In 42 everything runs (currently) on MacOS, but it's
The main idea of MLX42 is to be a cross-platform graphics interface. In 42 everything (currently) runs on MacOS, but it's
very useful to be able to work remotely on different machines. With MiniLibX this is not possible.

#### Documented
Almost all functions and types are fully documented giving you a clue as to how to approach and use the library.
No more guessing and searching how something functions or is supposed to work.
No more guessing and searching how something works or is supposed to work.

#### Custom XPM (XPM42) format
A custom simple to use XPM-like format which has some minor differences to the XPM3 format.
Expand Down
4 changes: 2 additions & 2 deletions docs/Colors.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Colors are commonly represented as `4-byte` integers. This 4-byte integer is a g
Channel | Description | RGBA representation
:------:|:-------------:|:-------------------:
`R` | Red Channel | `0xFF000000`
`G` | Green Channel | `0x00FF0000`
`B` | Blue Channel | `0x0000FF00`
`G` | Green Channel | `0x00FF0000`
`B` | Blue Channel | `0x0000FF00`
`A` | Alpha Channel | `0x000000FF`

Combining these four channel values into one will result in a non-transparent, white color.
Expand Down
4 changes: 2 additions & 2 deletions docs/Hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ See copyright and license notice in the root project for more information.
Hooks allow you to add your own functions to the main loop execution of the program, aka these functions get executed every frame.
They also serve to intercept certain keypresses such as scrolling or pressing enter.

Only one hook can be set at a time! You cannot attach/have multiple hooks for specialized hooks.
Only one hook can be set at a time! You cannot attach/have multiple specialized hooks.
You can however have multiple generic hooks.

## Specialized Hooks
Expand Down Expand Up @@ -207,7 +207,7 @@ void my_scrollhook(double xdelta, double ydelta, void* param)
else if (ydelta < 0)
puts("Down!");

// Can also detect a mousewheel that go along the X (e.g: MX Master 3)
// Can also detect a mousewheel that goes along the X (e.g: MX Master 3)
if (xdelta < 0)
puts("Sliiiide to the left!");
else if (xdelta > 0)
Expand Down
4 changes: 2 additions & 2 deletions docs/Images.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int32_t main(void)

mlx_loop(mlx);

// Optional, terminate will clean up any left overs, this is just to demonstrate.
// Optional, terminate will clean up any leftovers, this is just to demonstrate.
mlx_delete_image(mlx, img);
mlx_terminate(mlx);
return (EXIT_SUCCESS);
Expand All @@ -98,7 +98,7 @@ If two instances are on the same z layer and are transparent, the transparency b
To prevent this by default any new instances put onto window will be on their own layer.

## Internals
A noticeable feature of MLX42 is that it partly takes care of the rendering for you, that is, after you created your image you just display it
A noticeable feature of MLX42 is that it partly takes care of the rendering for you, that is, after you've created your image you just display it
and after that feel free to modify it without having to re-put it onto the window. In short MLX takes care of updating your images at all times.

Internally this is done via a render queue, anytime the `mlx_image_to_window` function is used, a new entry is added to a linked list.
Expand Down
2 changes: 1 addition & 1 deletion docs/Input.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ See copyright and license notice in the root project for more information.

# Input methods

MLX42 provides various ways of detecting input, you can read about all the available hooks on the hooks page.
MLX42 provides various ways of detecting input, you can read about all the available hooks on the [Hooks](./Hooks.md) page.

## Key Detection

Expand Down
2 changes: 1 addition & 1 deletion docs/Shaders.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ uniform mat4 ProjMatrix;
void main()
{
gl_Position = ProjMatrix * vec4(aPos, 1.0);
TexCoord = aTexCoord;
TexCoord = aTexCoord;
}
```
Expand Down
2 changes: 1 addition & 1 deletion docs/Textures.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ int32_t main(void)

mlx_loop(mlx);

// Optional, terminate will clean up any left overs, this is just to demonstrate.
// Optional, terminate will clean up any leftovers, this is just to demonstrate.
mlx_delete_image(mlx, img);
mlx_delete_texture(texture);
mlx_terminate(mlx);
Expand Down
16 changes: 8 additions & 8 deletions docs/XPM42.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ See copyright and license notice in the root project for more information.

# XPM42

XPM42 is a custom file format made for MLX42 to provide a easy to use and understand image file format to learn how
XPM42 is a custom file format made for MLX42 to provide an easy to use and understand image file format to learn how
images can be stored. The format is based on the actual [XPM3](https://en.wikipedia.org/wiki/X_PixMap) format.

A XPM file basically stores a look-up table inside of it to fetch which character corresponds to which color. Additionally in the
An XPM file basically stores a look-up table inside of it to fetch which character corresponds to which color. Additionally in the
header there is a character per pixel count, this is due to the limitation of the amount of characters. Each 'Pixel' in the XPM data can
be represented by multiple characters.

Expand All @@ -34,7 +34,7 @@ The file format looks as follows:

## Inner workings

Reading a XPM42 does a whole bunch of stuff but in essence it reads the file header and inserts each color entry into a hash table for fast lookups of the color value, the hash used is FNV-1a. Why, because it's an easy to use hash and also my favourite. After the header is read and the color values are inserted into the table each line is then read and each character is processed and inserted into the pixel buffer of the XPM. There is no collision checking for the look-up table, so artefacts may be present.
Reading an XPM42 does a whole bunch of stuff but in essence it reads the file header and inserts each color entry into a hash table for fast lookups of the color value, the hash used is FNV-1a. Why, because it's an easy to use hash and also my favourite. After the header is read and the color values are inserted into the table each line is then read and each character is processed and inserted into the pixel buffer of the XPM. There is no collision checking for the lookup table, so artefacts may be present.

## Tools

Expand Down Expand Up @@ -62,25 +62,25 @@ int32_t main(void)
// Start mlx
mlx_t* mlx = mlx_init(WIDTH, HEIGHT, "Test", true);
if (!mlx)
error();
error();

// Try to load the file
xpm_t* xpm = mlx_load_xpm42("./temp/42.xpm42");
if (!xpm)
error();
error();

// Convert texture to a displayable image
mlx_image_t* img = mlx_texture_to_image(mlx, &xpm->texture);
if (!img)
error();
error();

// Display the image
if (mlx_image_to_window(mlx, img, 0, 0) < 0)
error();
error();

mlx_loop(mlx);

// Optional, terminate will clean up any left overs, this is just to demonstrate.
// Optional, terminate will clean up any leftovers, this is just to demonstrate.
mlx_delete_image(mlx, img);
mlx_delete_xpm42(xpm);
mlx_terminate(mlx);
Expand Down
5 changes: 3 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ displaying images from disk or creating a drawing surface to draw pixels on.

* [Basics](./Basics.md)
* [Colors](./Colors.md)
* [Functions](./Functions.md)
* [Hooks](./Hooks.md)
* [Images](./Images.md)
* [Input](./Input.md)
Expand Down Expand Up @@ -58,15 +59,15 @@ OpenGL function pointers, compiling the shaders and more.

It returns a mlx_t* which is a structure containing the current window instance.
With this instance you can manipulate, hook onto and control what happens inside
your window instance. For example you would use it to send graphical orders such as
your window instance. For example you would use it to send graphical instructions such as
creating an image, which is used to display pixel data. You can also detect key
interactions such as checking if the W, A, S or D key is currently being pressed.

| Function | Description |
|-------------------|--------------------------------------------------------------|
| `mlx_init()` | Initialize and run a new window instance. |
| `mlx_loop()` | Keep the window open as long as a shutdown is not requested. |
| `mlx_terminate()` | Destroy and cleanup all images and mlx resources. |
| `mlx_terminate()` | Destroy and clean up all images and mlx resources. |

If mlx_init() fails to set up the connection to the graphical system, it will
return NULL, otherwise a non-null pointer is returned as a handle for the window.
Expand Down
31 changes: 31 additions & 0 deletions src/utils/mlx_comparison.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* mlx_comparison.c :+: :+: */
/* +:+ */
/* By: jvan-hal <jvan-hal@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2023/01/31 17:20:19 by jvan-hal #+# #+# */
/* Updated: 2023/01/31 17:23:49 by jvan-hal ######## odam.nl */
/* */
/* ************************************************************************** */

#include "MLX42/MLX42_Int.h"

//= Private =//

bool mlx_equal_image(void* lstcontent, void* value)
{
const mlx_image_t* lcontent = lstcontent;
const mlx_image_t* lvalue = value;

return (lcontent == lvalue);
}

bool mlx_equal_inst(void* lstcontent, void* value)
{
const draw_queue_t* lcontent = lstcontent;
const mlx_image_t* lvalue = value;

return (lcontent->image == lvalue);
}
19 changes: 1 addition & 18 deletions src/utils/mlx_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: W2Wizard <w2.wizzard@gmail.com> +#+ */
/* +#+ */
/* Created: 2021/12/28 01:53:51 by W2Wizard #+# #+# */
/* Updated: 2022/11/26 14:26:23 by jvan-hal ######## odam.nl */
/* Updated: 2023/01/31 17:23:11 by jvan-hal ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -92,23 +92,6 @@ void mlx_lstadd_front(mlx_list_t** lst, mlx_list_t* new)
*lst = new;
}

// TODO: Move this somewhere else...
bool mlx_equal_image(void* lstcontent, void* value)
{
const mlx_image_t* lcontent = lstcontent;
const mlx_image_t* lvalue = value;

return (lcontent == lvalue);
}

bool mlx_equal_inst(void* lstcontent, void* value)
{
const draw_queue_t* lcontent = lstcontent;
const mlx_image_t* lvalue = value;

return (lcontent->image == lvalue);
}

/**
* Removes the specified content from the list, if found.
* Also fixes any relinking that might be needed.
Expand Down

0 comments on commit 700a209

Please sign in to comment.