From 2875f205e24f19964d44ddce2470659d21fe902d Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 19 Nov 2019 17:51:40 +0100 Subject: Removed duplicate man, modify window buffer instead of writting each pixels --- Makefile | 2 +- cub3d.h | 35 +++++-- graphics.c | 65 +++++++++---- main.c | 11 ++- miniLibX_man/man1/mlx.1 | 115 ---------------------- miniLibX_man/man1/mlx_loop.1 | 143 --------------------------- miniLibX_man/man1/mlx_new_image.1 | 192 ------------------------------------- miniLibX_man/man1/mlx_new_window.1 | 79 --------------- miniLibX_man/man1/mlx_pixel_put.1 | 81 ---------------- miniLibX_man/man3/mlx.1 | 115 ---------------------- miniLibX_man/man3/mlx_loop.1 | 143 --------------------------- miniLibX_man/man3/mlx_new_image.1 | 192 ------------------------------------- miniLibX_man/man3/mlx_new_window.1 | 79 --------------- miniLibX_man/man3/mlx_pixel_put.1 | 81 ---------------- miniLibX_man/mlx.1 | 115 ++++++++++++++++++++++ miniLibX_man/mlx_loop.1 | 143 +++++++++++++++++++++++++++ miniLibX_man/mlx_new_image.1 | 192 +++++++++++++++++++++++++++++++++++++ miniLibX_man/mlx_new_window.1 | 79 +++++++++++++++ miniLibX_man/mlx_pixel_put.1 | 81 ++++++++++++++++ minimalist.cub | 2 +- textures/brick.xpm | 114 ++++++++++++++++++++++ 21 files changed, 809 insertions(+), 1250 deletions(-) delete mode 100644 miniLibX_man/man1/mlx.1 delete mode 100644 miniLibX_man/man1/mlx_loop.1 delete mode 100644 miniLibX_man/man1/mlx_new_image.1 delete mode 100644 miniLibX_man/man1/mlx_new_window.1 delete mode 100644 miniLibX_man/man1/mlx_pixel_put.1 delete mode 100644 miniLibX_man/man3/mlx.1 delete mode 100644 miniLibX_man/man3/mlx_loop.1 delete mode 100644 miniLibX_man/man3/mlx_new_image.1 delete mode 100644 miniLibX_man/man3/mlx_new_window.1 delete mode 100644 miniLibX_man/man3/mlx_pixel_put.1 create mode 100644 miniLibX_man/mlx.1 create mode 100644 miniLibX_man/mlx_loop.1 create mode 100644 miniLibX_man/mlx_new_image.1 create mode 100644 miniLibX_man/mlx_new_window.1 create mode 100644 miniLibX_man/mlx_pixel_put.1 create mode 100644 textures/brick.xpm diff --git a/Makefile b/Makefile index f529a12..e59c2a3 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ LIBFT_PATH = ./libft MINILIBX_PATH = ./miniLibX CC = gcc -CCFLAGS = -I$(LIBFT_PATH) -I$(MINILIBX_PATH) -I. -Wall -Wextra #-Werror +CCFLAGS = -I$(LIBFT_PATH) -I$(MINILIBX_PATH) -I. -Wall -Wextra -g #-Werror LDFLAGS = -L$(LIBFT_PATH) -lft \ -L$(MINILIBX_PATH) -lmlx \ -framework OpenGL -framework AppKit -lm diff --git a/cub3d.h b/cub3d.h index dfc40a1..2ea4fe8 100644 --- a/cub3d.h +++ b/cub3d.h @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/11/15 06:40:37 by cacharle #+# #+# */ -/* Updated: 2019/11/18 19:00:20 by cacharle ### ########.fr */ +/* Updated: 2019/11/19 17:38:22 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include @@ -87,7 +87,16 @@ typedef struct int map_height; } t_parsing; -typedef unsigned int* t_image; +typedef struct +{ + int width; + int height; + void *id; + char *data; + int depth; + int size_line; + int endian; +} t_image; typedef struct s_state { @@ -104,10 +113,11 @@ typedef struct s_state int map_height; t_color ceilling_color; t_color floor_color; - t_image window_buf; - int window_img_depth; - int window_img_line_size; - int window_img_endian; + t_image window_img; + t_image north_texture; + t_image south_texture; + t_image west_texture; + t_image east_texture; } t_state; typedef t_bool (*t_option_parser_func)(t_parsing *parsing, char *line); @@ -118,6 +128,12 @@ typedef struct s_option_parser t_option_parser_func func; } t_option_parser; +typedef enum +{ + SIDE_NORTH_SOUTH, + SIDE_WEST_EAST +} t_side; + /* ** parse.c */ @@ -152,10 +168,9 @@ int handle_key(int key, void *param); */ t_state *create_state(void *mlx_ptr, void *window_ptr, t_parsing *parsing); -int graphics_update(void *param); -void draw_column(t_state *state, int x); -t_vector vector_add(t_vector a, t_vector b); -t_vector vector_scale(t_vector v, double scalar); +int graphics_update(void *param); +void draw_column(t_state *state, int x); +void write_color(char *data, int y, int x, t_color color); /* ** render.c diff --git a/graphics.c b/graphics.c index 5655aa6..02b326d 100644 --- a/graphics.c +++ b/graphics.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* graphics.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/19 16:39:57 by cacharle #+# #+# */ +/* Updated: 2019/11/19 17:50:51 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "cub3d.h" t_state *create_state(void *mlx_ptr, void *window_ptr, t_parsing *parsing) @@ -6,10 +18,28 @@ t_state *create_state(void *mlx_ptr, void *window_ptr, t_parsing *parsing) if ((state = (t_state*)malloc(sizeof(t_state))) == NULL) return (NULL); - if ((state->window_img = mlx_new_image(mlx_ptr, parsing->resolution_width, parsing->resolution_height)) == NULL) + state->window_img.id = mlx_new_image(mlx_ptr, parsing->resolution_width, parsing->resolution_height); + state->window_img.width = parsing->resolution_width; + state->window_img.height = parsing->resolution_height; + state->window_img.data = mlx_get_data_addr(state->window_img.id, + &state->window_img.depth, &state->window_img.size_line, &state->window_img.endian); + printf("%d\n", state->window_img.width); + printf("%d\n", state->window_img.height); + printf("%d\n", state->window_img.depth); + printf("%d\n", state->window_img.size_line); + printf("%d\n", state->window_img.endian); + + state->north_texture.id = mlx_xpm_file_to_image(mlx_ptr, + parsing->north_texture_path, &state->north_texture.width, &state->north_texture.height); + if (state->north_texture.id == NULL) return (NULL); - state->window_buf = mlx_get_data_addr(state->window_img, - &state->window_img_depth, &state->window_img_line_size, &state->window_img_endian); + state->north_texture.data = mlx_get_data_addr(state->north_texture.id, &state->north_texture.depth, + &state->north_texture.size_line, &state->north_texture.endian); + /* printf("%d\n", state->north_texture.endian); */ + /* state->south_texture = ; */ + /* state->west_texture = ; */ + /* state->east_texture = ; */ + state->mlx_ptr = mlx_ptr; state->window_ptr = window_ptr; state->window_width = parsing->resolution_width; @@ -46,15 +76,15 @@ int graphics_update(void *param) while (++x < state->window_width) draw_column(state, x); + /* for (int i = 0; i < 200000; i++) */ + /* state->window_img.data[i] = 127; */ + mlx_put_image_to_window(state->mlx_ptr, state->window_ptr, state->window_img.id, 0, 0); + /* mlx_put_image_to_window(state->mlx_ptr, state->window_ptr, state->north_texture.id, 0, 0); */ + /* for (int i = 0; i < 200; i++) */ + /* printf("%d ", state->window_img.data[i]); */ return (0); } -typedef enum -{ - SIDE_NORTH_SOUTH, - SIDE_WEST_EAST -} t_side; - void draw_column(t_state *state, int x) { /* @@ -139,15 +169,18 @@ void draw_column(t_state *state, int x) if (draw_end >= state->window_height) draw_end = state->window_height - 1; + int tex_x; + + /* int wall_x = side == SIDE_WEST_EAST ? pos */ + int i; i = 0; - while (i < draw_start ) - state->window_buf[i * state->window_width + x] = state->ceilling_color.hexcode; - /* mlx_pixel_put(state->mlx_ptr, state->window_ptr, x, i++, state->ceilling_color.hexcode); */ + t_color white; + white.hexcode = 0x00ffffff; + while (i < draw_start) + ((t_color*)state->window_img.data)[i++ * state->window_img.width + x] = state->ceilling_color; while (i < draw_end) - state->window_buf[i * state->window_width + x] = 0x00ffffff; - /* mlx_pixel_put(state->mlx_ptr, state->window_ptr, x, i++, 0x00ffffff); */ + ((t_color*)state->window_img.data)[i++ * state->window_img.width + x] = white; while (i < state->window_height) - state->window_buf[i * state->window_width + x] = state->floor_color.hexcode; - /* mlx_pixel_put(state->mlx_ptr, state->window_ptr, x, i++, state->floor_color.hexcode); */ + ((t_color*)state->window_img.data)[i++ * state->window_img.width + x] = state->floor_color; } diff --git a/main.c b/main.c index a846062..feff126 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/11/15 06:39:39 by cacharle #+# #+# */ -/* Updated: 2019/11/16 12:58:08 by cacharle ### ########.fr */ +/* Updated: 2019/11/19 17:09:53 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,8 @@ int main(int argc, char **argv) return (1); } t_parsing *p = parse(argv[1]); + if (p == NULL) + return (1); /* printf("R %d %d\n", p->resolution_width, p->resolution_height); */ /* printf("NO %s\n", p->north_texture_path); */ /* printf("SO %s\n", p->south_texture_path); */ @@ -47,16 +49,21 @@ int main(int argc, char **argv) } void *mlx_ptr = mlx_init(); + if (mlx_ptr == NULL) + return (1); void *window_ptr = mlx_new_window(mlx_ptr, p->resolution_width, p->resolution_height, WINDOW_TITLE); + if (window_ptr == NULL) + return (1); t_state *state = create_state(mlx_ptr, window_ptr, p); + if (state == NULL) + return (1); /* for (int i = 0; i < 20; i++) */ /* draw_column(state, i); */ mlx_key_hook(window_ptr, handle_key, (void*)state); mlx_loop_hook(mlx_ptr, graphics_update, (void*)state); - /* */ mlx_loop(mlx_ptr); return (0); diff --git a/miniLibX_man/man1/mlx.1 b/miniLibX_man/man1/mlx.1 deleted file mode 100644 index cfdac3d..0000000 --- a/miniLibX_man/man1/mlx.1 +++ /dev/null @@ -1,115 +0,0 @@ -.TH MiniLibX 3 "September 19, 2002" -.SH NAME -MiniLibX - Simple Graphical Interface Library for students -.SH SYNOPSYS -#include - -.nf -.I void * -.fi -.B mlx_init -(); - -.SH DESCRIPTION -MiniLibX is an easy way to create graphical software, -without any X-Window/Cocoa programming knowledge. It provides -simple window creation, a drawing tool, image and basic events -management. - -.SH BSD/LINUX X-WINDOW CONCEPT - -X-Window is a network-oriented graphical system for Unix. -It is based on two main parts: -.br -On one side, your software wants to draw something on the screen and/or -get keyboard & mouse entries. -.br -On the other side, the X-Server manages the screen, keyboard and mouse -(It is often refered to as a "display"). -.br -A network connection must be established between these two entities to send -drawing orders (from the software to the X-Server), and keyboard/mouse -events (from the X-Server to the software). - -.SH MACOSX CONCEPT - -The MacOSX operating system handle graphical access to the screen (or "display"). -.br -On one side, your software wants to draw something on the screen and/or -get keyboard & mouse entries. -.br -On the other side, the underlying MacOSX graphical framework that handles -the screen, the windowing system, keyboard and mouse. -.br -A connection between these two entities must be established. - -.SH INCLUDE FILE -.B mlx.h -should be included for a correct use of the MiniLibX API. -It only contains function prototypes, no structure is needed. - -.SH LIBRARY FUNCTIONS -.P -First of all, you need to initialize the connection -between your software and the display. -Once this connection is established, you'll be able to -use other MiniLibX functions to send the graphical orders, -like "I want to draw a yellow pixel in this window" or "did the -user hit a key?". -.P -The -.B mlx_init -function will create this connection. No parameters are needed, ant it will -return a -.I "void *" -identifier, used for further calls to the library routines. -.P -All other MiniLibX functions are described in the following man pages: - -.TP 20 -.B mlx_new_window -: manage windows -.TP 20 -.B mlx_pixel_put -: draw inside window -.TP 20 -.B mlx_new_image -: manipulate images -.TP 20 -.B mlx_loop -: handle keyboard or mouse events - -.SH LINKING MiniLibX on BSD/Linux and X-Window -To use MiniLibX functions, you'll need to link -your software with several libraries, including the MiniLibX library itself. -To do this, simply add the following arguments at linking time: - -.B -lmlx -lXext -lX11 - -You may also need to specify the path to these libraries, using -the -.B -L -flag. - -.SH LINKING MiniLibX on MACOSX -To use MiniLibX functions, you'll need to link your software with the -MiniLibX library, and several system frameworks: - -.B -lmlx -framework OpenGL -framework AppKit - -You may also need to specify the path to the MiniLibX library, using -the -.B -L -flag. - -.SH RETURN VALUES -If -.B 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 connection identifier. - -.SH SEE ALSO -mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3) - -.SH AUTHOR -Copyright ol@ - 2002-2015 - Olivier Crouzet diff --git a/miniLibX_man/man1/mlx_loop.1 b/miniLibX_man/man1/mlx_loop.1 deleted file mode 100644 index fa2b835..0000000 --- a/miniLibX_man/man1/mlx_loop.1 +++ /dev/null @@ -1,143 +0,0 @@ -.TH MiniLibX 3 "September 19, 2002" -.SH NAME -MiniLibX - Handle events -.SH SYNOPSYS - -.nf -.I int -.fi -.B mlx_loop -( -.I void *mlx_ptr -); - -.nf -.I int -.fi -.B mlx_key_hook -( -.I void *win_ptr, int (*funct_ptr)(), void *param -); - -.nf -.I int -.fi -.B mlx_mouse_hook -( -.I void *win_ptr, int (*funct_ptr)(), void *param -); - -.nf -.I int -.fi -.B mlx_expose_hook -( -.I void *win_ptr, int (*funct_ptr)(), void *param -); - -.nf -.I int -.fi -.B mlx_loop_hook -( -.I void *mlx_ptr, int (*funct_ptr)(), void *param -); - -.SH EVENTS - -Both X-Window and MacOSX graphical systems are bi-directionnal. -On one hand, the program sends orders to -the screen to display pixels, images, and so on. On the other hand, -it can get information from the keyboard and mouse associated to -the screen. To do so, the program receives "events" from the keyboard or the -mouse. - -.SH DESCRIPTION - -To receive events, you must use -.B mlx_loop -(). This function never returns. It is an infinite loop that waits for -an event, and then calls a user-defined function associated with this event. -A single parameter is needed, the connection identifier -.I mlx_ptr -(see the -.B mlx manual). - -You can assign different functions to the three following events: -.br -- A key is pressed -.br -- The mouse button is pressed -.br -- A part of the window should be re-drawn -(this is called an "expose" event, and it is your program's job to handle it). -.br - -Each window can define a different function for the same event. - -The three functions -.B mlx_key_hook -(), -.B mlx_mouse_hook -() and -.B mlx_expose_hook -() work exactly the same way. -.I funct_ptr -is a pointer to the function you want to be called -when an event occurs. This assignment is specific to the window defined by the -.I win_ptr -identifier. The -.I param -adress will be passed to the function everytime it is called, and should be -used to store the parameters it might need. - -The syntax for the -.B mlx_loop_hook -() function is identical to the previous ones, but the given function will be -called when no event occurs. - -When it catches an event, the MiniLibX calls the corresponding function -with fixed parameters: -.nf - - expose_hook(void *param); - key_hook(int keycode,void *param); - mouse_hook(int button,int x,int y,void *param); - loop_hook(void *param); - -.fi -These function names are arbitrary. They here are used to distinguish -parameters according to the event. These functions are NOT part of the -MiniLibX. - -.I param -is the address specified in the mlx_*_hook calls. This address is never -used nor modified by the MiniLibX. On key and mouse events, additional -information is passed: -.I keycode -tells you which key is pressed (X11 : look for the include file "keysymdef.h", -MacOS : create a small software and find out by yourself), -( -.I x -, -.I y -) are the coordinates of the mouse click in the window, and -.I button -tells you which mouse button was pressed. - -.SH GOING FURTHER WITH EVENTS -The MiniLibX provides a much generic access to all type of events. The -.I mlx.h -include define -.B mlx_hook() -in the same manner mlx_*_hook functions work. The event and mask values -will be taken from the X11 include file "X.h" (even for MacOSX, for compatibility purposes) - -See source code of mlx_int_param_event.c to find out how the MiniLibX will -call your own function for a specific event. - -.SH SEE ALSO -mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3) - -.SH AUTHOR -Copyright ol@ - 2002-2015 - Olivier Crouzet diff --git a/miniLibX_man/man1/mlx_new_image.1 b/miniLibX_man/man1/mlx_new_image.1 deleted file mode 100644 index d46bf59..0000000 --- a/miniLibX_man/man1/mlx_new_image.1 +++ /dev/null @@ -1,192 +0,0 @@ -.TH MiniLibX 3 "September 19, 2002" -.SH NAME -MiniLibX - Manipulating images -.SH SYNOPSYS - -.nf -.I void * -.fi -.B mlx_new_image -( -.I void *mlx_ptr, int width, int height -); - -.nf -.I char * -.fi -.B mlx_get_data_addr -( -.I void *img_ptr, int *bits_per_pixel, int *size_line, int *endian -); - -.nf -.I int -.fi -.B mlx_put_image_to_window -( -.I void *mlx_ptr, void *win_ptr, void *img_ptr, int x, int y -); - -.nf -.I unsigned int -.fi -.B mlx_get_color_value -( -.I void *mlx_ptr, int color -); - -.nf -.I void * -.fi -.B mlx_xpm_to_image -( -.I void *mlx_ptr, char **xpm_data, int *width, int *height -); - -.nf -.I void * -.fi -.B mlx_xpm_file_to_image -( -.I void *mlx_ptr, char *filename, int *width, int *height -); - -.nf -.I int -.fi -.B mlx_destroy_image -( -.I void *mlx_ptr, void *img_ptr -); - - -.SH DESCRIPTION - -.B mlx_new_image -() creates a new image in memory. It returns a -.I void * -identifier needed to manipulate this image later. It only needs -the size of the image to be created, using the -.I width -and -.I height -parameters, and the -.I mlx_ptr -connection identifier (see the -.B mlx -manual). - -The user can draw inside the image (see below), and -can dump the image inside a specified window at any time to -display it on the screen. This is done using -.B mlx_put_image_to_window -(). Three identifiers are needed here, for the connection to the -display, the window to use, and the image (respectively -.I mlx_ptr -, -.I win_ptr -and -.I img_ptr -). The ( -.I x -, -.I y -) coordinates define where the image should be placed in the window. - -.B mlx_get_data_addr -() returns information about the created image, allowing a user -to modify it later. The -.I img_ptr -parameter specifies the image to use. The three next parameters should -be the addresses of three different valid integers. -.I bits_per_pixel -will be filled with the number of bits needed to represent a pixel color -(also called the depth of the image). -.I size_line -is the number of bytes used to store one line of the image in memory. -This information is needed to move from one line to another in the image. -.I endian -tells you wether the pixel color in the image needs to be stored in -little endian ( -.I endian -== 0), or big endian ( -.I endian -== 1). - -.B mlx_get_data_addr -returns a -.I char * -address that represents the begining of the memory area where the image -is stored. From this adress, the first -.I bits_per_pixel -bits represent the color of the first pixel in the first line of -the image. The second group of -.I bits_per_pixel -bits represent the second pixel of the first line, and so on. -Add -.I size_line -to the adress to get the begining of the second line. You can reach any -pixels of the image that way. - -.B mlx_destroy_image -destroys the given image ( -.I img_ptr -). - -.SH STORING COLOR INSIDE IMAGES - -Depending on the display, the number of bits used to store a pixel color -can change. The user usually represents a color in RGB mode, using -one byte for each component (see -.B mlx_pixel_put -manual). This must be translated to fit the -.I bits_per_pixel -requirement of the image, and make the color understandable to the graphical system. -That is the purpose of the -.B mlx_get_color_value -() function. It takes a standard RGB -.I color -parameter, and returns an -.I unsigned int -value. -The -.I bits_per_pixel -least significant bits of this value can be stored in the image. - -Keep in mind that the least significant bits position depends on the local -computer's endian. If the endian of the image (in fact the endian of -the X-Server's computer for remote X11 display) differs from the local endian, then the value should -be transformed before being used. - -.SH XPM IMAGES - -The -.B mlx_xpm_to_image -() and -.B mlx_xpm_file_to_image -() functions will create a new image the same way. -They will fill it using the specified -.I xpm_data -or -.I filename -, depending on which function is used. -Note that MiniLibX does not use the standard -Xpm library to deal with xpm images. You may not be able to -read all types of xpm images. It however handles transparency. - -.SH RETURN VALUES -The three functions that create images, -.B mlx_new_image() -, -.B mlx_xpm_to_image() -and -.B mlx_xpm_file_to_image() -, will return NULL if an error occurs. Otherwise they return a non-null pointer -as an image identifier. - - -.SH SEE ALSO -mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_loop(3) - -.SH AUTHOR -Copyright ol@ - 2002-2015 - Olivier Crouzet diff --git a/miniLibX_man/man1/mlx_new_window.1 b/miniLibX_man/man1/mlx_new_window.1 deleted file mode 100644 index 36176d7..0000000 --- a/miniLibX_man/man1/mlx_new_window.1 +++ /dev/null @@ -1,79 +0,0 @@ -.TH MiniLibX 3 "September 19, 2002" -.SH NAME -MiniLibX - Managing windows -.SH SYNOPSYS - -.nf -.I void * -.fi -.B mlx_new_window -( -.I void *mlx_ptr, int size_x, int size_y, char *title -); - -.nf -.I int -.fi -.B mlx_clear_window -( -.I void *mlx_ptr, void *win_ptr -); - -.nf -.I int -.fi -.B mlx_destroy_window -( -.I void *mlx_ptr, void *win_ptr -); - - -.SH DESCRIPTION -The -.B mlx_new_window -() function creates a new window on the screen, using the -.I size_x -and -.I size_y -parameters to determine its size, and -.I title -as the text that should be displayed in the window's title bar. -The -.I mlx_ptr -parameter is the connection identifier returned by -.B mlx_init -() (see the -.B mlx -man page). -.B mlx_new_window -() returns a -.I void * -window identifier that can be used by other MiniLibX calls. -Note that the MiniLibX -can handle an arbitrary number of separate windows. - -.B mlx_clear_window -() and -.B mlx_destroy_window -() respectively clear (in black) and destroy the given window. They both have -the same parameters: -.I mlx_ptr -is the screen connection identifier, and -.I win_ptr -is a window identifier. - -.SH RETURN VALUES -If -.B mlx_new_window() -fails to create a new window (for wathever reason), it will return NULL, -otherwise a non-null pointer is returned as a window identifier. -.B mlx_clear_window -and -.B mlx_destroy_window -right now return nothing. - -.SH SEE ALSO -mlx(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3) - -.SH AUTHOR -Copyright ol@ - 2002-2015 - Olivier Crouzet diff --git a/miniLibX_man/man1/mlx_pixel_put.1 b/miniLibX_man/man1/mlx_pixel_put.1 deleted file mode 100644 index caf89f2..0000000 --- a/miniLibX_man/man1/mlx_pixel_put.1 +++ /dev/null @@ -1,81 +0,0 @@ -.TH MiniLibX 3 "September 19, 2002" -.SH NAME -MiniLibX - Drawing inside windows -.SH SYNOPSYS - -.nf -.I int -.fi -.B mlx_pixel_put -( -.I void *mlx_ptr, void *win_ptr, int x, int y, int color -); - -.nf -.I int -.fi -.B mlx_string_put -( -.I void *mlx_ptr, void *win_ptr, int x, int y, int color, char *string -); - - -.SH DESCRIPTION -The -.B mlx_pixel_put -() function draws a defined pixel in the window -.I win_ptr -using the ( -.I x -, -.I y -) coordinates, and the specified -.I color -\&. The origin (0,0) is the upper left corner of the window, the x and y axis -respectively pointing right and down. The connection -identifier, -.I mlx_ptr -, is needed (see the -.B mlx -man page). - -Parameters for -.B mlx_string_put -() have the same meaning. Instead of a simple pixel, the specified -.I string -will be displayed at ( -.I x -, -.I y -). - -In both functions, it is impossible to display anything outside the -specified window, nor display in another window in front of the selected one. - -.SH COLOR MANAGEMENT -The -.I color -parameter has an integer type. The displayed color needs to be encoded -in this integer, following a defined scheme. All displayable colors -can be split in 3 basic colors: red, green and blue. Three associated -values, in the 0-255 range, represent how much of each color is mixed up -to create the original color. Theses three values must be set inside the -integer to display the right color. The three least significant bytes of -this integer are filled as shown in the picture below: - -.nf - | 0 | R | G | B | color integer - +---+---+---+---+ -.fi - - -While filling the integer, make sure you avoid endian problems. Remember -that the "blue" byte should always be the least significant one. - - -.SH SEE ALSO -mlx(3), mlx_new_window(3), mlx_new_image(3), mlx_loop(3) - - -.SH AUTHOR -Copyright ol@ - 2002-2015 - Olivier Crouzet diff --git a/miniLibX_man/man3/mlx.1 b/miniLibX_man/man3/mlx.1 deleted file mode 100644 index cfdac3d..0000000 --- a/miniLibX_man/man3/mlx.1 +++ /dev/null @@ -1,115 +0,0 @@ -.TH MiniLibX 3 "September 19, 2002" -.SH NAME -MiniLibX - Simple Graphical Interface Library for students -.SH SYNOPSYS -#include - -.nf -.I void * -.fi -.B mlx_init -(); - -.SH DESCRIPTION -MiniLibX is an easy way to create graphical software, -without any X-Window/Cocoa programming knowledge. It provides -simple window creation, a drawing tool, image and basic events -management. - -.SH BSD/LINUX X-WINDOW CONCEPT - -X-Window is a network-oriented graphical system for Unix. -It is based on two main parts: -.br -On one side, your software wants to draw something on the screen and/or -get keyboard & mouse entries. -.br -On the other side, the X-Server manages the screen, keyboard and mouse -(It is often refered to as a "display"). -.br -A network connection must be established between these two entities to send -drawing orders (from the software to the X-Server), and keyboard/mouse -events (from the X-Server to the software). - -.SH MACOSX CONCEPT - -The MacOSX operating system handle graphical access to the screen (or "display"). -.br -On one side, your software wants to draw something on the screen and/or -get keyboard & mouse entries. -.br -On the other side, the underlying MacOSX graphical framework that handles -the screen, the windowing system, keyboard and mouse. -.br -A connection between these two entities must be established. - -.SH INCLUDE FILE -.B mlx.h -should be included for a correct use of the MiniLibX API. -It only contains function prototypes, no structure is needed. - -.SH LIBRARY FUNCTIONS -.P -First of all, you need to initialize the connection -between your software and the display. -Once this connection is established, you'll be able to -use other MiniLibX functions to send the graphical orders, -like "I want to draw a yellow pixel in this window" or "did the -user hit a key?". -.P -The -.B mlx_init -function will create this connection. No parameters are needed, ant it will -return a -.I "void *" -identifier, used for further calls to the library routines. -.P -All other MiniLibX functions are described in the following man pages: - -.TP 20 -.B mlx_new_window -: manage windows -.TP 20 -.B mlx_pixel_put -: draw inside window -.TP 20 -.B mlx_new_image -: manipulate images -.TP 20 -.B mlx_loop -: handle keyboard or mouse events - -.SH LINKING MiniLibX on BSD/Linux and X-Window -To use MiniLibX functions, you'll need to link -your software with several libraries, including the MiniLibX library itself. -To do this, simply add the following arguments at linking time: - -.B -lmlx -lXext -lX11 - -You may also need to specify the path to these libraries, using -the -.B -L -flag. - -.SH LINKING MiniLibX on MACOSX -To use MiniLibX functions, you'll need to link your software with the -MiniLibX library, and several system frameworks: - -.B -lmlx -framework OpenGL -framework AppKit - -You may also need to specify the path to the MiniLibX library, using -the -.B -L -flag. - -.SH RETURN VALUES -If -.B 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 connection identifier. - -.SH SEE ALSO -mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3) - -.SH AUTHOR -Copyright ol@ - 2002-2015 - Olivier Crouzet diff --git a/miniLibX_man/man3/mlx_loop.1 b/miniLibX_man/man3/mlx_loop.1 deleted file mode 100644 index fa2b835..0000000 --- a/miniLibX_man/man3/mlx_loop.1 +++ /dev/null @@ -1,143 +0,0 @@ -.TH MiniLibX 3 "September 19, 2002" -.SH NAME -MiniLibX - Handle events -.SH SYNOPSYS - -.nf -.I int -.fi -.B mlx_loop -( -.I void *mlx_ptr -); - -.nf -.I int -.fi -.B mlx_key_hook -( -.I void *win_ptr, int (*funct_ptr)(), void *param -); - -.nf -.I int -.fi -.B mlx_mouse_hook -( -.I void *win_ptr, int (*funct_ptr)(), void *param -); - -.nf -.I int -.fi -.B mlx_expose_hook -( -.I void *win_ptr, int (*funct_ptr)(), void *param -); - -.nf -.I int -.fi -.B mlx_loop_hook -( -.I void *mlx_ptr, int (*funct_ptr)(), void *param -); - -.SH EVENTS - -Both X-Window and MacOSX graphical systems are bi-directionnal. -On one hand, the program sends orders to -the screen to display pixels, images, and so on. On the other hand, -it can get information from the keyboard and mouse associated to -the screen. To do so, the program receives "events" from the keyboard or the -mouse. - -.SH DESCRIPTION - -To receive events, you must use -.B mlx_loop -(). This function never returns. It is an infinite loop that waits for -an event, and then calls a user-defined function associated with this event. -A single parameter is needed, the connection identifier -.I mlx_ptr -(see the -.B mlx manual). - -You can assign different functions to the three following events: -.br -- A key is pressed -.br -- The mouse button is pressed -.br -- A part of the window should be re-drawn -(this is called an "expose" event, and it is your program's job to handle it). -.br - -Each window can define a different function for the same event. - -The three functions -.B mlx_key_hook -(), -.B mlx_mouse_hook -() and -.B mlx_expose_hook -() work exactly the same way. -.I funct_ptr -is a pointer to the function you want to be called -when an event occurs. This assignment is specific to the window defined by the -.I win_ptr -identifier. The -.I param -adress will be passed to the function everytime it is called, and should be -used to store the parameters it might need. - -The syntax for the -.B mlx_loop_hook -() function is identical to the previous ones, but the given function will be -called when no event occurs. - -When it catches an event, the MiniLibX calls the corresponding function -with fixed parameters: -.nf - - expose_hook(void *param); - key_hook(int keycode,void *param); - mouse_hook(int button,int x,int y,void *param); - loop_hook(void *param); - -.fi -These function names are arbitrary. They here are used to distinguish -parameters according to the event. These functions are NOT part of the -MiniLibX. - -.I param -is the address specified in the mlx_*_hook calls. This address is never -used nor modified by the MiniLibX. On key and mouse events, additional -information is passed: -.I keycode -tells you which key is pressed (X11 : look for the include file "keysymdef.h", -MacOS : create a small software and find out by yourself), -( -.I x -, -.I y -) are the coordinates of the mouse click in the window, and -.I button -tells you which mouse button was pressed. - -.SH GOING FURTHER WITH EVENTS -The MiniLibX provides a much generic access to all type of events. The -.I mlx.h -include define -.B mlx_hook() -in the same manner mlx_*_hook functions work. The event and mask values -will be taken from the X11 include file "X.h" (even for MacOSX, for compatibility purposes) - -See source code of mlx_int_param_event.c to find out how the MiniLibX will -call your own function for a specific event. - -.SH SEE ALSO -mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3) - -.SH AUTHOR -Copyright ol@ - 2002-2015 - Olivier Crouzet diff --git a/miniLibX_man/man3/mlx_new_image.1 b/miniLibX_man/man3/mlx_new_image.1 deleted file mode 100644 index d46bf59..0000000 --- a/miniLibX_man/man3/mlx_new_image.1 +++ /dev/null @@ -1,192 +0,0 @@ -.TH MiniLibX 3 "September 19, 2002" -.SH NAME -MiniLibX - Manipulating images -.SH SYNOPSYS - -.nf -.I void * -.fi -.B mlx_new_image -( -.I void *mlx_ptr, int width, int height -); - -.nf -.I char * -.fi -.B mlx_get_data_addr -( -.I void *img_ptr, int *bits_per_pixel, int *size_line, int *endian -); - -.nf -.I int -.fi -.B mlx_put_image_to_window -( -.I void *mlx_ptr, void *win_ptr, void *img_ptr, int x, int y -); - -.nf -.I unsigned int -.fi -.B mlx_get_color_value -( -.I void *mlx_ptr, int color -); - -.nf -.I void * -.fi -.B mlx_xpm_to_image -( -.I void *mlx_ptr, char **xpm_data, int *width, int *height -); - -.nf -.I void * -.fi -.B mlx_xpm_file_to_image -( -.I void *mlx_ptr, char *filename, int *width, int *height -); - -.nf -.I int -.fi -.B mlx_destroy_image -( -.I void *mlx_ptr, void *img_ptr -); - - -.SH DESCRIPTION - -.B mlx_new_image -() creates a new image in memory. It returns a -.I void * -identifier needed to manipulate this image later. It only needs -the size of the image to be created, using the -.I width -and -.I height -parameters, and the -.I mlx_ptr -connection identifier (see the -.B mlx -manual). - -The user can draw inside the image (see below), and -can dump the image inside a specified window at any time to -display it on the screen. This is done using -.B mlx_put_image_to_window -(). Three identifiers are needed here, for the connection to the -display, the window to use, and the image (respectively -.I mlx_ptr -, -.I win_ptr -and -.I img_ptr -). The ( -.I x -, -.I y -) coordinates define where the image should be placed in the window. - -.B mlx_get_data_addr -() returns information about the created image, allowing a user -to modify it later. The -.I img_ptr -parameter specifies the image to use. The three next parameters should -be the addresses of three different valid integers. -.I bits_per_pixel -will be filled with the number of bits needed to represent a pixel color -(also called the depth of the image). -.I size_line -is the number of bytes used to store one line of the image in memory. -This information is needed to move from one line to another in the image. -.I endian -tells you wether the pixel color in the image needs to be stored in -little endian ( -.I endian -== 0), or big endian ( -.I endian -== 1). - -.B mlx_get_data_addr -returns a -.I char * -address that represents the begining of the memory area where the image -is stored. From this adress, the first -.I bits_per_pixel -bits represent the color of the first pixel in the first line of -the image. The second group of -.I bits_per_pixel -bits represent the second pixel of the first line, and so on. -Add -.I size_line -to the adress to get the begining of the second line. You can reach any -pixels of the image that way. - -.B mlx_destroy_image -destroys the given image ( -.I img_ptr -). - -.SH STORING COLOR INSIDE IMAGES - -Depending on the display, the number of bits used to store a pixel color -can change. The user usually represents a color in RGB mode, using -one byte for each component (see -.B mlx_pixel_put -manual). This must be translated to fit the -.I bits_per_pixel -requirement of the image, and make the color understandable to the graphical system. -That is the purpose of the -.B mlx_get_color_value -() function. It takes a standard RGB -.I color -parameter, and returns an -.I unsigned int -value. -The -.I bits_per_pixel -least significant bits of this value can be stored in the image. - -Keep in mind that the least significant bits position depends on the local -computer's endian. If the endian of the image (in fact the endian of -the X-Server's computer for remote X11 display) differs from the local endian, then the value should -be transformed before being used. - -.SH XPM IMAGES - -The -.B mlx_xpm_to_image -() and -.B mlx_xpm_file_to_image -() functions will create a new image the same way. -They will fill it using the specified -.I xpm_data -or -.I filename -, depending on which function is used. -Note that MiniLibX does not use the standard -Xpm library to deal with xpm images. You may not be able to -read all types of xpm images. It however handles transparency. - -.SH RETURN VALUES -The three functions that create images, -.B mlx_new_image() -, -.B mlx_xpm_to_image() -and -.B mlx_xpm_file_to_image() -, will return NULL if an error occurs. Otherwise they return a non-null pointer -as an image identifier. - - -.SH SEE ALSO -mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_loop(3) - -.SH AUTHOR -Copyright ol@ - 2002-2015 - Olivier Crouzet diff --git a/miniLibX_man/man3/mlx_new_window.1 b/miniLibX_man/man3/mlx_new_window.1 deleted file mode 100644 index 36176d7..0000000 --- a/miniLibX_man/man3/mlx_new_window.1 +++ /dev/null @@ -1,79 +0,0 @@ -.TH MiniLibX 3 "September 19, 2002" -.SH NAME -MiniLibX - Managing windows -.SH SYNOPSYS - -.nf -.I void * -.fi -.B mlx_new_window -( -.I void *mlx_ptr, int size_x, int size_y, char *title -); - -.nf -.I int -.fi -.B mlx_clear_window -( -.I void *mlx_ptr, void *win_ptr -); - -.nf -.I int -.fi -.B mlx_destroy_window -( -.I void *mlx_ptr, void *win_ptr -); - - -.SH DESCRIPTION -The -.B mlx_new_window -() function creates a new window on the screen, using the -.I size_x -and -.I size_y -parameters to determine its size, and -.I title -as the text that should be displayed in the window's title bar. -The -.I mlx_ptr -parameter is the connection identifier returned by -.B mlx_init -() (see the -.B mlx -man page). -.B mlx_new_window -() returns a -.I void * -window identifier that can be used by other MiniLibX calls. -Note that the MiniLibX -can handle an arbitrary number of separate windows. - -.B mlx_clear_window -() and -.B mlx_destroy_window -() respectively clear (in black) and destroy the given window. They both have -the same parameters: -.I mlx_ptr -is the screen connection identifier, and -.I win_ptr -is a window identifier. - -.SH RETURN VALUES -If -.B mlx_new_window() -fails to create a new window (for wathever reason), it will return NULL, -otherwise a non-null pointer is returned as a window identifier. -.B mlx_clear_window -and -.B mlx_destroy_window -right now return nothing. - -.SH SEE ALSO -mlx(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3) - -.SH AUTHOR -Copyright ol@ - 2002-2015 - Olivier Crouzet diff --git a/miniLibX_man/man3/mlx_pixel_put.1 b/miniLibX_man/man3/mlx_pixel_put.1 deleted file mode 100644 index caf89f2..0000000 --- a/miniLibX_man/man3/mlx_pixel_put.1 +++ /dev/null @@ -1,81 +0,0 @@ -.TH MiniLibX 3 "September 19, 2002" -.SH NAME -MiniLibX - Drawing inside windows -.SH SYNOPSYS - -.nf -.I int -.fi -.B mlx_pixel_put -( -.I void *mlx_ptr, void *win_ptr, int x, int y, int color -); - -.nf -.I int -.fi -.B mlx_string_put -( -.I void *mlx_ptr, void *win_ptr, int x, int y, int color, char *string -); - - -.SH DESCRIPTION -The -.B mlx_pixel_put -() function draws a defined pixel in the window -.I win_ptr -using the ( -.I x -, -.I y -) coordinates, and the specified -.I color -\&. The origin (0,0) is the upper left corner of the window, the x and y axis -respectively pointing right and down. The connection -identifier, -.I mlx_ptr -, is needed (see the -.B mlx -man page). - -Parameters for -.B mlx_string_put -() have the same meaning. Instead of a simple pixel, the specified -.I string -will be displayed at ( -.I x -, -.I y -). - -In both functions, it is impossible to display anything outside the -specified window, nor display in another window in front of the selected one. - -.SH COLOR MANAGEMENT -The -.I color -parameter has an integer type. The displayed color needs to be encoded -in this integer, following a defined scheme. All displayable colors -can be split in 3 basic colors: red, green and blue. Three associated -values, in the 0-255 range, represent how much of each color is mixed up -to create the original color. Theses three values must be set inside the -integer to display the right color. The three least significant bytes of -this integer are filled as shown in the picture below: - -.nf - | 0 | R | G | B | color integer - +---+---+---+---+ -.fi - - -While filling the integer, make sure you avoid endian problems. Remember -that the "blue" byte should always be the least significant one. - - -.SH SEE ALSO -mlx(3), mlx_new_window(3), mlx_new_image(3), mlx_loop(3) - - -.SH AUTHOR -Copyright ol@ - 2002-2015 - Olivier Crouzet diff --git a/miniLibX_man/mlx.1 b/miniLibX_man/mlx.1 new file mode 100644 index 0000000..cfdac3d --- /dev/null +++ b/miniLibX_man/mlx.1 @@ -0,0 +1,115 @@ +.TH MiniLibX 3 "September 19, 2002" +.SH NAME +MiniLibX - Simple Graphical Interface Library for students +.SH SYNOPSYS +#include + +.nf +.I void * +.fi +.B mlx_init +(); + +.SH DESCRIPTION +MiniLibX is an easy way to create graphical software, +without any X-Window/Cocoa programming knowledge. It provides +simple window creation, a drawing tool, image and basic events +management. + +.SH BSD/LINUX X-WINDOW CONCEPT + +X-Window is a network-oriented graphical system for Unix. +It is based on two main parts: +.br +On one side, your software wants to draw something on the screen and/or +get keyboard & mouse entries. +.br +On the other side, the X-Server manages the screen, keyboard and mouse +(It is often refered to as a "display"). +.br +A network connection must be established between these two entities to send +drawing orders (from the software to the X-Server), and keyboard/mouse +events (from the X-Server to the software). + +.SH MACOSX CONCEPT + +The MacOSX operating system handle graphical access to the screen (or "display"). +.br +On one side, your software wants to draw something on the screen and/or +get keyboard & mouse entries. +.br +On the other side, the underlying MacOSX graphical framework that handles +the screen, the windowing system, keyboard and mouse. +.br +A connection between these two entities must be established. + +.SH INCLUDE FILE +.B mlx.h +should be included for a correct use of the MiniLibX API. +It only contains function prototypes, no structure is needed. + +.SH LIBRARY FUNCTIONS +.P +First of all, you need to initialize the connection +between your software and the display. +Once this connection is established, you'll be able to +use other MiniLibX functions to send the graphical orders, +like "I want to draw a yellow pixel in this window" or "did the +user hit a key?". +.P +The +.B mlx_init +function will create this connection. No parameters are needed, ant it will +return a +.I "void *" +identifier, used for further calls to the library routines. +.P +All other MiniLibX functions are described in the following man pages: + +.TP 20 +.B mlx_new_window +: manage windows +.TP 20 +.B mlx_pixel_put +: draw inside window +.TP 20 +.B mlx_new_image +: manipulate images +.TP 20 +.B mlx_loop +: handle keyboard or mouse events + +.SH LINKING MiniLibX on BSD/Linux and X-Window +To use MiniLibX functions, you'll need to link +your software with several libraries, including the MiniLibX library itself. +To do this, simply add the following arguments at linking time: + +.B -lmlx -lXext -lX11 + +You may also need to specify the path to these libraries, using +the +.B -L +flag. + +.SH LINKING MiniLibX on MACOSX +To use MiniLibX functions, you'll need to link your software with the +MiniLibX library, and several system frameworks: + +.B -lmlx -framework OpenGL -framework AppKit + +You may also need to specify the path to the MiniLibX library, using +the +.B -L +flag. + +.SH RETURN VALUES +If +.B 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 connection identifier. + +.SH SEE ALSO +mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3) + +.SH AUTHOR +Copyright ol@ - 2002-2015 - Olivier Crouzet diff --git a/miniLibX_man/mlx_loop.1 b/miniLibX_man/mlx_loop.1 new file mode 100644 index 0000000..fa2b835 --- /dev/null +++ b/miniLibX_man/mlx_loop.1 @@ -0,0 +1,143 @@ +.TH MiniLibX 3 "September 19, 2002" +.SH NAME +MiniLibX - Handle events +.SH SYNOPSYS + +.nf +.I int +.fi +.B mlx_loop +( +.I void *mlx_ptr +); + +.nf +.I int +.fi +.B mlx_key_hook +( +.I void *win_ptr, int (*funct_ptr)(), void *param +); + +.nf +.I int +.fi +.B mlx_mouse_hook +( +.I void *win_ptr, int (*funct_ptr)(), void *param +); + +.nf +.I int +.fi +.B mlx_expose_hook +( +.I void *win_ptr, int (*funct_ptr)(), void *param +); + +.nf +.I int +.fi +.B mlx_loop_hook +( +.I void *mlx_ptr, int (*funct_ptr)(), void *param +); + +.SH EVENTS + +Both X-Window and MacOSX graphical systems are bi-directionnal. +On one hand, the program sends orders to +the screen to display pixels, images, and so on. On the other hand, +it can get information from the keyboard and mouse associated to +the screen. To do so, the program receives "events" from the keyboard or the +mouse. + +.SH DESCRIPTION + +To receive events, you must use +.B mlx_loop +(). This function never returns. It is an infinite loop that waits for +an event, and then calls a user-defined function associated with this event. +A single parameter is needed, the connection identifier +.I mlx_ptr +(see the +.B mlx manual). + +You can assign different functions to the three following events: +.br +- A key is pressed +.br +- The mouse button is pressed +.br +- A part of the window should be re-drawn +(this is called an "expose" event, and it is your program's job to handle it). +.br + +Each window can define a different function for the same event. + +The three functions +.B mlx_key_hook +(), +.B mlx_mouse_hook +() and +.B mlx_expose_hook +() work exactly the same way. +.I funct_ptr +is a pointer to the function you want to be called +when an event occurs. This assignment is specific to the window defined by the +.I win_ptr +identifier. The +.I param +adress will be passed to the function everytime it is called, and should be +used to store the parameters it might need. + +The syntax for the +.B mlx_loop_hook +() function is identical to the previous ones, but the given function will be +called when no event occurs. + +When it catches an event, the MiniLibX calls the corresponding function +with fixed parameters: +.nf + + expose_hook(void *param); + key_hook(int keycode,void *param); + mouse_hook(int button,int x,int y,void *param); + loop_hook(void *param); + +.fi +These function names are arbitrary. They here are used to distinguish +parameters according to the event. These functions are NOT part of the +MiniLibX. + +.I param +is the address specified in the mlx_*_hook calls. This address is never +used nor modified by the MiniLibX. On key and mouse events, additional +information is passed: +.I keycode +tells you which key is pressed (X11 : look for the include file "keysymdef.h", +MacOS : create a small software and find out by yourself), +( +.I x +, +.I y +) are the coordinates of the mouse click in the window, and +.I button +tells you which mouse button was pressed. + +.SH GOING FURTHER WITH EVENTS +The MiniLibX provides a much generic access to all type of events. The +.I mlx.h +include define +.B mlx_hook() +in the same manner mlx_*_hook functions work. The event and mask values +will be taken from the X11 include file "X.h" (even for MacOSX, for compatibility purposes) + +See source code of mlx_int_param_event.c to find out how the MiniLibX will +call your own function for a specific event. + +.SH SEE ALSO +mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3) + +.SH AUTHOR +Copyright ol@ - 2002-2015 - Olivier Crouzet diff --git a/miniLibX_man/mlx_new_image.1 b/miniLibX_man/mlx_new_image.1 new file mode 100644 index 0000000..d46bf59 --- /dev/null +++ b/miniLibX_man/mlx_new_image.1 @@ -0,0 +1,192 @@ +.TH MiniLibX 3 "September 19, 2002" +.SH NAME +MiniLibX - Manipulating images +.SH SYNOPSYS + +.nf +.I void * +.fi +.B mlx_new_image +( +.I void *mlx_ptr, int width, int height +); + +.nf +.I char * +.fi +.B mlx_get_data_addr +( +.I void *img_ptr, int *bits_per_pixel, int *size_line, int *endian +); + +.nf +.I int +.fi +.B mlx_put_image_to_window +( +.I void *mlx_ptr, void *win_ptr, void *img_ptr, int x, int y +); + +.nf +.I unsigned int +.fi +.B mlx_get_color_value +( +.I void *mlx_ptr, int color +); + +.nf +.I void * +.fi +.B mlx_xpm_to_image +( +.I void *mlx_ptr, char **xpm_data, int *width, int *height +); + +.nf +.I void * +.fi +.B mlx_xpm_file_to_image +( +.I void *mlx_ptr, char *filename, int *width, int *height +); + +.nf +.I int +.fi +.B mlx_destroy_image +( +.I void *mlx_ptr, void *img_ptr +); + + +.SH DESCRIPTION + +.B mlx_new_image +() creates a new image in memory. It returns a +.I void * +identifier needed to manipulate this image later. It only needs +the size of the image to be created, using the +.I width +and +.I height +parameters, and the +.I mlx_ptr +connection identifier (see the +.B mlx +manual). + +The user can draw inside the image (see below), and +can dump the image inside a specified window at any time to +display it on the screen. This is done using +.B mlx_put_image_to_window +(). Three identifiers are needed here, for the connection to the +display, the window to use, and the image (respectively +.I mlx_ptr +, +.I win_ptr +and +.I img_ptr +). The ( +.I x +, +.I y +) coordinates define where the image should be placed in the window. + +.B mlx_get_data_addr +() returns information about the created image, allowing a user +to modify it later. The +.I img_ptr +parameter specifies the image to use. The three next parameters should +be the addresses of three different valid integers. +.I bits_per_pixel +will be filled with the number of bits needed to represent a pixel color +(also called the depth of the image). +.I size_line +is the number of bytes used to store one line of the image in memory. +This information is needed to move from one line to another in the image. +.I endian +tells you wether the pixel color in the image needs to be stored in +little endian ( +.I endian +== 0), or big endian ( +.I endian +== 1). + +.B mlx_get_data_addr +returns a +.I char * +address that represents the begining of the memory area where the image +is stored. From this adress, the first +.I bits_per_pixel +bits represent the color of the first pixel in the first line of +the image. The second group of +.I bits_per_pixel +bits represent the second pixel of the first line, and so on. +Add +.I size_line +to the adress to get the begining of the second line. You can reach any +pixels of the image that way. + +.B mlx_destroy_image +destroys the given image ( +.I img_ptr +). + +.SH STORING COLOR INSIDE IMAGES + +Depending on the display, the number of bits used to store a pixel color +can change. The user usually represents a color in RGB mode, using +one byte for each component (see +.B mlx_pixel_put +manual). This must be translated to fit the +.I bits_per_pixel +requirement of the image, and make the color understandable to the graphical system. +That is the purpose of the +.B mlx_get_color_value +() function. It takes a standard RGB +.I color +parameter, and returns an +.I unsigned int +value. +The +.I bits_per_pixel +least significant bits of this value can be stored in the image. + +Keep in mind that the least significant bits position depends on the local +computer's endian. If the endian of the image (in fact the endian of +the X-Server's computer for remote X11 display) differs from the local endian, then the value should +be transformed before being used. + +.SH XPM IMAGES + +The +.B mlx_xpm_to_image +() and +.B mlx_xpm_file_to_image +() functions will create a new image the same way. +They will fill it using the specified +.I xpm_data +or +.I filename +, depending on which function is used. +Note that MiniLibX does not use the standard +Xpm library to deal with xpm images. You may not be able to +read all types of xpm images. It however handles transparency. + +.SH RETURN VALUES +The three functions that create images, +.B mlx_new_image() +, +.B mlx_xpm_to_image() +and +.B mlx_xpm_file_to_image() +, will return NULL if an error occurs. Otherwise they return a non-null pointer +as an image identifier. + + +.SH SEE ALSO +mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_loop(3) + +.SH AUTHOR +Copyright ol@ - 2002-2015 - Olivier Crouzet diff --git a/miniLibX_man/mlx_new_window.1 b/miniLibX_man/mlx_new_window.1 new file mode 100644 index 0000000..36176d7 --- /dev/null +++ b/miniLibX_man/mlx_new_window.1 @@ -0,0 +1,79 @@ +.TH MiniLibX 3 "September 19, 2002" +.SH NAME +MiniLibX - Managing windows +.SH SYNOPSYS + +.nf +.I void * +.fi +.B mlx_new_window +( +.I void *mlx_ptr, int size_x, int size_y, char *title +); + +.nf +.I int +.fi +.B mlx_clear_window +( +.I void *mlx_ptr, void *win_ptr +); + +.nf +.I int +.fi +.B mlx_destroy_window +( +.I void *mlx_ptr, void *win_ptr +); + + +.SH DESCRIPTION +The +.B mlx_new_window +() function creates a new window on the screen, using the +.I size_x +and +.I size_y +parameters to determine its size, and +.I title +as the text that should be displayed in the window's title bar. +The +.I mlx_ptr +parameter is the connection identifier returned by +.B mlx_init +() (see the +.B mlx +man page). +.B mlx_new_window +() returns a +.I void * +window identifier that can be used by other MiniLibX calls. +Note that the MiniLibX +can handle an arbitrary number of separate windows. + +.B mlx_clear_window +() and +.B mlx_destroy_window +() respectively clear (in black) and destroy the given window. They both have +the same parameters: +.I mlx_ptr +is the screen connection identifier, and +.I win_ptr +is a window identifier. + +.SH RETURN VALUES +If +.B mlx_new_window() +fails to create a new window (for wathever reason), it will return NULL, +otherwise a non-null pointer is returned as a window identifier. +.B mlx_clear_window +and +.B mlx_destroy_window +right now return nothing. + +.SH SEE ALSO +mlx(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3) + +.SH AUTHOR +Copyright ol@ - 2002-2015 - Olivier Crouzet diff --git a/miniLibX_man/mlx_pixel_put.1 b/miniLibX_man/mlx_pixel_put.1 new file mode 100644 index 0000000..caf89f2 --- /dev/null +++ b/miniLibX_man/mlx_pixel_put.1 @@ -0,0 +1,81 @@ +.TH MiniLibX 3 "September 19, 2002" +.SH NAME +MiniLibX - Drawing inside windows +.SH SYNOPSYS + +.nf +.I int +.fi +.B mlx_pixel_put +( +.I void *mlx_ptr, void *win_ptr, int x, int y, int color +); + +.nf +.I int +.fi +.B mlx_string_put +( +.I void *mlx_ptr, void *win_ptr, int x, int y, int color, char *string +); + + +.SH DESCRIPTION +The +.B mlx_pixel_put +() function draws a defined pixel in the window +.I win_ptr +using the ( +.I x +, +.I y +) coordinates, and the specified +.I color +\&. The origin (0,0) is the upper left corner of the window, the x and y axis +respectively pointing right and down. The connection +identifier, +.I mlx_ptr +, is needed (see the +.B mlx +man page). + +Parameters for +.B mlx_string_put +() have the same meaning. Instead of a simple pixel, the specified +.I string +will be displayed at ( +.I x +, +.I y +). + +In both functions, it is impossible to display anything outside the +specified window, nor display in another window in front of the selected one. + +.SH COLOR MANAGEMENT +The +.I color +parameter has an integer type. The displayed color needs to be encoded +in this integer, following a defined scheme. All displayable colors +can be split in 3 basic colors: red, green and blue. Three associated +values, in the 0-255 range, represent how much of each color is mixed up +to create the original color. Theses three values must be set inside the +integer to display the right color. The three least significant bytes of +this integer are filled as shown in the picture below: + +.nf + | 0 | R | G | B | color integer + +---+---+---+---+ +.fi + + +While filling the integer, make sure you avoid endian problems. Remember +that the "blue" byte should always be the least significant one. + + +.SH SEE ALSO +mlx(3), mlx_new_window(3), mlx_new_image(3), mlx_loop(3) + + +.SH AUTHOR +Copyright ol@ - 2002-2015 - Olivier Crouzet diff --git a/minimalist.cub b/minimalist.cub index 51a4e99..f054994 100644 --- a/minimalist.cub +++ b/minimalist.cub @@ -1,5 +1,5 @@ R 640 480 -NO ./path_to_the_north_texture +NO ./textures/brick.xpm SO ./path_to_the_south_texture WE ./path_to_the_west_texture EA ./path_to_the_east_texture diff --git a/textures/brick.xpm b/textures/brick.xpm new file mode 100644 index 0000000..691f4c0 --- /dev/null +++ b/textures/brick.xpm @@ -0,0 +1,114 @@ +/* XPM */ +static char *_z63a_fwq0i[] = { +/* columns rows colors chars-per-pixel */ +"32 32 76 1 ", +" c #280C0C", +". c #2A0C0C", +"X c #2B0D0D", +"o c #2D0D0D", +"O c #2F0D0D", +"+ c #300E0E", +"@ c #320E0E", +"# c #330F0F", +"$ c #350F0F", +"% c #361010", +"& c #481414", +"* c #491515", +"= c #4B1515", +"- c #4C1616", +"; c #4E1616", +": c #501616", +"> c #511717", +", c #531717", +"< c #541818", +"1 c #561818", +"2 c #571919", +"3 c #561B19", +"4 c #561C1A", +"5 c #591919", +"6 c #581C1A", +"7 c #591D1B", +"8 c #5B1D1B", +"9 c #5D1D1B", +"0 c #5E1E1C", +"q c #601E1C", +"w c #611F1D", +"e c #621F1D", +"r c #64231F", +"t c #652320", +"y c #672320", +"u c #692320", +"i c #6A2421", +"p c #6B2421", +"a c #6E2623", +"s c #752A25", +"d c gray40", +"f c #686868", +"g c #6F6F6F", +"h c gray44", +"j c #717171", +"k c gray48", +"l c #7C7C7C", +"z c gray49", +"x c #7E7E7E", +"c c #808080", +"v c #818181", +"b c gray52", +"n c gray53", +"m c #8B8B8B", +"M c #8D8D8D", +"N c gray56", +"B c #909090", +"V c #929292", +"C c #939393", +"Z c gray58", +"A c #959595", +"S c gray59", +"D c #979797", +"F c #989898", +"G c gray60", +"H c #9B9B9B", +"J c gray61", +"K c #9D9D9D", +"L c #A2A2A2", +"P c #A4A4A4", +"I c #A5A5A5", +"U c gray65", +"Y c #AFAFAF", +"T c #B1B1B1", +"R c #B4B4B4", +"E c gray71", +/* pixels */ +"kbMFDDJKNBNNNBBBNNNBNBNYETLIPDmn", +".sypuuyuurtq09w778qw439979q7687f", +"Ou8e9904940w*--->11,=:<=*<:*:;,d", +"$i4*,:,<:;11<<;-=1&->;,=;>-==-*:,12,,-=;>::<=;<-,>-=*h", +"+a<>:,2<&><>11:=,-->,,<1->:,*=,x", +"@0>:&>*<>;1-;;<::2:=<-;-<>;1<:1l", +"oe=-<>*,<>,-<,:&>-<:;:1,1=><>2=Z", +"#,=;=-:>-*:,,-::>&=1,;2-=>:>,>:V", +"O;*,--:>1;>;2,22-1<=,:=,-15-><:A", +"+;=;;;<=;,<=:,,>--*5;>;1;;>>-*>C", +"#:*-2<:>:-2,<<1><:><;-:>*>>:,21C", +"$;,<<>;>2-:->&:;=;;&:-,=&-<:>=;A", +"+&;;-:,=,*112>=:>1;*1,>;*1<,;;:S", +"@;=>=:**>:>1==,,;,>1,,-;,>&>-;:l", +"O+O+o+@oXOO o++X+X$O@.%+#X@ooo+z", +"PPIPILLUJHHGcGcfjcvvIREYETJHJKKl", +"8qw439979q7687Xdsypuuyuurtq09w77", +"11,=:<=*<:*:;,Xgu8e9904940w*--->", +"1&->;,=;>-==-<+hi4*,:,<:;11<<;-=", +";>::<=;<-,>-=*+xy0::;->*:,12,,-=", +"-->,,<1->:,*=,@la<>:,2<&><>11:=,", +"2:=<-;-<>;1<:1$Z0>:&>*<>;1-;;<::", +"-<:;:1,1=><>2=oVe=-<>*,<>,-<,:&>", +"&=1,;2-=>:>,>:oA,=;=-:>-*:,,-::>", +"1<=,:=,-15-><:OC;*,--:>1;>;2,22-", +"-*5;>;1;;>>-*>.C;=;;;<=;,<=:,,>-", +":><;-:>*>>:,21%A:*-2<:>:-2,<<1><", +";;&:-,=&-<:>=;oS;,<<>;>2-:->&:;=", +"1;*1,>;*1<,;;:%l&;;-:,=,*112>=:>", +",>1,,-;,>&>-;:+z;=>=:**>:>1==,,;", +"X$O@.%+#X@ooo+Xl+O+o+@oXOO o++X+" +}; -- cgit