port to mac
This commit is contained in:
parent
fc4ec999f2
commit
231e813653
66 changed files with 5245 additions and 5356 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
*.swp
|
*.swp
|
||||||
cmake-build-debug
|
cmake-build-debug
|
||||||
.idea
|
.idea
|
||||||
|
._*
|
||||||
|
|
9
Makefile
9
Makefile
|
@ -6,7 +6,7 @@
|
||||||
# By: gtertysh <marvin@42.fr> +#+ +:+ +#+ #
|
# By: gtertysh <marvin@42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2016/12/14 16:54:48 by gtertysh #+# #+# #
|
# Created: 2016/12/14 16:54:48 by gtertysh #+# #+# #
|
||||||
# Updated: 2016/12/23 19:59:53 by gtertysh ### ########.fr #
|
# Updated: 2017/03/20 15:31:33 by gtertysh ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ MLX = libmlx.a
|
||||||
SRC_DIR = ./src/
|
SRC_DIR = ./src/
|
||||||
OBJ_DIR = ./obj/
|
OBJ_DIR = ./obj/
|
||||||
LIBFT_DIR = ./libft/
|
LIBFT_DIR = ./libft/
|
||||||
MLX_DIR = ./minilibx/
|
MLX_DIR = ./minilibx_macos/
|
||||||
|
|
||||||
# src and obj files
|
# src and obj files
|
||||||
|
|
||||||
|
@ -59,8 +59,7 @@ INC = -I $(LIBFT_DIR)includes/ \
|
||||||
# valgrind --tool=callgrind --dump-instr=yes --simulate-cache=yes --collect-jumps=yes program arguments
|
# valgrind --tool=callgrind --dump-instr=yes --simulate-cache=yes --collect-jumps=yes program arguments
|
||||||
|
|
||||||
LIBFT_FLAGS = -lft -L $(LIBFT_DIR)
|
LIBFT_FLAGS = -lft -L $(LIBFT_DIR)
|
||||||
MLX_FLAGS = -lmlx -lXext -lX11 -L $(MLX_DIR)
|
MLX_FLAGS = -lmlx -framework OpenGL -framework AppKit -L $(MLX_DIR)
|
||||||
OTHER_FLAGS = -lm
|
|
||||||
CC_FLAGS = -Werror -Wextra -Wall -O3
|
CC_FLAGS = -Werror -Wextra -Wall -O3
|
||||||
DEBUG = -g
|
DEBUG = -g
|
||||||
OPT = -O3
|
OPT = -O3
|
||||||
|
@ -83,7 +82,7 @@ $(NAME): $(LIBFT_DIR)$(LIBFT) $(MLX_DIR)$(MLX) $(OBJ)
|
||||||
|
|
||||||
$(OBJ_DIR)%.o: $(SRC_DIR)%.c $(FRACTOL_INC)$(FRACTOL_HEADER)
|
$(OBJ_DIR)%.o: $(SRC_DIR)%.c $(FRACTOL_INC)$(FRACTOL_HEADER)
|
||||||
@echo "$(CYAN)Compiling object files: $(BLUE)$@$(NORMAL)"
|
@echo "$(CYAN)Compiling object files: $(BLUE)$@$(NORMAL)"
|
||||||
@$(CC) $(FLAGS) $(INC) -c $< -o $@
|
@$(CC) $(CC_FLAGS) $(INC) -c $< -o $@
|
||||||
|
|
||||||
$(LIBFT_DIR)$(LIBFT):
|
$(LIBFT_DIR)$(LIBFT):
|
||||||
@echo "$(CYAN)Compiling libft library...$(NORMAL)"
|
@echo "$(CYAN)Compiling libft library...$(NORMAL)"
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/16 20:59:04 by gtertysh #+# #+# */
|
/* Created: 2017/03/16 20:59:04 by gtertysh #+# #+# */
|
||||||
/* Updated: 2017/03/16 21:09:30 by gtertysh ### ########.fr */
|
/* Updated: 2017/03/20 15:32:52 by gtertysh ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@
|
||||||
# include <math.h>
|
# include <math.h>
|
||||||
# include <fcntl.h>
|
# include <fcntl.h>
|
||||||
|
|
||||||
# define HEIGHT 700
|
# define HEIGHT 1200
|
||||||
# define WIDTH 1300
|
# define WIDTH 2500
|
||||||
# define COLOR1 0
|
# define COLOR1 0
|
||||||
# define COLOR2 16777215
|
# define COLOR2 16777215
|
||||||
# define INIT_X 30
|
# define INIT_X 30
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
|
|
||||||
This is the MinilibX, a simple X-Window (X11R6) programming API
|
|
||||||
in C, designed for students, suitable for X-beginners.
|
|
||||||
|
|
||||||
|
|
||||||
Contents
|
|
||||||
|
|
||||||
- source code in C to create the mlx library
|
|
||||||
- man pages (in man/ directory)
|
|
||||||
- a test program (in test/ directory) is built
|
|
||||||
with the library
|
|
||||||
- a public include file mlx.h
|
|
||||||
- a tiny configure script to generate an appropriate Makefile.gen
|
|
||||||
|
|
||||||
|
|
||||||
Requirements
|
|
||||||
|
|
||||||
- MinilibX only support TrueColor visual type (8,15,16,24 or 32 bits depth)
|
|
||||||
- gcc
|
|
||||||
- X11 include files
|
|
||||||
- XShm extension must be present
|
|
||||||
|
|
||||||
|
|
||||||
Compile MinilibX
|
|
||||||
|
|
||||||
- run ./configure or make
|
|
||||||
both will make a few tests, create Makefile.gen
|
|
||||||
and then automatically run make on this generated Makefile.gen .
|
|
||||||
libmlx.a and libmlx_$(HOSTTYPE).a are created.
|
|
||||||
test/mlx-test binary is also created.
|
|
||||||
|
|
||||||
|
|
||||||
Install MinilibX
|
|
||||||
|
|
||||||
- no installation script is provided. You may want to install
|
|
||||||
- libmlx.a and/or libmlx_$(HOSTTYPE).a in /usr/X11/lib or /usr/local/lib
|
|
||||||
- mlx.h in /usr/X11/include or /usr/local/include
|
|
||||||
- man/man3/mlx*.1 in /usr/X11/man/man3 or /usr/local/man/man3
|
|
||||||
|
|
||||||
|
|
||||||
Olivier CROUZET - 2014-01-06 -
|
|
|
@ -1,22 +0,0 @@
|
||||||
##
|
|
||||||
## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx
|
|
||||||
##
|
|
||||||
## Made by Olivier Crouzet
|
|
||||||
## Login <ol@epitech.net>
|
|
||||||
##
|
|
||||||
## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet
|
|
||||||
## Last update Tue May 15 15:44:41 2007 Olivier Crouzet
|
|
||||||
##
|
|
||||||
|
|
||||||
## Please use configure script
|
|
||||||
|
|
||||||
|
|
||||||
all : do_configure
|
|
||||||
|
|
||||||
do_configure :
|
|
||||||
./configure > /dev/null 2>&1
|
|
||||||
|
|
||||||
clean :
|
|
||||||
./configure clean > /dev/null 2>&1
|
|
||||||
|
|
||||||
re : clean all
|
|
|
@ -1,47 +0,0 @@
|
||||||
INC=/usr/include
|
|
||||||
HT=Linux
|
|
||||||
DOCP=do_cp
|
|
||||||
##
|
|
||||||
## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx
|
|
||||||
##
|
|
||||||
## Made by Olivier Crouzet
|
|
||||||
## Login <ol@epitech.net>
|
|
||||||
##
|
|
||||||
## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet
|
|
||||||
## Last update Tue May 15 15:41:20 2007 Olivier Crouzet
|
|
||||||
##
|
|
||||||
|
|
||||||
## Please use configure script
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CC = gcc
|
|
||||||
|
|
||||||
NAME = libmlx.a
|
|
||||||
|
|
||||||
SRC = mlx_init.c mlx_new_window.c mlx_pixel_put.c mlx_loop.c \
|
|
||||||
mlx_mouse_hook.c mlx_key_hook.c mlx_expose_hook.c mlx_loop_hook.c \
|
|
||||||
mlx_int_anti_resize_win.c mlx_int_do_nothing.c \
|
|
||||||
mlx_int_wait_first_expose.c mlx_int_get_visual.c \
|
|
||||||
mlx_flush_event.c mlx_string_put.c \
|
|
||||||
mlx_new_image.c mlx_get_data_addr.c \
|
|
||||||
mlx_put_image_to_window.c mlx_get_color_value.c mlx_clear_window.c \
|
|
||||||
mlx_xpm.c mlx_int_str_to_wordtab.c mlx_destroy_window.c \
|
|
||||||
mlx_int_param_event.c mlx_int_set_win_event_mask.c mlx_hook.c \
|
|
||||||
mlx_rgb.c mlx_destroy_image.c
|
|
||||||
|
|
||||||
OBJ =$(SRC:.c=.o)
|
|
||||||
CFLAGS = -O3 -I$(INC)
|
|
||||||
|
|
||||||
all : $(NAME) $(DOCP)
|
|
||||||
|
|
||||||
$(NAME) : $(OBJ)
|
|
||||||
ar -r $(NAME) $(OBJ)
|
|
||||||
ranlib $(NAME)
|
|
||||||
|
|
||||||
do_cp :
|
|
||||||
cp $(NAME) libmlx_$(HT).a
|
|
||||||
|
|
||||||
|
|
||||||
clean :
|
|
||||||
rm -f $(OBJ) $(NAME) *~ core *.core
|
|
|
@ -1,47 +0,0 @@
|
||||||
##
|
|
||||||
## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx
|
|
||||||
##
|
|
||||||
## Made by Olivier Crouzet
|
|
||||||
## Login <ol@epitech.net>
|
|
||||||
##
|
|
||||||
## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet
|
|
||||||
## Last update Tue May 15 15:41:20 2007 Olivier Crouzet
|
|
||||||
##
|
|
||||||
|
|
||||||
## Please use configure script
|
|
||||||
|
|
||||||
|
|
||||||
INC =%%%%
|
|
||||||
HT =%%%%
|
|
||||||
DOCP =%%%%
|
|
||||||
|
|
||||||
CC = gcc
|
|
||||||
|
|
||||||
NAME = libmlx.a
|
|
||||||
|
|
||||||
SRC = mlx_init.c mlx_new_window.c mlx_pixel_put.c mlx_loop.c \
|
|
||||||
mlx_mouse_hook.c mlx_key_hook.c mlx_expose_hook.c mlx_loop_hook.c \
|
|
||||||
mlx_int_anti_resize_win.c mlx_int_do_nothing.c \
|
|
||||||
mlx_int_wait_first_expose.c mlx_int_get_visual.c \
|
|
||||||
mlx_flush_event.c mlx_string_put.c \
|
|
||||||
mlx_new_image.c mlx_get_data_addr.c \
|
|
||||||
mlx_put_image_to_window.c mlx_get_color_value.c mlx_clear_window.c \
|
|
||||||
mlx_xpm.c mlx_int_str_to_wordtab.c mlx_destroy_window.c \
|
|
||||||
mlx_int_param_event.c mlx_int_set_win_event_mask.c mlx_hook.c \
|
|
||||||
mlx_rgb.c mlx_destroy_image.c
|
|
||||||
|
|
||||||
OBJ =$(SRC:.c=.o)
|
|
||||||
CFLAGS = -O3 -I$(INC)
|
|
||||||
|
|
||||||
all : $(NAME) $(DOCP)
|
|
||||||
|
|
||||||
$(NAME) : $(OBJ)
|
|
||||||
ar -r $(NAME) $(OBJ)
|
|
||||||
ranlib $(NAME)
|
|
||||||
|
|
||||||
do_cp :
|
|
||||||
cp $(NAME) libmlx_$(HT).a
|
|
||||||
|
|
||||||
|
|
||||||
clean :
|
|
||||||
rm -f $(OBJ) $(NAME) *~ core *.core
|
|
94
minilibx/configure
vendored
94
minilibx/configure
vendored
|
@ -1,94 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
|
|
||||||
if [ -n "$1" -a "$1" = "--help" ] ; then
|
|
||||||
echo "Usage : $0\n Auto-configure and make MinilibX"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
conf_inc=NO
|
|
||||||
|
|
||||||
for inc in \
|
|
||||||
/usr/X11/include \
|
|
||||||
/usr/X11R6/include \
|
|
||||||
/usr/X11R5/include \
|
|
||||||
/usr/X11R4/include \
|
|
||||||
\
|
|
||||||
/usr/include/X11 \
|
|
||||||
/usr/include/X11R6 \
|
|
||||||
/usr/include/X11R5 \
|
|
||||||
/usr/include/X11R4 \
|
|
||||||
\
|
|
||||||
/usr/local/X11/include \
|
|
||||||
/usr/local/X11R6/include \
|
|
||||||
/usr/local/X11R5/include \
|
|
||||||
/usr/local/X11R4/include \
|
|
||||||
\
|
|
||||||
/usr/local/include/X11 \
|
|
||||||
/usr/local/include/X11R6 \
|
|
||||||
/usr/local/include/X11R5 \
|
|
||||||
/usr/local/include/X11R4 \
|
|
||||||
\
|
|
||||||
/usr/X386/include \
|
|
||||||
/usr/x386/include \
|
|
||||||
/usr/XFree86/include/X11 \
|
|
||||||
\
|
|
||||||
/usr/include \
|
|
||||||
/usr/local/include \
|
|
||||||
/usr/athena/include \
|
|
||||||
/usr/local/x11r5/include \
|
|
||||||
/usr/lpp/Xamples/include \
|
|
||||||
\
|
|
||||||
/usr/openwin/include \
|
|
||||||
/usr/openwin/share/include
|
|
||||||
do
|
|
||||||
if [ -f "$inc/X11/Xlib.h" -a -f "$inc/X11/extensions/XShm.h" ]; then
|
|
||||||
conf_inc=$inc
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
if [ "$conf_inc" = "NO" ]; then
|
|
||||||
echo "Can't find a suitable X11 include directory."
|
|
||||||
exit
|
|
||||||
else
|
|
||||||
echo "X11 include dir : $conf_inc"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$HOSTTYPE" ]; then
|
|
||||||
conf_ht=`uname -s`
|
|
||||||
else
|
|
||||||
conf_ht=$HOSTTYPE
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$conf_ht" ]; then
|
|
||||||
conf_docp=""
|
|
||||||
else
|
|
||||||
conf_docp="do_cp"
|
|
||||||
echo "lib_$conf_ht generation"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
/bin/echo "INC=$conf_inc" > Makefile.gen
|
|
||||||
/bin/echo "HT=$conf_ht" >> Makefile.gen
|
|
||||||
/bin/echo "DOCP=$conf_docp" >> Makefile.gen
|
|
||||||
cat Makefile.mk | grep -v %%%% >> Makefile.gen
|
|
||||||
|
|
||||||
/bin/echo "INC=$conf_inc" > test/Makefile.gen
|
|
||||||
/bin/echo "HT=$conf_ht" >> test/Makefile.gen
|
|
||||||
/bin/echo "DOCP=$conf_docp" >> test/Makefile.gen
|
|
||||||
cat test/Makefile.mk | grep -v %%%% >> test/Makefile.gen
|
|
||||||
|
|
||||||
|
|
||||||
if [ -n "$1" -a "$1" = "clean" ] ; then
|
|
||||||
echo "Now make it clean."
|
|
||||||
make -f Makefile.gen clean
|
|
||||||
(cd test ; make -f Makefile.gen clean)
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Now make it."
|
|
||||||
make -f Makefile.gen all
|
|
||||||
(cd test ; make -f Makefile.gen all )
|
|
Binary file not shown.
|
@ -1,21 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_clear_window.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Thu Sep 7 19:46:15 2000 Charlie Root
|
|
||||||
** Last update Tue Sep 25 17:11:19 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_clear_window(t_xvar *xvar,t_win_list *win)
|
|
||||||
{
|
|
||||||
XClearWindow(xvar->display,win->window);
|
|
||||||
if (xvar->do_flush)
|
|
||||||
XFlush(xvar->display);
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_destroy_image.c for MinilibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Tue Mar 12 10:25:15 2002 Charlie Root
|
|
||||||
** Last update Tue May 15 16:45:54 2007 Olivier Crouzet
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_destroy_image(t_xvar *xvar, t_img *img)
|
|
||||||
{
|
|
||||||
if (img->type == MLX_TYPE_SHM_PIXMAP ||
|
|
||||||
img->type == MLX_TYPE_SHM)
|
|
||||||
{
|
|
||||||
XShmDetach(xvar->display, &(img->shm));
|
|
||||||
shmdt(img->shm.shmaddr);
|
|
||||||
/* shmctl IPC_RMID already done */
|
|
||||||
}
|
|
||||||
XDestroyImage(img->image); /* For image & shm-image. Also free img->data */
|
|
||||||
XFreePixmap(xvar->display, img->pix);
|
|
||||||
if (img->gc)
|
|
||||||
XFreeGC(xvar->display, img->gc);
|
|
||||||
free(img);
|
|
||||||
if (xvar->do_flush)
|
|
||||||
XFlush(xvar->display);
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_destroy_window.c for MinilibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Tue Mar 12 10:25:15 2002 Charlie Root
|
|
||||||
** Last update Tue May 15 16:46:08 2007 Olivier Crouzet
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_destroy_window(t_xvar *xvar,t_win_list *win)
|
|
||||||
{
|
|
||||||
t_win_list *w;
|
|
||||||
t_win_list *prev;
|
|
||||||
t_win_list first;
|
|
||||||
|
|
||||||
first.next = xvar->win_list;
|
|
||||||
prev = &first;
|
|
||||||
w = prev->next;
|
|
||||||
while (w)
|
|
||||||
{
|
|
||||||
if (w==win)
|
|
||||||
prev->next = w->next;
|
|
||||||
else
|
|
||||||
prev = w;
|
|
||||||
w = w->next;
|
|
||||||
}
|
|
||||||
xvar->win_list = first.next;
|
|
||||||
XDestroyWindow(xvar->display,win->window);
|
|
||||||
XFreeGC(xvar->display,win->gc);
|
|
||||||
free(win);
|
|
||||||
if (xvar->do_flush)
|
|
||||||
XFlush(xvar->display);
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_expose_hook.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Thu Aug 3 11:49:06 2000 Charlie Root
|
|
||||||
** Last update Fri Feb 23 17:07:42 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_expose_hook(t_win_list *win,int (*funct)(),void *param)
|
|
||||||
{
|
|
||||||
win->hooks[Expose].hook = funct;
|
|
||||||
win->hooks[Expose].param = param;
|
|
||||||
win->hooks[Expose].mask = ExposureMask;
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_flush_event.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Wed Aug 2 18:58:11 2000 Charlie Root
|
|
||||||
** Last update Fri Feb 23 17:08:48 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_flush_event(t_xvar *xvar)
|
|
||||||
{
|
|
||||||
XEvent ev;
|
|
||||||
|
|
||||||
while (XPending(xvar->display))
|
|
||||||
{
|
|
||||||
XNextEvent(xvar->display,&ev);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_get_color_value.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Mon Jul 31 19:01:33 2000 Charlie Root
|
|
||||||
** Last update Thu Oct 4 15:04:13 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_get_color_value(t_xvar *xvar,int color)
|
|
||||||
{
|
|
||||||
return(mlx_int_get_good_color(xvar,color));
|
|
||||||
}
|
|
||||||
|
|
||||||
int mlx_int_get_good_color(t_xvar *xvar,int color)
|
|
||||||
{
|
|
||||||
XColor xc;
|
|
||||||
|
|
||||||
if (xvar->depth>=24)
|
|
||||||
return (color);
|
|
||||||
xc.red = (color>>8)&0xFF00;
|
|
||||||
xc.green = color&0xFF00;
|
|
||||||
xc.blue = (color<<8)&0xFF00;
|
|
||||||
xc.pixel = ((xc.red>>(16-xvar->decrgb[1]))<<xvar->decrgb[0])+
|
|
||||||
((xc.green>>(16-xvar->decrgb[3]))<<xvar->decrgb[2])+
|
|
||||||
((xc.blue>>(16-xvar->decrgb[5]))<<xvar->decrgb[4]);
|
|
||||||
return (xc.pixel);
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_get_data_addr.c for MiniLibX in raytraceur
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Mon Aug 14 15:45:57 2000 Charlie Root
|
|
||||||
** Last update Thu Sep 27 19:05:25 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
char *mlx_get_data_addr(t_img *img,int *bits_per_pixel,
|
|
||||||
int *size_line,int *endian)
|
|
||||||
{
|
|
||||||
*bits_per_pixel = img->bpp;
|
|
||||||
*size_line = img->size_line;
|
|
||||||
*endian = img->image->byte_order;
|
|
||||||
return (img->data);
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_hook.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Thu Aug 3 11:49:06 2000 Charlie Root
|
|
||||||
** Last update Fri Jan 28 17:05:28 2005 Olivier Crouzet
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_hook(t_win_list *win, int x_event, int x_mask,
|
|
||||||
int (*funct)(),void *param)
|
|
||||||
{
|
|
||||||
win->hooks[x_event].hook = funct;
|
|
||||||
win->hooks[x_event].param = param;
|
|
||||||
win->hooks[x_event].mask = x_mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_do_key_autorepeatoff(t_xvar *xvar)
|
|
||||||
{
|
|
||||||
XAutoRepeatOff(xvar->display);
|
|
||||||
}
|
|
||||||
|
|
||||||
int mlx_do_key_autorepeaton(t_xvar *xvar)
|
|
||||||
{
|
|
||||||
XAutoRepeatOn(xvar->display);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_do_sync(t_xvar *xvar)
|
|
||||||
{
|
|
||||||
XSync(xvar->display, False);
|
|
||||||
}
|
|
|
@ -1,91 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_init.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Mon Jul 31 16:52:42 2000 Charlie Root
|
|
||||||
** Last update Fri Jan 28 17:05:09 2005 Olivier Crouzet
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void *mlx_init()
|
|
||||||
{
|
|
||||||
t_xvar *xvar;
|
|
||||||
|
|
||||||
if (!(xvar = malloc(sizeof(*xvar))) || (xvar->display = XOpenDisplay(""))==0)
|
|
||||||
return ((void *)0);
|
|
||||||
xvar->screen = DefaultScreen(xvar->display);
|
|
||||||
xvar->root = DefaultRootWindow(xvar->display);
|
|
||||||
xvar->cmap = DefaultColormap(xvar->display,xvar->screen);
|
|
||||||
xvar->depth = DefaultDepth(xvar->display,xvar->screen);
|
|
||||||
if (mlx_int_get_visual(xvar)==-1)
|
|
||||||
{
|
|
||||||
printf(ERR_NO_TRUECOLOR);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
xvar->win_list = 0;
|
|
||||||
xvar->loop_hook = 0;
|
|
||||||
xvar->loop_param = (void *)0;
|
|
||||||
xvar->do_flush = 1;
|
|
||||||
mlx_int_deal_shm(xvar);
|
|
||||||
if (xvar->private_cmap)
|
|
||||||
xvar->cmap = XCreateColormap(xvar->display,xvar->root,
|
|
||||||
xvar->visual,AllocNone);
|
|
||||||
mlx_int_rgb_conversion(xvar);
|
|
||||||
return (xvar);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
** pshm_format of -1 : Not XYBitmap|XYPixmap|ZPixmap
|
|
||||||
** alpha libX need a check of the DISPLAY env var, or shm is allowed
|
|
||||||
** in remote Xserver connections.
|
|
||||||
*/
|
|
||||||
|
|
||||||
int mlx_int_deal_shm(t_xvar *xvar)
|
|
||||||
{
|
|
||||||
int use_pshm;
|
|
||||||
int bidon;
|
|
||||||
char *dpy;
|
|
||||||
char buff[33];
|
|
||||||
|
|
||||||
xvar->use_xshm = XShmQueryVersion(xvar->display,&bidon,&bidon,&(use_pshm));
|
|
||||||
if (xvar->use_xshm && use_pshm)
|
|
||||||
xvar->pshm_format = XShmPixmapFormat(xvar->display);
|
|
||||||
else
|
|
||||||
xvar->pshm_format = -1;
|
|
||||||
gethostname(buff,32);
|
|
||||||
dpy = getenv(ENV_DISPLAY);
|
|
||||||
if (dpy && strlen(dpy) && *dpy!=':' && strncmp(dpy,buff,strlen(buff)) &&
|
|
||||||
strncmp(dpy,LOCALHOST,strlen(LOCALHOST)) )
|
|
||||||
{
|
|
||||||
xvar->pshm_format = -1;
|
|
||||||
xvar->use_xshm = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
** TrueColor Visual is needed to have *_mask correctly set
|
|
||||||
*/
|
|
||||||
|
|
||||||
int mlx_int_rgb_conversion(t_xvar *xvar)
|
|
||||||
{
|
|
||||||
bzero(xvar->decrgb,sizeof(int)*6);
|
|
||||||
while (!(xvar->visual->red_mask&1))
|
|
||||||
{ xvar->visual->red_mask >>= 1; xvar->decrgb[0] ++; }
|
|
||||||
while (xvar->visual->red_mask&1)
|
|
||||||
{ xvar->visual->red_mask >>= 1; xvar->decrgb[1] ++; }
|
|
||||||
while (!(xvar->visual->green_mask&1))
|
|
||||||
{ xvar->visual->green_mask >>= 1; xvar->decrgb[2] ++; }
|
|
||||||
while (xvar->visual->green_mask&1)
|
|
||||||
{ xvar->visual->green_mask >>= 1; xvar->decrgb[3] ++; }
|
|
||||||
while (!(xvar->visual->blue_mask&1))
|
|
||||||
{ xvar->visual->blue_mask >>= 1; xvar->decrgb[4] ++; }
|
|
||||||
while (xvar->visual->blue_mask&1)
|
|
||||||
{ xvar->visual->blue_mask >>= 1; xvar->decrgb[5] ++; }
|
|
||||||
}
|
|
|
@ -1,124 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_int.h for mlx in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Mon Jul 31 16:45:48 2000 Charlie Root
|
|
||||||
** Last update Wed May 25 16:44:16 2011 Olivier Crouzet
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Internal settings for MiniLibX
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <X11/Xlib.h>
|
|
||||||
#include <X11/Xutil.h>
|
|
||||||
#include <sys/ipc.h>
|
|
||||||
#include <sys/shm.h>
|
|
||||||
#include <X11/extensions/XShm.h>
|
|
||||||
/* #include <X11/xpm.h> */
|
|
||||||
|
|
||||||
#define MLX_TYPE_SHM_PIXMAP 3
|
|
||||||
#define MLX_TYPE_SHM 2
|
|
||||||
#define MLX_TYPE_XIMAGE 1
|
|
||||||
|
|
||||||
#define MLX_MAX_EVENT LASTEvent
|
|
||||||
|
|
||||||
|
|
||||||
#define ENV_DISPLAY "DISPLAY"
|
|
||||||
#define LOCALHOST "localhost"
|
|
||||||
#define ERR_NO_TRUECOLOR "MinilibX Error : No TrueColor Visual available.\n"
|
|
||||||
#define WARN_SHM_ATTACH "MinilibX Warning : X server can't attach shared memory.\n"
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct s_xpm_col
|
|
||||||
{
|
|
||||||
int name;
|
|
||||||
int col;
|
|
||||||
} t_xpm_col;
|
|
||||||
|
|
||||||
|
|
||||||
struct s_col_name
|
|
||||||
{
|
|
||||||
char *name;
|
|
||||||
int color;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct s_event_list
|
|
||||||
{
|
|
||||||
int mask;
|
|
||||||
int (*hook)();
|
|
||||||
void *param;
|
|
||||||
} t_event_list;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct s_win_list
|
|
||||||
{
|
|
||||||
Window window;
|
|
||||||
GC gc;
|
|
||||||
struct s_win_list *next;
|
|
||||||
int (*mouse_hook)();
|
|
||||||
int (*key_hook)();
|
|
||||||
int (*expose_hook)();
|
|
||||||
void *mouse_param;
|
|
||||||
void *key_param;
|
|
||||||
void *expose_param;
|
|
||||||
t_event_list hooks[MLX_MAX_EVENT];
|
|
||||||
} t_win_list;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct s_img
|
|
||||||
{
|
|
||||||
XImage *image;
|
|
||||||
Pixmap pix;
|
|
||||||
GC gc;
|
|
||||||
int size_line;
|
|
||||||
int bpp;
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
int type;
|
|
||||||
int format;
|
|
||||||
char *data;
|
|
||||||
XShmSegmentInfo shm;
|
|
||||||
} t_img;
|
|
||||||
|
|
||||||
typedef struct s_xvar
|
|
||||||
{
|
|
||||||
Display *display;
|
|
||||||
Window root;
|
|
||||||
int screen;
|
|
||||||
int depth;
|
|
||||||
Visual *visual;
|
|
||||||
Colormap cmap;
|
|
||||||
int private_cmap;
|
|
||||||
t_win_list *win_list;
|
|
||||||
int (*loop_hook)();
|
|
||||||
void *loop_param;
|
|
||||||
int use_xshm;
|
|
||||||
int pshm_format;
|
|
||||||
int do_flush;
|
|
||||||
int decrgb[6];
|
|
||||||
} t_xvar;
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_do_nothing();
|
|
||||||
int mlx_int_get_good_color();
|
|
||||||
int mlx_int_find_in_pcm();
|
|
||||||
int mlx_int_anti_resize_win();
|
|
||||||
int mlx_int_wait_first_expose();
|
|
||||||
int mlx_int_rgb_conversion();
|
|
||||||
int mlx_int_deal_shm();
|
|
||||||
void *mlx_int_new_xshm_image();
|
|
||||||
char **mlx_int_str_to_wordtab();
|
|
||||||
void *mlx_new_image();
|
|
||||||
int shm_att_pb();
|
|
|
@ -1,28 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_int_anti_resize_win.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Tue Aug 8 14:31:05 2000 Charlie Root
|
|
||||||
** Last update Tue Sep 25 15:56:58 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_anti_resize_win(t_xvar *xvar,Window win,int w,int h)
|
|
||||||
{
|
|
||||||
XSizeHints hints;
|
|
||||||
long toto;
|
|
||||||
|
|
||||||
XGetWMNormalHints(xvar->display,win,&hints,&toto);
|
|
||||||
hints.width = w;
|
|
||||||
hints.height = h;
|
|
||||||
hints.min_width = w;
|
|
||||||
hints.min_height = h;
|
|
||||||
hints.max_width = w;
|
|
||||||
hints.max_height = h;
|
|
||||||
hints.flags = PPosition | PSize | PMinSize | PMaxSize;
|
|
||||||
XSetWMNormalHints(xvar->display,win,&hints);
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_int_do_nothing.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Tue Aug 8 12:58:24 2000 Charlie Root
|
|
||||||
** Last update Tue Sep 25 15:56:22 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_do_nothing(void *param)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_int_get_visual.c for MinilibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Wed Oct 3 17:01:51 2001 Charlie Root
|
|
||||||
** Last update Thu Oct 4 15:00:45 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
** We need a private colormap for non-default Visual.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_get_visual(t_xvar *xvar)
|
|
||||||
{
|
|
||||||
XVisualInfo *vi;
|
|
||||||
XVisualInfo template;
|
|
||||||
int nb_item;
|
|
||||||
|
|
||||||
xvar->private_cmap = 0;
|
|
||||||
xvar->visual = DefaultVisual(xvar->display,xvar->screen);
|
|
||||||
if (xvar->visual->class == TrueColor)
|
|
||||||
return (0);
|
|
||||||
template.class = TrueColor;
|
|
||||||
template.depth = xvar->depth;
|
|
||||||
if (!(vi = XGetVisualInfo(xvar->display,VisualDepthMask|VisualClassMask,
|
|
||||||
&template,&nb_item)) )
|
|
||||||
return (-1);
|
|
||||||
xvar->visual = vi->visual;
|
|
||||||
xvar->private_cmap = 1;
|
|
||||||
return (0);
|
|
||||||
}
|
|
|
@ -1,100 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_int_param_event.c for MinilibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Mon Jul 31 16:37:50 2000 Charlie Root
|
|
||||||
** Last update Wed Oct 6 13:14:52 2004 Olivier Crouzet
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
int mlx_int_param_undef()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int mlx_int_param_KeyPress(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
|
||||||
{
|
|
||||||
win->hooks[KeyPress].hook(XkbKeycodeToKeysym(xvar->display,
|
|
||||||
ev->xkey.keycode, 0, 0),
|
|
||||||
win->hooks[KeyPress].param);
|
|
||||||
}
|
|
||||||
|
|
||||||
int mlx_int_param_KeyRelease(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
|
||||||
{
|
|
||||||
win->hooks[KeyRelease].hook(XkbKeycodeToKeysym(xvar->display,
|
|
||||||
ev->xkey.keycode, 0, 0),
|
|
||||||
win->hooks[KeyRelease].param);
|
|
||||||
}
|
|
||||||
|
|
||||||
int mlx_int_param_ButtonPress(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
|
||||||
{
|
|
||||||
win->hooks[ButtonPress].hook(ev->xbutton.button,ev->xbutton.x,ev->xbutton.y,
|
|
||||||
win->hooks[ButtonPress].param);
|
|
||||||
}
|
|
||||||
|
|
||||||
int mlx_int_param_ButtonRelease(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
|
||||||
{
|
|
||||||
win->hooks[ButtonRelease].hook(ev->xbutton.button,
|
|
||||||
ev->xbutton.x, ev->xbutton.y,
|
|
||||||
win->hooks[ButtonRelease].param);
|
|
||||||
}
|
|
||||||
|
|
||||||
int mlx_int_param_MotionNotify(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
|
||||||
{
|
|
||||||
win->hooks[MotionNotify].hook(ev->xbutton.x,ev->xbutton.y,
|
|
||||||
win->hooks[MotionNotify].param);
|
|
||||||
}
|
|
||||||
|
|
||||||
int mlx_int_param_Expose(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
|
||||||
{
|
|
||||||
if (!ev->xexpose.count)
|
|
||||||
win->hooks[Expose].hook(win->hooks[Expose].param);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_param_generic(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
|
||||||
{
|
|
||||||
win->hooks[ev->type].hook(win->hooks[ev->type].param);
|
|
||||||
}
|
|
||||||
|
|
||||||
int (*(mlx_int_param_event[]))() =
|
|
||||||
{
|
|
||||||
mlx_int_param_undef, /* 0 */
|
|
||||||
mlx_int_param_undef,
|
|
||||||
mlx_int_param_KeyPress,
|
|
||||||
mlx_int_param_KeyRelease, /* 3 */
|
|
||||||
mlx_int_param_ButtonPress,
|
|
||||||
mlx_int_param_ButtonRelease,
|
|
||||||
mlx_int_param_MotionNotify, /* 6 */
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_Expose, /* 12 */
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic
|
|
||||||
};
|
|
|
@ -1,34 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_int_set_win_event_mask.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Thu Aug 3 11:49:06 2000 Charlie Root
|
|
||||||
** Last update Fri Feb 23 17:07:42 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_set_win_event_mask(t_xvar *xvar)
|
|
||||||
{
|
|
||||||
t_win_list *win;
|
|
||||||
int mask;
|
|
||||||
int i;
|
|
||||||
XSetWindowAttributes xwa;
|
|
||||||
|
|
||||||
win = xvar->win_list;
|
|
||||||
while (win)
|
|
||||||
{
|
|
||||||
xwa.event_mask = 0;
|
|
||||||
i = MLX_MAX_EVENT;
|
|
||||||
while (i--)
|
|
||||||
xwa.event_mask |= win->hooks[i].mask;
|
|
||||||
XChangeWindowAttributes(xvar->display, win->window, CWEventMask, &xwa);
|
|
||||||
win = win->next;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_int_wait_first_expose.c for minilibx in
|
|
||||||
**
|
|
||||||
** Made by olivier crouzet
|
|
||||||
** Login <ol@epita.fr>
|
|
||||||
**
|
|
||||||
** Started on Tue Oct 17 09:26:45 2000 olivier crouzet
|
|
||||||
** Last update Fri Feb 23 17:27:10 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_wait_first_expose(t_xvar *xvar,Window win)
|
|
||||||
{
|
|
||||||
XEvent ev;
|
|
||||||
|
|
||||||
XWindowEvent(xvar->display,win,ExposureMask,&ev);
|
|
||||||
XPutBackEvent(xvar->display,&ev);
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_key_hook.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Thu Aug 3 11:49:06 2000 Charlie Root
|
|
||||||
** Last update Fri Feb 23 17:10:09 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_key_hook(t_win_list *win,int (*funct)(),void *param)
|
|
||||||
{
|
|
||||||
win->hooks[KeyRelease].hook = funct;
|
|
||||||
win->hooks[KeyRelease].param = param;
|
|
||||||
win->hooks[KeyRelease].mask = KeyReleaseMask;
|
|
||||||
}
|
|
|
@ -1,96 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_xpm.c for minilibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Fri Dec 8 11:07:24 2000 Charlie Root
|
|
||||||
** Last update Thu Oct 4 16:00:22 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void *mlx_int_xpm_f_image(t_xvar *xvar,int *width,int *height,
|
|
||||||
int (*xpm_func)(),void *param)
|
|
||||||
{
|
|
||||||
XImage *img1;
|
|
||||||
XImage *img2;
|
|
||||||
t_img *im2;
|
|
||||||
XpmAttributes xpm_att;
|
|
||||||
|
|
||||||
xpm_att.visual = xvar->visual;
|
|
||||||
xpm_att.colormap = xvar->cmap;
|
|
||||||
xpm_att.depth = xvar->depth;
|
|
||||||
xpm_att.bitmap_format = ZPixmap;
|
|
||||||
xpm_att.valuemask = XpmDepth|XpmBitmapFormat|XpmVisual|XpmColormap;
|
|
||||||
if (xpm_func(xvar->display,param,&img1,&img2,&xpm_att))
|
|
||||||
return ((void *)0);
|
|
||||||
if (img2)
|
|
||||||
XDestroyImage(img2);
|
|
||||||
|
|
||||||
if (!(im2 = (void *)mlx_new_image(xvar,img1->width,img1->height)))
|
|
||||||
{
|
|
||||||
XDestroyImage(img1);
|
|
||||||
return ((void *)0);
|
|
||||||
}
|
|
||||||
*width = img1->width;
|
|
||||||
*height = img1->height;
|
|
||||||
if (mlx_int_egal_img(im2->image,img1))
|
|
||||||
{
|
|
||||||
bcopy(img1->data,im2->data,img1->height*img1->bytes_per_line);
|
|
||||||
XDestroyImage(img1);
|
|
||||||
return (im2);
|
|
||||||
}
|
|
||||||
if (im2->type==MLX_TYPE_SHM_PIXMAP)
|
|
||||||
{
|
|
||||||
XFreePixmap(xvar->display,im2->pix);
|
|
||||||
im2->pix = XCreatePixmap(xvar->display,xvar->root,
|
|
||||||
*width,*height,xvar->depth);
|
|
||||||
}
|
|
||||||
if (im2->type>MLX_TYPE_XIMAGE)
|
|
||||||
{
|
|
||||||
XShmDetach(xvar->display,&(im2->shm));
|
|
||||||
shmdt(im2->data);
|
|
||||||
}
|
|
||||||
XDestroyImage(im2->image);
|
|
||||||
im2->image = img1;
|
|
||||||
im2->data = img1->data;
|
|
||||||
im2->type = MLX_TYPE_XIMAGE;
|
|
||||||
im2->size_line = img1->bytes_per_line;
|
|
||||||
im2->bpp = img1->bits_per_pixel;
|
|
||||||
return (im2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_egal_img(XImage *img1,XImage *img2)
|
|
||||||
{
|
|
||||||
if (img1->width!=img2->width || img1->height!=img2->height ||
|
|
||||||
img1->xoffset!=img2->xoffset || img1->format!=img2->format ||
|
|
||||||
img1->byte_order!=img2->byte_order ||
|
|
||||||
img1->bitmap_unit!=img2->bitmap_unit ||
|
|
||||||
img1->bitmap_bit_order!=img2->bitmap_bit_order ||
|
|
||||||
img1->bitmap_pad!=img2->bitmap_pad || img1->depth!=img2->depth ||
|
|
||||||
img1->bytes_per_line!=img2->bytes_per_line ||
|
|
||||||
img1->bits_per_pixel!=img2->bits_per_pixel ||
|
|
||||||
img1->red_mask!=img2->red_mask || img1->green_mask!=img2->green_mask ||
|
|
||||||
img1->blue_mask!=img2->blue_mask )
|
|
||||||
return (0);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void *mlx_xpm_file_to_image(t_xvar *xvar,char *filename,
|
|
||||||
int *width,int *height)
|
|
||||||
{
|
|
||||||
return (mlx_int_xpm_f_image(xvar,width,height,XpmReadFileToImage,filename));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void *mlx_xpm_to_image(t_xvar *xvar,char **data,int *width,int *height)
|
|
||||||
{
|
|
||||||
return (mlx_int_xpm_f_image(xvar,width,height,XpmCreateImageFromData,(void *)data));
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_loop.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Wed Aug 2 18:58:11 2000 Charlie Root
|
|
||||||
** Last update Fri Sep 30 14:47:41 2005 Olivier Crouzet
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
extern int (*(mlx_int_param_event[]))();
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_loop(t_xvar *xvar)
|
|
||||||
{
|
|
||||||
XEvent ev;
|
|
||||||
t_win_list *win;
|
|
||||||
|
|
||||||
mlx_int_set_win_event_mask(xvar);
|
|
||||||
xvar->do_flush = 0;
|
|
||||||
while (42)
|
|
||||||
{
|
|
||||||
while (!xvar->loop_hook || XPending(xvar->display))
|
|
||||||
{
|
|
||||||
XNextEvent(xvar->display,&ev);
|
|
||||||
win = xvar->win_list;
|
|
||||||
while (win && (win->window!=ev.xany.window))
|
|
||||||
win = win->next;
|
|
||||||
if (win && ev.type < MLX_MAX_EVENT)
|
|
||||||
if (win->hooks[ev.type].hook)
|
|
||||||
mlx_int_param_event[ev.type](xvar, &ev, win);
|
|
||||||
}
|
|
||||||
xvar->loop_hook(xvar->loop_param);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_loop_hook.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Thu Aug 3 11:49:06 2000 Charlie Root
|
|
||||||
** Last update Fri Feb 23 17:11:39 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_loop_hook(t_xvar *xvar,int (*funct)(),void *param)
|
|
||||||
{
|
|
||||||
xvar->loop_hook = funct;
|
|
||||||
xvar->loop_param = param;
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_mouse_hook.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Thu Aug 3 11:49:06 2000 Charlie Root
|
|
||||||
** Last update Fri Feb 23 17:11:05 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_mouse_hook(t_win_list *win,int (*funct)(),void *param)
|
|
||||||
{
|
|
||||||
win->hooks[ButtonPress].hook = funct;
|
|
||||||
win->hooks[ButtonPress].param = param;
|
|
||||||
win->hooks[ButtonPress].mask = ButtonPressMask;
|
|
||||||
}
|
|
|
@ -1,155 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_new_image.c for MiniLibX in raytraceur
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Mon Aug 14 15:29:14 2000 Charlie Root
|
|
||||||
** Last update Wed May 25 16:46:31 2011 Olivier Crouzet
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
** To handle X errors
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define X_ShmAttach 1
|
|
||||||
|
|
||||||
int mlx_X_error;
|
|
||||||
|
|
||||||
int shm_att_pb(Display *d,XErrorEvent *ev)
|
|
||||||
{
|
|
||||||
if (ev->request_code==146 && ev->minor_code==X_ShmAttach)
|
|
||||||
write(2,WARN_SHM_ATTACH,strlen(WARN_SHM_ATTACH));
|
|
||||||
mlx_X_error = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Data malloc : width+32 ( bitmap_pad=32 ), *4 = *32 / 8bit
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
void *mlx_int_new_xshm_image(t_xvar *xvar,int width,int height,int format)
|
|
||||||
{
|
|
||||||
t_img *img;
|
|
||||||
int (*save_handler)();
|
|
||||||
|
|
||||||
if (!(img = malloc(sizeof(*img))))
|
|
||||||
return ((void *)0);
|
|
||||||
bzero(img,sizeof(*img));
|
|
||||||
img->data = 0;
|
|
||||||
img->image = XShmCreateImage(xvar->display,xvar->visual,xvar->depth,
|
|
||||||
format,img->data,&(img->shm),width,height);
|
|
||||||
if (!img->image)
|
|
||||||
{
|
|
||||||
free(img);
|
|
||||||
return ((void *)0);
|
|
||||||
}
|
|
||||||
img->width = width;
|
|
||||||
img->height = height;
|
|
||||||
img->size_line = img->image->bytes_per_line;
|
|
||||||
img->bpp = img->image->bits_per_pixel;
|
|
||||||
img->format = format;
|
|
||||||
img->shm.shmid = shmget(IPC_PRIVATE,(width+32)*height*4,IPC_CREAT|0777);
|
|
||||||
if (img->shm.shmid==-1)
|
|
||||||
{
|
|
||||||
XDestroyImage(img->image);
|
|
||||||
free(img);
|
|
||||||
return ((void *)0);
|
|
||||||
}
|
|
||||||
img->data = img->shm.shmaddr = img->image->data = shmat(img->shm.shmid,0,0);
|
|
||||||
if (img->data==(void *)-1)
|
|
||||||
{
|
|
||||||
shmctl(img->shm.shmid,IPC_RMID,0);
|
|
||||||
XDestroyImage(img->image);
|
|
||||||
free(img);
|
|
||||||
return ((void *)0);
|
|
||||||
}
|
|
||||||
img->shm.readOnly = False;
|
|
||||||
mlx_X_error = 0;
|
|
||||||
save_handler = XSetErrorHandler(shm_att_pb);
|
|
||||||
if (!XShmAttach(xvar->display,&(img->shm)) ||
|
|
||||||
0&XSync(xvar->display,False) || mlx_X_error)
|
|
||||||
{
|
|
||||||
XSetErrorHandler(save_handler);
|
|
||||||
shmdt(img->data);
|
|
||||||
shmctl(img->shm.shmid,IPC_RMID,0);
|
|
||||||
XDestroyImage(img->image);
|
|
||||||
free(img);
|
|
||||||
return ((void *)0);
|
|
||||||
}
|
|
||||||
XSetErrorHandler(save_handler);
|
|
||||||
shmctl(img->shm.shmid,IPC_RMID,0);
|
|
||||||
if (xvar->pshm_format==format)
|
|
||||||
{
|
|
||||||
img->pix = XShmCreatePixmap(xvar->display,xvar->root,img->shm.shmaddr,
|
|
||||||
&(img->shm),width,height,xvar->depth);
|
|
||||||
img->type = MLX_TYPE_SHM_PIXMAP;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
img->pix = XCreatePixmap(xvar->display,xvar->root,
|
|
||||||
width,height,xvar->depth);
|
|
||||||
img->type = MLX_TYPE_SHM;
|
|
||||||
}
|
|
||||||
if (xvar->do_flush)
|
|
||||||
XFlush(xvar->display);
|
|
||||||
return (img);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void *mlx_int_new_image(t_xvar *xvar,int width, int height,int format)
|
|
||||||
{
|
|
||||||
t_img *img;
|
|
||||||
|
|
||||||
if (!(img = malloc(sizeof(*img))) ||
|
|
||||||
!(img->data = malloc((width+32)*height*4)))
|
|
||||||
return ((void *)0);
|
|
||||||
bzero(img->data,(width+32)*height*4);
|
|
||||||
img->image = XCreateImage(xvar->display,xvar->visual,xvar->depth,format,0,
|
|
||||||
img->data,width,height,32,0);
|
|
||||||
if (!img->image)
|
|
||||||
{
|
|
||||||
free(img->data);
|
|
||||||
free(img);
|
|
||||||
return ((void *)0);
|
|
||||||
}
|
|
||||||
img->gc = 0;
|
|
||||||
img->size_line = img->image->bytes_per_line;
|
|
||||||
img->bpp = img->image->bits_per_pixel;
|
|
||||||
img->width = width;
|
|
||||||
img->height = height;
|
|
||||||
img->pix = XCreatePixmap(xvar->display,xvar->root,width,height,xvar->depth);
|
|
||||||
img->format = format;
|
|
||||||
img->type = MLX_TYPE_XIMAGE;
|
|
||||||
if (xvar->do_flush)
|
|
||||||
XFlush(xvar->display);
|
|
||||||
return (img);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void *mlx_new_image(t_xvar *xvar,int width, int height)
|
|
||||||
{
|
|
||||||
t_img *img;
|
|
||||||
|
|
||||||
if (xvar->use_xshm)
|
|
||||||
if (img = mlx_int_new_xshm_image(xvar,width,height,ZPixmap))
|
|
||||||
return (img);
|
|
||||||
return (mlx_int_new_image(xvar,width,height,ZPixmap));
|
|
||||||
}
|
|
||||||
|
|
||||||
void *mlx_new_image2(t_xvar *xvar,int width, int height)
|
|
||||||
{
|
|
||||||
t_img *img;
|
|
||||||
|
|
||||||
if (xvar->use_xshm)
|
|
||||||
if (img = mlx_int_new_xshm_image(xvar,width,height,XYPixmap))
|
|
||||||
return (img);
|
|
||||||
return (mlx_int_new_image(xvar,width,height,XYPixmap));
|
|
||||||
}
|
|
|
@ -1,61 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_new_window.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Mon Jul 31 17:29:02 2000 Charlie Root
|
|
||||||
** Last update Thu Oct 4 15:44:43 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
** We do not use White/BlackPixel macro, TrueColor Visual make sure
|
|
||||||
** 0 is black & -1 is white
|
|
||||||
**
|
|
||||||
** With mlx_int_wait_first_expose, no flush is needed.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
void *mlx_new_window(t_xvar *xvar,int size_x,int size_y,char *title)
|
|
||||||
{
|
|
||||||
t_win_list *new_win;
|
|
||||||
XSetWindowAttributes xswa;
|
|
||||||
XGCValues xgcv;
|
|
||||||
|
|
||||||
xswa.background_pixel = 0;
|
|
||||||
xswa.border_pixel = -1;
|
|
||||||
xswa.colormap = xvar->cmap;
|
|
||||||
/*
|
|
||||||
xswa.event_mask = ButtonPressMask | ButtonReleaseMask | ExposureMask |
|
|
||||||
KeyPressMask | KeyReleaseMask | StructureNotifyMask;
|
|
||||||
*/
|
|
||||||
/* xswa.event_mask = ExposureMask; */
|
|
||||||
xswa.event_mask = 0xFFFFFF; /* all events */
|
|
||||||
if (!(new_win = malloc(sizeof(*new_win))))
|
|
||||||
return ((void *)0);
|
|
||||||
new_win->window = XCreateWindow(xvar->display,xvar->root,0,0,size_x,size_y,
|
|
||||||
0,CopyFromParent,InputOutput,xvar->visual,
|
|
||||||
CWEventMask|CWBackPixel|CWBorderPixel|
|
|
||||||
CWColormap,&xswa);
|
|
||||||
mlx_int_anti_resize_win(xvar,new_win->window,size_x,size_y);
|
|
||||||
XStoreName(xvar->display,new_win->window,title);
|
|
||||||
xgcv.foreground = -1;
|
|
||||||
xgcv.function = GXcopy;
|
|
||||||
xgcv.plane_mask = AllPlanes;
|
|
||||||
new_win->gc = XCreateGC(xvar->display,new_win->window,
|
|
||||||
GCFunction|GCPlaneMask|GCForeground,&xgcv);
|
|
||||||
new_win->next = xvar->win_list;
|
|
||||||
xvar->win_list = new_win;
|
|
||||||
/*
|
|
||||||
new_win->mouse_hook = mlx_int_do_nothing;
|
|
||||||
new_win->key_hook = mlx_int_do_nothing;
|
|
||||||
new_win->expose_hook = mlx_int_do_nothing;
|
|
||||||
*/
|
|
||||||
bzero(&(new_win->hooks), sizeof(new_win->hooks));
|
|
||||||
XMapRaised(xvar->display,new_win->window);
|
|
||||||
mlx_int_wait_first_expose(xvar,new_win->window);
|
|
||||||
return (new_win);
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_pixel_put.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Mon Jul 31 19:01:33 2000 Charlie Root
|
|
||||||
** Last update Tue Sep 25 17:09:49 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_pixel_put(t_xvar *xvar,t_win_list *win,
|
|
||||||
int x,int y,int color)
|
|
||||||
{
|
|
||||||
XGCValues xgcv;
|
|
||||||
|
|
||||||
xgcv.foreground = mlx_int_get_good_color(xvar,color);
|
|
||||||
XChangeGC(xvar->display,win->gc,GCForeground,&xgcv);
|
|
||||||
XDrawPoint(xvar->display,win->window,win->gc,x,y);
|
|
||||||
if (xvar->do_flush)
|
|
||||||
XFlush(xvar->display);
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_put_image_to_window.c for MiniLibX in raytraceur
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Mon Aug 14 15:55:49 2000 Charlie Root
|
|
||||||
** Last update Sun Oct 2 09:53:00 2005 Olivier Crouzet
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_put_image_to_window(t_xvar *xvar,t_win_list *win,t_img *img,
|
|
||||||
int x,int y)
|
|
||||||
{
|
|
||||||
GC gc;
|
|
||||||
|
|
||||||
gc = win->gc;
|
|
||||||
if (img->gc)
|
|
||||||
{
|
|
||||||
gc = img->gc;
|
|
||||||
XSetClipOrigin(xvar->display, gc, x, y);
|
|
||||||
}
|
|
||||||
if (img->type==MLX_TYPE_SHM)
|
|
||||||
XShmPutImage(xvar->display,img->pix, win->gc, img->image,0,0,0,0,
|
|
||||||
img->width,img->height,False);
|
|
||||||
if (img->type==MLX_TYPE_XIMAGE)
|
|
||||||
XPutImage(xvar->display,img->pix, win->gc, img->image,0,0,0,0,
|
|
||||||
img->width,img->height);
|
|
||||||
XCopyArea(xvar->display,img->pix,win->window, gc,
|
|
||||||
0,0,img->width,img->height,x,y);
|
|
||||||
if (xvar->do_flush)
|
|
||||||
XFlush(xvar->display);
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
/*
|
|
||||||
** mlx_string_put.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Mon Jul 31 19:01:33 2000 Charlie Root
|
|
||||||
** Last update Tue Sep 25 17:11:47 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_string_put(t_xvar *xvar,t_win_list *win,
|
|
||||||
int x,int y,int color,char *string)
|
|
||||||
{
|
|
||||||
XGCValues xgcv;
|
|
||||||
|
|
||||||
xgcv.foreground = mlx_int_get_good_color(xvar,color);
|
|
||||||
XChangeGC(xvar->display,win->gc,GCForeground,&xgcv);
|
|
||||||
XDrawString(xvar->display,win->window,win->gc,x,y,string,strlen(string));
|
|
||||||
if (xvar->do_flush)
|
|
||||||
XFlush(xvar->display);
|
|
||||||
}
|
|
|
@ -1,310 +0,0 @@
|
||||||
/*
|
|
||||||
** xpm-read.c for MinilibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Tue Dec 11 15:25:27 2001 olivier crouzet
|
|
||||||
** Last update Sat Oct 1 14:40:55 2005 Olivier Crouzet
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
extern struct s_col_name mlx_col_name[];
|
|
||||||
|
|
||||||
|
|
||||||
#define RETURN { if (colors) free(colors); if (tab) free(tab); \
|
|
||||||
if (colors_direct) free(colors_direct); \
|
|
||||||
if (img) {XDestroyImage(img->image); \
|
|
||||||
XFreePixmap(xvar->display,img->pix);free(img);} \
|
|
||||||
return ((void *)0);}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
char *mlx_int_get_line(char *ptr,int *pos,int size)
|
|
||||||
{
|
|
||||||
int pos2;
|
|
||||||
int pos3;
|
|
||||||
int pos4;
|
|
||||||
|
|
||||||
if ((pos2 = mlx_int_str_str(ptr+*pos,"\"",size-*pos))==-1)
|
|
||||||
return ((char *)0);
|
|
||||||
if ((pos3 = mlx_int_str_str(ptr+*pos+pos2+1,"\"",size-*pos-pos2-1))==-1)
|
|
||||||
return ((char *)0);
|
|
||||||
*(ptr+*pos+pos2) = 0;
|
|
||||||
*(ptr+*pos+pos2+1+pos3) = 0;
|
|
||||||
pos4 = *pos+pos2+1;
|
|
||||||
*pos += pos2+pos3+2;
|
|
||||||
return (ptr+pos4);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
char *mlx_int_static_line(char **xpm_data,int *pos,int size)
|
|
||||||
{
|
|
||||||
static char *copy = 0;
|
|
||||||
static int len = 0;
|
|
||||||
int len2;
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
str = xpm_data[(*pos)++];
|
|
||||||
if ((len2 = strlen(str))>len)
|
|
||||||
{
|
|
||||||
if (copy)
|
|
||||||
free(copy);
|
|
||||||
if (!(copy = malloc(len2+1)))
|
|
||||||
return ((char *)0);
|
|
||||||
len = len2;
|
|
||||||
}
|
|
||||||
/* strcpy(copy,str); */
|
|
||||||
strlcpy(copy, str, len2+1);
|
|
||||||
return (copy);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_get_col_name(char *str,int size)
|
|
||||||
{
|
|
||||||
int result;
|
|
||||||
|
|
||||||
result = 0;
|
|
||||||
while (size--)
|
|
||||||
result = (result<<8)+*(str++);
|
|
||||||
return (result);
|
|
||||||
}
|
|
||||||
|
|
||||||
int mlx_int_get_text_rgb(char *name)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (*name == '#')
|
|
||||||
return (strtol(name+1,0,16));
|
|
||||||
i = 0;
|
|
||||||
while (mlx_col_name[i].name)
|
|
||||||
{
|
|
||||||
if (!strcasecmp(mlx_col_name[i].name, name))
|
|
||||||
return (mlx_col_name[i].color);
|
|
||||||
i ++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_xpm_set_pixel(t_img *img, char *data, int opp, int col, int x)
|
|
||||||
{
|
|
||||||
int dec;
|
|
||||||
|
|
||||||
dec = opp;
|
|
||||||
while (dec--)
|
|
||||||
{
|
|
||||||
if (img->image->byte_order)
|
|
||||||
*(data+x*opp+dec) = col&0xFF;
|
|
||||||
else
|
|
||||||
*(data+x*opp+opp-dec-1) = col&0xFF;
|
|
||||||
col >>= 8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void *mlx_int_parse_xpm(t_xvar *xvar,void *info,int info_size,char *(*f)())
|
|
||||||
{
|
|
||||||
int pos;
|
|
||||||
char *line;
|
|
||||||
char **tab;
|
|
||||||
char *data;
|
|
||||||
char *clip_data;
|
|
||||||
int nc;
|
|
||||||
int opp;
|
|
||||||
int cpp;
|
|
||||||
int col;
|
|
||||||
int rgb_col;
|
|
||||||
int col_name;
|
|
||||||
int method;
|
|
||||||
int x;
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
t_img *img;
|
|
||||||
t_xpm_col *colors;
|
|
||||||
int *colors_direct;
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
XImage *clip_img;
|
|
||||||
XGCValues xgcv;
|
|
||||||
Pixmap clip_pix;
|
|
||||||
|
|
||||||
colors = 0;
|
|
||||||
colors_direct = 0;
|
|
||||||
img = 0;
|
|
||||||
tab = 0;
|
|
||||||
pos = 0;
|
|
||||||
if (!(line = f(info,&pos,info_size)) ||
|
|
||||||
!(tab = mlx_int_str_to_wordtab(line)) || !(width = atoi(tab[0])) ||
|
|
||||||
!(height = atoi(tab[1])) || !(nc = atoi(tab[2])) ||
|
|
||||||
!(cpp = atoi(tab[3])) )
|
|
||||||
RETURN;
|
|
||||||
free(tab);
|
|
||||||
tab = 0;
|
|
||||||
|
|
||||||
method = 0;
|
|
||||||
if (cpp<=2)
|
|
||||||
{
|
|
||||||
method = 1;
|
|
||||||
if (!(colors_direct = malloc((cpp==2?65536:256)*sizeof(int))))
|
|
||||||
RETURN;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (!(colors = malloc(nc*sizeof(*colors))))
|
|
||||||
RETURN;
|
|
||||||
|
|
||||||
clip_data = 0;
|
|
||||||
|
|
||||||
i = nc;
|
|
||||||
while (i--)
|
|
||||||
{
|
|
||||||
if (!(line = f(info,&pos,info_size)) ||
|
|
||||||
!(tab = mlx_int_str_to_wordtab(line+cpp)) )
|
|
||||||
RETURN;
|
|
||||||
j = 0;
|
|
||||||
while (tab[j] && strcmp(tab[j++],"c"));
|
|
||||||
if (!tab[j])
|
|
||||||
RETURN;
|
|
||||||
|
|
||||||
if ((rgb_col = mlx_int_get_text_rgb(tab[j]))==-1)
|
|
||||||
{
|
|
||||||
if (!(clip_data = malloc(4*width*height)) || /* ok, nice size .. */
|
|
||||||
!(clip_img = XCreateImage(xvar->display, xvar->visual,
|
|
||||||
1, XYPixmap, 0, clip_data,
|
|
||||||
width, height, 8, (width+7)/8)) )
|
|
||||||
RETURN;
|
|
||||||
memset(clip_data, 0xFF, 4*width*height);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (method)
|
|
||||||
colors_direct[mlx_int_get_col_name(line,cpp)] =
|
|
||||||
rgb_col>=0?mlx_get_color_value(xvar, rgb_col):rgb_col;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
colors[i].name = mlx_int_get_col_name(line,cpp);
|
|
||||||
colors[i].col = rgb_col>=0?mlx_get_color_value(xvar,rgb_col):rgb_col;
|
|
||||||
}
|
|
||||||
free(tab);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(img = mlx_new_image(xvar,width,height)))
|
|
||||||
RETURN;
|
|
||||||
opp = img->bpp/8;
|
|
||||||
|
|
||||||
|
|
||||||
i = height;
|
|
||||||
data = img->data;
|
|
||||||
while (i--)
|
|
||||||
{
|
|
||||||
if (!(line = f(info,&pos,info_size)))
|
|
||||||
RETURN;
|
|
||||||
x = 0;
|
|
||||||
while (x<width)
|
|
||||||
{
|
|
||||||
col = 0;
|
|
||||||
col_name = mlx_int_get_col_name(line+cpp*x,cpp);
|
|
||||||
if (method)
|
|
||||||
col = colors_direct[col_name];
|
|
||||||
else
|
|
||||||
{
|
|
||||||
j = nc;
|
|
||||||
while (j--)
|
|
||||||
if (colors[j].name==col_name)
|
|
||||||
{
|
|
||||||
col = colors[j].col;
|
|
||||||
j = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (col==-1)
|
|
||||||
XPutPixel(clip_img, x, height-1-i, 0);
|
|
||||||
else
|
|
||||||
mlx_int_xpm_set_pixel(img, data, opp, col, x);
|
|
||||||
x ++;
|
|
||||||
}
|
|
||||||
data += img->size_line;
|
|
||||||
}
|
|
||||||
if (clip_data)
|
|
||||||
{
|
|
||||||
if (!(clip_pix = XCreatePixmap(xvar->display, xvar->root,
|
|
||||||
width, height, 1)) )
|
|
||||||
RETURN;
|
|
||||||
img->gc = XCreateGC(xvar->display, clip_pix, 0, &xgcv);
|
|
||||||
XPutImage(xvar->display, clip_pix, img->gc, clip_img,
|
|
||||||
0, 0, 0, 0, width, height);
|
|
||||||
XFreeGC(xvar->display, img->gc);
|
|
||||||
xgcv.clip_mask = clip_pix;
|
|
||||||
xgcv.function = GXcopy;
|
|
||||||
xgcv.plane_mask = AllPlanes;
|
|
||||||
img->gc = XCreateGC(xvar->display, xvar->root, GCClipMask|GCFunction|
|
|
||||||
GCPlaneMask, &xgcv);
|
|
||||||
XSync(xvar->display, False);
|
|
||||||
XDestroyImage(clip_img);
|
|
||||||
}
|
|
||||||
if (colors)
|
|
||||||
free(colors);
|
|
||||||
if (colors_direct)
|
|
||||||
free(colors_direct);
|
|
||||||
return (img);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_file_get_rid_comment(char *ptr, int size)
|
|
||||||
{
|
|
||||||
int com_begin;
|
|
||||||
int com_end;
|
|
||||||
|
|
||||||
while ((com_begin = mlx_int_str_str_cote(ptr,"/*",size))!=-1)
|
|
||||||
{
|
|
||||||
com_end = mlx_int_str_str(ptr+com_begin+2,"*/",size-com_begin-2);
|
|
||||||
memset(ptr+com_begin,' ',com_end+4);
|
|
||||||
}
|
|
||||||
while ((com_begin = mlx_int_str_str_cote(ptr,"//",size))!=-1)
|
|
||||||
{
|
|
||||||
com_end = mlx_int_str_str(ptr+com_begin+2,"\n",size-com_begin-2);
|
|
||||||
memset(ptr+com_begin,' ',com_end+3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void *mlx_xpm_file_to_image(t_xvar *xvar,char *file,int *width,int *height)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
int size;
|
|
||||||
char *ptr;
|
|
||||||
t_img *img;
|
|
||||||
|
|
||||||
fd = -1;
|
|
||||||
if ((fd = open(file,O_RDONLY))==-1 || (size = lseek(fd,0,SEEK_END))==-1 ||
|
|
||||||
(ptr = mmap(0,size,PROT_WRITE|PROT_READ,MAP_PRIVATE,fd,0))==
|
|
||||||
(void *)MAP_FAILED)
|
|
||||||
{
|
|
||||||
if (fd>=0)
|
|
||||||
close(fd);
|
|
||||||
return ((void *)0);
|
|
||||||
}
|
|
||||||
mlx_int_file_get_rid_comment(ptr, size);
|
|
||||||
if (img = mlx_int_parse_xpm(xvar,ptr,size,mlx_int_get_line))
|
|
||||||
{
|
|
||||||
*width = img->width;
|
|
||||||
*height = img->height;
|
|
||||||
}
|
|
||||||
munmap(ptr,size);
|
|
||||||
close(fd);
|
|
||||||
return (img);
|
|
||||||
}
|
|
||||||
|
|
||||||
void *mlx_xpm_to_image(t_xvar *xvar,char **xpm_data,int *width,int *height)
|
|
||||||
{
|
|
||||||
t_img *img;
|
|
||||||
|
|
||||||
if (img = mlx_int_parse_xpm(xvar,xpm_data,0,mlx_int_static_line))
|
|
||||||
{
|
|
||||||
*width = img->width;
|
|
||||||
*height = img->height;
|
|
||||||
}
|
|
||||||
return (img);
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
#!/usr/bin/perl
|
|
||||||
#
|
|
||||||
## rgb2c.pl for MiniLibX in /home/boulon/work/c/raytraceur/minilibx
|
|
||||||
##
|
|
||||||
## Made by Olivier Crouzet
|
|
||||||
## Login <ol@epitech.net>
|
|
||||||
##
|
|
||||||
## Started on Tue Oct 5 16:33:46 2004 Olivier Crouzet
|
|
||||||
## Last update Tue Oct 5 16:36:11 2004 Olivier Crouzet
|
|
||||||
##
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# Generate a .c file with encoded colors, from the XFree86 rgb.txt file.
|
|
||||||
#
|
|
||||||
|
|
||||||
open(RGB, "/usr/X11/lib/X11/rgb.txt");
|
|
||||||
|
|
||||||
|
|
||||||
printf("/*\n** This is a generated file with rgb2c.pl and rgb.txt from\n");
|
|
||||||
printf("** the XFree86 distribution.\n*/\n\n");
|
|
||||||
printf("struct s_col_name mlx_col_name[] =\n{\n");
|
|
||||||
|
|
||||||
while (<RGB>)
|
|
||||||
{
|
|
||||||
@tab = split;
|
|
||||||
if ($tab[0] ne "!")
|
|
||||||
{
|
|
||||||
$color = $tab[3];
|
|
||||||
if ("$tab[4]" ne "")
|
|
||||||
{
|
|
||||||
$color = "$tab[3] $tab[4]";
|
|
||||||
}
|
|
||||||
printf(" { \"%s\" , 0x%x },\n", $color, $tab[0]*65536+$tab[1]*256+$tab[2]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printf(" { 0, 0 }\n};\n");
|
|
|
@ -1,26 +0,0 @@
|
||||||
INC=/usr/include
|
|
||||||
HT=Linux
|
|
||||||
DOCP=do_cp
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
INCLIB=$(INC)/../lib
|
|
||||||
|
|
||||||
CC=gcc
|
|
||||||
|
|
||||||
CFLAGS= -I$(INC) -O3 -I..
|
|
||||||
|
|
||||||
NAME= mlx-test
|
|
||||||
SRC = main.c
|
|
||||||
OBJ = $(SRC:.c=.o)
|
|
||||||
|
|
||||||
all :$(NAME)
|
|
||||||
|
|
||||||
$(NAME) :$(OBJ)
|
|
||||||
$(CC) -o $(NAME) $(OBJ) -L.. -lmlx -L$(INCLIB) -lXext -lX11 -lm
|
|
||||||
|
|
||||||
clean :
|
|
||||||
rm -f $(NAME) $(OBJ) *~ core *.core
|
|
||||||
|
|
||||||
|
|
||||||
re : clean all
|
|
|
@ -1,24 +0,0 @@
|
||||||
|
|
||||||
|
|
||||||
INC=%%%%
|
|
||||||
|
|
||||||
INCLIB=$(INC)/../lib
|
|
||||||
|
|
||||||
CC=gcc
|
|
||||||
|
|
||||||
CFLAGS= -I$(INC) -O3 -I..
|
|
||||||
|
|
||||||
NAME= mlx-test
|
|
||||||
SRC = main.c
|
|
||||||
OBJ = $(SRC:.c=.o)
|
|
||||||
|
|
||||||
all :$(NAME)
|
|
||||||
|
|
||||||
$(NAME) :$(OBJ)
|
|
||||||
$(CC) -o $(NAME) $(OBJ) -L.. -lmlx -L$(INCLIB) -lXext -lX11 -lm
|
|
||||||
|
|
||||||
clean :
|
|
||||||
rm -f $(NAME) $(OBJ) *~ core *.core
|
|
||||||
|
|
||||||
|
|
||||||
re : clean all
|
|
|
@ -1,284 +0,0 @@
|
||||||
|
|
||||||
#include "mlx.h"
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
#define WIN1_SX 242
|
|
||||||
#define WIN1_SY 242
|
|
||||||
#define IM1_SX 42
|
|
||||||
#define IM1_SY 42
|
|
||||||
#define IM3_SX 242
|
|
||||||
#define IM3_SY 242
|
|
||||||
|
|
||||||
void *mlx;
|
|
||||||
void *win1;
|
|
||||||
void *win2;
|
|
||||||
void *win3;
|
|
||||||
void *im1;
|
|
||||||
void *im2;
|
|
||||||
void *im3;
|
|
||||||
void *im4;
|
|
||||||
int bpp1;
|
|
||||||
int bpp2;
|
|
||||||
int bpp3;
|
|
||||||
int bpp4;
|
|
||||||
int sl1;
|
|
||||||
int sl2;
|
|
||||||
int sl3;
|
|
||||||
int sl4;
|
|
||||||
int endian1;
|
|
||||||
int endian2;
|
|
||||||
int endian3;
|
|
||||||
int endian4;
|
|
||||||
char *data1;
|
|
||||||
char *data2;
|
|
||||||
char *data3;
|
|
||||||
char *data4;
|
|
||||||
int xpm1_x;
|
|
||||||
int xpm1_y;
|
|
||||||
|
|
||||||
int local_endian;
|
|
||||||
|
|
||||||
int expose_win1(void *p)
|
|
||||||
{
|
|
||||||
mlx_put_image_to_window(mlx,win1,im3,0,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int expose_win2(void *p)
|
|
||||||
{
|
|
||||||
mlx_put_image_to_window(mlx,win2,im4,0,0);
|
|
||||||
mlx_put_image_to_window(mlx,win2,im2,0,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int key_win1(int key,void *p)
|
|
||||||
{
|
|
||||||
printf("Key in Win1 : %d\n",key);
|
|
||||||
if (key==0xFF1B)
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int key_win2(int key,void *p)
|
|
||||||
{
|
|
||||||
printf("Key in Win2 : %d\n",key);
|
|
||||||
if (key==0xFF1B)
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int key_win3(int key,void *p)
|
|
||||||
{
|
|
||||||
printf("Key in Win3 : %d\n",key);
|
|
||||||
if (key==0xFF1B)
|
|
||||||
mlx_destroy_window(mlx,win3);
|
|
||||||
}
|
|
||||||
|
|
||||||
int mouse_win1(int button,int x,int y, void *p)
|
|
||||||
{
|
|
||||||
printf("Mouse in Win1, button %d at %dx%d.\n",button,x,y);
|
|
||||||
}
|
|
||||||
|
|
||||||
int mouse_win2(int button,int x,int y, void *p)
|
|
||||||
{
|
|
||||||
printf("Mouse in Win2, button %d at %dx%d.\n",button,x,y);
|
|
||||||
}
|
|
||||||
|
|
||||||
int mouse_win3(int x,int y, void *p)
|
|
||||||
{
|
|
||||||
printf("Mouse moving in Win3, at %dx%d.\n",x,y);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
int a;
|
|
||||||
|
|
||||||
printf("MinilibX Test Program\n");
|
|
||||||
a = 0x11223344;
|
|
||||||
if (((unsigned char *)&a)[0] == 0x11)
|
|
||||||
local_endian = 1;
|
|
||||||
else
|
|
||||||
local_endian = 0;
|
|
||||||
printf(" => Local Endian : %d\n",local_endian);
|
|
||||||
|
|
||||||
printf(" => Connection ...");
|
|
||||||
if (!(mlx = mlx_init()))
|
|
||||||
{
|
|
||||||
printf(" !! KO !!\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
printf("OK (use_xshm %d pshm_format %d)\n",((t_xvar *)mlx)->use_xshm,((t_xvar *)mlx)->pshm_format);
|
|
||||||
|
|
||||||
printf(" => Window1 %dx%d \"Title 1\" ...",WIN1_SX,WIN1_SY);
|
|
||||||
if (!(win1 = mlx_new_window(mlx,WIN1_SX,WIN1_SY,"Title1")))
|
|
||||||
{
|
|
||||||
printf(" !! KO !!\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
printf("OK\n");
|
|
||||||
|
|
||||||
printf(" => Colormap sans event ...");
|
|
||||||
color_map_1(win1,WIN1_SX,WIN1_SY);
|
|
||||||
printf("OK\n");
|
|
||||||
sleep(2);
|
|
||||||
|
|
||||||
printf(" => Clear Window ...");
|
|
||||||
mlx_clear_window(mlx,win1);
|
|
||||||
printf("OK\n");
|
|
||||||
sleep(2);
|
|
||||||
|
|
||||||
printf(" => Image1 ZPixmap %dx%d ...",IM1_SX,IM1_SY);
|
|
||||||
if (!(im1 = mlx_new_image(mlx,IM1_SX,IM1_SY)))
|
|
||||||
{
|
|
||||||
printf(" !! KO !!\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
data1 = mlx_get_data_addr(im1,&bpp1,&sl1,&endian1);
|
|
||||||
printf("OK (bpp1: %d, sizeline1: %d endian: %d type: %d)\n",bpp1,sl1,endian1,
|
|
||||||
((t_img *)im1)->type);
|
|
||||||
|
|
||||||
printf(" => Fill Image1 ...");
|
|
||||||
color_map_2(data1,bpp1,sl1,IM1_SX,IM1_SY,endian1, 1);
|
|
||||||
printf("OK (pixmap : %d)\n",(int)((t_img *)im1)->pix);
|
|
||||||
|
|
||||||
printf(" => Put Image1 ...");
|
|
||||||
mlx_put_image_to_window(mlx,win1,im1,20,20);
|
|
||||||
printf("OK\n");
|
|
||||||
sleep(2);
|
|
||||||
|
|
||||||
printf(" => Destroy Image1 ... ");
|
|
||||||
mlx_destroy_image(mlx, im1);
|
|
||||||
printf("OK\n");
|
|
||||||
sleep(2);
|
|
||||||
|
|
||||||
printf(" => Image3 ZPixmap %dx%d ...",IM3_SX,IM3_SY);
|
|
||||||
if (!(im3 = mlx_new_image(mlx,IM3_SX,IM3_SY)))
|
|
||||||
{
|
|
||||||
printf(" !! KO !!\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
data3 = mlx_get_data_addr(im3,&bpp3,&sl3,&endian3);
|
|
||||||
printf("OK (bpp3 %d, sizeline3 %d endian3 %d type %d)\n",bpp3,sl3,endian3,
|
|
||||||
((t_img *)im3)->type);
|
|
||||||
|
|
||||||
printf(" => Fill Image3 ...");
|
|
||||||
color_map_2(data3,bpp3,sl3,IM3_SX,IM3_SY,endian3, 1);
|
|
||||||
printf("OK (pixmap : %d)\n",(int)((t_img *)im3)->pix);
|
|
||||||
|
|
||||||
printf(" => Put Image3 ...");
|
|
||||||
mlx_put_image_to_window(mlx,win1,im3,20,20);
|
|
||||||
printf("OK\n");
|
|
||||||
sleep(2);
|
|
||||||
|
|
||||||
printf(" => String ...");
|
|
||||||
mlx_string_put(mlx,win1,5,WIN1_SY/2,0xFF99FF,"String output");
|
|
||||||
mlx_string_put(mlx,win1,15,WIN1_SY/2+20,0x00FFFF,"MinilibX test");
|
|
||||||
printf("OK\n");
|
|
||||||
sleep(2);
|
|
||||||
|
|
||||||
printf(" => Xpm from file ...");
|
|
||||||
if (!(im2 = mlx_xpm_file_to_image(mlx,"open.xpm",&xpm1_x,&xpm1_y)))
|
|
||||||
{
|
|
||||||
printf(" !! KO !!\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
data2 = mlx_get_data_addr(im2,&bpp2,&sl2,&endian2);
|
|
||||||
printf("OK (xpm %dx%d)(img bpp2: %d, sizeline2: %d endian: %d type: %d)\n",
|
|
||||||
xpm1_x,xpm1_y,bpp2,sl2,endian2,((t_img *)im2)->type);
|
|
||||||
sleep(2);
|
|
||||||
|
|
||||||
printf(" => Put xpm ...");
|
|
||||||
mlx_put_image_to_window(mlx,win1,im2,0,0);
|
|
||||||
mlx_put_image_to_window(mlx,win1,im2,100,100);
|
|
||||||
printf("OK\n");
|
|
||||||
sleep(2);
|
|
||||||
|
|
||||||
printf(" => 2nd window,");
|
|
||||||
win2 = mlx_new_window(mlx,WIN1_SX,WIN1_SY,"Title2");
|
|
||||||
if (!(im4 = mlx_new_image(mlx,IM3_SX, IM3_SY)))
|
|
||||||
{
|
|
||||||
printf(" !! KO !!\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
data4 = mlx_get_data_addr(im4,&bpp4,&sl4,&endian4);
|
|
||||||
color_map_2(data4,bpp4,sl4,IM3_SX,IM3_SY,endian4, 2);
|
|
||||||
|
|
||||||
printf(" 3rd window, Installing hooks ...");
|
|
||||||
win3 = mlx_new_window(mlx,WIN1_SX,WIN1_SY,"Title3");
|
|
||||||
mlx_expose_hook(win1,expose_win1,0);
|
|
||||||
mlx_mouse_hook(win1,mouse_win1,0);
|
|
||||||
mlx_key_hook(win1,key_win1,0);
|
|
||||||
mlx_expose_hook(win2,expose_win2,0);
|
|
||||||
mlx_mouse_hook(win2,mouse_win2,0);
|
|
||||||
mlx_key_hook(win2,key_win2,0);
|
|
||||||
mlx_key_hook(win3,key_win3,0);
|
|
||||||
|
|
||||||
mlx_hook(win3, MotionNotify, PointerMotionMask, mouse_win3, 0);
|
|
||||||
|
|
||||||
printf("OK\nNow in Loop. Just play. Esc in 3 to destroy, 1&2 to quit.\n");
|
|
||||||
|
|
||||||
mlx_loop(mlx);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int color_map_1(void *win,int w,int h)
|
|
||||||
{
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
int color;
|
|
||||||
|
|
||||||
x = w;
|
|
||||||
while (x--)
|
|
||||||
{
|
|
||||||
y = h;
|
|
||||||
while (y--)
|
|
||||||
{
|
|
||||||
color = (x*255)/w+((((w-x)*255)/w)<<16)+(((y*255)/h)<<8);
|
|
||||||
mlx_pixel_put(mlx,win,x,y,color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int color_map_2(unsigned char *data,int bpp,int sl,int w,int h,int endian, int type)
|
|
||||||
{
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
int opp;
|
|
||||||
int dec;
|
|
||||||
int color;
|
|
||||||
int color2;
|
|
||||||
unsigned char *ptr;
|
|
||||||
|
|
||||||
opp = bpp/8;
|
|
||||||
printf("(opp : %d) ",opp);
|
|
||||||
y = h;
|
|
||||||
while (y--)
|
|
||||||
{
|
|
||||||
ptr = data+y*sl;
|
|
||||||
x = w;
|
|
||||||
while (x--)
|
|
||||||
{
|
|
||||||
if (type==2)
|
|
||||||
color = (y*255)/w+((((w-x)*255)/w)<<16)
|
|
||||||
+(((y*255)/h)<<8);
|
|
||||||
else
|
|
||||||
color = (x*255)/w+((((w-x)*255)/w)<<16)+(((y*255)/h)<<8);
|
|
||||||
color2 = mlx_get_color_value(mlx,color);
|
|
||||||
dec = opp;
|
|
||||||
while (dec--)
|
|
||||||
if (endian==local_endian)
|
|
||||||
{
|
|
||||||
if (endian)
|
|
||||||
*(ptr+x*opp+dec) = ((unsigned char *)(&color2))[4-opp+dec];
|
|
||||||
else
|
|
||||||
*(ptr+x*opp+dec) = ((unsigned char *)(&color2))[dec];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (endian)
|
|
||||||
*(ptr+x*opp+dec) = ((unsigned char *)(&color2))[opp-1-dec];
|
|
||||||
else
|
|
||||||
*(ptr+x*opp+dec) = ((unsigned char *)(&color2))[3-dec];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx.h"
|
|
||||||
|
|
||||||
|
|
||||||
void *mlx;
|
|
||||||
void *win1;
|
|
||||||
void *win2;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int gere_mouse(int x,int y,int button,void*toto)
|
|
||||||
{
|
|
||||||
printf("Mouse event - new win\n");
|
|
||||||
mlx_destroy_window(mlx,win1);
|
|
||||||
win1 = mlx_new_window(mlx,random()%500,random()%500,"new win");
|
|
||||||
mlx_mouse_hook(win1,gere_mouse,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
srandom(time(0));
|
|
||||||
mlx = mlx_init();
|
|
||||||
win1 = mlx_new_window(mlx,300,300,"win1");
|
|
||||||
win2 = mlx_new_window(mlx,600,600,"win2");
|
|
||||||
mlx_mouse_hook(win1,gere_mouse,0);
|
|
||||||
mlx_mouse_hook(win2,gere_mouse,0);
|
|
||||||
mlx_loop(mlx);
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,230 +0,0 @@
|
||||||
/* XPM */
|
|
||||||
static char *open[] = {
|
|
||||||
/* width height num_colors chars_per_pixel */
|
|
||||||
" 45 55 168 2",
|
|
||||||
/* colors */
|
|
||||||
".. s None c None",
|
|
||||||
".# c #450304",
|
|
||||||
".a c #ce7e7c",
|
|
||||||
".b c #b94344",
|
|
||||||
".c c #b65254",
|
|
||||||
".d c #780204",
|
|
||||||
".e c #b04c4c",
|
|
||||||
".f c #b00204",
|
|
||||||
".g c #8a8a64",
|
|
||||||
".h c #969a24",
|
|
||||||
".i c #b6b60c",
|
|
||||||
".j c #cac614",
|
|
||||||
".k c #cece34",
|
|
||||||
".l c #cace54",
|
|
||||||
".m c #caca94",
|
|
||||||
".n c #c24e4c",
|
|
||||||
".o c #aa0204",
|
|
||||||
".p c #9e4244",
|
|
||||||
".q c #bc0204",
|
|
||||||
".r c #a40204",
|
|
||||||
".s c #9e262c",
|
|
||||||
".t c #8c3a3c",
|
|
||||||
".u c #5c1414",
|
|
||||||
".v c #5b0204",
|
|
||||||
".w c #700204",
|
|
||||||
".x c #722214",
|
|
||||||
".y c #b52624",
|
|
||||||
".z c #8e3234",
|
|
||||||
".A c #b60204",
|
|
||||||
".B c #c20204",
|
|
||||||
".C c #860204",
|
|
||||||
".D c #560304",
|
|
||||||
".E c #800204",
|
|
||||||
".F c #9e0204",
|
|
||||||
".G c #920204",
|
|
||||||
".H c #620204",
|
|
||||||
".I c #a41314",
|
|
||||||
".J c #996a6c",
|
|
||||||
".K c #920d09",
|
|
||||||
".L c #c80204",
|
|
||||||
".M c #690204",
|
|
||||||
".N c #980204",
|
|
||||||
".O c #984c4c",
|
|
||||||
".P c #e2dedc",
|
|
||||||
".Q c #ae5e5c",
|
|
||||||
".R c #bc6a6c",
|
|
||||||
".S c #a21a1c",
|
|
||||||
".T c #8a0a04",
|
|
||||||
".U c #671e1c",
|
|
||||||
".V c #941b1c",
|
|
||||||
".W c #b8b4b4",
|
|
||||||
".X c #e8e6e4",
|
|
||||||
".Y c #ccb4b4",
|
|
||||||
".Z c #c07c7c",
|
|
||||||
".0 c #f3f2eb",
|
|
||||||
".1 c #b49696",
|
|
||||||
".2 c #521614",
|
|
||||||
".3 c #9e5a5c",
|
|
||||||
".4 c #d4d4d4",
|
|
||||||
".5 c #a7a5a1",
|
|
||||||
".6 c #dec4c4",
|
|
||||||
".7 c #e4d6d4",
|
|
||||||
".8 c #f4f2f4",
|
|
||||||
".9 c #cccac4",
|
|
||||||
"#. c #9a161c",
|
|
||||||
"## c #8c0204",
|
|
||||||
"#a c #862c2c",
|
|
||||||
"#b c #7e5e5c",
|
|
||||||
"#c c #a39694",
|
|
||||||
"#d c #6b6667",
|
|
||||||
"#e c #322624",
|
|
||||||
"#f c #b09e9c",
|
|
||||||
"#g c #b23234",
|
|
||||||
"#h c #500304",
|
|
||||||
"#i c #222224",
|
|
||||||
"#j c #2e322c",
|
|
||||||
"#k c #925c5c",
|
|
||||||
"#l c #721a1c",
|
|
||||||
"#m c #6e6e6c",
|
|
||||||
"#n c #0a0a0c",
|
|
||||||
"#o c #b2b2b4",
|
|
||||||
"#p c #8e6264",
|
|
||||||
"#q c #884444",
|
|
||||||
"#r c #8c5c5c",
|
|
||||||
"#s c #121214",
|
|
||||||
"#t c #b2aeac",
|
|
||||||
"#u c #c21e1c",
|
|
||||||
"#v c #6e0e0c",
|
|
||||||
"#w c #623e3c",
|
|
||||||
"#x c #b64e4c",
|
|
||||||
"#y c #bc3634",
|
|
||||||
"#z c #624e1c",
|
|
||||||
"#A c #6e727c",
|
|
||||||
"#B c #824e4c",
|
|
||||||
"#C c #8b8d87",
|
|
||||||
"#D c #a09674",
|
|
||||||
"#E c #766844",
|
|
||||||
"#F c #7a663c",
|
|
||||||
"#G c #828c90",
|
|
||||||
"#H c #beb6a4",
|
|
||||||
"#I c #3a0204",
|
|
||||||
"#J c #8e9298",
|
|
||||||
"#K c #562529",
|
|
||||||
"#L c #7c3838",
|
|
||||||
"#M c #bab294",
|
|
||||||
"#N c #7e4644",
|
|
||||||
"#O c #929a9c",
|
|
||||||
"#P c #762a2c",
|
|
||||||
"#Q c #a60e0c",
|
|
||||||
"#R c #ae1e1c",
|
|
||||||
"#S c #460a0c",
|
|
||||||
"#T c #a6aaa4",
|
|
||||||
"#U c #6a4a4c",
|
|
||||||
"#V c #784c50",
|
|
||||||
"#W c #761214",
|
|
||||||
"#X c #9e1e1c",
|
|
||||||
"#Y c #988c90",
|
|
||||||
"#Z c #821e1c",
|
|
||||||
"#0 c #7a1618",
|
|
||||||
"#1 c #7a6e74",
|
|
||||||
"#2 c #7e7a77",
|
|
||||||
"#3 c #808688",
|
|
||||||
"#4 c #828284",
|
|
||||||
"#5 c #828279",
|
|
||||||
"#6 c #827a64",
|
|
||||||
"#7 c #7e765c",
|
|
||||||
"#8 c #864a34",
|
|
||||||
"#9 c #825a44",
|
|
||||||
"a. c #766e54",
|
|
||||||
"a# c #7e7e74",
|
|
||||||
"aa c #806464",
|
|
||||||
"ab c #7e724c",
|
|
||||||
"ac c #766634",
|
|
||||||
"ad c #765a2c",
|
|
||||||
"ae c #8e7e54",
|
|
||||||
"af c #a69e8c",
|
|
||||||
"ag c #c7c2ac",
|
|
||||||
"ah c #9a2a1c",
|
|
||||||
"ai c #aa3a3c",
|
|
||||||
"aj c #979894",
|
|
||||||
"ak c #70684c",
|
|
||||||
"al c #62522c",
|
|
||||||
"am c #6e5e3c",
|
|
||||||
"an c #92866c",
|
|
||||||
"ao c #968e6c",
|
|
||||||
"ap c #826e54",
|
|
||||||
"aq c #84765c",
|
|
||||||
"ar c #86522c",
|
|
||||||
"as c #7e4624",
|
|
||||||
"at c #7e3614",
|
|
||||||
"au c #6e5254",
|
|
||||||
"av c #712e2c",
|
|
||||||
"aw c #7a5654",
|
|
||||||
"ax c #82727c",
|
|
||||||
"ay c #a63634",
|
|
||||||
"az c #8a6a6c",
|
|
||||||
"aA c #863534",
|
|
||||||
"aB c #5c1a18",
|
|
||||||
"aC c #6a2c2c",
|
|
||||||
"aD c #5e0e14",
|
|
||||||
"aE c #868684",
|
|
||||||
"aF c #922624",
|
|
||||||
"aG c #901614",
|
|
||||||
"aH c #c21614",
|
|
||||||
"aI c #520e0c",
|
|
||||||
"aJ c #805654",
|
|
||||||
"aK c #b00c0c",
|
|
||||||
"aL c #c2221c",
|
|
||||||
/* pixels */
|
|
||||||
"..........................................................................................",
|
|
||||||
"..........................................................................................",
|
|
||||||
".....................................#.a.#................................................",
|
|
||||||
"...................................#.b.c.#.#.#.#...........#.d............................",
|
|
||||||
".................................#.e.f.f.#.g.h.i.j.k.l.m...f.n............................",
|
|
||||||
".................................d.f.o.f.#.#.#.d.d.#.#.#...f.f.d..........................",
|
|
||||||
".................................p.q.q.r.s.t.u.v.w.x.d.d.#.d.r.y.d........................",
|
|
||||||
".................................z.A.B.q.C.D.E.F.G.E.H.E.I.F.q.A.d........................",
|
|
||||||
".................................J.G.f.G.w.K.f.L.B.B.r.M.f.B.L.A.d........................",
|
|
||||||
".................................d.w.N.M.O.P.Q.B.B.o.R.S.E.q.q.T.d........................",
|
|
||||||
".................................d.U.M.V.W.X.Y.q.B.Z.0.1.E.r.N.d..........................",
|
|
||||||
".................................d.2.r.3.4.5.6.A.f.7.8.9#.###a.#..........................",
|
|
||||||
"................................#b.d.L#c#d#e#f.N.V.5#d.4#g.E.d............................",
|
|
||||||
"...............................d#h.r.L#f#i#j#k.M#l#m#n#o.b.r.d............................",
|
|
||||||
"...............................d#h##.q#g#p#q##.q.N#r#s#t#u.q#v.#..........................",
|
|
||||||
"..............#j................#w.w.C.r.q##.r.B.f.T#x#y.L.r.M.d..........................",
|
|
||||||
"............#j#z#j#A#A#j.........d.D.r.M.C.f.r.r.r.q.B.C.N.E#B............................",
|
|
||||||
"..........#j#C#D#E#z#F#G#j.......d.d.#.G##.w.M.M.C.C.d.G.r.u.d............................",
|
|
||||||
"....................#E#H#C#j.........d#I.w.F.f.o.o.o.N.M.#.d..............................",
|
|
||||||
"......................#E#j#J#j......#K.M.#.#.v.w.M.v.##h.H#L.d............................",
|
|
||||||
"..........................#M#j.......v.F.q.r.d.w.w.C.E.M.v.M#N.d..........................",
|
|
||||||
"..........................#E#O#j#j#K##.f.L.L.L.B.q.f##.M.v.w.w#P.d.#...d.d................",
|
|
||||||
"............................#C#E.#.v.o.B.L.L.q.q.q.q.N.M.D#h.M.N.r#Q#R#S.H.J.#............",
|
|
||||||
"............................#j#T#U.C.q.q.o.G.F.f.q.A.N.d.v.v##.o.q.L.r.C.A###k............",
|
|
||||||
"..............................#C#V.N.A.N.f.q.F.C.E.f.F.E.H#n#W.K.I#X#a.z.V.q.d#p.d........",
|
|
||||||
"................................#Y.r.K#Z.K.q.A.G.w#0#b#1#2#3#4#5#5#6#6#7#8.q.G#9..........",
|
|
||||||
"..................#j#oa..5#j..#J#Ja##4#4aa.o.A##.E.xabacadae#Daf#M#Magah.r.qai.#..........",
|
|
||||||
"................aja#akalamanaoapaqaaarasat.r.o.E.w.T.T.E.H.#...........#.d.d.#............",
|
|
||||||
"...........E....#j#j#C#M#j#n#naa#V.O.f.N.F.q.G.d.w.r.C.d.H.#...............#..............",
|
|
||||||
"...........#.F.F.J#n#n#n#n#n#nauav#p.q.N.d.d.w.M.F.F.E.d.U................................",
|
|
||||||
".........E.F.E.E.d.z#n.d#n#n#naw.Uax.r##.d.w.D.M.r.N.E.w.d................................",
|
|
||||||
".........E.F.......d.Fay.E.F#naz.2#A.D#h.r.f.w##.r##.d.H.M................................",
|
|
||||||
".........F.#...........E.E.F.baAaB#A.#.E.f.r.w.N.N.E.waC.#................................",
|
|
||||||
".........F.#...............d.F.E#K#d.H.G.F.G.w.N##.d.D.#..................................",
|
|
||||||
".........F.#....................#Aau.v.E##.w.E.E.w.H.d.......d..av.d......................",
|
|
||||||
".........E.#..................#j#GaC.M.H.M.d.d.w.H.#.d.d.#aC.w.C##.E.d....................",
|
|
||||||
"...........F.................5#O...#aD.w.d.w.H.D.M######.G.F.o.f.o.N.3....................",
|
|
||||||
"...........F.E...........5aEakak.....#.##h#h.v.N.o.f.q.L.L.L.L.L.q.faF....................",
|
|
||||||
"...........E.E......#E#C.5aq#j.....#.v.N.F.d.N.r.F.r.F#Q.I.o.q.L.L.L.y....................",
|
|
||||||
".............E.....................#.E.B.qaG.d.d.d.....#.#.....d#x.b......................",
|
|
||||||
".............E.F...................E.w.L.LaG.#............................................",
|
|
||||||
"...............E.E.................EaA.q.qaG.#............................................",
|
|
||||||
"...............E.F.E.................E.r.r#Z.#............................................",
|
|
||||||
".................E.F.E...............E.G.NaA..............................................",
|
|
||||||
".................E#uaH.................w.dav..............................................",
|
|
||||||
"...................E.E.............EaI.M.w.v.#............................................",
|
|
||||||
"...................................E.D.d.E.waJ............................................",
|
|
||||||
".....................................C.N.N##.M............................................",
|
|
||||||
"..................................#W.f.q.A.f.G#q..........................................",
|
|
||||||
".....................................q.L.L.L.q.V.#........................................",
|
|
||||||
"...................................#.daK.q.qaL.d..........................................",
|
|
||||||
".......................................#.#.#..............................................",
|
|
||||||
"..........................................................................................",
|
|
||||||
"..........................................................................................",
|
|
||||||
".........................................................................................."
|
|
||||||
};
|
|
File diff suppressed because it is too large
Load diff
20
minilibx_macos/Makefile
Normal file
20
minilibx_macos/Makefile
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
NOM=libmlx.a
|
||||||
|
SRC= mlx_shaders.c mlx_new_window.m mlx_init_loop.m mlx_new_image.m mlx_xpm.c mlx_int_str_to_wordtab.c
|
||||||
|
OBJ1=$(SRC:.c=.o)
|
||||||
|
OBJ=$(OBJ1:.m=.o)
|
||||||
|
CFLAGS+=-O2
|
||||||
|
|
||||||
|
all: $(NOM)
|
||||||
|
|
||||||
|
$(NOM): $(OBJ)
|
||||||
|
ar -rc $(NOM) $(OBJ)
|
||||||
|
ranlib $(NOM)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(NOM) $(OBJ) *~
|
||||||
|
rm -f mlx_app
|
||||||
|
|
||||||
|
re: clean all
|
29
minilibx_macos/_README_
Normal file
29
minilibx_macos/_README_
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# 14/10/2015
|
||||||
|
# ol@staff.42.fr
|
||||||
|
#
|
||||||
|
|
||||||
|
MinilibX
|
||||||
|
|
||||||
|
Interface simplifiee de programmation graphique pour debutant
|
||||||
|
#
|
||||||
|
|
||||||
|
Cette minilibX est la version native pour MacOSX.
|
||||||
|
[ Elle n'utilise plus les librairies graphiques X11, ni XQuartz le serveur X pour MacOSX. ]
|
||||||
|
L'interface / l'API, reste identique a la version precedente. Les man presents dans la minilibX
|
||||||
|
d'origine sont toujours valides.
|
||||||
|
|
||||||
|
Le fichier mlx.h a inclure dans vos programmes rapelle les petites differences de comportement
|
||||||
|
entre les 2 versions, dues a la gestion graphique differente selon les systemes d'exploitation.
|
||||||
|
|
||||||
|
#
|
||||||
|
|
||||||
|
Cette version utilise le systeme de fenetrage Cocoa de MacOSX ( AppKit ), et les primitives
|
||||||
|
graphiques OpenGL moderne.
|
||||||
|
|
||||||
|
#
|
||||||
|
|
||||||
|
License: la MinilibX macos est fournie sous license BSD: Copyright Olivier Crouzet - 2014-2015
|
||||||
|
la MinilibX est fournie sous license BSD: Copyright Olivier Crouzet - 1999-2015
|
||||||
|
#
|
3525
minilibx_macos/font.c
Normal file
3525
minilibx_macos/font.c
Normal file
File diff suppressed because it is too large
Load diff
BIN
minilibx_macos/font.xcf
Normal file
BIN
minilibx_macos/font.xcf
Normal file
Binary file not shown.
|
@ -1,6 +1,6 @@
|
||||||
.TH MiniLibX 3 "September 19, 2002"
|
.TH MiniLibX 3 "September 19, 2002"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
MiniLibX - Simple X-Window Interface Library for students
|
MiniLibX - Simple Graphical Interface Library for students
|
||||||
.SH SYNOPSYS
|
.SH SYNOPSYS
|
||||||
#include <mlx.h>
|
#include <mlx.h>
|
||||||
|
|
||||||
|
@ -12,11 +12,11 @@ MiniLibX - Simple X-Window Interface Library for students
|
||||||
|
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
MiniLibX is an easy way to create graphical software,
|
MiniLibX is an easy way to create graphical software,
|
||||||
without any X-Window programming knowledge. It provides
|
without any X-Window/Cocoa programming knowledge. It provides
|
||||||
simple window creation, a drawing tool, image and basic events
|
simple window creation, a drawing tool, image and basic events
|
||||||
management.
|
management.
|
||||||
|
|
||||||
.SH X-WINDOW CONCEPT
|
.SH BSD/LINUX X-WINDOW CONCEPT
|
||||||
|
|
||||||
X-Window is a network-oriented graphical system for Unix.
|
X-Window is a network-oriented graphical system for Unix.
|
||||||
It is based on two main parts:
|
It is based on two main parts:
|
||||||
|
@ -31,6 +31,18 @@ A network connection must be established between these two entities to send
|
||||||
drawing orders (from the software to the X-Server), and keyboard/mouse
|
drawing orders (from the software to the X-Server), and keyboard/mouse
|
||||||
events (from the X-Server to the software).
|
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
|
.SH INCLUDE FILE
|
||||||
.B mlx.h
|
.B mlx.h
|
||||||
should be included for a correct use of the MiniLibX API.
|
should be included for a correct use of the MiniLibX API.
|
||||||
|
@ -41,7 +53,7 @@ It only contains function prototypes, no structure is needed.
|
||||||
First of all, you need to initialize the connection
|
First of all, you need to initialize the connection
|
||||||
between your software and the display.
|
between your software and the display.
|
||||||
Once this connection is established, you'll be able to
|
Once this connection is established, you'll be able to
|
||||||
use other MiniLibX functions to send the X-Server messages,
|
use other MiniLibX functions to send the graphical orders,
|
||||||
like "I want to draw a yellow pixel in this window" or "did the
|
like "I want to draw a yellow pixel in this window" or "did the
|
||||||
user hit a key?".
|
user hit a key?".
|
||||||
.P
|
.P
|
||||||
|
@ -67,7 +79,7 @@ All other MiniLibX functions are described in the following man pages:
|
||||||
.B mlx_loop
|
.B mlx_loop
|
||||||
: handle keyboard or mouse events
|
: handle keyboard or mouse events
|
||||||
|
|
||||||
.SH LINKING MiniLibX
|
.SH LINKING MiniLibX on BSD/Linux and X-Window
|
||||||
To use MiniLibX functions, you'll need to link
|
To use MiniLibX functions, you'll need to link
|
||||||
your software with several libraries, including the MiniLibX library itself.
|
your software with several libraries, including the MiniLibX library itself.
|
||||||
To do this, simply add the following arguments at linking time:
|
To do this, simply add the following arguments at linking time:
|
||||||
|
@ -79,15 +91,25 @@ the
|
||||||
.B -L
|
.B -L
|
||||||
flag.
|
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
|
.SH RETURN VALUES
|
||||||
If
|
If
|
||||||
.B mlx_init()
|
.B mlx_init()
|
||||||
fails to set up the connection to the X server, it will return NULL, otherwise
|
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.
|
a non-null pointer is returned as a connection identifier.
|
||||||
|
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3)
|
mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3)
|
||||||
|
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
Copyright ol@ - 2002-2015 - Olivier Crouzet
|
|
@ -43,9 +43,10 @@ MiniLibX - Handle events
|
||||||
.I void *mlx_ptr, int (*funct_ptr)(), void *param
|
.I void *mlx_ptr, int (*funct_ptr)(), void *param
|
||||||
);
|
);
|
||||||
|
|
||||||
.SH X-WINDOW EVENTS
|
.SH EVENTS
|
||||||
|
|
||||||
The X-Window system is bi-directionnal. On one hand, the program sends orders to
|
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,
|
the screen to display pixels, images, and so on. On the other hand,
|
||||||
it can get information from the keyboard and mouse associated to
|
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
|
the screen. To do so, the program receives "events" from the keyboard or the
|
||||||
|
@ -114,7 +115,8 @@ 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
|
used nor modified by the MiniLibX. On key and mouse events, additional
|
||||||
information is passed:
|
information is passed:
|
||||||
.I keycode
|
.I keycode
|
||||||
tells you which key is pressed (look for the X11 include file "keysymdef.h"),
|
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 x
|
||||||
,
|
,
|
||||||
|
@ -124,12 +126,12 @@ tells you which key is pressed (look for the X11 include file "keysymdef.h"),
|
||||||
tells you which mouse button was pressed.
|
tells you which mouse button was pressed.
|
||||||
|
|
||||||
.SH GOING FURTHER WITH EVENTS
|
.SH GOING FURTHER WITH EVENTS
|
||||||
The MiniLibX provides a much generic access to all X-Window events. The
|
The MiniLibX provides a much generic access to all type of events. The
|
||||||
.I mlx.h
|
.I mlx.h
|
||||||
include define
|
include define
|
||||||
.B mlx_hook()
|
.B mlx_hook()
|
||||||
in the same manner mlx_*_hook functions work. The event and mask values
|
in the same manner mlx_*_hook functions work. The event and mask values
|
||||||
will be taken from the X11 include file "X.h".
|
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
|
See source code of mlx_int_param_event.c to find out how the MiniLibX will
|
||||||
call your own function for a specific event.
|
call your own function for a specific event.
|
||||||
|
@ -138,4 +140,4 @@ call your own function for a specific event.
|
||||||
mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3)
|
mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3)
|
||||||
|
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
Copyright ol@ - 2002-2015 - Olivier Crouzet
|
|
@ -141,7 +141,7 @@ one byte for each component (see
|
||||||
.B mlx_pixel_put
|
.B mlx_pixel_put
|
||||||
manual). This must be translated to fit the
|
manual). This must be translated to fit the
|
||||||
.I bits_per_pixel
|
.I bits_per_pixel
|
||||||
requirement of the image, and make the color understandable to the X-Server.
|
requirement of the image, and make the color understandable to the graphical system.
|
||||||
That is the purpose of the
|
That is the purpose of the
|
||||||
.B mlx_get_color_value
|
.B mlx_get_color_value
|
||||||
() function. It takes a standard RGB
|
() function. It takes a standard RGB
|
||||||
|
@ -155,7 +155,7 @@ 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
|
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
|
computer's endian. If the endian of the image (in fact the endian of
|
||||||
the X-Server's computer) differs from the local endian, then the value should
|
the X-Server's computer for remote X11 display) differs from the local endian, then the value should
|
||||||
be transformed before being used.
|
be transformed before being used.
|
||||||
|
|
||||||
.SH XPM IMAGES
|
.SH XPM IMAGES
|
||||||
|
@ -189,4 +189,4 @@ as an image identifier.
|
||||||
mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_loop(3)
|
mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_loop(3)
|
||||||
|
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
Copyright ol@ - 2002-2015 - Olivier Crouzet
|
|
@ -76,4 +76,4 @@ right now return nothing.
|
||||||
mlx(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3)
|
mlx(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3)
|
||||||
|
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
Copyright ol@ - 2002-2015 - Olivier Crouzet
|
|
@ -78,4 +78,4 @@ mlx(3), mlx_new_window(3), mlx_new_image(3), mlx_loop(3)
|
||||||
|
|
||||||
|
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
Copyright ol@ - 2002-2015 - Olivier Crouzet
|
|
@ -2,10 +2,10 @@
|
||||||
** mlx.h for MinilibX in
|
** mlx.h for MinilibX in
|
||||||
**
|
**
|
||||||
** Made by Charlie Root
|
** Made by Charlie Root
|
||||||
** Login <ol@epitech.net>
|
** Login <ol@staff.42.fr>
|
||||||
**
|
**
|
||||||
** Started on Mon Jul 31 16:37:50 2000 Charlie Root
|
** Started on Mon Jul 31 16:37:50 2000 Charlie Root
|
||||||
** Last update Tue May 15 16:23:28 2007 Olivier Crouzet
|
** Last update Tue Oct 01 16:23:28 2014 Olivier Crouzet
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -16,14 +16,29 @@
|
||||||
/*
|
/*
|
||||||
** FR msg - FR msg - FR msg
|
** FR msg - FR msg - FR msg
|
||||||
**
|
**
|
||||||
|
** MacOSX
|
||||||
|
** La MinilibX utilise 2 frameworks Mac : OpenGL et AppKit
|
||||||
|
** qu'il faut ajouter a la compilation :
|
||||||
|
** -framework OpenGL -framework AppKit
|
||||||
|
**
|
||||||
|
** UNIX / Linux
|
||||||
** La MinilibX utilise 2 librairies supplementaires qu'il
|
** La MinilibX utilise 2 librairies supplementaires qu'il
|
||||||
** est necessaire de rajouter a la compilation :
|
** est necessaire de rajouter a la compilation :
|
||||||
** -lmlx -lXext -lX11
|
** -lmlx -lXext -lX11
|
||||||
**
|
**
|
||||||
** La MinilibX permet le chargement des images de type Xpm.
|
** La MinilibX permet le chargement des images de type Xpm.
|
||||||
** Notez que cette implementation est incomplete.
|
** Notez que cette implementation est incomplete.
|
||||||
** Merci de communiquer tout probleme de chargement d'image
|
**
|
||||||
** de ce type.
|
** Il y a des differences entre X11 et MacOS.
|
||||||
|
** les numeros des touches ne sont pas les memes,
|
||||||
|
** les numeros des boutons souris ne sont pas les memes.
|
||||||
|
** Egalement l'expose est gere differemment, et sous MacOS
|
||||||
|
** il est preferable d'entrer le plus tot possible dans mlx_loop,
|
||||||
|
** il est normal que les fenetres n'apparaissent pas avant mlx_loop
|
||||||
|
** (ou bien forcez avec mlx_do_sync mais c'est pas genial).
|
||||||
|
** Sous MacOS, l'octet Alpha est pris en compte dans toutes les
|
||||||
|
** images, et represente la transparence et non l'opacite comme
|
||||||
|
** c'est normalement le cas.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,14 +78,12 @@ int mlx_pixel_put(void *mlx_ptr, void *win_ptr, int x, int y, int color);
|
||||||
void *mlx_new_image(void *mlx_ptr,int width,int height);
|
void *mlx_new_image(void *mlx_ptr,int width,int height);
|
||||||
/*
|
/*
|
||||||
** return void *0 if failed
|
** return void *0 if failed
|
||||||
** obsolete : image2 data is stored using bit planes
|
|
||||||
** void *mlx_new_image2(void *mlx_ptr,int width,int height);
|
|
||||||
*/
|
*/
|
||||||
char *mlx_get_data_addr(void *img_ptr, int *bits_per_pixel,
|
char *mlx_get_data_addr(void *img_ptr, int *bits_per_pixel,
|
||||||
int *size_line, int *endian);
|
int *size_line, int *endian);
|
||||||
/*
|
/*
|
||||||
** endian : 0 = sever X is little endian, 1 = big endian
|
** endian : 0 = sever X is little endian, 1 = big endian
|
||||||
** for mlx_new_image2, 2nd arg of mlx_get_data_addr is number_of_planes
|
** endian : useless on macos, client and graphical framework have the same endian
|
||||||
*/
|
*/
|
||||||
int mlx_put_image_to_window(void *mlx_ptr, void *win_ptr, void *img_ptr,
|
int mlx_put_image_to_window(void *mlx_ptr, void *win_ptr, void *img_ptr,
|
||||||
int x, int y);
|
int x, int y);
|
184
minilibx_macos/mlx_init_loop.m
Normal file
184
minilibx_macos/mlx_init_loop.m
Normal file
|
@ -0,0 +1,184 @@
|
||||||
|
// mlx_init_loop.m
|
||||||
|
// By Ol
|
||||||
|
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
#import <OpenGL/gl3.h>
|
||||||
|
#import <AppKit/NSOpenGLView.h>
|
||||||
|
|
||||||
|
#include "mlx_int.h"
|
||||||
|
#include "mlx_new_window.h"
|
||||||
|
|
||||||
|
#include "font.c"
|
||||||
|
|
||||||
|
|
||||||
|
void do_loop_hook2(CFRunLoopTimerRef observer, void * info)
|
||||||
|
{
|
||||||
|
((mlx_ptr_t *)info)->loop_hook(((mlx_ptr_t *)info)->loop_hook_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void do_loop_flush(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void * info)
|
||||||
|
{
|
||||||
|
mlx_ptr_t *mlx_ptr;
|
||||||
|
mlx_win_list_t *win;
|
||||||
|
|
||||||
|
mlx_ptr = (mlx_ptr_t *)info;
|
||||||
|
win = mlx_ptr->win_list;
|
||||||
|
while (win)
|
||||||
|
{
|
||||||
|
if (win->nb_flush > 0 && win->pixmgt)
|
||||||
|
{
|
||||||
|
[(id)win->winid selectGLContext];
|
||||||
|
[(id)win->winid mlx_gl_draw];
|
||||||
|
glFlush();
|
||||||
|
win->nb_flush = 0;
|
||||||
|
}
|
||||||
|
win = win->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void *mlx_init()
|
||||||
|
{
|
||||||
|
mlx_ptr_t *new_mlx;
|
||||||
|
int bidon;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if ((new_mlx = malloc(sizeof(*new_mlx))) == NULL)
|
||||||
|
return ((void *)0);
|
||||||
|
new_mlx->win_list = NULL;
|
||||||
|
new_mlx->img_list = NULL;
|
||||||
|
new_mlx->loop_hook = NULL;
|
||||||
|
new_mlx->loop_hook_data = NULL;
|
||||||
|
new_mlx->main_loop_active = 0;
|
||||||
|
|
||||||
|
new_mlx->appid = [NSApplication sharedApplication];
|
||||||
|
|
||||||
|
// super magic trick to detach app from terminal, get menubar & key input events
|
||||||
|
for (NSRunningApplication * app in [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.finder"])
|
||||||
|
{
|
||||||
|
[app activateWithOptions:NSApplicationActivateIgnoringOtherApps];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
usleep(100000);
|
||||||
|
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
||||||
|
(void) TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||||
|
usleep(100000);
|
||||||
|
[[NSRunningApplication currentApplication] activateWithOptions:NSApplicationActivateIgnoringOtherApps];
|
||||||
|
|
||||||
|
// load font
|
||||||
|
new_mlx->font = mlx_new_image(new_mlx, (FONT_WIDTH+2)*95, FONT_HEIGHT);
|
||||||
|
i = 0;
|
||||||
|
while (i < 4*(FONT_WIDTH+2)*95*FONT_HEIGHT)
|
||||||
|
{
|
||||||
|
new_mlx->font->buffer[i+0] = font_atlas.pixel_data[i+2];
|
||||||
|
new_mlx->font->buffer[i+1] = font_atlas.pixel_data[i+1];
|
||||||
|
new_mlx->font->buffer[i+2] = font_atlas.pixel_data[i+0];
|
||||||
|
((unsigned char *)new_mlx->font->buffer)[i+3] = 0xFF-font_atlas.pixel_data[i+3];
|
||||||
|
i += 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
new_mlx->font->vertexes[2] = FONT_WIDTH;
|
||||||
|
new_mlx->font->vertexes[4] = FONT_WIDTH;
|
||||||
|
new_mlx->font->vertexes[5] = -FONT_HEIGHT-1;
|
||||||
|
new_mlx->font->vertexes[7] = -FONT_HEIGHT-1;
|
||||||
|
|
||||||
|
return ((void *)new_mlx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void mlx_loop(mlx_ptr_t *mlx_ptr)
|
||||||
|
{
|
||||||
|
CFRunLoopObserverRef observer;
|
||||||
|
CFRunLoopObserverContext ocontext = {.version = 0, .info = mlx_ptr, .retain = NULL, .release = NULL, .copyDescription = NULL};
|
||||||
|
|
||||||
|
mlx_ptr->main_loop_active = 1;
|
||||||
|
|
||||||
|
observer = CFRunLoopObserverCreate(NULL, kCFRunLoopBeforeTimers, true, 0, do_loop_flush, &ocontext);
|
||||||
|
CFRunLoopAddObserver(CFRunLoopGetMain(), observer, kCFRunLoopCommonModes);
|
||||||
|
|
||||||
|
// [[[MlxLoopHookObj alloc] initWithPtr:mlx_ptr] performSelector:@selector(do_loop_hook) withObject:nil afterDelay:0.0];
|
||||||
|
|
||||||
|
[NSApp run];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void mlx_pixel_put(mlx_ptr_t *mlx_ptr, mlx_win_list_t *win_ptr, int x, int y, int color)
|
||||||
|
{
|
||||||
|
if (!win_ptr->pixmgt)
|
||||||
|
return ;
|
||||||
|
[(id)(win_ptr->winid) selectGLContext];
|
||||||
|
[(id)(win_ptr->winid) pixelPutColor:color X:x Y:y];
|
||||||
|
win_ptr->nb_flush ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void mlx_int_loop_once()
|
||||||
|
{
|
||||||
|
NSEvent *event;
|
||||||
|
NSDate *thedate;
|
||||||
|
|
||||||
|
thedate = [NSDate dateWithTimeIntervalSinceNow:0.1];
|
||||||
|
while (42)
|
||||||
|
{
|
||||||
|
event = [NSApp nextEventMatchingMask:NSAnyEventMask
|
||||||
|
untilDate:thedate
|
||||||
|
inMode:NSDefaultRunLoopMode
|
||||||
|
dequeue:YES];
|
||||||
|
if (event == nil)
|
||||||
|
{
|
||||||
|
[thedate release];
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
[NSApp sendEvent:event];
|
||||||
|
[NSApp updateWindows];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mlx_do_sync(mlx_ptr_t *mlx_ptr)
|
||||||
|
{
|
||||||
|
mlx_win_list_t *win;
|
||||||
|
|
||||||
|
win = mlx_ptr->win_list;
|
||||||
|
while (win)
|
||||||
|
{
|
||||||
|
if (win->pixmgt)
|
||||||
|
{
|
||||||
|
[(id)(win->winid) selectGLContext];
|
||||||
|
[(id)(win->winid) mlx_gl_draw];
|
||||||
|
glFlush();
|
||||||
|
if (!mlx_ptr->main_loop_active)
|
||||||
|
mlx_int_loop_once();
|
||||||
|
}
|
||||||
|
win = win->next;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mlx_loop_hook(mlx_ptr_t *mlx_ptr, void (*fct)(void *), void *param)
|
||||||
|
{
|
||||||
|
CFRunLoopTimerContext tcontext = {0, mlx_ptr, NULL, NULL, NULL};
|
||||||
|
CFRunLoopTimerRef timer;
|
||||||
|
|
||||||
|
if (mlx_ptr->loop_hook != NULL)
|
||||||
|
{
|
||||||
|
CFRunLoopTimerInvalidate(mlx_ptr->loop_timer);
|
||||||
|
[(id)(mlx_ptr->loop_timer) release];
|
||||||
|
}
|
||||||
|
|
||||||
|
mlx_ptr->loop_hook = fct;
|
||||||
|
mlx_ptr->loop_hook_data = param;
|
||||||
|
|
||||||
|
if (fct)
|
||||||
|
{
|
||||||
|
timer = CFRunLoopTimerCreate(kCFAllocatorDefault, 0.0, 0.0001, 0, 0, &do_loop_hook2, &tcontext);
|
||||||
|
mlx_ptr->loop_timer = timer;
|
||||||
|
CFRunLoopAddTimer(CFRunLoopGetMain(), timer, kCFRunLoopCommonModes);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
102
minilibx_macos/mlx_int.h
Normal file
102
minilibx_macos/mlx_int.h
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
//
|
||||||
|
// mlx_int.h for minilibx
|
||||||
|
//
|
||||||
|
// ol@staff.42.fr
|
||||||
|
//
|
||||||
|
// include opengl needed before mlx_int.h
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
#define MAX_EVENT 32
|
||||||
|
#define MAX_PIXEL_NB 200000
|
||||||
|
#define UNIQ_BPP 4
|
||||||
|
|
||||||
|
#define FONT_WIDTH 10
|
||||||
|
#define FONT_HEIGHT 20
|
||||||
|
|
||||||
|
|
||||||
|
typedef int (*func_t)();
|
||||||
|
|
||||||
|
/* structs */
|
||||||
|
|
||||||
|
typedef struct glsl_info_s
|
||||||
|
{
|
||||||
|
GLuint pixel_vshader;
|
||||||
|
GLuint pixel_fshader;
|
||||||
|
GLuint pixel_program;
|
||||||
|
GLint loc_pixel_position;
|
||||||
|
GLint loc_pixel_texture;
|
||||||
|
GLint loc_pixel_winhalfsize;
|
||||||
|
|
||||||
|
GLuint image_vshader;
|
||||||
|
GLuint image_fshader;
|
||||||
|
GLuint image_program;
|
||||||
|
GLint loc_image_position;
|
||||||
|
GLint loc_image_winhalfsize;
|
||||||
|
GLint loc_image_texture;
|
||||||
|
GLint loc_image_pos;
|
||||||
|
GLint loc_image_size;
|
||||||
|
|
||||||
|
GLuint font_vshader;
|
||||||
|
GLuint font_fshader;
|
||||||
|
GLuint font_program;
|
||||||
|
GLint loc_font_position;
|
||||||
|
GLint loc_font_winhalfsize;
|
||||||
|
GLint loc_font_texture;
|
||||||
|
GLint loc_font_color;
|
||||||
|
GLint loc_font_posinwin;
|
||||||
|
GLint loc_font_posinatlas;
|
||||||
|
GLint loc_font_atlassize;
|
||||||
|
} glsl_info_t;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct mlx_img_list_s
|
||||||
|
{
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
char *buffer;
|
||||||
|
GLfloat vertexes[8];
|
||||||
|
struct mlx_img_list_s *next;
|
||||||
|
} mlx_img_list_t;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct mlx_img_ctx_s
|
||||||
|
{
|
||||||
|
GLuint texture;
|
||||||
|
GLuint vbuffer;
|
||||||
|
mlx_img_list_t *img;
|
||||||
|
struct mlx_img_ctx_s *next;
|
||||||
|
} mlx_img_ctx_t;
|
||||||
|
|
||||||
|
typedef struct mlx_win_list_s
|
||||||
|
{
|
||||||
|
void *winid;
|
||||||
|
mlx_img_ctx_t *img_list;
|
||||||
|
int nb_flush;
|
||||||
|
int pixmgt;
|
||||||
|
struct mlx_win_list_s *next;
|
||||||
|
} mlx_win_list_t;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct mlx_ptr_s
|
||||||
|
{
|
||||||
|
void *appid;
|
||||||
|
mlx_win_list_t *win_list;
|
||||||
|
mlx_img_list_t *img_list;
|
||||||
|
void (*loop_hook)(void *);
|
||||||
|
void *loop_hook_data;
|
||||||
|
void *loop_timer;
|
||||||
|
mlx_img_list_t *font;
|
||||||
|
int main_loop_active;
|
||||||
|
} mlx_ptr_t;
|
||||||
|
|
||||||
|
// proto
|
||||||
|
|
||||||
|
int mlx_shaders(glsl_info_t *glsl);
|
||||||
|
char **mlx_int_str_to_wordtab(char *str);
|
||||||
|
int mlx_int_str_str(char *str,char *find,int len);
|
||||||
|
int mlx_int_str_str_cote(char *str,char *find,int len);
|
||||||
|
int mlx_destroy_image(mlx_ptr_t *mlx_ptr, mlx_img_list_t *img_ptr);
|
||||||
|
void *mlx_new_image();
|
||||||
|
void *mlx_xpm_to_image(mlx_ptr_t *xvar,char **xpm_data,int *width,int *height);
|
||||||
|
int mlx_do_sync(mlx_ptr_t *mlx_ptr);
|
|
@ -1,16 +1,10 @@
|
||||||
/*
|
//
|
||||||
** mlx_int_str_to_wordtab.c for MinilibX in
|
// str 2 wordtab & co
|
||||||
**
|
// by ol
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Wed Sep 13 11:36:09 2000 Charlie Root
|
|
||||||
** Last update Fri Dec 14 11:02:09 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
int mlx_int_str_str(char *str,char *find,int len)
|
int mlx_int_str_str(char *str,char *find,int len)
|
||||||
{
|
{
|
190
minilibx_macos/mlx_new_image.m
Normal file
190
minilibx_macos/mlx_new_image.m
Normal file
|
@ -0,0 +1,190 @@
|
||||||
|
// mlx_new_image
|
||||||
|
//
|
||||||
|
// by Ol
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
#import <OpenGL/gl3.h>
|
||||||
|
|
||||||
|
#include "mlx_int.h"
|
||||||
|
#include "mlx_new_window.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void *mlx_new_image(mlx_ptr_t *mlx_ptr, int width, int height)
|
||||||
|
{
|
||||||
|
mlx_img_list_t *newimg;
|
||||||
|
|
||||||
|
// if (mlx_ptr->win_list == NULL)
|
||||||
|
// return (NULL); // need at leat one window created to have openGL context and create texture
|
||||||
|
if ((newimg = malloc(sizeof(*newimg))) == NULL)
|
||||||
|
return ((void *)0);
|
||||||
|
newimg->next = mlx_ptr->img_list;
|
||||||
|
mlx_ptr->img_list = newimg;
|
||||||
|
newimg->width = width;
|
||||||
|
newimg->height = height;
|
||||||
|
newimg->vertexes[0] = 0.0; newimg->vertexes[1] = 0.0;
|
||||||
|
newimg->vertexes[2] = width; newimg->vertexes[3] = 0.0;
|
||||||
|
newimg->vertexes[4] = width; newimg->vertexes[5] = -height;
|
||||||
|
newimg->vertexes[6] = 0.0; newimg->vertexes[7] = -height;
|
||||||
|
newimg->buffer = malloc(UNIQ_BPP*width*height);
|
||||||
|
bzero(newimg->buffer, UNIQ_BPP*width*height);
|
||||||
|
|
||||||
|
return (newimg);
|
||||||
|
}
|
||||||
|
|
||||||
|
mlx_img_ctx_t *add_img_to_ctx(mlx_img_list_t *img, mlx_win_list_t *win)
|
||||||
|
{
|
||||||
|
mlx_img_ctx_t *imgctx;
|
||||||
|
|
||||||
|
imgctx = win->img_list;
|
||||||
|
while (imgctx)
|
||||||
|
{
|
||||||
|
if (imgctx->img == img)
|
||||||
|
return (imgctx);
|
||||||
|
imgctx = imgctx->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
imgctx = malloc(sizeof(*imgctx));
|
||||||
|
imgctx->img = img;
|
||||||
|
imgctx->next = win->img_list;
|
||||||
|
win->img_list = imgctx;
|
||||||
|
|
||||||
|
glGenTextures(1, &(imgctx->texture));
|
||||||
|
glBindTexture(GL_TEXTURE_2D, imgctx->texture);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexImage2D(
|
||||||
|
GL_TEXTURE_2D, 0, /* target, level of detail */
|
||||||
|
GL_RGBA8, /* internal format */
|
||||||
|
img->width, img->height, 0, /* width, height, border */
|
||||||
|
GL_BGRA, GL_UNSIGNED_BYTE, /* external format, type */
|
||||||
|
img->buffer /* pixels */
|
||||||
|
);
|
||||||
|
|
||||||
|
glGenBuffers(1, &(imgctx->vbuffer));
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, imgctx->vbuffer);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(img->vertexes), img->vertexes, GL_DYNAMIC_DRAW); // 4 points buff
|
||||||
|
|
||||||
|
return (imgctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void mlx_put_image_to_window(mlx_ptr_t *mlx_ptr, mlx_win_list_t *win_ptr, mlx_img_list_t *img_ptr, int x, int y)
|
||||||
|
{
|
||||||
|
mlx_img_ctx_t *imgctx;
|
||||||
|
|
||||||
|
if (!win_ptr->pixmgt)
|
||||||
|
return ;
|
||||||
|
|
||||||
|
[(id)(win_ptr->winid) selectGLContext];
|
||||||
|
imgctx = add_img_to_ctx(img_ptr, win_ptr);
|
||||||
|
|
||||||
|
// update texture
|
||||||
|
glBindTexture(GL_TEXTURE_2D, imgctx->texture);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, img_ptr->width, img_ptr->height, 0,
|
||||||
|
GL_BGRA, GL_UNSIGNED_BYTE, img_ptr->buffer);
|
||||||
|
|
||||||
|
[(id)(win_ptr->winid) mlx_gl_draw_img:img_ptr andCtx:imgctx andX:x andY:y];
|
||||||
|
|
||||||
|
win_ptr->nb_flush ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// assume here 32bpp little endian
|
||||||
|
|
||||||
|
char *mlx_get_data_addr(mlx_img_list_t *img_ptr, int *bits_per_pixel, int *size_line, int *endian)
|
||||||
|
{
|
||||||
|
*bits_per_pixel = UNIQ_BPP*8;
|
||||||
|
*size_line = img_ptr->width*UNIQ_BPP;
|
||||||
|
*endian = 0; // little endian for now on mac-intel
|
||||||
|
return (img_ptr->buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int mlx_get_color_value(mlx_ptr_t *mlx_ptr, int color)
|
||||||
|
{
|
||||||
|
return (color);
|
||||||
|
}
|
||||||
|
|
||||||
|
int mlx_string_put(mlx_ptr_t *mlx_ptr, mlx_win_list_t *win_ptr, int x, int y, int color, unsigned char *string)
|
||||||
|
{
|
||||||
|
mlx_img_ctx_t *imgctx;
|
||||||
|
int gX;
|
||||||
|
int gY;
|
||||||
|
|
||||||
|
if (!win_ptr->pixmgt)
|
||||||
|
return(0);
|
||||||
|
|
||||||
|
[(id)(win_ptr->winid) selectGLContext];
|
||||||
|
|
||||||
|
imgctx = add_img_to_ctx(mlx_ptr->font, win_ptr);
|
||||||
|
|
||||||
|
while (*string)
|
||||||
|
{
|
||||||
|
if (*string >= 32 && *string <= 127)
|
||||||
|
{
|
||||||
|
gX = (FONT_WIDTH+2)*(*string-32);
|
||||||
|
gY = 0;
|
||||||
|
// printf("put char %c pos %d %d\n", *string, gX, gY);
|
||||||
|
[(id)(win_ptr->winid) mlx_gl_draw_font:mlx_ptr->font andCtx:imgctx andX:x andY:y andColor:color glyphX:gX glyphY:gY];
|
||||||
|
x += FONT_WIDTH;
|
||||||
|
}
|
||||||
|
string ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
win_ptr->nb_flush ++;
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int mlx_destroy_image(mlx_ptr_t *mlx_ptr, mlx_img_list_t *img_todel)
|
||||||
|
{
|
||||||
|
mlx_img_ctx_t ctx_first;
|
||||||
|
mlx_img_ctx_t *ctx;
|
||||||
|
mlx_img_ctx_t *ctx_to_del;
|
||||||
|
mlx_img_list_t img_first;
|
||||||
|
mlx_img_list_t *img;
|
||||||
|
mlx_win_list_t *win;
|
||||||
|
|
||||||
|
img_first.next = mlx_ptr->img_list;
|
||||||
|
img = &img_first;
|
||||||
|
while (img && img->next)
|
||||||
|
{
|
||||||
|
if (img->next == img_todel)
|
||||||
|
img->next = img->next->next;
|
||||||
|
img = img->next;
|
||||||
|
}
|
||||||
|
mlx_ptr->img_list = img_first.next;
|
||||||
|
|
||||||
|
|
||||||
|
win = mlx_ptr->win_list;
|
||||||
|
while (win)
|
||||||
|
{
|
||||||
|
ctx_first.next = win->img_list;
|
||||||
|
ctx = &ctx_first;
|
||||||
|
while (ctx && ctx->next)
|
||||||
|
{
|
||||||
|
if (ctx->next->img == img_todel)
|
||||||
|
{
|
||||||
|
[(id)(win->winid) selectGLContext];
|
||||||
|
glDeleteBuffers(1, &(ctx->next->vbuffer));
|
||||||
|
glDeleteTextures(1, &(ctx->next->texture));
|
||||||
|
ctx_to_del = ctx->next;
|
||||||
|
ctx->next = ctx->next->next;
|
||||||
|
free(ctx_to_del);
|
||||||
|
}
|
||||||
|
ctx = ctx->next;
|
||||||
|
}
|
||||||
|
win->img_list = ctx_first.next;
|
||||||
|
win = win->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
free(img_todel->buffer);
|
||||||
|
free(img_todel);
|
||||||
|
|
||||||
|
// printf("destroy image done.\n");
|
||||||
|
return (0);
|
||||||
|
}
|
56
minilibx_macos/mlx_new_window.h
Normal file
56
minilibx_macos/mlx_new_window.h
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
//
|
||||||
|
// mlx_int.h for minilibx
|
||||||
|
//
|
||||||
|
// ol@staff.42.fr
|
||||||
|
//
|
||||||
|
// include opengl needed before mlx_int.h
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
#import "mlx_int.h"
|
||||||
|
|
||||||
|
@interface NSWindowEvent : NSWindow
|
||||||
|
{
|
||||||
|
func_t event_funct[MAX_EVENT];
|
||||||
|
void *(event_param[MAX_EVENT]);
|
||||||
|
int keyrepeat;
|
||||||
|
int keyflag;
|
||||||
|
int size_x;
|
||||||
|
int size_y;
|
||||||
|
}
|
||||||
|
- (NSWindowEvent *) initWithContentRect:(NSRect)rect styleMask:(NSUInteger)winstyle backing:(NSBackingStoreType)bck defer:(BOOL) dfr;
|
||||||
|
- (void) setEvent:(int)event andFunc:(func_t)func andParam:(void *)param;
|
||||||
|
- (void) setKeyRepeat:(int)mode;
|
||||||
|
- (void) exposeNotification:(NSNotification *)note;
|
||||||
|
- (void) closeNotification:(NSNotification *)note;
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@interface MlxWin : NSOpenGLView
|
||||||
|
{
|
||||||
|
NSWindowEvent *win;
|
||||||
|
NSOpenGLContext *ctx;
|
||||||
|
glsl_info_t glsl;
|
||||||
|
int openglwin;
|
||||||
|
|
||||||
|
int size_x;
|
||||||
|
int size_y;
|
||||||
|
|
||||||
|
int pixel_nb;
|
||||||
|
GLuint pixel_vbuffer;
|
||||||
|
GLuint pixel_texture;
|
||||||
|
unsigned int *pixtexbuff;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id) initWithRect: (NSRect)rect andTitle: (NSString *)title pfaAttrs: (NSOpenGLPixelFormatAttribute *)attrs;
|
||||||
|
- (void) selectGLContext;
|
||||||
|
- (void) flushGLContext;
|
||||||
|
- (void) pixelPutColor: (int)color X:(int)x Y:(int)y;
|
||||||
|
- (void) mlx_gl_draw;
|
||||||
|
- (void) mlx_gl_draw_img:(mlx_img_list_t *)img andCtx:(mlx_img_ctx_t *)imgctx andX:(int)x andY:(int)y;
|
||||||
|
- (void) mlx_gl_draw_font:(mlx_img_list_t *)img andCtx:(mlx_img_ctx_t *)imgctx andX:(int)x andY:(int)y andColor:(int)color glyphX:(int)gx glyphY:(int)gy;
|
||||||
|
- (NSOpenGLContext *) ctx;
|
||||||
|
- (void) setEvent:(int)event andFunc:(func_t)func andParam:(void *)param;
|
||||||
|
- (void) setKeyRepeat:(int)mode;
|
||||||
|
- (void) ctxNeedsUpdate;
|
||||||
|
@end
|
760
minilibx_macos/mlx_new_window.m
Normal file
760
minilibx_macos/mlx_new_window.m
Normal file
|
@ -0,0 +1,760 @@
|
||||||
|
// mlx_new_window.m
|
||||||
|
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
#import <OpenGL/gl3.h>
|
||||||
|
#import <AppKit/NSOpenGLView.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "mlx_int.h"
|
||||||
|
#include "mlx_new_window.h"
|
||||||
|
|
||||||
|
|
||||||
|
NSOpenGLPixelFormatAttribute pfa_attrs[] =
|
||||||
|
{
|
||||||
|
NSOpenGLPFADepthSize, 32,
|
||||||
|
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersionLegacy,
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
static const GLfloat pixel_vertexes[8] =
|
||||||
|
{
|
||||||
|
-1.0 , -1.0,
|
||||||
|
1.0, -1.0,
|
||||||
|
1.0, 1.0,
|
||||||
|
-1.0, 1.0
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int get_mouse_button(NSEventType eventtype)
|
||||||
|
{
|
||||||
|
switch (eventtype) {
|
||||||
|
case NSLeftMouseDown:
|
||||||
|
case NSLeftMouseUp:
|
||||||
|
case NSLeftMouseDragged:
|
||||||
|
return 1;
|
||||||
|
case NSRightMouseDown:
|
||||||
|
case NSRightMouseUp:
|
||||||
|
case NSRightMouseDragged:
|
||||||
|
return 2;
|
||||||
|
case NSOtherMouseDown:
|
||||||
|
case NSOtherMouseUp:
|
||||||
|
case NSOtherMouseDragged:
|
||||||
|
return 3;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// classes for window & events
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@implementation NSWindowEvent
|
||||||
|
|
||||||
|
- (NSWindowEvent *) initWithContentRect:(NSRect)rect styleMask:(NSUInteger)winstyle backing:(NSBackingStoreType)bck defer:(BOOL) dfr
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if ((self = [super initWithContentRect:rect
|
||||||
|
styleMask:winstyle
|
||||||
|
backing:bck
|
||||||
|
defer:dfr]))
|
||||||
|
{
|
||||||
|
i = MAX_EVENT;
|
||||||
|
while (i--)
|
||||||
|
{
|
||||||
|
event_funct[i] = NULL;
|
||||||
|
event_param[i] = NULL;
|
||||||
|
}
|
||||||
|
keyrepeat = 0;
|
||||||
|
keyflag = 0;
|
||||||
|
size_x = rect.size.width;
|
||||||
|
size_y = rect.size.height;
|
||||||
|
}
|
||||||
|
return (self);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) setEvent:(int)event andFunc:(func_t)func andParam:(void *)param
|
||||||
|
{
|
||||||
|
event_funct[event] = func;
|
||||||
|
event_param[event] = param;
|
||||||
|
if (event == 6) // motion notify
|
||||||
|
{
|
||||||
|
if (func == NULL)
|
||||||
|
[self setAcceptsMouseMovedEvents:NO];
|
||||||
|
else
|
||||||
|
[self setAcceptsMouseMovedEvents:YES];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) setKeyRepeat:(int)mode
|
||||||
|
{
|
||||||
|
keyrepeat = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) acceptsFirstResponder
|
||||||
|
{
|
||||||
|
return (YES);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) flagsChanged:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
unsigned int flag;
|
||||||
|
int the_key;
|
||||||
|
unsigned int val;
|
||||||
|
|
||||||
|
flag = [theEvent modifierFlags];
|
||||||
|
// printf("Key flag changed: %x => %x\n", keyflag, flag);
|
||||||
|
// printf("**mlx flag low part : %d - %x\n", flag&0xFFFF, flag&0xFFFF);
|
||||||
|
|
||||||
|
if (!(val = (keyflag|flag)&(~(keyflag&flag))))
|
||||||
|
return ; // no change - can happen when loosing focus on special key pressed, then re-pressed later
|
||||||
|
the_key = 1;
|
||||||
|
while (((val >> (the_key-1)) & 0x01)==0)
|
||||||
|
the_key ++;
|
||||||
|
if (flag > keyflag && event_funct[2] != NULL)
|
||||||
|
event_funct[2](0xFF+the_key, event_param[2]);
|
||||||
|
if (flag < keyflag && event_funct[3] != NULL)
|
||||||
|
event_funct[3](0xFF+the_key, event_param[3]);
|
||||||
|
/*
|
||||||
|
if (event_funct[2] != NULL)
|
||||||
|
{
|
||||||
|
if (!(keyflag & NSAlphaShiftKeyMask) && (flag&NSAlphaShiftKeyMask)) event_funct[2](0xFF+1, event_param[2]);
|
||||||
|
if (!(keyflag & NSShiftKeyMask) && (flag&NSShiftKeyMask)) event_funct[2](0xFF+2, event_param[2]);
|
||||||
|
if (!(keyflag & NSControlKeyMask) && (flag&NSControlKeyMask)) event_funct[2](0xFF+3, event_param[2]);
|
||||||
|
if (!(keyflag & NSAlternateKeyMask) && (flag&NSAlternateKeyMask)) event_funct[2](0xFF+4, event_param[2]);
|
||||||
|
if (!(keyflag & NSCommandKeyMask) && (flag&NSCommandKeyMask)) event_funct[2](0xFF+5, event_param[2]);
|
||||||
|
if (!(keyflag & NSNumericPadKeyMask) && (flag&NSNumericPadKeyMask)) event_funct[2](0xFF+6, event_param[2]);
|
||||||
|
if (!(keyflag & NSHelpKeyMask) && (flag&NSHelpKeyMask)) event_funct[2](0xFF+7, event_param[2]);
|
||||||
|
if (!(keyflag & NSFunctionKeyMask) && (flag&NSFunctionKeyMask)) event_funct[2](0xFF+8, event_param[2]);
|
||||||
|
}
|
||||||
|
if (event_funct[3] != NULL)
|
||||||
|
{
|
||||||
|
if ((keyflag & NSShiftKeyMask) && !(flag&NSShiftKeyMask)) event_funct[3](NSShiftKeyMask, event_param[3]);
|
||||||
|
|
||||||
|
if ((keyflag & NSAlphaShiftKeyMask) && !(flag&NSAlphaShiftKeyMask)) event_funct[3](0xFF+1, event_param[3]);
|
||||||
|
if ((keyflag & NSShiftKeyMask) && !(flag&NSShiftKeyMask)) event_funct[3](0xFF+2, event_param[3]);
|
||||||
|
if ((keyflag & NSControlKeyMask) && !(flag&NSControlKeyMask)) event_funct[3](0xFF+3, event_param[3]);
|
||||||
|
if ((keyflag & NSAlternateKeyMask) && !(flag&NSAlternateKeyMask)) event_funct[3](0xFF+4, event_param[3]);
|
||||||
|
if ((keyflag & NSCommandKeyMask) && !(flag&NSCommandKeyMask)) event_funct[3](0xFF+5, event_param[3]);
|
||||||
|
if ((keyflag & NSNumericPadKeyMask) && !(flag&NSNumericPadKeyMask)) event_funct[3](0xFF+6, event_param[3]);
|
||||||
|
if ((keyflag & NSHelpKeyMask) && !(flag&NSHelpKeyMask)) event_funct[3](0xFF+7, event_param[3]);
|
||||||
|
if ((keyflag & NSFunctionKeyMask) && !(flag&NSFunctionKeyMask)) event_funct[3](0xFF+8, event_param[3]);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
keyflag = flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) keyDown:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
if (keyrepeat==0 && [theEvent isARepeat])
|
||||||
|
return ;
|
||||||
|
// printf("Key Down: %d\n", [theEvent keyCode]);
|
||||||
|
if (event_funct[2] != NULL)
|
||||||
|
event_funct[2]([theEvent keyCode], event_param[2]);
|
||||||
|
// else [super keyDown: theEvent];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) keyUp:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
// printf("Key Up: %d\n", [theEvent keyCode]);
|
||||||
|
if (event_funct[3] != NULL)
|
||||||
|
event_funct[3]([theEvent keyCode], event_param[3]);
|
||||||
|
// else [super keyUp: theEvent];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) mouseDown:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
NSPoint thepoint;
|
||||||
|
int button;
|
||||||
|
|
||||||
|
thepoint = [theEvent locationInWindow];
|
||||||
|
button = get_mouse_button([theEvent type]);
|
||||||
|
// printf("Mouse pressed bt %d pos: %f, %f\n", button, thepoint.x, thepoint.y);
|
||||||
|
if (event_funct[4] != NULL)
|
||||||
|
event_funct[4](button, (int)(thepoint.x), size_y - 1 - (int)(thepoint.y), event_param[4]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) rightMouseDown:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
NSPoint thepoint;
|
||||||
|
int button;
|
||||||
|
|
||||||
|
thepoint = [theEvent locationInWindow];
|
||||||
|
button = get_mouse_button([theEvent type]);
|
||||||
|
// printf("Mouse pressed bt %d pos: %f, %f\n", button, thepoint.x, thepoint.y);
|
||||||
|
if (event_funct[4] != NULL)
|
||||||
|
event_funct[4](button, (int)(thepoint.x), size_y - 1 - (int)(thepoint.y), event_param[4]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) otherMouseDown:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
NSPoint thepoint;
|
||||||
|
int button;
|
||||||
|
|
||||||
|
thepoint = [theEvent locationInWindow];
|
||||||
|
button = get_mouse_button([theEvent type]);
|
||||||
|
// printf("Mouse pressed bt %d pos: %f, %f\n", button, thepoint.x, thepoint.y);
|
||||||
|
if (event_funct[4] != NULL)
|
||||||
|
event_funct[4](button, (int)(thepoint.x), size_y - 1 - (int)(thepoint.y), event_param[4]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) mouseUp:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
NSPoint thepoint;
|
||||||
|
int button;
|
||||||
|
|
||||||
|
thepoint = [theEvent locationInWindow];
|
||||||
|
button = get_mouse_button([theEvent type]);
|
||||||
|
// printf("Mouse release bt %d pos: %f, %f\n", button, thepoint.x, thepoint.y);
|
||||||
|
if (event_funct[5] != NULL)
|
||||||
|
event_funct[5](button, (int)(thepoint.x), size_y - 1 - (int)(thepoint.y), event_param[5]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) rightMouseUp:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
NSPoint thepoint;
|
||||||
|
int button;
|
||||||
|
|
||||||
|
thepoint = [theEvent locationInWindow];
|
||||||
|
button = get_mouse_button([theEvent type]);
|
||||||
|
// printf("Mouse release bt %d pos: %f, %f\n", button, thepoint.x, thepoint.y);
|
||||||
|
if (event_funct[5] != NULL)
|
||||||
|
event_funct[5](button, (int)(thepoint.x), size_y - 1 - (int)(thepoint.y), event_param[5]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) otherMouseUp:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
NSPoint thepoint;
|
||||||
|
int button;
|
||||||
|
|
||||||
|
thepoint = [theEvent locationInWindow];
|
||||||
|
button = get_mouse_button([theEvent type]);
|
||||||
|
// printf("Mouse release bt %d pos: %f, %f\n", button, thepoint.x, thepoint.y);
|
||||||
|
if (event_funct[5] != NULL)
|
||||||
|
event_funct[5](button, (int)(thepoint.x), size_y - 1 - (int)(thepoint.y), event_param[5]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) mouseMoved:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
NSPoint thepoint;
|
||||||
|
|
||||||
|
thepoint = [theEvent locationInWindow];
|
||||||
|
// printf("Mouse moved pos: %f, %f\n", thepoint.x, thepoint.y);
|
||||||
|
if (event_funct[6] != NULL)
|
||||||
|
event_funct[6]((int)(thepoint.x), size_y - 1 - (int)(thepoint.y), event_param[6]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) mouseDragged:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
NSPoint thepoint;
|
||||||
|
|
||||||
|
thepoint = [theEvent locationInWindow];
|
||||||
|
// printf("Mouse moved pos: %f, %f\n", thepoint.x, thepoint.y);
|
||||||
|
if (event_funct[6] != NULL)
|
||||||
|
event_funct[6]((int)(thepoint.x), size_y - 1 - (int)(thepoint.y), event_param[6]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) rightMouseDragged:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
NSPoint thepoint;
|
||||||
|
|
||||||
|
thepoint = [theEvent locationInWindow];
|
||||||
|
// printf("Mouse moved pos: %f, %f\n", thepoint.x, thepoint.y);
|
||||||
|
if (event_funct[6] != NULL)
|
||||||
|
event_funct[6]((int)(thepoint.x), size_y - 1 - (int)(thepoint.y), event_param[6]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) otherMouseDragged:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
NSPoint thepoint;
|
||||||
|
|
||||||
|
thepoint = [theEvent locationInWindow];
|
||||||
|
// printf("Mouse moved pos: %f, %f\n", thepoint.x, thepoint.y);
|
||||||
|
if (event_funct[6] != NULL)
|
||||||
|
event_funct[6]((int)(thepoint.x), size_y - 1 - (int)(thepoint.y), event_param[6]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) scrollWheel:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
NSPoint thepoint;
|
||||||
|
int button;
|
||||||
|
float sens;
|
||||||
|
|
||||||
|
if (event_funct[4] == NULL)
|
||||||
|
return ;
|
||||||
|
|
||||||
|
button = 0;
|
||||||
|
thepoint = [theEvent locationInWindow];
|
||||||
|
sens = [theEvent deltaY];
|
||||||
|
if (sens > 0.2)
|
||||||
|
button = 4;
|
||||||
|
if (sens < -0.2)
|
||||||
|
button = 5;
|
||||||
|
sens = [theEvent deltaX];
|
||||||
|
if (sens > 0.2)
|
||||||
|
button = 6;
|
||||||
|
if (sens < -0.2)
|
||||||
|
button = 7;
|
||||||
|
if (button != 0)
|
||||||
|
event_funct[4](button, (int)(thepoint.x), size_y - 1 - (int)(thepoint.y), event_param[4]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) exposeNotification:(NSNotification *)note
|
||||||
|
{
|
||||||
|
// printf("Expose...\n");
|
||||||
|
if (event_funct[12] != NULL)
|
||||||
|
event_funct[12](event_param[12]);
|
||||||
|
// printf("Expose done.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) closeNotification:(NSNotification *)note
|
||||||
|
{
|
||||||
|
if (event_funct[17] != NULL)
|
||||||
|
event_funct[17](event_param[17]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) deminiaturizeNotification:(NSNotification *)note
|
||||||
|
{
|
||||||
|
// if (event_funct[??] != NULL)
|
||||||
|
// event_funct[??](event_param[??]);
|
||||||
|
[self exposeNotification:note];
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@implementation MlxWin
|
||||||
|
|
||||||
|
- (id) initWithRect: (NSRect)rect andTitle: (NSString *)title pfaAttrs: (NSOpenGLPixelFormatAttribute *)attrs
|
||||||
|
{
|
||||||
|
NSOpenGLPixelFormat* pixFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
|
||||||
|
|
||||||
|
if ((self = [super initWithFrame:rect pixelFormat:pixFmt]) != nil)
|
||||||
|
{
|
||||||
|
NSUInteger windowStyle = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask;
|
||||||
|
|
||||||
|
win = [[NSWindowEvent alloc] initWithContentRect:rect
|
||||||
|
styleMask:windowStyle
|
||||||
|
backing:NSBackingStoreBuffered // NSBackingStoreNonretained
|
||||||
|
defer:NO];
|
||||||
|
[win setContentView:self];
|
||||||
|
[win setTitle:title];
|
||||||
|
[win setKeyRepeat:1];
|
||||||
|
[win makeKeyAndOrderFront:self];
|
||||||
|
|
||||||
|
// printf("init ctx: current %p ", [NSOpenGLContext currentContext]);
|
||||||
|
|
||||||
|
// ctx = [[NSOpenGLContext alloc] initWithFormat:pixFmt shareContext:[NSOpenGLContext currentContext]]; //other_context];
|
||||||
|
// [ctx setView:self];
|
||||||
|
// [ctx makeCurrentContext];
|
||||||
|
|
||||||
|
[[self openGLContext] makeCurrentContext];
|
||||||
|
[[self openGLContext] setView:self];
|
||||||
|
[self prepareOpenGL];
|
||||||
|
|
||||||
|
[self setNextKeyView:self];
|
||||||
|
|
||||||
|
// [[NSNotificationCenter defaultCenter] addObserver:win selector:@selector(exposeNotification:) name:@"NSWindowDidExposeNotification" object:nil];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:win selector:@selector(exposeNotification:) name:@"NSWindowDidBecomeKeyNotification" object:win];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:win selector:@selector(deminiaturizeNotification:) name:@"NSWindowDidDeminiaturizeNotification" object:win];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:win selector:@selector(closeNotification:) name:@"NSWindowWillCloseNotification" object:win];
|
||||||
|
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ctxNeedsUpdate:)
|
||||||
|
// name:NSViewGlobalFrameDidChangeNotification
|
||||||
|
// object:nil];
|
||||||
|
|
||||||
|
size_x = rect.size.width;
|
||||||
|
size_y = rect.size.height;
|
||||||
|
|
||||||
|
glClearColor(0, 0, 0, 0);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
glFlush();
|
||||||
|
|
||||||
|
//[win makeKeyAndOrderFront:nil];
|
||||||
|
// BOOL r = [win isKeyWindow];
|
||||||
|
// if (r==YES) printf("keywindow ok\n"); else printf("keywindow KO\n");
|
||||||
|
|
||||||
|
// Window controller subclass to set title
|
||||||
|
// NSWindowController* windowController = [[NSWindowController alloc] initWithWindow:win];
|
||||||
|
// [windowController windowTitleForDocumentDisplayName:title];
|
||||||
|
// [windowController showWindow:nil];
|
||||||
|
// MlxWinController *mlxWinCont = [[MlxWinController alloc] initWin:win andTitle:title];
|
||||||
|
|
||||||
|
// after nswindowcontroller who will retake first responder
|
||||||
|
// BOOL r = [win makeFirstResponder:nil];
|
||||||
|
// if (r==YES) printf("responder ok\n"); else printf("responder KO\n");
|
||||||
|
|
||||||
|
[pixFmt release];
|
||||||
|
}
|
||||||
|
return (self);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (int) pixel_management
|
||||||
|
{
|
||||||
|
bzero(&glsl, sizeof(glsl)); // so gldelete[shader/program] go silent on error.
|
||||||
|
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
glGenBuffers(1, &pixel_vbuffer);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, pixel_vbuffer);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(pixel_vertexes), pixel_vertexes, GL_DYNAMIC_DRAW); // 4 points buff
|
||||||
|
// pixel_ptr = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||||
|
|
||||||
|
glGenTextures(1, &pixel_texture);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, pixel_texture);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
pixtexbuff = malloc(sizeof(unsigned int)*size_x*size_y);
|
||||||
|
pixel_nb = size_x*size_y;
|
||||||
|
while (pixel_nb--) pixtexbuff[pixel_nb] = 0xFF000000;
|
||||||
|
pixel_nb = 0;
|
||||||
|
glTexImage2D(
|
||||||
|
GL_TEXTURE_2D, 0, /* target, level of detail */
|
||||||
|
GL_RGBA8, /* internal format */
|
||||||
|
size_x, size_y, 0, /* width, height, border */
|
||||||
|
GL_BGRA, GL_UNSIGNED_BYTE, /* external format, type */
|
||||||
|
pixtexbuff /* pixels */
|
||||||
|
);
|
||||||
|
// printf("pix tex err? 0x%x\n", glGetError());
|
||||||
|
|
||||||
|
if (mlx_shaders(&glsl))
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
glUseProgram(glsl.pixel_program);
|
||||||
|
glsl.loc_pixel_texture = glGetUniformLocation(glsl.pixel_program, "texture");
|
||||||
|
//glsl.loc_pixel_winhalfsize = glGetUniformLocation(glsl.pixel_program, "winhalfsize");
|
||||||
|
glsl.loc_pixel_position = glGetAttribLocation(glsl.pixel_program, "position");
|
||||||
|
// printf("err? 0x%x\n", glGetError());
|
||||||
|
|
||||||
|
glUseProgram(glsl.image_program);
|
||||||
|
glsl.loc_image_texture = glGetUniformLocation(glsl.image_program, "texture");
|
||||||
|
glsl.loc_image_pos = glGetUniformLocation(glsl.image_program, "imagepos");
|
||||||
|
glsl.loc_image_size = glGetUniformLocation(glsl.image_program, "imagesize");
|
||||||
|
glsl.loc_image_winhalfsize = glGetUniformLocation(glsl.image_program, "winhalfsize");
|
||||||
|
glsl.loc_image_position = glGetAttribLocation(glsl.image_program, "position");
|
||||||
|
// printf("err? 0x%x\n", glGetError());
|
||||||
|
|
||||||
|
glUseProgram(glsl.font_program);
|
||||||
|
glsl.loc_font_texture = glGetUniformLocation(glsl.font_program, "texture");
|
||||||
|
glsl.loc_font_color = glGetUniformLocation(glsl.font_program, "color");
|
||||||
|
glsl.loc_font_posinwin = glGetUniformLocation(glsl.font_program, "fontposinwin");
|
||||||
|
glsl.loc_font_posinatlas = glGetUniformLocation(glsl.font_program, "fontposinatlas");
|
||||||
|
glsl.loc_font_atlassize = glGetUniformLocation(glsl.font_program, "fontatlassize");
|
||||||
|
glsl.loc_font_winhalfsize = glGetUniformLocation(glsl.font_program, "winhalfsize");
|
||||||
|
glsl.loc_font_position = glGetAttribLocation(glsl.font_program, "position");
|
||||||
|
// printf("err? 0x%x\n", glGetError());
|
||||||
|
|
||||||
|
glFlush();
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) ctxNeedsUpdate
|
||||||
|
{
|
||||||
|
// printf("Context update\n");
|
||||||
|
[ctx update];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) selectGLContext
|
||||||
|
{
|
||||||
|
if ([NSOpenGLContext currentContext] != [self openGLContext])
|
||||||
|
{
|
||||||
|
// printf("ctx: %p => %p\n", [NSOpenGLContext currentContext], [self openGLContext]);
|
||||||
|
[[self openGLContext] makeCurrentContext];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) flushGLContext
|
||||||
|
{
|
||||||
|
[[self openGLContext] flushBuffer];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSOpenGLContext *) ctx
|
||||||
|
{
|
||||||
|
return (ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) pixelPutColor: (int)color X:(int)x Y:(int)y
|
||||||
|
{
|
||||||
|
pixel_nb ++;
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_2D, pixel_vbuffer);
|
||||||
|
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, 1, 1, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid *)(&color));
|
||||||
|
|
||||||
|
if (pixel_nb >= MAX_PIXEL_NB)
|
||||||
|
[self mlx_gl_draw];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) destroyPixelManagement
|
||||||
|
{
|
||||||
|
free(pixtexbuff);
|
||||||
|
[self selectGLContext];
|
||||||
|
glDeleteBuffers(1, &pixel_vbuffer);
|
||||||
|
glDeleteTextures(1, &pixel_texture);
|
||||||
|
glDeleteProgram(glsl.pixel_program);
|
||||||
|
glDeleteProgram(glsl.image_program);
|
||||||
|
glDeleteShader(glsl.pixel_vshader);
|
||||||
|
glDeleteShader(glsl.pixel_fshader);
|
||||||
|
glDeleteShader(glsl.image_vshader);
|
||||||
|
glDeleteShader(glsl.image_fshader);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) destroyMe
|
||||||
|
{
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:win];
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||||
|
// [ctx release];
|
||||||
|
[win close];
|
||||||
|
[self release];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) setEvent:(int)event andFunc:(func_t)func andParam:(void *)param
|
||||||
|
{
|
||||||
|
[win setEvent:event andFunc:func andParam:param];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) setKeyRepeat:(int)mode
|
||||||
|
{
|
||||||
|
[win setKeyRepeat:mode];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) clearWin
|
||||||
|
{
|
||||||
|
glClearColor(0, 0, 0, 0);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) mlx_gl_draw_img:(mlx_img_list_t *)img andCtx:(mlx_img_ctx_t *)imgctx andX:(int)x andY:(int)y
|
||||||
|
{
|
||||||
|
|
||||||
|
if (pixel_nb >0)
|
||||||
|
[self mlx_gl_draw];
|
||||||
|
|
||||||
|
glUseProgram(glsl.image_program);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, imgctx->texture);
|
||||||
|
glUniform1i(glsl.loc_image_texture, 0);
|
||||||
|
|
||||||
|
glUniform2f(glsl.loc_image_winhalfsize, size_x/2, size_y/2);
|
||||||
|
glUniform2f(glsl.loc_image_pos, x, size_y - y);
|
||||||
|
glUniform2f(glsl.loc_image_size, img->width, -img->height);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, imgctx->vbuffer);
|
||||||
|
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2*sizeof(GLfloat), (void*)0);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); // src alpha 0xFF : keep dst
|
||||||
|
glBlendEquation(GL_FUNC_ADD);
|
||||||
|
|
||||||
|
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||||
|
glDisableVertexAttribArray(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) mlx_gl_draw_font:(mlx_img_list_t *)img andCtx:(mlx_img_ctx_t *)imgctx andX:(int)x andY:(int)y andColor:(int)color glyphX:(int)gx glyphY:(int)gy
|
||||||
|
{
|
||||||
|
GLfloat color_tab[4];
|
||||||
|
|
||||||
|
if (pixel_nb >0)
|
||||||
|
[self mlx_gl_draw];
|
||||||
|
|
||||||
|
color_tab[0] = ((float)((color&0xFF0000)>>16))/255.0;
|
||||||
|
color_tab[1] = ((float)((color&0xFF00)>>8))/255.0;
|
||||||
|
color_tab[2] = ((float)((color&0xFF)>>0))/255.0;
|
||||||
|
color_tab[3] = 1.0;
|
||||||
|
glUseProgram(glsl.font_program);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, imgctx->texture);
|
||||||
|
glUniform1i(glsl.loc_font_texture, 0);
|
||||||
|
glUniform4fv(glsl.loc_font_color, 1, color_tab);
|
||||||
|
|
||||||
|
glUniform2f(glsl.loc_font_winhalfsize, size_x/2, size_y/2);
|
||||||
|
glUniform2f(glsl.loc_font_posinwin, x, size_y - 1 - y);
|
||||||
|
glUniform2f(glsl.loc_font_posinatlas, gx, gy);
|
||||||
|
glUniform2f(glsl.loc_font_atlassize, img->width, img->height);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, imgctx->vbuffer);
|
||||||
|
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2*sizeof(GLfloat), (void*)0);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); // src alpha 0xFF : keep dst
|
||||||
|
glBlendEquation(GL_FUNC_ADD);
|
||||||
|
|
||||||
|
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||||
|
glDisableVertexAttribArray(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) mlx_gl_draw
|
||||||
|
{
|
||||||
|
if (pixel_nb <= 0)
|
||||||
|
return ;
|
||||||
|
|
||||||
|
glUseProgram(glsl.pixel_program);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, pixel_vbuffer);
|
||||||
|
glUniform1i(glsl.loc_pixel_texture, 0);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, pixel_vbuffer);
|
||||||
|
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2*sizeof(GLfloat), (void*)0);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); // src alpha 0xFF : keep dst
|
||||||
|
glBlendEquation(GL_FUNC_ADD);
|
||||||
|
|
||||||
|
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||||
|
glDisableVertexAttribArray(0);
|
||||||
|
|
||||||
|
pixel_nb = size_x*size_y;
|
||||||
|
while (pixel_nb--) pixtexbuff[pixel_nb] = 0xFF000000;
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, size_x, size_y, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixtexbuff);
|
||||||
|
pixel_nb = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
// mlx API
|
||||||
|
|
||||||
|
|
||||||
|
void *mlx_new_window(mlx_ptr_t *mlx_ptr, int size_x, int size_y, char *title)
|
||||||
|
{
|
||||||
|
mlx_win_list_t *newwin;
|
||||||
|
NSString *str;
|
||||||
|
|
||||||
|
if ((newwin = malloc(sizeof(*newwin))) == NULL)
|
||||||
|
return ((void *)0);
|
||||||
|
newwin->img_list = NULL;
|
||||||
|
newwin->next = mlx_ptr->win_list;
|
||||||
|
newwin->nb_flush = 0;
|
||||||
|
newwin->pixmgt = 1;
|
||||||
|
mlx_ptr->win_list = newwin;
|
||||||
|
|
||||||
|
NSRect windowRect = NSMakeRect(100, 100, size_x, size_y);
|
||||||
|
str = [NSString stringWithCString:title encoding:NSASCIIStringEncoding];
|
||||||
|
newwin->winid = [[MlxWin alloc] initWithRect:windowRect andTitle:str pfaAttrs:pfa_attrs];
|
||||||
|
if (newwin->winid)
|
||||||
|
if (![(id)(newwin->winid) pixel_management])
|
||||||
|
{
|
||||||
|
[(id)(newwin->winid) destroyPixelManagement];
|
||||||
|
[(id)(newwin->winid) destroyMe];
|
||||||
|
}
|
||||||
|
return ((void *)newwin);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void mlx_clear_window(mlx_ptr_t *mlx_ptr, mlx_win_list_t *win_ptr)
|
||||||
|
{
|
||||||
|
[(id)(win_ptr->winid) selectGLContext];
|
||||||
|
[(id)(win_ptr->winid) clearWin];
|
||||||
|
win_ptr->nb_flush ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void mlx_expose_hook(mlx_win_list_t *win_ptr, int (*funct_ptr)(), void *param)
|
||||||
|
{
|
||||||
|
[(id)(win_ptr->winid) setEvent:12 andFunc:funct_ptr andParam:param];
|
||||||
|
}
|
||||||
|
|
||||||
|
void mlx_key_hook(mlx_win_list_t *win_ptr, int (*funct_ptr)(), void *param)
|
||||||
|
{
|
||||||
|
[(id)(win_ptr->winid) setEvent:3 andFunc:funct_ptr andParam:param];
|
||||||
|
}
|
||||||
|
|
||||||
|
void mlx_mouse_hook(mlx_win_list_t *win_ptr, int (*funct_ptr)(), void *param)
|
||||||
|
{
|
||||||
|
[(id)(win_ptr->winid) setEvent:4 andFunc:funct_ptr andParam:param];
|
||||||
|
}
|
||||||
|
|
||||||
|
void mlx_hook(mlx_win_list_t *win_ptr, int x_event, int x_mask, int (*funct_ptr)(), void *param)
|
||||||
|
{
|
||||||
|
[(id)(win_ptr->winid) setEvent:x_event andFunc:funct_ptr andParam:param];
|
||||||
|
}
|
||||||
|
|
||||||
|
int mlx_do_key_autorepeatoff(mlx_ptr_t *mlx_ptr)
|
||||||
|
{
|
||||||
|
mlx_win_list_t *win;
|
||||||
|
|
||||||
|
win = mlx_ptr->win_list;
|
||||||
|
while (win)
|
||||||
|
{
|
||||||
|
[(id)(win->winid) setKeyRepeat:0];
|
||||||
|
win = win->next;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int mlx_do_key_autorepeaton(mlx_ptr_t *mlx_ptr)
|
||||||
|
{
|
||||||
|
mlx_win_list_t *win;
|
||||||
|
|
||||||
|
win = mlx_ptr->win_list;
|
||||||
|
while (win)
|
||||||
|
{
|
||||||
|
[(id)(win->winid) setKeyRepeat:1];
|
||||||
|
win = win->next;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mlx_destroy_window(mlx_ptr_t *mlx_ptr, mlx_win_list_t *win_to_del)
|
||||||
|
{
|
||||||
|
mlx_win_list_t first;
|
||||||
|
mlx_win_list_t *win;
|
||||||
|
mlx_img_ctx_t *ctx;
|
||||||
|
mlx_img_ctx_t *ctx2;
|
||||||
|
|
||||||
|
first.next = mlx_ptr->win_list;
|
||||||
|
win = &first;
|
||||||
|
while (win && win->next)
|
||||||
|
{
|
||||||
|
if (win->next == win_to_del)
|
||||||
|
win->next = win->next->next;
|
||||||
|
win = win->next;
|
||||||
|
}
|
||||||
|
mlx_ptr->win_list = first.next;
|
||||||
|
|
||||||
|
if (win_to_del->pixmgt)
|
||||||
|
{
|
||||||
|
[(id)(win_to_del->winid) selectGLContext];
|
||||||
|
ctx = win_to_del->img_list; // should be null anyway if no pixel management
|
||||||
|
while (ctx)
|
||||||
|
{
|
||||||
|
glDeleteBuffers(1, &(ctx->vbuffer));
|
||||||
|
glDeleteTextures(1, &(ctx->texture));
|
||||||
|
ctx2 = ctx;
|
||||||
|
ctx = ctx->next;
|
||||||
|
free(ctx2);
|
||||||
|
}
|
||||||
|
[(id)(win_to_del->winid) destroyPixelManagement];
|
||||||
|
}
|
||||||
|
[(id)(win_to_del->winid) destroyMe];
|
||||||
|
free(win_to_del);
|
||||||
|
|
||||||
|
// printf("destroy window done.\n");
|
||||||
|
mlx_do_sync(mlx_ptr);
|
||||||
|
return (0);
|
||||||
|
}
|
|
@ -3,7 +3,6 @@
|
||||||
** the XFree86 distribution.
|
** the XFree86 distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
struct s_col_name mlx_col_name[] =
|
struct s_col_name mlx_col_name[] =
|
||||||
{
|
{
|
236
minilibx_macos/mlx_shaders.c
Normal file
236
minilibx_macos/mlx_shaders.c
Normal file
|
@ -0,0 +1,236 @@
|
||||||
|
// mlx_shaders.c
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <OpenGL/gl3.h>
|
||||||
|
#include "mlx_int.h"
|
||||||
|
|
||||||
|
|
||||||
|
void display_log(GLuint object, void (*param_func)(), void (*getlog_func)())
|
||||||
|
{
|
||||||
|
GLint log_length;
|
||||||
|
char *log;
|
||||||
|
|
||||||
|
param_func(object, GL_INFO_LOG_LENGTH, &log_length);
|
||||||
|
log = malloc(log_length);
|
||||||
|
getlog_func(object, log_length, NULL, log);
|
||||||
|
fprintf(stderr, "%s", log);
|
||||||
|
free(log);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mlx_shaders_pixel(glsl_info_t *glsl)
|
||||||
|
{
|
||||||
|
char *source;
|
||||||
|
int length;
|
||||||
|
GLint action_ok;
|
||||||
|
|
||||||
|
glsl->pixel_vshader = glCreateShader(GL_VERTEX_SHADER);
|
||||||
|
source = strdup("#version 110 \n"
|
||||||
|
"attribute vec2 position;"
|
||||||
|
"varying vec2 texcoord;"
|
||||||
|
"void main()"
|
||||||
|
"{"
|
||||||
|
" gl_Position = vec4( position, 0.0, 1.0);"
|
||||||
|
" texcoord = vec2(position[0]+1.0, 1.0 - position[1]) / 2.0;"
|
||||||
|
"}");
|
||||||
|
length = strlen(source);
|
||||||
|
glShaderSource(glsl->pixel_vshader, 1, (const GLchar**)&source, &length);
|
||||||
|
glCompileShader(glsl->pixel_vshader);
|
||||||
|
free(source);
|
||||||
|
|
||||||
|
glGetShaderiv(glsl->pixel_vshader, GL_COMPILE_STATUS, &action_ok);
|
||||||
|
if (!action_ok) {
|
||||||
|
fprintf(stderr, "Failed to compile pixel vshader :\n");
|
||||||
|
display_log(glsl->pixel_vshader, glGetShaderiv, glGetShaderInfoLog);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
glsl->pixel_fshader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
|
source = strdup("#version 110 \n"
|
||||||
|
"uniform sampler2D texture;"
|
||||||
|
"varying vec2 texcoord;"
|
||||||
|
"void main()"
|
||||||
|
"{"
|
||||||
|
" gl_FragColor = texture2D(texture, texcoord);"
|
||||||
|
"}");
|
||||||
|
length = strlen(source);
|
||||||
|
glShaderSource(glsl->pixel_fshader, 1, (const GLchar**)&source, &length);
|
||||||
|
glCompileShader(glsl->pixel_fshader);
|
||||||
|
free(source);
|
||||||
|
|
||||||
|
glGetShaderiv(glsl->pixel_fshader, GL_COMPILE_STATUS, &action_ok);
|
||||||
|
if (!action_ok) {
|
||||||
|
fprintf(stderr, "Failed to compile pixel fshader :\n");
|
||||||
|
display_log(glsl->pixel_fshader, glGetShaderiv, glGetShaderInfoLog);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
glsl->pixel_program = glCreateProgram();
|
||||||
|
glAttachShader(glsl->pixel_program, glsl->pixel_vshader);
|
||||||
|
glAttachShader(glsl->pixel_program, glsl->pixel_fshader);
|
||||||
|
glLinkProgram(glsl->pixel_program);
|
||||||
|
|
||||||
|
glGetProgramiv(glsl->pixel_program, GL_LINK_STATUS, &action_ok);
|
||||||
|
if (!action_ok) {
|
||||||
|
fprintf(stderr, "Failed to link pixel shader program:\n");
|
||||||
|
display_log(glsl->pixel_program, glGetProgramiv, glGetProgramInfoLog);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
glFlush();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mlx_shaders_image(glsl_info_t *glsl)
|
||||||
|
{
|
||||||
|
char *source;
|
||||||
|
int length;
|
||||||
|
GLint action_ok;
|
||||||
|
|
||||||
|
glsl->image_vshader = glCreateShader(GL_VERTEX_SHADER);
|
||||||
|
source = strdup("#version 110 \n"
|
||||||
|
"attribute vec2 position;"
|
||||||
|
"uniform vec2 winhalfsize;"
|
||||||
|
"uniform vec2 imagepos;"
|
||||||
|
"uniform vec2 imagesize;"
|
||||||
|
"varying vec2 texcoord;"
|
||||||
|
"void main()"
|
||||||
|
"{"
|
||||||
|
" texcoord = position / imagesize;"
|
||||||
|
" vec2 pos = position - winhalfsize + imagepos;"
|
||||||
|
" pos = pos / winhalfsize;"
|
||||||
|
" gl_Position = vec4( pos, 0.0, 1.0);"
|
||||||
|
"}");
|
||||||
|
length = strlen(source);
|
||||||
|
glShaderSource(glsl->image_vshader, 1, (const GLchar**)&source, &length);
|
||||||
|
glCompileShader(glsl->image_vshader);
|
||||||
|
free(source);
|
||||||
|
|
||||||
|
glGetShaderiv(glsl->image_vshader, GL_COMPILE_STATUS, &action_ok);
|
||||||
|
if (!action_ok) {
|
||||||
|
fprintf(stderr, "Failed to compile image vshader :\n");
|
||||||
|
display_log(glsl->image_vshader, glGetShaderiv, glGetShaderInfoLog);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
glsl->image_fshader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
|
source = strdup("#version 110 \n"
|
||||||
|
"uniform sampler2D texture;"
|
||||||
|
"varying vec2 texcoord;"
|
||||||
|
"void main()"
|
||||||
|
"{"
|
||||||
|
" gl_FragColor = texture2D(texture, texcoord);"
|
||||||
|
"}");
|
||||||
|
length = strlen(source);
|
||||||
|
glShaderSource(glsl->image_fshader, 1, (const GLchar**)&source, &length);
|
||||||
|
glCompileShader(glsl->image_fshader);
|
||||||
|
free(source);
|
||||||
|
|
||||||
|
glGetShaderiv(glsl->image_fshader, GL_COMPILE_STATUS, &action_ok);
|
||||||
|
if (!action_ok) {
|
||||||
|
fprintf(stderr, "Failed to compile image fshader :\n");
|
||||||
|
display_log(glsl->image_fshader, glGetShaderiv, glGetShaderInfoLog);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
glsl->image_program = glCreateProgram();
|
||||||
|
glAttachShader(glsl->image_program, glsl->image_vshader);
|
||||||
|
glAttachShader(glsl->image_program, glsl->image_fshader);
|
||||||
|
glLinkProgram(glsl->image_program);
|
||||||
|
|
||||||
|
glGetProgramiv(glsl->image_program, GL_LINK_STATUS, &action_ok);
|
||||||
|
if (!action_ok) {
|
||||||
|
fprintf(stderr, "Failed to link image shader program:\n");
|
||||||
|
display_log(glsl->image_program, glGetProgramiv, glGetProgramInfoLog);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
glFlush();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int mlx_shaders_font(glsl_info_t *glsl)
|
||||||
|
{
|
||||||
|
char *source;
|
||||||
|
int length;
|
||||||
|
GLint action_ok;
|
||||||
|
|
||||||
|
glsl->font_vshader = glCreateShader(GL_VERTEX_SHADER);
|
||||||
|
source = strdup("#version 110 \n"
|
||||||
|
"attribute vec2 position;"
|
||||||
|
"uniform vec2 winhalfsize;"
|
||||||
|
"uniform vec2 fontposinwin;"
|
||||||
|
"uniform vec2 fontposinatlas;"
|
||||||
|
"uniform vec2 fontatlassize;"
|
||||||
|
"varying vec2 texcoord;"
|
||||||
|
"void main()"
|
||||||
|
"{"
|
||||||
|
" texcoord = (position * vec2(1.0, -1.0) + fontposinatlas ) / fontatlassize;"
|
||||||
|
" vec2 pos = position - winhalfsize + fontposinwin;"
|
||||||
|
" pos = pos / winhalfsize;"
|
||||||
|
" gl_Position = vec4( pos, 0.0, 1.0);"
|
||||||
|
"}");
|
||||||
|
length = strlen(source);
|
||||||
|
glShaderSource(glsl->font_vshader, 1, (const GLchar**)&source, &length);
|
||||||
|
glCompileShader(glsl->font_vshader);
|
||||||
|
free(source);
|
||||||
|
|
||||||
|
glGetShaderiv(glsl->font_vshader, GL_COMPILE_STATUS, &action_ok);
|
||||||
|
if (!action_ok) {
|
||||||
|
fprintf(stderr, "Failed to compile font vshader :\n");
|
||||||
|
display_log(glsl->font_vshader, glGetShaderiv, glGetShaderInfoLog);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
glsl->font_fshader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
|
source = strdup("#version 110 \n"
|
||||||
|
"uniform sampler2D texture;"
|
||||||
|
"uniform vec4 color;"
|
||||||
|
"varying vec2 texcoord;"
|
||||||
|
"void main()"
|
||||||
|
"{"
|
||||||
|
" gl_FragColor = color * texture2D(texture, texcoord);"
|
||||||
|
"}");
|
||||||
|
length = strlen(source);
|
||||||
|
glShaderSource(glsl->font_fshader, 1, (const GLchar**)&source, &length);
|
||||||
|
glCompileShader(glsl->font_fshader);
|
||||||
|
free(source);
|
||||||
|
|
||||||
|
glGetShaderiv(glsl->font_fshader, GL_COMPILE_STATUS, &action_ok);
|
||||||
|
if (!action_ok) {
|
||||||
|
fprintf(stderr, "Failed to compile font fshader :\n");
|
||||||
|
display_log(glsl->font_fshader, glGetShaderiv, glGetShaderInfoLog);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
glsl->font_program = glCreateProgram();
|
||||||
|
glAttachShader(glsl->font_program, glsl->font_vshader);
|
||||||
|
glAttachShader(glsl->font_program, glsl->font_fshader);
|
||||||
|
glLinkProgram(glsl->font_program);
|
||||||
|
|
||||||
|
glGetProgramiv(glsl->font_program, GL_LINK_STATUS, &action_ok);
|
||||||
|
if (!action_ok) {
|
||||||
|
fprintf(stderr, "Failed to link font shader program:\n");
|
||||||
|
display_log(glsl->font_program, glGetProgramiv, glGetProgramInfoLog);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
glFlush();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int mlx_shaders(glsl_info_t *glsl)
|
||||||
|
{
|
||||||
|
return (mlx_shaders_pixel(glsl) + mlx_shaders_image(glsl) + mlx_shaders_font(glsl));
|
||||||
|
}
|
|
@ -1,24 +1,36 @@
|
||||||
/*
|
// mlx xpm
|
||||||
** xpm-read.c for MinilibX in
|
// by ol
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Tue Dec 11 15:25:27 2001 olivier crouzet
|
|
||||||
** Last update Sat Oct 1 14:56:13 2005 Olivier Crouzet
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <OpenGL/gl3.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <string.h>
|
||||||
#include "mlx_int.h"
|
#include "mlx_int.h"
|
||||||
|
|
||||||
extern struct s_col_name mlx_col_name[];
|
typedef struct s_xpm_col
|
||||||
|
{
|
||||||
|
int name;
|
||||||
|
int col;
|
||||||
|
} t_xpm_col;
|
||||||
|
|
||||||
|
|
||||||
|
struct s_col_name
|
||||||
|
{
|
||||||
|
char *name;
|
||||||
|
int color;
|
||||||
|
};
|
||||||
|
|
||||||
|
//extern struct s_col_name mlx_col_name[];
|
||||||
|
#include "mlx_rgb.c"
|
||||||
|
|
||||||
|
|
||||||
#define RETURN { if (colors) free(colors); if (tab) free(tab); \
|
#define RETURN { if (colors) free(colors); if (tab) free(tab); \
|
||||||
if (colors_direct) free(colors_direct); \
|
if (colors_direct) free(colors_direct); \
|
||||||
if (img) {XDestroyImage(img->image); \
|
if (img) mlx_destroy_image(xvar, img); \
|
||||||
XFreePixmap(xvar->display,img->pix);free(img);} \
|
return ((void *)0); }
|
||||||
return ((void *)0);}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,7 +71,7 @@ char *mlx_int_static_line(char **xpm_data,int *pos,int size)
|
||||||
len = len2;
|
len = len2;
|
||||||
}
|
}
|
||||||
/* strcpy(copy,str); */
|
/* strcpy(copy,str); */
|
||||||
strncpy(copy, str, len2+1);
|
strlcpy(copy, str, len2+1);
|
||||||
return (copy);
|
return (copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,8 +109,9 @@ int mlx_int_get_text_rgb(char *name, char *end)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_xpm_set_pixel(t_img *img, char *data, int opp, int col, int x)
|
void mlx_int_xpm_set_pixel(mlx_img_list_t *img, char *data, int opp, int col, int x)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
int dec;
|
int dec;
|
||||||
|
|
||||||
dec = opp;
|
dec = opp;
|
||||||
|
@ -110,10 +123,13 @@ int mlx_int_xpm_set_pixel(t_img *img, char *data, int opp, int col, int x)
|
||||||
*(data+x*opp+opp-dec-1) = col&0xFF;
|
*(data+x*opp+opp-dec-1) = col&0xFF;
|
||||||
col >>= 8;
|
col >>= 8;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
// opp is 4, do it the simple way
|
||||||
|
*((unsigned int *)(data+4*x)) = col;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void *mlx_int_parse_xpm(t_xvar *xvar,void *info,int info_size,char *(*f)())
|
void *mlx_int_parse_xpm(mlx_ptr_t *xvar,void *info,int info_size,char *(*f)())
|
||||||
{
|
{
|
||||||
int pos;
|
int pos;
|
||||||
char *line;
|
char *line;
|
||||||
|
@ -130,14 +146,11 @@ void *mlx_int_parse_xpm(t_xvar *xvar,void *info,int info_size,char *(*f)())
|
||||||
int x;
|
int x;
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
t_img *img;
|
mlx_img_list_t *img;
|
||||||
t_xpm_col *colors;
|
t_xpm_col *colors;
|
||||||
int *colors_direct;
|
int *colors_direct;
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
XImage *clip_img;
|
|
||||||
XGCValues xgcv;
|
|
||||||
Pixmap clip_pix;
|
|
||||||
|
|
||||||
colors = 0;
|
colors = 0;
|
||||||
colors_direct = 0;
|
colors_direct = 0;
|
||||||
|
@ -176,35 +189,39 @@ void *mlx_int_parse_xpm(t_xvar *xvar,void *info,int info_size,char *(*f)())
|
||||||
|
|
||||||
if (!tab[j])
|
if (!tab[j])
|
||||||
RETURN;
|
RETURN;
|
||||||
|
|
||||||
|
rgb_col = mlx_int_get_text_rgb(tab[j], tab[j+1]);
|
||||||
|
/*
|
||||||
if ((rgb_col = mlx_int_get_text_rgb(tab[j], tab[j+1]))==-1)
|
if ((rgb_col = mlx_int_get_text_rgb(tab[j], tab[j+1]))==-1)
|
||||||
{
|
{
|
||||||
if (!(clip_data = malloc(4*width*height)) || /* ok, nice size .. */
|
if (!(clip_data = malloc(4*width*height)) || // ok, nice size ..
|
||||||
!(clip_img = XCreateImage(xvar->display, xvar->visual,
|
!(clip_img = XCreateImage(xvar->display, xvar->visual,
|
||||||
1, XYPixmap, 0, clip_data,
|
1, XYPixmap, 0, clip_data,
|
||||||
width, height, 8, (width+7)/8)) )
|
width, height, 8, (width+7)/8)) )
|
||||||
RETURN;
|
RETURN;
|
||||||
memset(clip_data, 0xFF, 4*width*height);
|
memset(clip_data, 0xFF, 4*width*height);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
if (method)
|
if (method)
|
||||||
colors_direct[mlx_int_get_col_name(line,cpp)] =
|
colors_direct[mlx_int_get_col_name(line,cpp)] = rgb_col;
|
||||||
rgb_col>=0?mlx_get_color_value(xvar, rgb_col):rgb_col;
|
// rgb_col>=0?mlx_get_color_value(xvar, rgb_col):rgb_col;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
colors[i].name = mlx_int_get_col_name(line,cpp);
|
colors[i].name = mlx_int_get_col_name(line,cpp);
|
||||||
colors[i].col = rgb_col>=0?mlx_get_color_value(xvar,rgb_col):rgb_col;
|
colors[i].col = rgb_col; // rgb_col>=0?mlx_get_color_value(xvar,rgb_col):rgb_col;
|
||||||
}
|
}
|
||||||
free(tab);
|
free(tab);
|
||||||
|
tab = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(img = mlx_new_image(xvar,width,height)))
|
if (!(img = mlx_new_image(xvar,width,height)))
|
||||||
RETURN;
|
RETURN;
|
||||||
opp = img->bpp/8;
|
//opp = img->bpp/8;
|
||||||
|
opp = 4;
|
||||||
|
|
||||||
|
|
||||||
i = height;
|
i = height;
|
||||||
data = img->data;
|
data = img->buffer;
|
||||||
while (i--)
|
while (i--)
|
||||||
{
|
{
|
||||||
if (!(line = f(info,&pos,info_size)))
|
if (!(line = f(info,&pos,info_size)))
|
||||||
|
@ -226,14 +243,18 @@ void *mlx_int_parse_xpm(t_xvar *xvar,void *info,int info_size,char *(*f)())
|
||||||
j = 0;
|
j = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// if (col==-1)
|
||||||
|
// XPutPixel(clip_img, x, height-1-i, 0);
|
||||||
|
// else
|
||||||
if (col==-1)
|
if (col==-1)
|
||||||
XPutPixel(clip_img, x, height-1-i, 0);
|
col = 0xFF000000;
|
||||||
else
|
mlx_int_xpm_set_pixel(img, data, opp, col, x);
|
||||||
mlx_int_xpm_set_pixel(img, data, opp, col, x);
|
|
||||||
x ++;
|
x ++;
|
||||||
}
|
}
|
||||||
data += img->size_line;
|
// data += img->size_line;
|
||||||
|
data += img->width*4;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
if (clip_data)
|
if (clip_data)
|
||||||
{
|
{
|
||||||
if (!(clip_pix = XCreatePixmap(xvar->display, xvar->root,
|
if (!(clip_pix = XCreatePixmap(xvar->display, xvar->root,
|
||||||
|
@ -251,6 +272,7 @@ void *mlx_int_parse_xpm(t_xvar *xvar,void *info,int info_size,char *(*f)())
|
||||||
XSync(xvar->display, False);
|
XSync(xvar->display, False);
|
||||||
XDestroyImage(clip_img);
|
XDestroyImage(clip_img);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
if (colors)
|
if (colors)
|
||||||
free(colors);
|
free(colors);
|
||||||
if (colors_direct)
|
if (colors_direct)
|
||||||
|
@ -259,7 +281,7 @@ void *mlx_int_parse_xpm(t_xvar *xvar,void *info,int info_size,char *(*f)())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_file_get_rid_comment(char *ptr, int size)
|
void mlx_int_file_get_rid_comment(char *ptr, int size)
|
||||||
{
|
{
|
||||||
int com_begin;
|
int com_begin;
|
||||||
int com_end;
|
int com_end;
|
||||||
|
@ -277,14 +299,13 @@ int mlx_int_file_get_rid_comment(char *ptr, int size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void *mlx_xpm_file_to_image(t_xvar *xvar,char *file,int *width,int *height)
|
void *mlx_xpm_file_to_image(mlx_ptr_t *xvar,char *file,int *width,int *height)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int size;
|
int size;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
t_img *img;
|
mlx_img_list_t *img;
|
||||||
|
|
||||||
fd = -1;
|
|
||||||
if ((fd = open(file,O_RDONLY))==-1 || (size = lseek(fd,0,SEEK_END))==-1 ||
|
if ((fd = open(file,O_RDONLY))==-1 || (size = lseek(fd,0,SEEK_END))==-1 ||
|
||||||
(ptr = mmap(0,size,PROT_WRITE|PROT_READ,MAP_PRIVATE,fd,0))==
|
(ptr = mmap(0,size,PROT_WRITE|PROT_READ,MAP_PRIVATE,fd,0))==
|
||||||
(void *)MAP_FAILED)
|
(void *)MAP_FAILED)
|
||||||
|
@ -294,7 +315,7 @@ void *mlx_xpm_file_to_image(t_xvar *xvar,char *file,int *width,int *height)
|
||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
}
|
}
|
||||||
mlx_int_file_get_rid_comment(ptr, size);
|
mlx_int_file_get_rid_comment(ptr, size);
|
||||||
if (img = mlx_int_parse_xpm(xvar,ptr,size,mlx_int_get_line))
|
if ((img = mlx_int_parse_xpm(xvar,ptr,size,mlx_int_get_line)))
|
||||||
{
|
{
|
||||||
*width = img->width;
|
*width = img->width;
|
||||||
*height = img->height;
|
*height = img->height;
|
||||||
|
@ -304,11 +325,11 @@ void *mlx_xpm_file_to_image(t_xvar *xvar,char *file,int *width,int *height)
|
||||||
return (img);
|
return (img);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *mlx_xpm_to_image(t_xvar *xvar,char **xpm_data,int *width,int *height)
|
void *mlx_xpm_to_image(mlx_ptr_t *xvar,char **xpm_data,int *width,int *height)
|
||||||
{
|
{
|
||||||
t_img *img;
|
mlx_img_list_t *img;
|
||||||
|
|
||||||
if (img = mlx_int_parse_xpm(xvar,xpm_data,0,mlx_int_static_line))
|
if ((img = mlx_int_parse_xpm(xvar,xpm_data,0,mlx_int_static_line)))
|
||||||
{
|
{
|
||||||
*width = img->width;
|
*width = img->width;
|
||||||
*height = img->height;
|
*height = img->height;
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/16 18:59:03 by gtertysh #+# #+# */
|
/* Created: 2017/03/16 18:59:03 by gtertysh #+# #+# */
|
||||||
/* Updated: 2017/03/16 18:59:06 by gtertysh ### ########.fr */
|
/* Updated: 2017/03/20 15:29:10 by gtertysh ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
int key_hook(int keycode, void *fdf)
|
int key_hook(int keycode, void *fdf)
|
||||||
{
|
{
|
||||||
ft_putnbr(keycode);
|
ft_putnbr(keycode);
|
||||||
if (keycode == 65307)
|
if (keycode == 53)
|
||||||
quit(fdf);
|
quit(fdf);
|
||||||
// if (keycode == 89)
|
// if (keycode == 89)
|
||||||
// aclock_rot(fdf);
|
// aclock_rot(fdf);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/16 18:58:41 by gtertysh #+# #+# */
|
/* Created: 2017/03/16 18:58:41 by gtertysh #+# #+# */
|
||||||
/* Updated: 2017/03/16 18:58:44 by gtertysh ### ########.fr */
|
/* Updated: 2017/03/20 15:33:20 by gtertysh ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ void recursive_circles(t_pnt pnt, float radius, t_fractol *fr)
|
||||||
int tmp;
|
int tmp;
|
||||||
drawcircle(pnt, radius, fr);
|
drawcircle(pnt, radius, fr);
|
||||||
pnt.color = color_lerp(pnt.color, color_lerp(pnt.color, color_init(0, 97, 255), 0.4), 0.3);
|
pnt.color = color_lerp(pnt.color, color_lerp(pnt.color, color_init(0, 97, 255), 0.4), 0.3);
|
||||||
if (radius > 2)
|
if (radius > 3)
|
||||||
{
|
{
|
||||||
tmp = pnt.x;
|
tmp = pnt.x;
|
||||||
pnt.x = tmp + (int)radius / 2;
|
pnt.x = tmp + (int)radius / 2;
|
||||||
|
@ -70,8 +70,8 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
fr = NULL;
|
fr = NULL;
|
||||||
argc = argc;
|
argc = 0;
|
||||||
argv = argv;
|
argv = 0;
|
||||||
fr = fractol_init();
|
fr = fractol_init();
|
||||||
// while (pnt.y < fr->w_height)
|
// while (pnt.y < fr->w_height)
|
||||||
// {
|
// {
|
||||||
|
|
Loading…
Add table
Reference in a new issue